Function: ad--defalias-fset

ad--defalias-fset is a byte-compiled function defined in advice.el.gz.

Signature

(ad--defalias-fset FSETFUN FUNCTION NEWDEF)

Documentation

Handle re/definition of an advised FUNCTION during de/activation.

If FUNCTION does not have an original definition associated with it and the current definition is usable, then it will be stored as FUNCTION's original definition. If no current definition is available (even in the case of undefinition) nothing will be done. In the case of redefinition the action taken depends on the value of ad-redefinition-action (which see). Redefinition occurs when FUNCTION already has an original definition associated with it but got redefined with a new definition and then de/activated. If you do not like the current redefinition action change the value of ad-redefinition-action and de/activate again.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/advice.el.gz
(defun ad--defalias-fset (fsetfun function newdef)
  ;; Besides ad-redefinition-action we use this defalias-fset-function hook
  ;; for two other reasons:
  ;; - for `activation/deactivation' advices.
  ;; - to rebuild the ad-Advice-* function with the right argument names.
  "Handle re/definition of an advised FUNCTION during de/activation.
If FUNCTION does not have an original definition associated with it and
the current definition is usable, then it will be stored as FUNCTION's
original definition.  If no current definition is available (even in the
case of undefinition) nothing will be done.  In the case of redefinition
the action taken depends on the value of `ad-redefinition-action' (which
see).  Redefinition occurs when FUNCTION already has an original definition
associated with it but got redefined with a new definition and then
de/activated.  If you do not like the current redefinition action change
the value of `ad-redefinition-action' and de/activate again."
  (let ((original-definition (ad-get-orig-definition function))
	(current-definition (ad-get-orig-definition newdef)))
    (if original-definition
	(if current-definition
	    (if (not (eq current-definition original-definition))
		;; We have a redefinition:
		(if (not (memq ad-redefinition-action '(accept discard warn)))
		    (error "ad-redefinition-action: `%s' %s"
			   function "invalidly redefined")
		  (if (eq ad-redefinition-action 'discard)
		      nil ;; Just drop it!
		    (funcall (or fsetfun #'fset) function newdef)
                    (ad-activate-internal function)
		    (if (eq ad-redefinition-action 'warn)
			(message "ad-handle-definition: `%s' got redefined"
				 function))))
	      ;; either advised def or correct original is in place:
	      nil)
	  ;; We have an undefinition, ignore it:
          (funcall (or fsetfun #'fset) function newdef))
      (funcall (or fsetfun #'fset) function newdef)
      (when current-definition (ad-activate-internal function)))))