# HG changeset patch # User youngs # Date 1024869813 0 # Node ID 64f38afaab2d741de8f421481079c4b75d884f72 # Parent e54d47b2d7360d2f47f0922e54f04b3adcf61fa2 [xemacs-hg @ 2002-06-23 22:03:32 by youngs] 2002-06-22 Ville Skyttä * subr.el (add-to-list): Sync with GNU Emacs 21.2, adding the "&optional append" argument. diff -r e54d47b2d736 -r 64f38afaab2d lisp/ChangeLog --- a/lisp/ChangeLog Sun Jun 23 09:54:41 2002 +0000 +++ b/lisp/ChangeLog Sun Jun 23 22:03:33 2002 +0000 @@ -1,3 +1,8 @@ +2002-06-22 Ville Skyttä + + * subr.el (add-to-list): Sync with GNU Emacs 21.2, adding the + "&optional append" argument. + 2002-06-23 Stephen J. Turnbull * unicode.el (load-unicode-tables): Comment loading 8859-1.TXT. diff -r e54d47b2d736 -r 64f38afaab2d lisp/subr.el --- a/lisp/subr.el Sun Jun 23 09:54:41 2002 +0000 +++ b/lisp/subr.el Sun Jun 23 22:03:33 2002 +0000 @@ -301,16 +301,24 @@ (make-local-hook hook) (add-one-shot-hook hook function append t)) -(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, +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' into a hook function that will be run only after loading the package. `eval-after-load' provides one way to do this. In some cases other hooks, such as major mode hooks, can do the job." - (or (member element (symbol-value list-var)) - (set list-var (cons element (symbol-value list-var))))) + (if (member element (symbol-value list-var)) + (symbol-value list-var) + (set list-var + (if append + (append (symbol-value list-var) (list element)) + (cons element (symbol-value list-var)))))) ;; XEmacs additions ;; called by Fkill_buffer()