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: John Mastro
Subject: Re: Help setting nadvice for indent-region
Date: Sun, 7 Feb 2016 10:51:29 -0800

Kaushal Modi <kaushal.modi@gmail.com> wrote:
> For the sake of completeness, this is how I actually needed to implement
> this advice in my config:
> https://github.com/kaushalmodi/.emacs.d/blob/1f9daf3587863de8561fc34e0bafda80be389dbf/setup-files/setup-editing.el#L686-L731
>
> I am open to comments and criticism.
>
> Thanks!

My preference is for something a bit simpler, which avoids the use of
macros. Macros can be awesome, but IMO they don't contribute much here.

The downside to my solution is that it doesn't print the "Executed... on
the whole buffer" message, since the advice function never sees the
symbol that names the adviced function. It has access to ‘orig’, of
course, but that may be something that wouldn't print well (e.g. a
compiled Lisp function). However, I don't see that as critical.

(defvar modi/region-or-whole-fns '(indent-region eval-region))

(defun modi/region-or-whole-advice (orig &rest _)
  (interactive)
  (if (use-region-p)
      (funcall orig (region-beginning) (region-end))
    (funcall orig (point-min) (point-max))))

(dolist (fn modi/region-or-whole-fns)
  (advice-add fn :around #'modi/region-or-whole-advice))

-- 
john



reply via email to

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