aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2014-11-18 23:57:01 +0800
committerLeo Liu2014-11-18 23:57:01 +0800
commit1148d375898652ce5dec986d11bec46bb8ac0e6d (patch)
tree3d8cdc9a9b9c832395292ef85031187ecf1b4b60
parentb59998eb5b9c4e6e142b530604539c54028acb8d (diff)
downloademacs-1148d375898652ce5dec986d11bec46bb8ac0e6d.tar.gz
emacs-1148d375898652ce5dec986d11bec46bb8ac0e6d.zip
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.
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/functions.texi7
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/emacs-lisp/lisp-mode.el4
-rw-r--r--lisp/emacs-lisp/nadvice.el24
5 files changed, 45 insertions, 2 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 0a8a0a88cce..6706f936c5e 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12014-11-18 Leo Liu <sdl.web@gmail.com>
2
3 * functions.texi (Advising Named Functions): Document
4 define-advice.
5
12014-11-17 Paul Eggert <eggert@cs.ucla.edu> 62014-11-17 Paul Eggert <eggert@cs.ucla.edu>
2 7
3 Improve time stamp handling, and be more consistent about it. 8 Improve time stamp handling, and be more consistent about it.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 023175e3632..50849d4228c 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
1360up in a confusing situation where some calls (occurring from Lisp 1360up in a confusing situation where some calls (occurring from Lisp
1361code) obey the advice and other calls (from C code) do not. 1361code) obey the advice and other calls (from C code) do not.
1362 1362
1363@defmac define-advice symbol (where lambda-list &optional name depth) &rest body
1364This macro defines an advice and adds it to the function named
1365@var{symbol}. The advice is an anonymous function if @var{name} is
1366nil or a function named @code{symbol@@name}. See @code{advice-add}
1367for explanation of other arguments.
1368@end defmac
1369
1363@defun advice-add symbol where function &optional props 1370@defun advice-add symbol where function &optional props
1364Add the advice @var{function} to the named function @var{symbol}. 1371Add the advice @var{function} to the named function @var{symbol}.
1365@var{where} and @var{props} have the same meaning as for @code{add-function} 1372@var{where} and @var{props} have the same meaning as for @code{add-function}
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e885c924487..a1635bc475c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12014-11-18 Leo Liu <sdl.web@gmail.com>
2
3 * emacs-lisp/nadvice.el (define-advice): New macro.
4 * emacs-lisp/lisp-mode.el (lisp-imenu-generic-expression): Add
5 define-advice.
6 (lisp-font-lock-keywords-1): Add define-advice.
7
12014-11-18 Daiki Ueno <ueno@gnu.org> 82014-11-18 Daiki Ueno <ueno@gnu.org>
2 9
3 * epg.el (epg-context): New slot EDIT-CALLBACK. 10 * 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 a13baf0ee22..d84113b418a 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -96,7 +96,7 @@
96 '("defun" "defmacro" 96 '("defun" "defmacro"
97 ;; Elisp. 97 ;; Elisp.
98 "defun*" "defsubst" 98 "defun*" "defsubst"
99 "defadvice" "define-skeleton" 99 "define-advice" "defadvice" "define-skeleton"
100 "define-compilation-mode" "define-minor-mode" 100 "define-compilation-mode" "define-minor-mode"
101 "define-global-minor-mode" 101 "define-global-minor-mode"
102 "define-globalized-minor-mode" 102 "define-globalized-minor-mode"
@@ -195,7 +195,7 @@
195 "ignore-errors" "dotimes" "dolist" "declare")) 195 "ignore-errors" "dotimes" "dolist" "declare"))
196 (lisp-errs '("warn" "error" "signal")) 196 (lisp-errs '("warn" "error" "signal"))
197 ;; Elisp constructs. FIXME: update dynamically from obarray. 197 ;; Elisp constructs. FIXME: update dynamically from obarray.
198 (el-fdefs '("defadvice" "defalias" 198 (el-fdefs '("define-advice" "defadvice" "defalias"
199 "define-derived-mode" "define-minor-mode" 199 "define-derived-mode" "define-minor-mode"
200 "define-generic-mode" "define-global-minor-mode" 200 "define-generic-mode" "define-global-minor-mode"
201 "define-globalized-minor-mode" "define-skeleton" 201 "define-globalized-minor-mode" "define-skeleton"
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index bfd939d69e2..a81d3e43de3 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -441,6 +441,30 @@ of the piece of advice."
441 (fset symbol (car (get symbol 'advice--saved-rewrite))))))) 441 (fset symbol (car (get symbol 'advice--saved-rewrite)))))))
442 nil) 442 nil)
443 443
444;;;###autoload
445(defmacro define-advice (symbol args &rest body)
446 "Define an advice and add it to function named SYMBOL.
447See `advice-add' and `add-function' for explanation on the
448arguments. Note if NAME is nil the advice is anonymous;
449otherwise it is named `SYMBOL@NAME'.
450
451\(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
452 (declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
453 (or (listp args) (signal 'wrong-type-argument (list 'listp args)))
454 (or (<= 2 (length args) 4)
455 (signal 'wrong-number-of-arguments (list 2 4 (length args))))
456 (let* ((where (nth 0 args))
457 (lambda-list (nth 1 args))
458 (name (nth 2 args))
459 (depth (nth 3 args))
460 (props (and depth `((depth . ,depth))))
461 (advice (cond ((null name) `(lambda ,lambda-list ,@body))
462 ((or (stringp name) (symbolp name))
463 (intern (format "%s@%s" symbol name)))
464 (t (error "Unrecognized name spec `%S'" name)))))
465 `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
466 (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
467
444(defun advice-mapc (fun symbol) 468(defun advice-mapc (fun symbol)
445 "Apply FUN to every advice function in SYMBOL. 469 "Apply FUN to every advice function in SYMBOL.
446FUN is called with a two arguments: the function that was added, and the 470FUN is called with a two arguments: the function that was added, and the