summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/nadvice.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2017-07-18 14:07:16 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2017-07-18 14:07:41 -0400
commit24bd52565a7652817e6bf9b7a5cb9ad99c955a13 (patch)
tree393aea4a4e799aac1d5ba10aab3f317743ff3823 /lisp/emacs-lisp/nadvice.el
parent5ab91020fbc2f3bf75aa732a7456d9119ccbc347 (diff)
downloademacs-24bd52565a7652817e6bf9b7a5cb9ad99c955a13.tar.gz
* lisp/emacs-lisp/nadvice.el (advice--defalias-fset): Strip advices
This tries to make sure that (defalias F (symbol-function F)) stays a no-op.
Diffstat (limited to 'lisp/emacs-lisp/nadvice.el')
-rw-r--r--lisp/emacs-lisp/nadvice.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index fd1cd2c7aaf..c68ecbc59ee 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -385,6 +385,18 @@ of the piece of advice."
(defun advice--defalias-fset (fsetfun symbol newdef)
(unless fsetfun (setq fsetfun #'fset))
+ ;; `newdef' shouldn't include advice wrappers, since that's what *we* manage!
+ ;; So if `newdef' includes advice wrappers, it's usually because someone
+ ;; naively took (symbol-function F) and then passed that back to `defalias':
+ ;; let's strip them away.
+ (cond
+ ((advice--p newdef) (setq newdef (advice--cd*r newdef)))
+ ((and (eq 'macro (car-safe newdef))
+ (advice--p (cdr newdef)))
+ (setq newdef `(macro . ,(advice--cd*r (cdr newdef))))))
+ ;; The saved-rewrite is specific to the current value, so since we are about
+ ;; to overwrite that current value with new value, the old saved-rewrite is
+ ;; not relevant any more.
(when (get symbol 'advice--saved-rewrite)
(put symbol 'advice--saved-rewrite nil))
(setq newdef (advice--normalize symbol newdef))