aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-11-26 14:56:14 -0500
committerStefan Monnier2012-11-26 14:56:14 -0500
commit848a2dd19d1b030303de1b568edf9e33281e4440 (patch)
tree78cf366a8c94bf407b59024468b190f70fd0de30
parent551aaa664fcc94c80a7cb4f34bdc12c7dfe18fb2 (diff)
downloademacs-848a2dd19d1b030303de1b568edf9e33281e4440.tar.gz
emacs-848a2dd19d1b030303de1b568edf9e33281e4440.zip
* lisp/emacs-lisp/advice.el (ad-should-compile): Don't compile advice if the
base function is not yet defined. (ad-activate-advised-definition): Use ad-compile-function. (ad-activate): Use cond. Fixes: debbugs:12965
-rw-r--r--lisp/ChangeLog21
-rw-r--r--lisp/emacs-lisp/advice.el55
2 files changed, 41 insertions, 35 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9e403af6416..2771ca42f25 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12012-11-26 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/advice.el (ad-should-compile): Don't compile advice if the
4 base function is not yet defined (bug#12965).
5 (ad-activate-advised-definition): Use ad-compile-function.
6 (ad-activate): Use cond.
7
12012-11-25 Leo Liu <sdl.web@gmail.com> 82012-11-25 Leo Liu <sdl.web@gmail.com>
2 9
3 * textmodes/sgml-mode.el (sgml-tag): Fix indentation for closing tag. 10 * textmodes/sgml-mode.el (sgml-tag): Fix indentation for closing tag.
@@ -10,14 +17,14 @@
10 Texinfo integration. 17 Texinfo integration.
11 18
12 * textmodes/reftex.el (reftex-section-pre-regexp) 19 * textmodes/reftex.el (reftex-section-pre-regexp)
13 (reftex-section-post-regexp, reftex-section-info-function): New 20 (reftex-section-post-regexp, reftex-section-info-function):
14 variable. 21 New variable.
15 (reftex-compile-variables): Use variables 22 (reftex-compile-variables): Use variables reftex-section-pre-regexp,
16 reftex-section-pre-regexp, reftex-section-post-regexp, and 23 reftex-section-post-regexp, and reftex-section-info-function in order
17 reftex-section-info-function in order to be compatible with Texinfo integration. 24 to be compatible with Texinfo integration.
18 25
19 * textmodes/reftex-toc.el (reftex-toc-promote-action): use 26 * textmodes/reftex-toc.el (reftex-toc-promote-action):
20 reftex-section-pre-regexp variable in order to be compatible with 27 use reftex-section-pre-regexp variable in order to be compatible with
21 Texinfo integration. 28 Texinfo integration.
22 29
232012-11-25 Chong Yidong <cyd@gnu.org> 302012-11-25 Chong Yidong <cyd@gnu.org>
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el
index c2ebb3bbdc6..a947dceccc9 100644
--- a/lisp/emacs-lisp/advice.el
+++ b/lisp/emacs-lisp/advice.el
@@ -2900,19 +2900,18 @@ If COMPILE is non-nil and not a negative number then it returns t.
2900If COMPILE is a negative number then it returns nil. 2900If COMPILE is a negative number then it returns nil.
2901If COMPILE is nil then the result depends on the value of 2901If COMPILE is nil then the result depends on the value of
2902`ad-default-compilation-action' (which see)." 2902`ad-default-compilation-action' (which see)."
2903 (if (integerp compile) 2903 (cond
2904 (>= compile 0) 2904 ;; Don't compile until the real function definition is known (bug#12965).
2905 (if compile 2905 ((not (ad-real-orig-definition function)) nil)
2906 compile 2906 ((integerp compile) (>= compile 0))
2907 (cond ((eq ad-default-compilation-action 'never) 2907 (compile)
2908 nil) 2908 ((eq ad-default-compilation-action 'never) nil)
2909 ((eq ad-default-compilation-action 'always) 2909 ((eq ad-default-compilation-action 'always) t)
2910 t) 2910 ((eq ad-default-compilation-action 'like-original)
2911 ((eq ad-default-compilation-action 'like-original) 2911 (or (ad-subr-p (ad-get-orig-definition function))
2912 (or (ad-subr-p (ad-get-orig-definition function)) 2912 (ad-compiled-p (ad-get-orig-definition function))))
2913 (ad-compiled-p (ad-get-orig-definition function)))) 2913 ;; everything else means `maybe':
2914 ;; everything else means `maybe': 2914 (t (featurep 'byte-compile))))
2915 (t (featurep 'byte-compile))))))
2916 2915
2917(defun ad-activate-advised-definition (function compile) 2916(defun ad-activate-advised-definition (function compile)
2918 "Redefine FUNCTION with its advised definition from cache or scratch. 2917 "Redefine FUNCTION with its advised definition from cache or scratch.
@@ -2927,7 +2926,7 @@ The current definition and its cache-id will be put into the cache."
2927 (ad-make-advised-definition function))) 2926 (ad-make-advised-definition function)))
2928 (advice-add function :around advicefunname) 2927 (advice-add function :around advicefunname)
2929 (if (ad-should-compile function compile) 2928 (if (ad-should-compile function compile)
2930 (byte-compile advicefunname)) 2929 (ad-compile-function function))
2931 (if verified-cached-definition 2930 (if verified-cached-definition
2932 (if (not (eq verified-cached-definition 2931 (if (not (eq verified-cached-definition
2933 (symbol-function advicefunname))) 2932 (symbol-function advicefunname)))
@@ -3003,20 +3002,20 @@ definition will always be cached for later usage."
3003 (interactive 3002 (interactive
3004 (list (ad-read-advised-function "Activate advice of") 3003 (list (ad-read-advised-function "Activate advice of")
3005 current-prefix-arg)) 3004 current-prefix-arg))
3006 (if (not (ad-is-advised function)) 3005 (cond
3007 (error "ad-activate: `%s' is not advised" function) 3006 ((not (ad-is-advised function))
3008 ;; Just return for forward advised and not yet defined functions: 3007 (error "ad-activate: `%s' is not advised" function))
3009 (if (ad-get-orig-definition function) 3008 ;; Just return for forward advised and not yet defined functions:
3010 (if (not (ad-has-any-advice function)) 3009 ((not (ad-get-orig-definition function)) nil)
3011 (ad-unadvise function) 3010 ((not (ad-has-any-advice function)) (ad-unadvise function))
3012 ;; Otherwise activate the advice: 3011 ;; Otherwise activate the advice:
3013 (cond ((ad-has-redefining-advice function) 3012 ((ad-has-redefining-advice function)
3014 (ad-activate-advised-definition function compile) 3013 (ad-activate-advised-definition function compile)
3015 (ad-set-advice-info-field function 'active t) 3014 (ad-set-advice-info-field function 'active t)
3016 (eval (ad-make-hook-form function 'activation)) 3015 (eval (ad-make-hook-form function 'activation))
3017 function) 3016 function)
3018 ;; Here we are if we have all disabled advices: 3017 ;; Here we are if we have all disabled advices:
3019 (t (ad-deactivate function))))))) 3018 (t (ad-deactivate function))))
3020 3019
3021(defalias 'ad-activate-on 'ad-activate) 3020(defalias 'ad-activate-on 'ad-activate)
3022 3021