Emacs: Hook

By Xah Lee. Date: . Last updated: .

What is Hook

For example,

Hook is similar to the concept of event in JavaScript . Adding functions to a hook is similar to adding event handlers. (note: emacs lisp manual also uses the term “event”, but that is lower level events to emacs.)

Hook is often used to change Keys for Major Mode . see Emacs Keys: Change Major Mode Keys

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)

Remove Function in Hook

(remove-hook 'js-mode-hook 'variable-pitch-mode)
;; remove all functions in the hook
(setq js-mode-hook nil)

Show Value of a Hook

Emacs Hook

Emacs, major mode, hook

Emacs Principle