Inspecting / modifying Emacs hooks for minor modes
emacs
Solution
(1) Emacs does not define a minor mode hook automatically, but you can define one with the `:after-hook` keyword (as per manual page for defining minor mode). (UPDATE: as per Legoscia's last comment, the minor-mode hook gets defined automatically as of emacs version 24.3.90. Thanks, Legoscia!)
(2) hooks are just variables, so you can inspect them as you would any other variable (e.g., `C-h v` or `M-x describe-variable RET some-hook`).
(3) you can use `add-hook` and `remove-hook` to change elements of the hook (see the manual on setting hooks), eg:
(add-hook 'python-mode-hook 'my-python-mode-hook)
(remove-hook 'python-mode-hook 'my-python-mode-hook)
(Note, by the way, that it's preferable to use named functions in your hooks rather than anonymous `lambda`s because you can use `remove-hook` on your named functions.)
Problem
I use the following to enable `linum-mode` for Python buffers: ``` (defun my-python-mode-hook () (linum-mode 1)) (add-hook 'python-mode-hook 'my-python-mode-hook) ``` However, my understanding of hooks is still quite limited. As far as I understand, the code above adds a function to `python-mode-hook` so I assume this hook has already been defined, and may even have some code in it already. With this: - Does Emacs define a hook of the form `<minor_mode_name>-hook` for all minor modes? Or do the modes themshelves define them? - How can I look up the code added to a hook already? - How can I change elements of that hook? This question is partly motivated by this GitHub issue for elpy where `elpy-mode` seems to have left a hook for `python-mode` that doesn't go away after uninstalling elpy.