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: Mon, 8 Feb 2016 12:03:12 -0800

Emanuel Berg <embe8573@student.uu.se> wrote:
> 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) )))

I don't have strong feelings about this one way or the other, but the
points I would make in defense of advice are:
  - It's "just" function composition, nothing scary
  - Your solution requires you to define a new `dwim' function every
    time you want overload a function like this, whereas with advice you
    can simply add it to the list of functions to be adviced (assuming
    it will be adviced in the same way).

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

Avoid funcall because it has a fun-y (haha) name? This part I can't get
behind at all.

-- 
john



reply via email to

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