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

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

Re: Help setting nadvice for indent-region


From: Kaushal Modi
Subject: Re: Help setting nadvice for indent-region
Date: Thu, 11 Feb 2016 18:47:00 +0000

On Thu, Feb 11, 2016 at 1:10 PM Michael Heerdegen <michael_heerdegen@web.de>
wrote:

>
> > I have just one concern.. that this will not work for advising
> > functions like eval-defun.
>
> What exactly did you try to do? - `eval-defun' has only one argument
> that is not related to the region, so the advises that were discussed
> yet are not applicable here.  In what way do you want to change the
> behavior of `eval-defun'?
>
>
Sorry, let me rephrase that. I meant to say that using Stefan's suggested
method to advise eval-region also affected eval-defun.  Without a region
selected, if I did C-M-x with the point in a defun, this advice begin
applied to eval-region would cause the whole buffer to be evaluated (not
just that defun as I would expect C-M-x to do). That would adversely affect
instrumenting edebug too (C-u C-M-x).


> But in general, what Stefan pointed out was important: changing the
> semantics of the functions is not a good idea.
>
> I agree but I did not find an alternative solution by which,
- I apply the advice to eval-region when called interactively.
- But not when it is called by a wrapper fn like eval-defun that presets
the args for eval-region.
I am open to adopt a cleaner, canonical solution.

>
> Be careful: this changes the return value of the advised function to the
> value returned by `when' -- this is not `defadvice'!
>
> Point taken, I will fix that.


> And BTW, (just a hint) you also don't need to `setq' the ARGS variable
> (of course you can), just do
>
>   (apply orig-fun (calculate-new-args-somehow-here-using-the args))
>
> Agreed. As I need to set the let-bound variable msg's value too, based on
(region-active-p), I decided to have just one (if ..) form and modify args
and msg in there as appropriate.

I really appreciate this feedback.


reply via email to

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