34

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.

X.Arthur
  • 443
  • 4
  • 9
  • 2
    Sorry, my bad. Found the answer: http://stackoverflow.com/questions/2701698/emacs-elisp-what-is-the-hash-pound-number-sign-octothorp-symbol-used-for – X.Arthur Apr 26 '15 at 18:25
  • See also http://www.emacswiki.org/emacs/EmacsSymbolNotation – xuchunyang Apr 26 '15 at 18:32
  • 2
    Duplicates on other sites are fine. There's one here, though, which is *almost* a duplicate. http://emacs.stackexchange.com/q/3595/50 – Malabarba Apr 26 '15 at 18:49

1 Answers1

32

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

jch
  • 5,680
  • 22
  • 39