From c8bfa68964432f0d00c23917a7c8a28dca5ae1a3 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 10 Oct 2000 02:47:30 +0000 Subject: [PATCH] (add-to-list): Add optional argument APPEND. --- lisp/subr.el | 11 ++++++++--- 1 file 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. -- 2.39.2