Skip to content

Commit d07f177

Browse files
committed
Clarify add-to-list documentation (bug#39373)
While add-to-list often works with lexical variables, this is a hack that isn't always effective; better tell the user not to try. * doc/lispref/lists.texi (List Variables): Add a note about lexical variables to the add-to-list description. Fix the equivalent code. * lisp/subr.el (add-to-list): Amend doc string.
1 parent d3d2ea9 commit d07f177

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

doc/lispref/lists.texi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ non-@code{nil}, it is added at the end.
777777
The argument @var{symbol} is not implicitly quoted; @code{add-to-list}
778778
is an ordinary function, like @code{set} and unlike @code{setq}. Quote
779779
the argument yourself if that is what you want.
780+
781+
Do not use this function when @var{symbol} refers to a lexical
782+
variable.
780783
@end defun
781784

782785
Here's a scenario showing how to use @code{add-to-list}:
@@ -799,8 +802,9 @@ foo ;; @r{@code{foo} was changed.}
799802
@var{value})} is this:
800803

801804
@example
802-
(or (member @var{value} @var{var})
803-
(setq @var{var} (cons @var{value} @var{var})))
805+
(if (member @var{value} @var{var})
806+
@var{var}
807+
(setq @var{var} (cons @var{value} @var{var})))
804808
@end example
805809

806810
@defun add-to-ordered-list symbol element &optional order

lisp/subr.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ COMPARE-FN if that's non-nil.
18451845
If ELEMENT is added, it is added at the beginning of the list,
18461846
unless the optional argument APPEND is non-nil, in which case
18471847
ELEMENT is added at the end.
1848+
LIST-VAR should not refer to a lexical variable.
18481849
18491850
The return value is the new value of LIST-VAR.
18501851

0 commit comments

Comments
 (0)