help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question at Emacs.SE: Practical benefits of new advice system in Ema


From: Michael Heerdegen
Subject: Re: Question at Emacs.SE: Practical benefits of new advice system in Emacs 24.4
Date: Thu, 06 Nov 2014 04:23:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi Artur,

I can't speak for the author (Stefan), but I'll try to give my best to
give an answer.

>  What are the practical benefits and implications of this new package?

Generally, it's a new implementation of the functionality of advice.el.
It is shorter, has a much simpler and clearer semantic, and some new
features.

>    If I am only using advice to customize Emacs (as opposed to writing
>    add-on packages), do I need to switch to the new system? Will it replace
>    the old system at some point?

In general there's no strong need to switch to the new system soon.
Note that advice.el has been completely rewritten based on nadvice, so,
strictly speaking, you're probably already using nadvice (indirectly).

Since tons of third party packages still depend on advice.el, it will
probably be part of Emacs for a very long time.

A disadvantage of still using advice is that there are some few issues
with it now. For example, AFAICT the generated documentation of
functions adviced with advice.el in *Help*states all advices as being of
type :around now, since advices in the rewritten advice.el are all
implemented as :around advices in terms of nadvice.el.

And there are some rarely used features of the old advice.el that the
rewritten version doesn't reimplement, features I never heard of.

>    What *exactly* can I do with the new system that I can't accomplish with
>    defadvice?

When you only use nadvice for customization reasons, there are not many
new things you can do with it, apart from the fact that your new advices
will look "lispier".  There are much more advice types now as in the old
package which are more handy in several situations.

>    What is the significance of being able to "add/remove code on any
>    function-carrying place"?

For your Emacs init file, there is not so much relevance.

With the old system, you could only advice named functions (defuns).
With nadvice, this has been generalized.  It's best to read the manual,
and to grep for "add-function" in the Emacs sources to see some real
life examples.

One example are the numerous function valued variables in Emacs named
"...-function" that you can now advice.  That had not been possible with
advice.el.

Or, have a look at this example from the manual:

,----------------------------------------------------------------------
| For example, in order to trace the calls to the process filter of a
| process PROC, you could use:
| 
|      (defun my-tracing-function (proc string)
|        (message "Proc %S received %S" proc string))
| 
|      (add-function :before (process-filter PROC) #'my-tracing-function)
| 
|    This will cause the process’s output to be passed to
| ‘my-tracing-function’ before being passed to the original process
| filter.
`----------------------------------------------------------------------

This would not be possible with advice.el, since the process filter is
an anonymous function - there is not even a variable bound to this
function.


HTH, and that I didn't tell something wrong,

Michael.




reply via email to

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