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: Emanuel Berg
Subject: Re: Help setting nadvice for indent-region
Date: Mon, 08 Feb 2016 01:03:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

John Mastro <john.b.mastro@gmail.com> writes:

> 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.

Macros and advices are absolutely at the next level
compared to stapling defuns as another bricklayer, but
just because it is more advanced doesn't make it
better - it depends.

> (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))

OK, if this is "simpler", I'd say my DWIM groyne is
simpler still:

    (defun indent-region-dwim ()
      (interactive)
      (if mark-active
          (indent-region (mark) (point))
        (indent-region (point-min) (point-max) )))

It it also more natural and "human-ish" to read
without all the computer lingo (`funcall' etc.).

Anyway, another interesting difference, where I'm not
sure what is the best way, is

    `mark-active', then (mark) and (point)

vs.

    (use-region-p), then (region-beginning) and (region-help)

What does "the book" say on this?

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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