]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve docstring of add-hook and remove-hook
authorTomas Nordin <tomasn@posteo.net>
Thu, 27 Feb 2025 21:06:25 +0000 (22:06 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 20:51:09 +0000 (21:51 +0100)
* lisp/subr.el (add-hook, remove-hook): Remove detail about setting to
nil and talk about functions instead of hooks.  (Bug#72915)

(cherry picked from commit 1352b184f3f7bd1e31ee71ee4b60491dacaf347b)

lisp/subr.el

index 6b08a36c713360cda3a1b6b5ec3ba57c260c7830..8f524e11298cb2b13e98476dea3cd38dd55c4f62 100644 (file)
@@ -2165,6 +2165,9 @@ instead; it will indirectly limit the specpdl stack size as well.")
   "Add to the value of HOOK the function FUNCTION.
 FUNCTION is not added if already present.
 
+HOOK should be a symbol.  If HOOK is void, or if HOOK's value is a
+single function, it is changed to a list of functions.
+
 The place where the function is added depends on the DEPTH
 parameter.  DEPTH defaults to 0.  By convention, it should be
 a number between -100 and 100 where 100 means that the function
@@ -2183,10 +2186,6 @@ 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.  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
@@ -2251,10 +2250,11 @@ performance impact when running `add-hook' and `remove-hook'."
       (set-default hook hook-value))))
 
 (defun remove-hook (hook function &optional local)
-  "Remove from the value of HOOK the function FUNCTION.
-HOOK should be a symbol, and FUNCTION may be any valid function.  If
-FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
-list of hooks to run in HOOK, then nothing is done.  See `add-hook'.
+  "Remove FUNCTION from HOOK's functions.
+HOOK should be a symbol, and FUNCTION may be any valid function.
+Do nothing if HOOK does not currently contain FUNCTION.
+Compare functions with `equal`, which means that it can be
+slow if FUNCTION is not a symbol.  See `add-hook'.
 
 The optional third argument, LOCAL, if non-nil, says to modify
 the hook's buffer-local value rather than its default value.