... when a symbol referencing a function is actually used?
Documentation states:
Like ‘add-function’ but for the function named SYMBOL. Contrary to ‘add-function’, this will properly handle the cases where SYMBOL is defined as a macro, alias, command, ...
I usually see the following around:
(advice-add 'some-function :after #'some-other-function)
My question is, wouldn't be the case to use #'some-function
in that case?
Of course I tried, and it works, and in fact with the sharp quote, Emacs is able to throw a warning if some-function
is not defined when I byte-compile the code.
I even tried advising aliased functions (with defalias
) and saw no difference.
So why the common advice is not to use the sharp quote for SYMBOL
too?
advice-add
behaves likedefadvice
then there's no need forsome-function
to be defined when you byte-compile the code. The function will be advised if and when it becomes defined. I guess if you want byte-compiler warnings being thrown in the case where the function is not yet defined, then#'
would be useful.some-function
is expected to be defined whenadvice-add
is evaluated. Thanks for pointing this out.#'
is: use it if and only if(lambda (args...) (FOO args...))
could be used as well.advice-add
wants a symbol and anyway that would advise a (anonymous) wrapper not the function itself, which makes little sense in this context.