From: Lars Ingebrigtsen Date: Mon, 3 May 2021 08:45:30 +0000 (+0200) Subject: Note that function symbols are preferred in `add-hook' X-Git-Tag: emacs-28.0.90~2635 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=eddb00c5bf9ed51bd0b6ea4ff1613f8af6e3cbdd;p=emacs.git Note that function symbols are preferred in `add-hook' * lisp/subr.el (add-hook): Note that FUNCTION should preferably be a symbol (bug#47992). --- diff --git a/lisp/subr.el b/lisp/subr.el index 964eb8f8ca2..7a055f2ba1e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1815,9 +1815,15 @@ This makes the hook buffer-local, and it makes t a member of the buffer-local value. That acts as a flag to run the hook functions of the global value as well as in the local value. -HOOK should be a symbol, and FUNCTION may be any valid function. If -HOOK is void, it is first set to nil. If HOOK's value is a single -function, it is changed to a list of functions." +HOOK should be a symbol. If HOOK is void, it is first set to +nil. If HOOK's value is a single function, it is changed to a +list of functions. + +FUNCTION may be any valid function, but it's recommended to use a +function symbol and not a lambda form. Using a symbol will +ensure that the function is not re-added if the function is +edited, and using lambda forms may also have a negative +performance impact when running `add-hook' and `remove-hook'." (or (boundp hook) (set hook nil)) (or (default-boundp hook) (set-default hook nil)) (unless (numberp depth) (setq depth (if depth 90 0)))