aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2005-06-13 21:29:52 +0000
committerKim F. Storm2005-06-13 21:29:52 +0000
commitcbbd0b5a94d8b76f353a188490db6afe62e82538 (patch)
tree080006e9f99cb1120674d8faa02b5cddbe9af2cf
parent929129fff15b719bba929c2f0ded074c1b6f231c (diff)
downloademacs-cbbd0b5a94d8b76f353a188490db6afe62e82538.tar.gz
emacs-cbbd0b5a94d8b76f353a188490db6afe62e82538.zip
(add-to-ordered-list): New defun.
-rw-r--r--lisp/subr.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 9371df1a794..fb48e578157 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -957,6 +957,32 @@ other hooks, such as major mode hooks, can do the job."
957 (append (symbol-value list-var) (list element)) 957 (append (symbol-value list-var) (list element))
958 (cons element (symbol-value list-var)))))) 958 (cons element (symbol-value list-var))))))
959 959
960
961(defun add-to-ordered-list (list-var element &optional order)
962 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
963The test for presence of ELEMENT is done with `equal'.
964
965The resulting list is reordered so that the elements are in the
966order given by each element's `list-order' property (a number).
967Elements which are not symbols, and symbol elements without a
968numeric `lisp-order' property are placed at the end of the list.
969
970If the third optional argument ORDER is non-nil and ELEMENT is
971a symbol, set the symbol's `list-order' property to the given value.
972
973The return value is the new value of LIST-VAR."
974 (when (and order (symbolp element))
975 (put element 'list-order (and (numberp order) order)))
976 (add-to-list list-var element)
977 (set list-var (sort (symbol-value list-var)
978 (lambda (a b)
979 (let ((oa (and (symbolp a) (get a 'list-order)))
980 (ob (and (symbolp b) (get b 'list-order))))
981 (cond
982 ((not oa) nil)
983 ((not ob) t)
984 (t (< oa ob))))))))
985
960 986
961;;; Load history 987;;; Load history
962 988