help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strangeness with let


From: Pascal J. Bourguignon
Subject: Re: strangeness with let
Date: Wed, 28 Mar 2012 19:19:52 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

jpkotta <jpkotta@gmail.com> writes:

> I want to have an easy way to do rgrep with context lines.  C-u M-x
> rgrep to manually edit the command doesn't count as easy.  So I tried
> this:
>
> (defun rgrep-context (arg)
>   (interactive "p")
>   (setq arg (or arg grep-context-lines))
>   (let ((c (number-to-string arg))
>         grep-find-template
>         current-prefix-arg)
>     (grep-apply-setting 'grep-find-template
>                         (concat "find . <X> -type f <F> -print0 |
> xargs -0 -e grep <C> -nH -C " c " -e <R>"))
>     (call-interactively 'rgrep)))
>
> It works, but then grep-find-template still has the "-C <number>" in
> it and I get context lines when I run plain rgrep.

grep-apply-setting calls (set-default symbol value), this doesn't set
the value of the symbol, but the default value.   Notably, when the
symbol is a buffer local variable, it has no effect on it.


>  Then I try this in
> a scratch buffer:
>
> (progn
>   (let (grep-find-template)
>     (grep-apply-setting 'grep-find-template "true")
>     (call-interactively 'rgrep))
>   (sleep-for 1)
>   (message "grep-find-template: '%s'" grep-find-template))
>
> and it doesn't print "true", IOW the let is doing what it should here,
> but not in rgrep-context.  What am I doing wrong?  Is there a simpler
> way to achieve my ultimate goal?

Yes.  Just bind the variable with let.

(let ((grep-find-template "true"))
  (call-interactively 'rgrep)
  (sleep-for 1)
  (message "grep-find-template: '%s'" grep-find-template))

-*- mode: grep; default-directory: "/tmp/emacs1000/" -*-
Grep started at Wed Jul 27 00:12:52

true

Grep finished (matches found) at Wed Jul 27 00:12:52


--> "grep-find-template: 'true'"

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]