For example: (add-hook 'after-init-hook #'global-flycheck-mode)
Why #
needs to be prepended to 'global-flycheck-mode
?
For example: (add-hook 'after-init-hook #'global-flycheck-mode)
Why #
needs to be prepended to 'global-flycheck-mode
?
#'
is just a short-hand for using function
. From the elisp manual:
-- Special Form: function function-object
This special form returns FUNCTION-OBJECT without evaluating it.
In this, it is similar to ‘quote’ (see Quoting). But unlike
‘quote’, it also serves as a note to the Emacs evaluator and
byte-compiler that FUNCTION-OBJECT is intended to be used as a
function. Assuming FUNCTION-OBJECT is a valid lambda expression,
this has two effects:
• When the code is byte-compiled, FUNCTION-OBJECT is compiled
into a byte-code function object (see Byte Compilation).
• When lexical binding is enabled, FUNCTION-OBJECT is converted
into a closure. See Closures.
You can see the difference when byte-compiling/loading this
(setq f1 '(lambda (x) (* x x)))
(setq f2 #'(lambda (x) (* x x)))
Only the the correctly quoted form is byte-compiled:
(byte-code-function-p f1)
nil
(byte-code-function-p f2)
t