+2014-11-18 Leo Liu <sdl.web@gmail.com>
+
+ * functions.texi (Advising Named Functions): Document
+ define-advice.
+
2014-11-17 Paul Eggert <eggert@cs.ucla.edu>
Improve time stamp handling, and be more consistent about it.
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 <sdl.web@gmail.com>
+
+ * 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 <ueno@gnu.org>
* epg.el (epg-context): New slot EDIT-CALLBACK.
'("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"
"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"
(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 `SYMBOL@NAME'.
+
+\(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 "%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