emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master b8c4a9e: Add an advice-add/interactive spec example


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master b8c4a9e: Add an advice-add/interactive spec example
Date: Sun, 18 Aug 2019 19:05:54 -0400 (EDT)

branch: master
commit b8c4a9e0f8d10b2c3948d8f12279238b1e58b76d
Author: Štěpán Němec <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add an advice-add/interactive spec example
    
    * doc/lispref/functions.texi (Core Advising Primitives): Add an
    advice-add example that extends the `interactive' spec (bug#17871).
---
 doc/lispref/functions.texi | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index e65d398..d082225 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1752,6 +1752,30 @@ with such a spec would, and then return the 
corresponding list of arguments
 that was built.  E.g., @code{(advice-eval-interactive-spec "r\nP")} will
 return a list of three elements, containing the boundaries of the region and
 the current prefix argument.
+
+For instance, if you want to make the @kbd{C-x m}
+(@code{compose-mail}) command prompt for a @samp{From:} header, you
+could say something like this:
+
+@example
+(defun my-compose-mail-advice (orig &rest args)
+  "Read From: address interactively."
+  (interactive
+   (lambda (spec)
+     (let* ((user-mail-address
+             (completing-read "From: "
+                              '("one.address@@example.net"
+                                "alternative.address@@example.net")))
+            (from (message-make-from user-full-name
+                                     user-mail-address))
+            (spec (advice-eval-interactive-spec spec)))
+       ;; Put the From header into the OTHER-HEADERS argument.
+       (push (cons 'From from) (nth 2 spec))
+       spec)))
+  (apply orig args))
+
+(advice-add 'compose-mail :around #'my-compose-mail-advice)
+@end example
 @end defun
 
 @node Advising Named Functions



reply via email to

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