简体   繁体   中英

Is it a good idea to factor out LaTeX-mode-hook?

Is it a good idea to factor out (add-hook 'LaTeX-mode-hook) ? What are the advantages and disadvantage when doing this.

For example you could write:

(add-hook 'LaTeX-mode-hook (lambda ()
;;(add-to-list [...]
)

(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)

;;[...lots of other LaTeX config stuff]

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

or one could factor out the LaTeX-mode-hook statement and write something like this:

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

;;(add-to-list) [...]

(TeX-PDF-mode)

;;[...lots of other LaTeX config stuff]

(flyspell-mode)
))

There are two parts to your question: factoring and using a lambda.

I find that factoring is a good idea because it is easier to maintain a .emacs file where there is a single location where the hook is added. However, using a lambda for this purpose is slightly frowned upon. If you look at the value of the hook after you used a lambda you will see that it is "ugly". Furthermore it will be harder to work on that hook. For example, you sometimes want to disable a hook with remove-hook . It is easier to do so when you have named your hook explicitely instead of using a lambda.

I wouldn't say that it matters much: you can check this by eg evaluating LaTeX-mode-hook in *scratch* with both types of statements. It will look slightly different, but the executing behavior should be the same.

One advantage of keeping it in one lambda is that it's easier to maintain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM