diff options
| author | Richard M. Stallman | 2006-09-10 17:45:42 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-09-10 17:45:42 +0000 |
| commit | 62e197b19443de3cf3c7eb4c150dc343d6175d2f (patch) | |
| tree | c74af69d772ae4c811b8fcd17874d8e180e5d929 | |
| parent | 3b5e5e309bea103e63293fe0fe4f5c255ce04be2 (diff) | |
| download | emacs-62e197b19443de3cf3c7eb4c150dc343d6175d2f.tar.gz emacs-62e197b19443de3cf3c7eb4c150dc343d6175d2f.zip | |
(add-to-list): New argument COMPARE-FN.
| -rw-r--r-- | lisp/subr.el | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index b2ea997d623..33aac6081f9 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1085,9 +1085,10 @@ the hook's buffer-local value rather than its default value." | |||
| 1085 | (kill-local-variable hook) | 1085 | (kill-local-variable hook) |
| 1086 | (set hook hook-value)))))) | 1086 | (set hook hook-value)))))) |
| 1087 | 1087 | ||
| 1088 | (defun add-to-list (list-var element &optional append) | 1088 | (defun add-to-list (list-var element &optional append compare-fn) |
| 1089 | "Add ELEMENT to the value of LIST-VAR if it isn't there yet. | 1089 | "Add ELEMENT to the value of LIST-VAR if it isn't there yet. |
| 1090 | The test for presence of ELEMENT is done with `equal'. | 1090 | The test for presence of ELEMENT is done with `equal', |
| 1091 | or with COMPARE-FN if that's non-nil. | ||
| 1091 | If ELEMENT is added, it is added at the beginning of the list, | 1092 | If ELEMENT is added, it is added at the beginning of the list, |
| 1092 | unless the optional argument APPEND is non-nil, in which case | 1093 | unless the optional argument APPEND is non-nil, in which case |
| 1093 | ELEMENT is added at the end. | 1094 | 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' | |||
| 1099 | into a hook function that will be run only after loading the package. | 1100 | into a hook function that will be run only after loading the package. |
| 1100 | `eval-after-load' provides one way to do this. In some cases | 1101 | `eval-after-load' provides one way to do this. In some cases |
| 1101 | other hooks, such as major mode hooks, can do the job." | 1102 | other hooks, such as major mode hooks, can do the job." |
| 1102 | (if (member element (symbol-value list-var)) | 1103 | (if (if compare-fn |
| 1104 | (let (present) | ||
| 1105 | (dolist (elt (symbol-value list-var)) | ||
| 1106 | (if (funcall compare-fn element elt) | ||
| 1107 | (setq present t))) | ||
| 1108 | present) | ||
| 1109 | (member element (symbol-value list-var))) | ||
| 1103 | (symbol-value list-var) | 1110 | (symbol-value list-var) |
| 1104 | (set list-var | 1111 | (set list-var |
| 1105 | (if append | 1112 | (if append |
| @@ -1730,16 +1737,20 @@ in milliseconds; this was useful when Emacs was built without | |||
| 1730 | floating point support. | 1737 | floating point support. |
| 1731 | 1738 | ||
| 1732 | \(fn SECONDS &optional NODISP)" | 1739 | \(fn SECONDS &optional NODISP)" |
| 1733 | (when (or obsolete (numberp nodisp)) | 1740 | (unless (or unread-command-events |
| 1734 | (setq seconds (+ seconds (* 1e-3 nodisp))) | 1741 | unread-post-input-method-events |
| 1735 | (setq nodisp obsolete)) | 1742 | unread-input-method-events |
| 1736 | (if noninteractive | 1743 | (>= unread-command-char 0)) |
| 1737 | (progn (sleep-for seconds) t) | 1744 | (when (or obsolete (numberp nodisp)) |
| 1738 | (unless nodisp (redisplay)) | 1745 | (setq seconds (+ seconds (* 1e-3 nodisp))) |
| 1739 | (or (<= seconds 0) | 1746 | (setq nodisp obsolete)) |
| 1740 | (let ((read (read-event nil nil seconds))) | 1747 | (if noninteractive |
| 1741 | (or (null read) | 1748 | (progn (sleep-for seconds) t) |
| 1742 | (progn (push read unread-command-events) nil)))))) | 1749 | (unless nodisp (redisplay)) |
| 1750 | (or (<= seconds 0) | ||
| 1751 | (let ((read (read-event nil nil seconds))) | ||
| 1752 | (or (null read) | ||
| 1753 | (progn (push read unread-command-events) nil))))))) | ||
| 1743 | 1754 | ||
| 1744 | ;;; Atomic change groups. | 1755 | ;;; Atomic change groups. |
| 1745 | 1756 | ||