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 20:15:37 +0000

> I tried it, and can't reproduce what you describe.  How did you try it
(recipe)?

You are right. I am not able to recreate that. I was actually getting
confused because of this:

(defun modi/advice-region-or-whole (&rest args)
  "Advice function that applies the ORIG-FN function to the whole buffer if
a region is not selected."
  (interactive (if (use-region-p) ; when region is selected
                   (list (region-beginning) (region-end))
                 (list (point-min) (point-max))))
  (message "Args: %S use-region-p: %S" args (use-region-p))
  (when (not (use-region-p))
    (message "Executing %s on the whole buffer."
             (propertize (symbol-name this-command)
                         'face
                         'font-lock-function-name-face)))
  nil)

Of course when I did C-M-x, (use-region-p) was nil and so it printed:
"Executing eval-defun on the whole buffer."

Things became clear after I added this debug statement:

 (message "Args: %S use-region-p: %S" args (use-region-p))

In any case, I will be going the right way of advising this as Stefan and
you advised. Now I only need to figure out how not to print that message
when doing eval-defun.


> The around advice function should return the value you want the advised 
> function
to return.

Thank you! So with a let-bound variable 'ret', I can have something like

(setq ret (apply orig-fn args))

and return 'ret' at the end of the :around advice function definition.
Right?


reply via email to

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