summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorKim F. Storm <storm@cua.dk>2005-06-20 21:41:34 +0000
committerKim F. Storm <storm@cua.dk>2005-06-20 21:41:34 +0000
commitef1eef065fadb7ca04d97d455162f2ec45f175e9 (patch)
treeb7ea941f1dfaf91578406d4757d6084b115e3e91 /lisp/subr.el
parentc72c50043b950cbcc4c463194595571715984d71 (diff)
downloademacs-ef1eef065fadb7ca04d97d455162f2ec45f175e9.tar.gz
(add-to-ordered-list): Test membership with eq. Simplify.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el19
1 files changed, 9 insertions, 10 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index f913e984b88..f0b8f9e96a7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -960,12 +960,11 @@ other hooks, such as major mode hooks, can do the job."
(defun add-to-ordered-list (list-var element &optional order)
"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'.
+The test for presence of ELEMENT is done with `eq'.
The resulting list is reordered so that the elements are in the
-order given by each element's numeric list order.
-Elements without a numeric list order are placed at the end of
-the list.
+order given by each element's numeric list order. Elements
+without a numeric list order are placed at the end of the list.
If the third optional argument ORDER is non-nil, set the
element's list order to the given value.
@@ -979,16 +978,16 @@ The return value is the new value of LIST-VAR."
(put list-var 'list-order
(setq ordering (make-hash-table :weakness 'key :test 'eq))))
(when order
- (puthash element order ordering))
- (add-to-list list-var element)
+ (puthash element (and (numberp order) order) ordering))
+ (unless (memq element (symbol-value list-var))
+ (set list-var (cons element (symbol-value list-var))))
(set list-var (sort (symbol-value list-var)
(lambda (a b)
(let ((oa (gethash a ordering))
(ob (gethash b ordering)))
- (cond
- ((not oa) nil)
- ((not ob) t)
- (t (< oa ob)))))))))
+ (if (and oa ob)
+ (< oa ob)
+ oa)))))))
;;; Load history