Skip to content

Commit 53f0de5

Browse files
author
Richard Stallman
committed
Lispref: Explain avoiding lambdas on hooks.
(lispref/modes.texi): Explain avoiding lambdas on hooks.
1 parent 12d004d commit 53f0de5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

doc/lispref/modes.texi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,26 @@ non-@code{nil} value, it returns that value; otherwise it returns
135135
@node Setting Hooks
136136
@subsection Setting Hooks
137137

138-
Here's an example that uses a mode hook to turn on Auto Fill mode when
139-
in Lisp Interaction mode:
138+
Here's an example that adds a funtion to a mode hook to turn
139+
on Auto Fill mode when in Lisp Interaction mode:
140140

141141
@example
142142
(add-hook 'lisp-interaction-mode-hook 'auto-fill-mode)
143143
@end example
144144

145+
The value of a hook variable should be a list of functions. You can
146+
manipulate that list using the normal Lisp facilities, but the modular
147+
way is to use the functions @code{add-hook} and @code{remove-hook},
148+
defined below. They take care to handle some unusual situations and
149+
avoid problems.
150+
151+
It works to put a @code{lambda}-expression function on a hook, but
152+
we recommend avoiding this because it can lead to confusion. If you
153+
add the same @code{lambda}-expression a second time but write it
154+
slightly differently, you will get two equivalent but distinct
155+
functions on the hook. If you then remove one of them, the other will
156+
still be on it.
157+
145158
@defun add-hook hook function &optional depth local
146159
This function is the handy way to add function @var{function} to hook
147160
variable @var{hook}. You can use it for abnormal hooks as well as for

0 commit comments

Comments
 (0)