emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 1a1b5f9 3/3: Add a really simple nadvice example


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 1a1b5f9 3/3: Add a really simple nadvice example
Date: Tue, 9 Jul 2019 11:14:03 -0400 (EDT)

branch: master
commit 1a1b5f9802577a09317dd036ccefba4222702f4f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add a really simple nadvice example
    
    * doc/lispref/functions.texi (Advising Functions): Add a really
    trivial and simple example (bug#35250).
---
 doc/lispref/functions.texi | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index ab07d38..6eb1af6 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1578,8 +1578,26 @@ primitives being @code{add-function} and 
@code{remove-function}) and another
 set layered on top of it for named functions (with the main primitives being
 @code{advice-add} and @code{advice-remove}).
 
-For example, in order to trace the calls to the process filter of a process
-@var{proc}, you could use:
+As a trivial example, here's how to add advice that'll modify the
+return value of a function every time it's called:
+
+@example
+(defun my-double (x)
+  (* x 2))
+(defun my-increase (x)
+  (+ x 1))
+(advice-add 'my-double :filter-return #'my-increase)
+@end example
+
+After adding this advice, if you call @code{my-double} with @samp{3},
+the return value will be @samp{7}.  To remove this advice, say
+
+@example
+(advice-remove 'my-double #'my-increase)
+@end example
+
+A more advanced example would be to trace the calls to the process
+filter of a process @var{proc}:
 
 @example
 (defun my-tracing-function (proc string)



reply via email to

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