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: Mon, 08 Feb 2016 04:22:55 +0000

On Sun, Feb 7, 2016 at 7:03 PM Emanuel Berg <embe8573@student.uu.se> wrote:

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


That's a good question. At times, I use mark-active and at times,
(use-region-p). In this particular case, I used mark-active because (mark)
being nil was what bit me in my first version of advising indent-region. I
believe, using either would be fine here.

> That file is 871 lines. Surely all that isn't how you
> solved this particular problem and that alone.

I am sorry, I did not follow that. The link I pasted was to a particular
commit in my config, highlighting only 46 lines pertaining to this advice
definition. On a PC, clicking that link should show you that highlighted
section of 46 lines in a browser like Chrome/Firefox.

> So why not yank it into a Gnus message buffer and fire
> it away here as well?

I simply find it convenient to read code on github with monospace fonts and
syntax highlighting. I use a wonderful package called git-link to quickly
get permalinks to my code snippets on github.

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

I like the message telling me exactly what happened i.e. I indented the
whole buffer or I eval'ed the whole buffer. But I can understand that that
does not give much value. My initial purpose to use macro here was to learn
how to use a macro. I like to grow my config with new styles and snippets
of elisp.

Just one important thing I'd like to point out in my code is the necessity
to modify the orig-fn args ONLY when args is nil. This is to protect from
corrupting the args when the advised fn is called by a wrapper fn. E.g. we
do not want to override all 4 args to eval-region (set by eval-defun) with
just 2 args when eval-region is being called by eval-defun.

Finally, thank you all for taking time to go through my code and providing
your feedback.

Kaushal


reply via email to

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