On Mon, Sep 05, 2022 at 12:16:31AM +0200, Alessandro Bertulli wrote: > > Stefan Monnier via Users list for the GNU Emacs text editor writes: > > > `LaTeX-mode-map`, like most package variables, is only defined once > > its package is actually loaded, which is done lazily in response to the > > use of the package (e.g. opening a LaTeX file). > > > > So it's normal that `LaTeX-mode-map` is not defined when your init file > > is loaded. This is on purpose to try and speed up Emacs's startup. > > > > You can use things like: > > > > (with-eval-after-load 'latex > > (define-key LaTeX-mode-map (kbd "C-c a") #'my-bar) > > (define-key LaTeX-mode-map (kbd "C-c b") #'my-foo)) > > You honestly opened a world to me. I have long wondered the difference > between require and with-eval-after-load (of course I could have read > the docs, but I never found time). :-) > > > or > > > > (defun my-latex-setup () > > (define-key LaTeX-mode-map (kbd "C-c a") #'my-bar) > > (define-key LaTeX-mode-map (kbd "C-c b") #'my-foo)) > > (add-hook 'LaTeX-mode-hook #'my-latex-setup) > > > > in order to delay the customization to after the variable is defined. > > Isn't this redundant? You call the function every time a LaTeX file is > loaded. The first method is preferrable, right? I think they are doing different things. There are things you want to happen on each buffer when and once it becomes a "LaTeX buffer". Setting buffer-local variables comes to mind. And to nitpick a bit more: it doesn't happen when a LaTeX file is loaded, but when LaTeX mode is "switched on", that can happen in other occassions too (when creating a new buffer you know it will be LaTeX, but you can also switch the mode on and off; LaTeX isn't a good example for the second). Cheers -- t