emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 01/01: New macro define-advice


From: Leo Liu
Subject: [Emacs-diffs] master 01/01: New macro define-advice
Date: Tue, 18 Nov 2014 16:00:33 +0000

branch: master
commit 1148d375898652ce5dec986d11bec46bb8ac0e6d
Author: Leo Liu <address@hidden>
Date:   Tue Nov 18 23:57:01 2014 +0800

    New macro define-advice
    
    * doc/lispref/functions.texi (Advising Named Functions): Document
    define-advice.
    
    * lisp/emacs-lisp/nadvice.el (define-advice): New macro.
    * lisp/emacs-lisp/lisp-mode.el (lisp-imenu-generic-expression): Add
    define-advice.
    (lisp-font-lock-keywords-1): Add define-advice.
---
 doc/lispref/ChangeLog        |    5 +++++
 doc/lispref/functions.texi   |    7 +++++++
 lisp/ChangeLog               |    7 +++++++
 lisp/emacs-lisp/lisp-mode.el |    4 ++--
 lisp/emacs-lisp/nadvice.el   |   24 ++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 0a8a0a8..6706f93 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-18  Leo Liu  <address@hidden>
+
+       * functions.texi (Advising Named Functions): Document
+       define-advice.
+
 2014-11-17  Paul Eggert  <address@hidden>
 
        Improve time stamp handling, and be more consistent about it.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 023175e..50849d4 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1360,6 +1360,13 @@ called directly from C, and such calls ignore advice; 
hence, one ends
 up in a confusing situation where some calls (occurring from Lisp
 code) obey the advice and other calls (from C code) do not.
 
address@hidden define-advice symbol (where lambda-list &optional name depth) 
&rest body
+This macro defines an advice and adds it to the function named
address@hidden  The advice is an anonymous function if @var{name} is
+nil or a function named @code{symbol@@name}.  See @code{advice-add}
+for explanation of other arguments.
address@hidden defmac
+
 @defun advice-add symbol where function &optional props
 Add the advice @var{function} to the named function @var{symbol}.
 @var{where} and @var{props} have the same meaning as for @code{add-function}
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e885c92..a1635bc 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-18  Leo Liu  <address@hidden>
+
+       * emacs-lisp/nadvice.el (define-advice): New macro.
+       * emacs-lisp/lisp-mode.el (lisp-imenu-generic-expression): Add
+       define-advice.
+       (lisp-font-lock-keywords-1): Add define-advice.
+
 2014-11-18  Daiki Ueno  <address@hidden>
 
        * epg.el (epg-context): New slot EDIT-CALLBACK.
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index a13baf0..d84113b 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -96,7 +96,7 @@
                              '("defun" "defmacro"
                                 ;; Elisp.
                                 "defun*" "defsubst"
-                               "defadvice" "define-skeleton"
+                               "define-advice" "defadvice" "define-skeleton"
                                "define-compilation-mode" "define-minor-mode"
                                "define-global-minor-mode"
                                "define-globalized-minor-mode"
@@ -195,7 +195,7 @@
                          "ignore-errors" "dotimes" "dolist" "declare"))
               (lisp-errs '("warn" "error" "signal"))
               ;; Elisp constructs.  FIXME: update dynamically from obarray.
-              (el-fdefs '("defadvice" "defalias"
+              (el-fdefs '("define-advice" "defadvice" "defalias"
                           "define-derived-mode" "define-minor-mode"
                           "define-generic-mode" "define-global-minor-mode"
                           "define-globalized-minor-mode" "define-skeleton"
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index bfd939d..a81d3e4 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -441,6 +441,30 @@ of the piece of advice."
              (fset symbol (car (get symbol 'advice--saved-rewrite)))))))
   nil)
 
+;;;###autoload
+(defmacro define-advice (symbol args &rest body)
+  "Define an advice and add it to function named SYMBOL.
+See `advice-add' and `add-function' for explanation on the
+arguments.  Note if NAME is nil the advice is anonymous;
+otherwise it is named address@hidden'.
+
+\(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
+  (declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
+  (or (listp args) (signal 'wrong-type-argument (list 'listp args)))
+  (or (<= 2 (length args) 4)
+      (signal 'wrong-number-of-arguments (list 2 4 (length args))))
+  (let* ((where         (nth 0 args))
+         (lambda-list   (nth 1 args))
+         (name          (nth 2 args))
+         (depth         (nth 3 args))
+         (props         (and depth `((depth . ,depth))))
+         (advice (cond ((null name) `(lambda ,lambda-list ,@body))
+                       ((or (stringp name) (symbolp name))
+                        (intern (format "address@hidden" symbol name)))
+                       (t (error "Unrecognized name spec `%S'" name)))))
+    `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
+       (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
+
 (defun advice-mapc (fun symbol)
   "Apply FUN to every advice function in SYMBOL.
 FUN is called with a two arguments: the function that was added, and the



reply via email to

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