summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>2000-10-10 02:47:30 +0000
committerMiles Bader <miles@gnu.org>2000-10-10 02:47:30 +0000
commitc8bfa68964432f0d00c23917a7c8a28dca5ae1a3 (patch)
treefadc1497d732569caaa81a7192f8f90d28affc62 /lisp/subr.el
parent10e5ab47673405960c83a866d96fcecbc4522a8b (diff)
downloademacs-c8bfa68964432f0d00c23917a7c8a28dca5ae1a3.tar.gz
(add-to-list): Add optional argument APPEND.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el11
1 files changed, 8 insertions, 3 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index ebf35337bb3..ca75c9f97a3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -761,10 +761,12 @@ To make a hook variable buffer-local, always use
;; Set the actual variable
(if local (set hook hook-value) (set-default hook hook-value))))
-(defun add-to-list (list-var element)
+(defun add-to-list (list-var element &optional append)
"Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
The test for presence of ELEMENT is done with `equal'.
-If ELEMENT is added, it is added at the beginning of the list.
+If ELEMENT is added, it is added at the beginning of the list,
+unless the optional argument APPEND is non-nil, in which case
+ELEMENT is added at the end.
If you want to use `add-to-list' on a variable that is not defined
until a certain package is loaded, you should put the call to `add-to-list'
@@ -773,7 +775,10 @@ into a hook function that will be run only after loading the package.
other hooks, such as major mode hooks, can do the job."
(if (member element (symbol-value list-var))
(symbol-value list-var)
- (set list-var (cons element (symbol-value list-var)))))
+ (set list-var
+ (if append
+ (append (symbol-value list-var) (list element))
+ (cons element (symbol-value list-var))))))
;;;; Specifying things to do after certain files are loaded.