]> git.eshelyaron.com Git - emacs.git/commitdiff
(add-to-list): New argument COMPARE-FN.
authorRichard M. Stallman <rms@gnu.org>
Sun, 10 Sep 2006 17:45:42 +0000 (17:45 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 10 Sep 2006 17:45:42 +0000 (17:45 +0000)
lisp/subr.el

index b2ea997d62353436178fdec66c85d397a11fc5ef..33aac6081f98dc039ef0330b1766d5373be6c55d 100644 (file)
@@ -1085,9 +1085,10 @@ the hook's buffer-local value rather than its default value."
            (kill-local-variable hook)
          (set hook hook-value))))))
 
-(defun add-to-list (list-var element &optional append)
+(defun add-to-list (list-var element &optional append compare-fn)
   "Add ELEMENT to the value of LIST-VAR if it isn't there yet.
-The test for presence of ELEMENT is done with `equal'.
+The test for presence of ELEMENT is done with `equal',
+or with COMPARE-FN if that's non-nil.
 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.
@@ -1099,7 +1100,13 @@ 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 compare-fn
+         (let (present)
+           (dolist (elt (symbol-value list-var))
+             (if (funcall compare-fn element elt)
+                 (setq present t)))
+           present)
+       (member element (symbol-value list-var)))
       (symbol-value list-var)
     (set list-var
         (if append
@@ -1730,16 +1737,20 @@ in milliseconds; this was useful when Emacs was built without
 floating point support.
 
 \(fn SECONDS &optional NODISP)"
-  (when (or obsolete (numberp nodisp))
-    (setq seconds (+ seconds (* 1e-3 nodisp)))
-    (setq nodisp obsolete))
-  (if noninteractive
-      (progn (sleep-for seconds) t)
-    (unless nodisp (redisplay))
-    (or (<= seconds 0)
-       (let ((read (read-event nil nil seconds)))
-         (or (null read)
-             (progn (push read unread-command-events) nil))))))
+  (unless (or unread-command-events
+             unread-post-input-method-events
+             unread-input-method-events
+             (>= unread-command-char 0))
+    (when (or obsolete (numberp nodisp))
+      (setq seconds (+ seconds (* 1e-3 nodisp)))
+      (setq nodisp obsolete))
+    (if noninteractive
+       (progn (sleep-for seconds) t)
+      (unless nodisp (redisplay))
+      (or (<= seconds 0)
+         (let ((read (read-event nil nil seconds)))
+           (or (null read)
+               (progn (push read unread-command-events) nil)))))))
 \f
 ;;; Atomic change groups.