aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLeo Liu2014-11-18 23:57:01 +0800
committerLeo Liu2014-11-18 23:57:01 +0800
commit1148d375898652ce5dec986d11bec46bb8ac0e6d (patch)
tree3d8cdc9a9b9c832395292ef85031187ecf1b4b60 /lisp
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/emacs-lisp/lisp-mode.el4
-rw-r--r--lisp/emacs-lisp/nadvice.el24
3 files changed, 33 insertions, 2 deletions
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