Function: advice--add-function

advice--add-function is a byte-compiled function defined in nadvice.el.gz.

Signature

(advice--add-function HOW REF FUNCTION PROPS)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/nadvice.el.gz
;;;###autoload
(defun advice--add-function (how ref function props)
  (when (and (featurep 'native-compile)
             (subr-primitive-p (gv-deref ref)))
    (let ((subr-name (intern (subr-name (gv-deref ref)))))
      ;; Requiring the native compiler to advice `macroexpand' cause a
      ;; circular dependency in eager macro expansion.  uniquify is
      ;; advising `rename-buffer' while being loaded in loadup.el.
      ;; This would require the whole native compiler machinery but we
      ;; don't want to include it in the dump.  Because these two
      ;; functions are already handled in
      ;; `native-comp-never-optimize-functions' we hack the problem
      ;; this way for now :/
      (unless (memq subr-name '(macroexpand rename-buffer))
        ;; Must require explicitly as during bootstrap we have no
        ;; autoloads.
        (require 'comp)
        (comp-subr-trampoline-install subr-name))))
  (let* ((name (cdr (assq 'name props)))
         (a (advice--member-p (or name function) (if name t) (gv-deref ref))))
    (when a
      ;; The advice is already present.  Remove the old one, first.
      (setf (gv-deref ref)
            (advice--remove-function (gv-deref ref)
                                     (or name (advice--car a)))))
    (setf (gv-deref ref)
          (advice--make how function (gv-deref ref) props))))