简体   繁体   English

排除LaTeX模式挂钩是个好主意吗?

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

Is it a good idea to factor out (add-hook 'LaTeX-mode-hook) ? 排除(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: 或者可以排除LaTeX-mode-hook语句并编写如下内容:

(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. 您的问题有两个部分:分解和使用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. 我发现分解是一个好主意,因为维护.emacs文件更容易,因为在其中添加钩子的位置只有一个。 However, using a lambda for this purpose is slightly frowned upon. 但是,为此目的而使用lambda却很少。 If you look at the value of the hook after you used a lambda you will see that it is "ugly". 如果您在使用lambda之后查看钩子的值,您会发现它是“丑陋的”。 Furthermore it will be harder to work on that hook. 此外,在该钩子上工作将更加困难。 For example, you sometimes want to disable a hook with remove-hook . 例如,有时您想使用remove-hook禁用remove-hook It is easier to do so when you have named your hook explicitely instead of using a lambda. 当显式命名钩子而不是使用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. 我不会说这很重要:您可以通过使用两种类型的语句在*scratch*评估LaTeX-mode-hook来进行检查。 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. 将其保留在一个lambda一个优点是它更易于维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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