Function: ad-activate-advised-definition

ad-activate-advised-definition is a byte-compiled function defined in advice.el.gz.

Signature

(ad-activate-advised-definition FUNCTION COMPILE)

Documentation

Redefine FUNCTION with its advised definition from cache or scratch.

The resulting FUNCTION will be compiled if ad-should-compile returns t. The current definition and its cache-id will be put into the cache.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/advice.el.gz
(defun ad-activate-advised-definition (function compile)
  "Redefine FUNCTION with its advised definition from cache or scratch.
The resulting FUNCTION will be compiled if `ad-should-compile' returns t.
The current definition and its cache-id will be put into the cache."
  (let* ((verified-cached-definition
          (if (ad-verify-cache-id function)
              (ad-get-cache-definition function)))
         (advicefunname (ad-get-advice-info-field function 'advicefunname))
         (old-ispec (interactive-form advicefunname)))
    (fset advicefunname
          (or verified-cached-definition
              (ad-make-advised-definition function)))
    (put advicefunname 'function-documentation
	 `(ad--make-advised-docstring ',advicefunname))
    (unless (equal (interactive-form advicefunname) old-ispec)
      ;; If the interactive-spec of advicefunname has changed, force nadvice to
      ;; refresh its copy.
      (advice-remove function advicefunname))
    (advice-add function :around advicefunname)
    (if (ad-should-compile function compile)
	(ad-compile-function function))
    (if verified-cached-definition
	(if (not (eq verified-cached-definition
                     (symbol-function advicefunname)))
	    ;; we must have compiled, cache the compiled definition:
	    (ad-set-cache function (symbol-function advicefunname)
                          (ad-get-cache-id function)))
      ;; We created a new advised definition, cache it with a proper id:
      (ad-clear-cache function)
      ;; ad-make-cache-id needs the new cached definition:
      (ad-set-cache function (symbol-function advicefunname) nil)
      (ad-set-cache
       function (symbol-function advicefunname) (ad-make-cache-id function)))))