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: Michael Heerdegen
Subject: Re: Help setting nadvice for indent-region
Date: Fri, 12 Feb 2016 15:09:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.90 (gnu/linux)

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

> OK, so this is what I have now.
>
> (defun modi/advice-region-or-whole (&rest args)
>   "Advice function that sets the region boundaries to that of the whole
> buffer
> if no region is selected."
>   (interactive (if (use-region-p)
>                    (list (region-beginning) (region-end))
>                  (list (point-min) (point-max))))
>   ;; (message "Args: %S R: %S I: %S"
>   ;;          args (use-region-p) (called-interactively-p 'interactive))
>   (when (and (eq (first args) (point-min))
>              (eq (second args) (point-max)))
>     (message "Executing %s on the whole buffer."
>              (propertize (symbol-name this-command)
>                          'face 'font-lock-function-name-face)))
>   nil)

Two more comments:

1.  If you want to show the name of the adviced function instead of the
current command: you know it when you install the advice (in your
dolist) - use it when defining the advice.  Then you can't use the same
constantpiece of advice for all functions, of course.

But if it's only for debugging, you don't need this anymore, I think.
If you need to debug, I recommend to use trace.el instead:

   M-x trace-function your-adviced-function-here

this will show you which arguments the function received (from the
interactive call, or when it had been called from Lisp, the arguments it
received from there).


2.  The nil return value is insignificant.  Stefan used it only to avoid
an empty function body in his advice.  Actually, as you see from the
semantics:

‘:before’       (lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))

the return value of calling the advice FUNCTION is not used.


Regards,

Michael.




reply via email to

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