Commit 1148d375 authored by Leo Liu's avatar Leo Liu
Browse files

New macro define-advice

* doc/lispref/functions.texi (Advising Named Functions): Document

* lisp/emacs-lisp/nadvice.el (define-advice): New macro.
* lisp/emacs-lisp/lisp-mode.el (lisp-imenu-generic-expression): Add
(lisp-font-lock-keywords-1): Add define-advice.
parent b59998eb
2014-11-18 Leo Liu <>
* functions.texi (Advising Named Functions): Document
2014-11-17 Paul Eggert <>
Improve time stamp handling, and be more consistent about it.
......@@ -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.
@defmac define-advice symbol (where lambda-list &optional name depth) &rest body
This macro defines an advice and adds it to the function named
@var{symbol}. 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.
@end 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}
2014-11-18 Leo Liu <>
* emacs-lisp/nadvice.el (define-advice): New macro.
* emacs-lisp/lisp-mode.el (lisp-imenu-generic-expression): Add
(lisp-font-lock-keywords-1): Add define-advice.
2014-11-18 Daiki Ueno <>
* epg.el (epg-context): New slot EDIT-CALLBACK.
......@@ -96,7 +96,7 @@
'("defun" "defmacro"
;; Elisp.
"defun*" "defsubst"
"defadvice" "define-skeleton"
"define-advice" "defadvice" "define-skeleton"
"define-compilation-mode" "define-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"
......@@ -441,6 +441,30 @@ of the piece of advice."
(fset symbol (car (get symbol 'advice--saved-rewrite)))))))
(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 `SYMBOL@NAME'.
(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 "%s@%s" 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment