35

I'm a little new to Emacs. When looking at some of the configurations, I found there are two types command in "add-hook".

(add-hook 'LaTeX-mode-hook #'LaTeX-math-mode)

and

(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

This has confused me for a long time and I don't know how to search "#'" in google...

Thanks.

3

1 Answer 1

33

In Emacs Lisp, if foo is a symbol, then 'foo and #'foo are completely equivalent. The latter form (with #') is preferred when foo is a function, as it documents the fact that it is intended to be funcalled.

Your two forms are therefore completely equivalent, and the one with #' is preferred.

Edit: as pointed out by Malabarba, this is not quite true: #' on symbols will cause the byte-compiler to emit a warning if the function is not defined.

(Note that this is not the case for lambda-forms, for which plain ' prevents the byte-compiler from compiling the lambda-form, as documented elsewhere. Note further that this is also not necessarily the case in other Lisp dialects, for example in Common Lisp #'foo performs early binding.)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.