Note added. By "independent copy," I mean that a modification, such as an advice, to the original function should not affect the copy of that function. Let's take this code as an example:
(defun test-origin ()
"Test function"
(message "origin"))
(defalias 'defalias-copy 'test-origin
"Alias of `test-origin'")
(defalias 'symbol-function-copy
(symbol-function 'test-origin)
"Copy (in my intention) of `test-origin`")
(defun test-override ()
(message "override"))
- If I advice
test-origin
:
(advice-add 'test-origin
:override
#'test-override)
(test-origin) ; => "override"
(defalias-copy) ; => "override"
(symbol-function-copy) ; => "origin"
also defalias-copy
get adviced.
- If I advice
defalias-copy
:
(advice-remove 'test-origin #'test-override)
(advice-add 'defalias-copy
:override
#'test-override)
(test-origin) ; => "origin"
(defalias-copy) ; => "override"
(symbol-function-copy) ; => "origin"
- If I advice
symbol-function-copy
(advice-remove 'defalias-copy #'test-override)
(advice-add 'symbol-function-copy
:override
#'test-override)
(test-origin) ; => "origin"
(defalias-copy) ; => "origin"
(symbol-function-copy) ; => "override"
But due to the bug mentioned above, I suspect that the combination of defalias
and symbol-function
is not the appropriate way to obtain a copy of a function that is completely independent from the original