aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-10-18 11:37:57 -0400
committerStefan Monnier2012-10-18 11:37:57 -0400
commitaaf0c30025d24dba6d50fda6e61510020c2d611e (patch)
tree797b61d064b0ce79b7351798cefc97cb9acaa795
parent90eacf9920c2d9dc4edffdefe7e7a2a781493cc2 (diff)
downloademacs-aaf0c30025d24dba6d50fda6e61510020c2d611e.tar.gz
emacs-aaf0c30025d24dba6d50fda6e61510020c2d611e.zip
* lisp/emacs-lisp/advice.el: Clean up commentary a bit.
(ad-do-advised-functions, ad-with-originals): Use `declare'. (byte-code-function-p): Never redefine.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/advice.el85
2 files changed, 20 insertions, 69 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8c8f88dc89b..51e6b67b86c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12012-10-18 Stefan Monnier <monnier@iro.umontreal.ca> 12012-10-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/advice.el: Clean up commentary a bit.
4 (ad-do-advised-functions, ad-with-originals): Use `declare'.
5 (byte-code-function-p): Never redefine.
6
3 * emacs-lisp/gv.el (cond): Same fix as before for `if'. 7 * emacs-lisp/gv.el (cond): Same fix as before for `if'.
4 8
52012-10-18 Glenn Morris <rgm@gnu.org> 92012-10-18 Glenn Morris <rgm@gnu.org>
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el
index d96076d17a6..007871aa3a6 100644
--- a/lisp/emacs-lisp/advice.el
+++ b/lisp/emacs-lisp/advice.el
@@ -31,10 +31,6 @@
31 31
32;;; Commentary: 32;;; Commentary:
33 33
34;; NOTE: This documentation is slightly out of date. In particular, all the
35;; references to Emacs-18 are obsolete now, because it is not any longer
36;; supported by this version of Advice.
37
38;; Advice is documented in the Emacs Lisp Manual. 34;; Advice is documented in the Emacs Lisp Manual.
39 35
40;; @ Introduction: 36;; @ Introduction:
@@ -83,21 +79,10 @@
83;; - Provides manipulation mechanisms for sets of advised functions via 79;; - Provides manipulation mechanisms for sets of advised functions via
84;; regular expressions that match advice names 80;; regular expressions that match advice names
85 81
86;; @ How to get Advice for Emacs-18:
87;; =================================
88;; `advice18.el', a version of Advice that also works in Emacs-18 is available
89;; either via anonymous ftp from `ftp.cs.buffalo.edu (128.205.32.9)' with
90;; pathname `/pub/Emacs/advice18.el', or from one of the Emacs Lisp archive
91;; sites, or send email to <hans@cs.buffalo.edu> and I'll mail it to you.
92
93;; @ Overview, or how to read this file: 82;; @ Overview, or how to read this file:
94;; ===================================== 83;; =====================================
95;; NOTE: This documentation is slightly out of date. In particular, all the 84;; You can use `outline-mode' to help you read this documentation (set
96;; references to Emacs-18 are obsolete now, because it is not any longer 85;; `outline-regexp' to `";; @+"').
97;; supported by this version of Advice. An up-to-date version will soon be
98;; available as an info file (thanks to the kind help of Jack Vinson and
99;; David M. Smith). Until then you can use `outline-mode' to help you read
100;; this documentation (set `outline-regexp' to `";; @+"').
101;; 86;;
102;; The four major sections of this file are: 87;; The four major sections of this file are:
103;; 88;;
@@ -111,9 +96,6 @@
111 96
112;; @ Restrictions: 97;; @ Restrictions:
113;; =============== 98;; ===============
114;; - This version of Advice only works for Emacs 19.26 and later. It uses
115;; new versions of the built-in functions `fset/defalias' which are not
116;; yet available in Lucid Emacs, hence, it won't work there.
117;; - Advised functions/macros/subrs will only exhibit their advised behavior 99;; - Advised functions/macros/subrs will only exhibit their advised behavior
118;; when they are invoked via their function cell. This means that advice will 100;; when they are invoked via their function cell. This means that advice will
119;; not work for the following: 101;; not work for the following:
@@ -229,13 +211,8 @@
229 211
230;; @@ Terminology: 212;; @@ Terminology:
231;; =============== 213;; ===============
232;; - Emacs, Emacs-19: Emacs as released by the GNU Project 214;; - Emacs: Emacs as released by the GNU Project
233;; - Lemacs: Lucid's version of Emacs with major version 19 215;; - jwz: Jamie Zawinski - creator of the byte-compiler used in v19s.
234;; - v18: Any Emacs with major version 18 or built as an extension to that
235;; (such as Epoch)
236;; - v19: Any Emacs with major version 19
237;; - jwz: Jamie Zawinski - former keeper of Lemacs and creator of the optimizing
238;; byte-compiler used in v19s.
239;; - Advice: The name of this package. 216;; - Advice: The name of this package.
240;; - advices: Short for "pieces of advice". 217;; - advices: Short for "pieces of advice".
241 218
@@ -294,8 +271,7 @@
294;; generates a compiled advised definition according to the 271;; generates a compiled advised definition according to the
295;; current advice state which will be used during activation 272;; current advice state which will be used during activation
296;; if appropriate. Only use this if the `defadvice' gets 273;; if appropriate. Only use this if the `defadvice' gets
297;; actually compiled (with a v18 byte-compiler put the `defadvice' 274;; actually compiled.
298;; into the body of a `defun' to accomplish proper compilation).
299 275
300;; An optional <documentation-string> can be supplied to document the advice. 276;; An optional <documentation-string> can be supplied to document the advice.
301;; On call of the `documentation' function it will be combined with the 277;; On call of the `documentation' function it will be combined with the
@@ -399,10 +375,7 @@
399;; gets redefined in a non-advice style into a function by the edebug 375;; gets redefined in a non-advice style into a function by the edebug
400;; package. If the advice assumes `eval-region' to be a subr it might break 376;; package. If the advice assumes `eval-region' to be a subr it might break
401;; once edebug is loaded. Similar situations arise when one wants to use the 377;; once edebug is loaded. Similar situations arise when one wants to use the
402;; same piece of advice across different versions of Emacs. Some subrs in a 378;; same piece of advice across different versions of Emacs.
403;; v18 Emacs are functions in v19 and vice versa, but for the most part the
404;; semantics remain the same, hence, the same piece of advice might be usable
405;; in both Emacs versions.
406 379
407;; As a solution to that advice provides argument list access macros that get 380;; As a solution to that advice provides argument list access macros that get
408;; translated into the proper access forms at activation time, i.e., when the 381;; translated into the proper access forms at activation time, i.e., when the
@@ -556,12 +529,7 @@
556;; defined. The special forms `defun' and `defmacro' have been advised to 529;; defined. The special forms `defun' and `defmacro' have been advised to
557;; check whether the function/macro they defined had advice information 530;; check whether the function/macro they defined had advice information
558;; associated with it. If so and forward advice is enabled, the original 531;; associated with it. If so and forward advice is enabled, the original
559;; definition will be saved, and then the advice will be activated. When a 532;; definition will be saved, and then the advice will be activated.
560;; file is loaded in a v18 Emacs the functions/macros it defines are also
561;; defined with calls to `defun/defmacro'. Hence, we can forward advise
562;; functions/macros which will be defined later during a load/autoload of some
563;; file (for compiled files generated by jwz's byte-compiler in a v19 Emacs
564;; this is slightly more complicated but the basic idea is the same).
565 533
566;; @@ Enabling/disabling pieces or sets of advice: 534;; @@ Enabling/disabling pieces or sets of advice:
567;; =============================================== 535;; ===============================================
@@ -694,10 +662,8 @@
694;; specified as disabled) and all other currently enabled pieces of advice to 662;; specified as disabled) and all other currently enabled pieces of advice to
695;; construct an advised definition and an identifying cache-id and makes them 663;; construct an advised definition and an identifying cache-id and makes them
696;; part of the `defadvice' expansion which will then be compiled by the 664;; part of the `defadvice' expansion which will then be compiled by the
697;; byte-compiler (to ensure that in a v18 emacs you have to put the 665;; byte-compiler.
698;; `defadvice' inside a `defun' to get it compiled and then you have to call 666;; When the file with the compiled, preactivating `defadvice' gets loaded the
699;; that compiled `defun' in order to actually execute the `defadvice'). When
700;; the file with the compiled, preactivating `defadvice' gets loaded the
701;; precompiled advised definition will be cached on the advised function's 667;; precompiled advised definition will be cached on the advised function's
702;; advice-info. When it gets activated (can be immediately on execution of the 668;; advice-info. When it gets activated (can be immediately on execution of the
703;; `defadvice' or any time later) the cache-id gets checked against the 669;; `defadvice' or any time later) the cache-id gets checked against the
@@ -792,8 +758,7 @@
792;; advised definition of a function, rather they are assembled into a hook 758;; advised definition of a function, rather they are assembled into a hook
793;; form which will be evaluated whenever the advice-info of the advised 759;; form which will be evaluated whenever the advice-info of the advised
794;; function gets activated or deactivated. One application of this mechanism 760;; function gets activated or deactivated. One application of this mechanism
795;; is to define file load hooks for files that do not provide such hooks 761;; is to define file load hooks for files that do not provide such hooks.
796;; (v19s already come with a general file-load-hook mechanism, v18s don't).
797;; For example, suppose you want to print a message whenever `file-x' gets 762;; For example, suppose you want to print a message whenever `file-x' gets
798;; loaded, and suppose the last function defined in `file-x' is 763;; loaded, and suppose the last function defined in `file-x' is
799;; `file-x-last-fn'. Then we can define the following advice: 764;; `file-x-last-fn'. Then we can define the following advice:
@@ -1400,8 +1365,8 @@
1400;; 1365;;
1401;; If you put a preactivating `defadvice' into a Lisp file that gets byte- 1366;; If you put a preactivating `defadvice' into a Lisp file that gets byte-
1402;; compiled then the constructed advised definition will get compiled by 1367;; compiled then the constructed advised definition will get compiled by
1403;; the byte-compiler. For that to occur in a v18 emacs you have to put the 1368;; the byte-compiler. For that to occur in a v18 Emacs you had to put the
1404;; `defadvice' inside a `defun' because the v18 compiler does not compile 1369;; `defadvice' inside a `defun' because the v18 compiler did not compile
1405;; top-level forms other than `defun' or `defmacro', for example, 1370;; top-level forms other than `defun' or `defmacro', for example,
1406;; 1371;;
1407;; (defun fg-defadvice-fum () 1372;; (defun fg-defadvice-fum ()
@@ -1496,10 +1461,7 @@
1496;; if one advises a subr such as `eval-region' which then gets redefined by 1461;; if one advises a subr such as `eval-region' which then gets redefined by
1497;; some package (e.g., edebug) into a function with different argument names, 1462;; some package (e.g., edebug) into a function with different argument names,
1498;; then a piece of advice written for `eval-region' that was written with 1463;; then a piece of advice written for `eval-region' that was written with
1499;; the subr arguments in mind will break. Similar situations arise when one 1464;; the subr arguments in mind will break.
1500;; switches between major Emacs versions, e.g., certain subrs in v18 are
1501;; functions in v19 and vice versa. Also, in v19s subr argument lists
1502;; are available and will be used, while they are not available in v18.
1503;; 1465;;
1504;; Argument access text macros allow one to access arguments of an advised 1466;; Argument access text macros allow one to access arguments of an advised
1505;; function in a portable way without having to worry about all these 1467;; function in a portable way without having to worry about all these
@@ -1882,15 +1844,13 @@ generates a copy of TREE."
1882 BODY-FORM...) 1844 BODY-FORM...)
1883On each iteration VAR will be bound to the name of an advised function 1845On each iteration VAR will be bound to the name of an advised function
1884\(a symbol)." 1846\(a symbol)."
1847 (declare (indent 1))
1885 `(cl-dolist (,(car varform) 1848 `(cl-dolist (,(car varform)
1886 ad-advised-functions 1849 ad-advised-functions
1887 ,(car (cdr varform))) 1850 ,(car (cdr varform)))
1888 (setq ,(car varform) (intern (car ,(car varform)))) 1851 (setq ,(car varform) (intern (car ,(car varform))))
1889 ,@body)) 1852 ,@body))
1890 1853
1891(if (not (get 'ad-do-advised-functions 'lisp-indent-hook))
1892 (put 'ad-do-advised-functions 'lisp-indent-hook 1))
1893
1894(defun ad-get-advice-info (function) 1854(defun ad-get-advice-info (function)
1895 (get function 'ad-advice-info)) 1855 (get function 'ad-advice-info))
1896 1856
@@ -2117,7 +2077,7 @@ function at point for which PREDICATE returns non-nil)."
2117 (lambda (function) 2077 (lambda (function)
2118 ;; Oops, no closures - the joys of dynamic scoping: 2078 ;; Oops, no closures - the joys of dynamic scoping:
2119 ;; `predicate' clashed with the `predicate' argument 2079 ;; `predicate' clashed with the `predicate' argument
2120 ;; of Lemacs' `completing-read'..... 2080 ;; of `completing-read'.....
2121 (funcall ad-pReDiCaTe (intern (car function)))))) 2081 (funcall ad-pReDiCaTe (intern (car function))))))
2122 t))) 2082 t)))
2123 (if (equal function "") 2083 (if (equal function "")
@@ -2394,12 +2354,6 @@ See Info node `(elisp)Computed Advice' for detailed documentation."
2394 ;;"non-nil if DEFINITION is a piece of advice." 2354 ;;"non-nil if DEFINITION is a piece of advice."
2395 `(eq (car-safe ,definition) 'advice)) 2355 `(eq (car-safe ,definition) 'advice))
2396 2356
2397;; Emacs/Lemacs cross-compatibility
2398;; (compiled-function-p is an obsolete function in Emacs):
2399(if (and (not (fboundp 'byte-code-function-p))
2400 (fboundp 'compiled-function-p))
2401 (ad-safe-fset 'byte-code-function-p 'compiled-function-p))
2402
2403(defmacro ad-compiled-p (definition) 2357(defmacro ad-compiled-p (definition)
2404 "Return non-nil if DEFINITION is a compiled byte-code object." 2358 "Return non-nil if DEFINITION is a compiled byte-code object."
2405 `(or (byte-code-function-p ,definition) 2359 `(or (byte-code-function-p ,definition)
@@ -3696,6 +3650,7 @@ usage: (defadvice FUNCTION (CLASS NAME [POSITION] [ARGLIST] FLAG...)
3696For any members of FUNCTIONS that are not currently advised the rebinding will 3650For any members of FUNCTIONS that are not currently advised the rebinding will
3697be a noop. Any modifications done to the definitions of FUNCTIONS will be 3651be a noop. Any modifications done to the definitions of FUNCTIONS will be
3698undone on exit of this macro." 3652undone on exit of this macro."
3653 (declare (indent 1))
3699 (let* ((index -1) 3654 (let* ((index -1)
3700 ;; Make let-variables to store current definitions: 3655 ;; Make let-variables to store current definitions:
3701 (current-bindings 3656 (current-bindings
@@ -3735,14 +3690,6 @@ undone on exit of this macro."
3735 ,(car (nth index current-bindings))))) 3690 ,(car (nth index current-bindings)))))
3736 functions)))))) 3691 functions))))))
3737 3692
3738(if (not (get 'ad-with-originals 'lisp-indent-hook))
3739 (put 'ad-with-originals 'lisp-indent-hook 1))
3740
3741
3742;; @@ Advising `documentation':
3743;; ============================
3744;; Use the advice mechanism to advise `documentation' to make it
3745;; generate proper documentation strings for advised definitions:
3746 3693
3747;; @@ Starting, stopping and recovering from the advice package magic: 3694;; @@ Starting, stopping and recovering from the advice package magic:
3748;; =================================================================== 3695;; ===================================================================