diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2012-11-12 15:43:43 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2012-11-12 15:43:43 -0500 |
commit | 231d8498eb1a10fadf7a4cd860cc934e05516433 (patch) | |
tree | 91b3cac4bf733674c999b4d8acbc8f6d272f7736 /lisp/emacs-lisp/advice.el | |
parent | be49ba7461368989e0a8ac7d1f555d2f042e8c52 (diff) | |
download | emacs-231d8498eb1a10fadf7a4cd860cc934e05516433.tar.gz |
* lisp/emacs-lisp/nadvice.el: New package.
* lisp/subr.el (special-form-p): New function.
* lisp/emacs-lisp/elp.el: Use lexical-binding and advice-add.
(elp-all-instrumented-list): Remove var.
(elp-not-profilable): Remove elp-wrapper.
(elp-profilable-p): Use autoloadp and special-form-p.
(elp--advice-name): New const.
(elp-instrument-function): Use advice-add.
(elp--instrumented-p): New predicate.
(elp-restore-function): Use advice-remove.
(elp-restore-all, elp-reset-all): Use mapatoms.
(elp-set-master): Use elp--instrumented-p.
(elp--make-wrapper): Rename from elp-wrapper, return a function
suitable for advice-add. Use cl-inf.
(elp-results): Use mapatoms+elp--instrumented-p.
* lisp/emacs-lisp/debug.el: Use lexical-binding and advice-add.
(debug-function-list): Remove var.
(debug): Rename arg, and then let-bind it explicitly inside.
(debugger-setup-buffer): Rename arg.
(debugger-setup-buffer): Adjust counts to new debug-on-entry setup.
(debugger-frame-number): Adjust to new debug-on-entry setup.
(debug--implement-debug-on-entry): Rename from
implement-debug-on-entry, add argument.
(debugger-special-form-p): Remove, use special-form-p instead.
(debug-on-entry): Use advice-add.
(debug--function-list): New function.
(cancel-debug-on-entry): Use it, along with advice-remove.
(debug-arglist, debug-convert-byte-code, debug-on-entry-1): Remove.
(debugger-list-functions): Use debug--function-list instead of
debug-function-list.
* lisp/emacs-lisp/advice.el (ad-save-real-definition): Remove, unused.
(ad-special-form-p): Remove, use special-form-p instead.
(ad-set-advice-info): Use add-function and remove-function.
(ad--defalias-fset): Adjust accordingly.
* test/automated/advice-tests.el: New tests.
Diffstat (limited to 'lisp/emacs-lisp/advice.el')
-rw-r--r-- | lisp/emacs-lisp/advice.el | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el index 8239522c0f8..16c12aad29b 100644 --- a/lisp/emacs-lisp/advice.el +++ b/lisp/emacs-lisp/advice.el @@ -1776,27 +1776,6 @@ generates a copy of TREE." (funcall fUnCtIoN tReE)) (t tReE))) -;; @@ Save real definitions of subrs used by Advice: -;; ================================================= -;; Advice depends on the real, unmodified functionality of various subrs, -;; we save them here so advised versions will not interfere (eventually, -;; we will save all subrs used in code generated by Advice): - -(defmacro ad-save-real-definition (function) - (let ((saved-function (intern (format "ad-real-%s" function)))) - ;; Make sure the compiler is loaded during macro expansion: - (require 'byte-compile "bytecomp") - `(if (not (fboundp ',saved-function)) - (progn (fset ',saved-function (symbol-function ',function)) - ;; Copy byte-compiler properties: - ,@(if (get function 'byte-compile) - `((put ',saved-function 'byte-compile - ',(get function 'byte-compile)))) - ,@(if (get function 'byte-opcode) - `((put ',saved-function 'byte-opcode - ',(get function 'byte-opcode)))))))) - - ;; @@ Advice info access fns: ;; ========================== @@ -1849,9 +1828,12 @@ On each iteration VAR will be bound to the name of an advised function (defsubst ad-set-advice-info (function advice-info) (cond - (advice-info (put function 'defalias-fset-function #'ad--defalias-fset)) + (advice-info + (add-function :around (get function 'defalias-fset-function) + #'ad--defalias-fset)) ((get function 'defalias-fset-function) - (put function 'defalias-fset-function nil))) + (remove-function (get function 'defalias-fset-function) + #'ad--defalias-fset))) (put function 'ad-advice-info advice-info)) (defmacro ad-copy-advice-info (function) @@ -1974,8 +1956,8 @@ Redefining advices affect the construction of an advised definition." ;; to `ad-activate' by using `ad-with-auto-activation-disabled' where ;; appropriate, especially in a safe version of `fset'. -(defun ad--defalias-fset (function definition) - (fset function definition) +(defun ad--defalias-fset (fsetfun function definition) + (funcall (or fsetfun #'fset) function definition) (ad-activate-internal function nil)) ;; For now define `ad-activate-internal' to the dummy definition: @@ -2310,12 +2292,6 @@ See Info node `(elisp)Computed Advice' for detailed documentation." "Take a macro function DEFINITION and make a lambda out of it." `(cdr ,definition)) -(defun ad-special-form-p (definition) - "Non-nil if and only if DEFINITION is a special form." - (if (and (symbolp definition) (fboundp definition)) - (setq definition (indirect-function definition))) - (and (subrp definition) (eq (cdr (subr-arity definition)) 'unevalled))) - (defmacro ad-subr-p (definition) ;;"non-nil if DEFINITION is a subr." (list 'subrp definition)) @@ -2415,7 +2391,7 @@ definition (see the code for `documentation')." (cond ((ad-macro-p definition) 'macro) ((ad-subr-p definition) - (if (ad-special-form-p definition) + (if (special-form-p definition) 'special-form 'subr)) ((or (ad-lambda-p definition) @@ -2804,7 +2780,7 @@ in any of these classes." (origname (ad-get-advice-info-field function 'origname)) (orig-interactive-p (commandp origdef)) (orig-subr-p (ad-subr-p origdef)) - (orig-special-form-p (ad-special-form-p origdef)) + (orig-special-form-p (special-form-p origdef)) (orig-macro-p (ad-macro-p origdef)) ;; Construct the individual pieces that we need for assembly: (orig-arglist (ad-arglist origdef)) |