# HG changeset patch # User Aidan Kehoe # Date 1210801678 -7200 # Node ID 42fad34efb3f4dcf7cc389b6dffcba286f67503d # Parent 04ec3340612e4e1b351e381fdfd75d0813fb1dec Support COMPARE-FN in add-to-list; thank you Brian Palmer. 2008-02-25 bpalmer * subr.el(add-to-list): add support for `compare-fn' to sync with emacs. diff -r 04ec3340612e -r 42fad34efb3f lisp/ChangeLog --- 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 + + * subr.el(add-to-list): add support for `compare-fn' to sync with + emacs. + 2008-05-14 Aidan Kehoe * mule/mule-coding.el (make-8-bit-choose-category):=20 diff -r 04ec3340612e -r 42fad34efb3f lisp/subr.el --- 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