Let's assume the particular mode I'm working with is python-mode.
The Emacs manual specifies following for hooks:
Every major mode command is supposed to run a normal hook called the mode hook as one of the last steps of initialization.
From Major mode conventions:
Each major mode should have a normal mode hook named
modename-mode-hook. The very last thing the major mode command should do is to callrun-mode-hooks.
And with-eval-after-load executes code after code is loaded (e.g. required), and runs immediately if already required.
I have following in my init file:
(add-hook 'python-mode-hook 'my-post-python)
Also I have added
(with-eval-after-load 'python-mode
(setq-default python-basic-offset 7) ; setting some option
(add-to-list 'python-globals-list "console"))
Now assuming I open Emacs, followed by opening a Python file buffer, what are the loading/execution orders with respect to hooks and with-eval-after-load? From the docs specified at start, it seems mode hooks will run before with-eval-after-load code?
More specifically, are mode hooks are run every time a buffer is entered/ made the current buffer? (P.S. this is hard to find from the docs/manual, any links clarifying any of the above in the docs/manual are welcome).
Assuming
python.elhas not already been loaded, then:foo.py.set-auto-modeis called and determines thatpython-modeis appropriate, and calls that.python-modefunction is (at this point) an autoload definition for thepython-modelibrary1, which is consequently loaded.with-eval-after-loadfor thepython-modelibrary is evaluated.python-modefunction (newly defined by loading the library) is called, at the end of which:python-mode-hookruns.No, they run every time the mode function is called.
1 The default library is
python.elwhich uses(provide 'python), but from yourwith-eval-after-loadyou're evidentially using thepython-mode.ellibrary instead.