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

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

Re: A way for interactive to modify a let-bound variable?


From: Michael Heerdegen
Subject: Re: A way for interactive to modify a let-bound variable?
Date: Fri, 12 Feb 2016 19:38:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.90 (gnu/linux)

Kaushal Modi <kaushal.modi@gmail.com> writes:

> This is an :around advice function and it needs to return the (apply
> orig-fun args) value.

FWIW, for the side effect you want, a :before advice is still
sufficient.

>
> > You can of course use `let' _inside_ `interactive'
>
> If I move the let form inside interactive, the let form needs to
> return the list required for interactive. Then how would I return the
> (apply ..)  value?

Well, `let' returns the result of the evaluation of the last form, so
you have to arrange that this last form is your (apply ...), or evals to
the result of it.

> Eventually I want something like below that actually works:
>
> (defun modi/advice-region-or-whole (orig-fun &rest args)
>   (let (msg)
>     (interactive (if (use-region-p)
>                      (list (region-beginning) (region-end))
>                    (setq msg (format "Executed %s on the whole buffer."
>                                      (propertize (symbol-name this-command)
>                                                  'face
> 'font-lock-function-name-face)))
>                    (list (point-min) (point-max))))
>     (prog1
>         (apply orig-fun args)
>       (when msg
>         (message msg)))))

It may work, but that doesn't define an interactive spec for your
function, so again you change the function you want to advice, which you
wanted to avoid.


Michael.




reply via email to

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