Emacs: What is Hook
What is Hook
A hook is a variable, its value is a list of functions ( Symbol or Lambda ).
Hook variables are associated with events. When the event happens, all functions in that hook are called.
js-modeis loaded, js-mode-hook's functions are called.
- when any command is called, post-command-hook's functions are called.
There are hundreds of hooks. Each Major Mode usually have at least 1 hook, designed to run when the mode is loaded.
Add Function to Hook
Here's example of setting proportional width font for some modes:
;; use proportional width font for some modes (add-hook 'js-mode-hook 'variable-pitch-mode)
💡 TIP: hook is often used to change Keys for Major Mode . see Emacs: Change Major Mode Keybinding
Remove Function in Hook
(remove-hook 'js-mode-hook 'variable-pitch-mode)
Show Value of a Hook
Emacs Lisp: Create a Hook
For emacs lisp programers: Emacs Lisp: Create a Hook