Function: ad-with-originals

ad-with-originals is a macro defined in advice.el.gz.

This macro is obsolete since 27.1.

Signature

(ad-with-originals FUNCTIONS &rest BODY)

Documentation

Binds FUNCTIONS to their original definitions and execute BODY.

For any members of FUNCTIONS that are not currently advised the rebinding will be a noop. Any modifications done to the definitions of FUNCTIONS will be undone on exit of this macro.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/advice.el.gz
;; @@ Tools:
;; =========

(defmacro ad-with-originals (functions &rest body)
  "Binds FUNCTIONS to their original definitions and execute BODY.
For any members of FUNCTIONS that are not currently advised the rebinding will
be a noop.  Any modifications done to the definitions of FUNCTIONS will be
undone on exit of this macro."
  (declare (indent 1) (obsolete nil "27.1"))
  (let* ((index -1)
	 ;; Make let-variables to store current definitions:
	 (current-bindings
          (mapcar (lambda (function)
                    (setq index (1+ index))
                    (list (intern (format "ad-oRiGdEf-%d" index))
                          `(symbol-function ',function)))
		  functions)))
    `(let ,current-bindings
      (unwind-protect
           (progn
             ,@(progn
                ;; Make forms to redefine functions to their
                ;; original definitions if they are advised:
                (setq index -1)
                (mapcar (lambda (function)
                          (setq index (1+ index))
                           `(fset ',function
                            (or (ad-get-orig-definition ',function)
                                ,(car (nth index current-bindings)))))
                        functions))
             ,@body)
        ,@(progn
           ;; Make forms to back-define functions to the definitions
           ;; they had outside this macro call:
           (setq index -1)
           (mapcar (lambda (function)
                     (setq index (1+ index))
                       `(fset ',function
                       ,(car (nth index current-bindings))))
                   functions))))))