You can do this. I think it does what you're looking for.
(defalias 'bar 'forward-char)
(advice-add 'bar :after (lambda (&rest _) (message "AFTER")))
M-x forward-char ; No message "AFTER"
M-x bar ; Message "AFTER"
(symbol-function 'forward-char) ; => #<subr forward-char>
(symbol-function 'bar) ; => forward-char
IOW, you advise bar
, not the original function, forward-char
. And you defalias bar
to forward-char
, not to (symbol-function 'forward-char)
.
Note this difference:
(defalias 'foo (symbol-function 'forward-char))
(eq (symbol-function 'foo) (symbol-function 'forward-char)) ; => t
(defalias 'bar 'forward-char)
(eq (symbol-function 'bar) (symbol-function 'forward-char)) ; => nil
(symbol-function 'forward-char) ; => #<subr forward-char>
(symbol-function 'bar) ; => forward-char