18

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.

16

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.)

  • Right about warnings. As to lambdas, #' instructs the compiler to compile the lambda, as opposed to plain quote, which doesn't. I've reformulated in a hopefully clearer manner. – jch Apr 26 '15 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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