I'm trying to adapt this answer to use-package elegantly. It requires that I hook a lambda function to python-mode. I came up with this solution — which works:
(use-package python
:hook
(python-mode . (lambda ()
(setq indent-tabs-mode t)
(setq tab-width 4)
(setq python-indent-offset 4))))
but I find it inelegant, as it requires me to repeat "python-mode" inside the use-package for python (shouldn't that be obvious?). Is there a better way, and if not, why? I'm not sure I understand well the hook process in use-package.
prog-mode
would be. That's why you need to give its name first. In this case why not just place those variables in:config
?:config
? I reread your first sentence 5 times and still find it a little cryptic. It means that in use-package,:hook
is used to load a package that the current package would need if a different third package were loaded, is that it?indent-tabs-mode
andtab-width
are buffer-local variables, and since they potentially have optimal values that differ depending on the major mode you're in, they should NOT be moved inside:config
as suggested (unless you always want to have that as default, for all major modes). You might movepython-indent-offset
though.:config
has code that is evaluated after the major mode is loaded (usually once), and the functions you add to the hook are called every time a new buffer triggers that major mode.X
and I want to add to a hook, that the hook name would beX-mode-hook
?". The answer is no, it's not obvious. It might well be a common case, but it's absolutely not a given.