Emacs Elisp Overriding Default Value

2019-09-19 06:30发布

问题:

I have several abbrev defined that I was accessible everywhere except in latex mode. I defined

(setq-default abbrev-mode t)
(add-hook 'latex-mode-hook (lambda () (abbrev-mode -1)))

But whenever I open a latex file it still has abbrev mode enabled. What's going on?

回答1:

Never worked with latex before, but for me the following works fine:

(setq auto-mode-alist (cons '("\\.lat\\'" . latex-mode) auto-mode-alist))
(setq-default abbrev-mode t)
(add-hook 'latex-mode-hook (lambda () (abbrev-mode -1)))

M-x abbrev-mode
%Abbrev mode enabled in current buffer

Please make sure the emacs recognized your file as a latex file, the first line I wrote should do the trick.



回答2:

The reason was that AUCTex uses LaTeX-mode-hook. Thanks to stefan in the comment for pointing that out



标签: emacs elisp