student
student

Reputation: 1646

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

Upvotes: 2

Views: 257

Answers (2)

Nicolas Dudebout
Nicolas Dudebout

Reputation: 9262

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.

Upvotes: 4

abo-abo
abo-abo

Reputation: 20342

I wouldn't say that it matters much: you can check this by e.g. 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.

Upvotes: 2

Related Questions