Add support for a compare-fn in add-to-list

Aidan Kehoe kehoea at parhasard.net
Wed May 14 17:59:33 EDT 2008


APPROVE COMMIT

NOTE: This patch has been committed

Thank you Brian! Note that I’ve made a change to follow this up; it calls
#'member* unconditionally, as Stephen suggested, and uses (or ...) to
determine COMPARE-FN.

 Ar an cúigiú lá is fiche de mí Feabhra, scríobh Brian Palmer: 

 > Apparently gnu emacs has this, and it's a comparatively easy thing to add,
 > so I thought it'd be worth trying to add. These are the diff lines
 > from
 > 
 > comparing with http://hg.debian.org/hg/xemacs/xemacs-beta
 > searching for changes
 > changeset:   4425:fa7844674ed2
 > user:        bpalmer at bpalmer-mac.local
 > date:        Mon Feb 25 04:45:41 2008 -0800
 > summary:     * subr.el(add-to-list): add support for `compare-fn' to sync
 > with
 > 
 > diff -r 42711a251efd -r fa7844674ed2 lisp/subr.el
 > --- a/lisp/subr.el      Fri Feb 15 13:11:56 2008 +0100
 > +++ b/lisp/subr.el      Mon Feb 25 04:45:41 2008 -0800
 > @@ -390,19 +390,21 @@ argument to `add-one-shot-hook'."
 >  argument to `add-one-shot-hook'."
 >    (add-one-shot-hook hook function append t))
 > 
 > -(defun add-to-list (list-var element &optional append)
 > +(defun add-to-list (list-var element &optional append compare-fn)
 >    "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.
 > +The test for presence of ELEMENT is done with COMPARE-FN; if
 > +COMPARE-FN is nil, then it defaults to `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."
 > -  (if (member element (symbol-value list-var))
 > +  (if (if (not compare-fn)
 > +         (member element (symbol-value list-var))
 > +       (member* element (symbol-value list-var) :test compare-fn))
 >        (symbol-value list-var)
 >      (set list-var
 >           (if append

-- 
¿Dónde estará ahora mi sobrino Yoghurtu Nghé, que tuvo que huir
precipitadamente de la aldea por culpa de la escasez de rinocerontes?



More information about the XEmacs-Patches mailing list