Understanding hooks

72 Views Asked by At

I want to understand hooks in elisp. I have tematika-minor-mode which needs to be activated for emacs-lisp-mode and sh-mode.

Is this the way to do it ?

(defun tematika-activate ()
  "Activate `tematika-minor-mode'."
  (tematika-minor-mode 1))

(defun tematika-hooks ()
  "TODO"
  (add-hook 'emacs-lisp-mode-hook #'tematika-activate)
  (add-hook 'sh-mode-hook #'tematika-activate))
1

There are 1 best solutions below

3
phils On BEST ANSWER

Prior to Emacs 24.1 that was correct.

Since 24.1 you don't need the intermediate function. Quoting its NEWS file:

* Incompatible Lisp Changes in Emacs 24.1

** Passing a nil argument to a minor mode function call now ENABLES
the minor mode unconditionally.  This is so that you can write e.g.

 (add-hook 'text-mode-hook #'foo-mode)

to enable foo-mode in Text mode buffers, removing the need for
`turn-on-foo-mode' style functions.  This affects all mode commands
defined by `define-minor-mode'.  If called interactively, the mode
command still toggles the minor mode.