I am studying the following code snippet taken from prelude-c.el:
;; taken from prelude-c.el
(defun prelude-makefile-mode-defaults ()
(whitespace-toggle-options '(tabs))
(setq indent-tabs-mode t))
(setq prelude-makefile-mode-hook 'prelude-makefile-mode-defaults)
(add-hook 'makefile-mode-hook (lambda ()
(run-hooks 'prelude-makefile-mode-hook)))
The author defined a function named prelude-makefile-mode-defaults
, then made prelude-makefile-mode-hook
an alias to it, and finally run it with lambda
and run-hooks
. This looks tedious to me. In my humble opinion, it can be simplified to
(defun prelude-makefile-mode-defaults ()
(whitespace-toggle-options '(tabs))
(setq indent-tabs-mode t))
(add-hook 'makefile-mode-hook #'prelude-makefile-mode-defaults)
Now it is much clearer, and they appears to have the same effect, but of course, the authors of prelude.el must be much more sophisticated than me, who is just a beginner. Is there any hidden advantage of writing down all these seemingly redundant code?
(foo)
and(run-hooks foo)
? If they are equivalent, then the functionrun-hooks
would be pointless... – nalzok Feb 16 '19 at 16:22prelude
might be useful. – user12563 Feb 20 '19 at 18:46