changeset 4461:42fad34efb3f

Support COMPARE-FN in add-to-list; thank you Brian Palmer. 2008-02-25 bpalmer <bpalmer@gmail.com> * subr.el(add-to-list): add support for `compare-fn' to sync with emacs.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 14 May 2008 23:47:58 +0200
parents 04ec3340612e
children 34b42224a066
files lisp/ChangeLog lisp/subr.el
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed May 14 23:43:12 2008 +0200
+++ b/lisp/ChangeLog	Wed May 14 23:47:58 2008 +0200
@@ -1,3 +1,8 @@
+2008-02-25  bpalmer  <bpalmer@gmail.com>
+
+	* subr.el(add-to-list): add support for `compare-fn' to sync with
+	emacs.
+
 2008-05-14  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* mule/mule-coding.el (make-8-bit-choose-category):=20
--- a/lisp/subr.el	Wed May 14 23:43:12 2008 +0200
+++ b/lisp/subr.el	Wed May 14 23:47:58 2008 +0200
@@ -390,19 +390,21 @@
 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