aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2005-06-14 08:14:06 +0000
committerKim F. Storm2005-06-14 08:14:06 +0000
commit8da6c2f88823000244c6f8d2c5eb6d199bccbae6 (patch)
treec489bdb8c68d95233d7f002d30ca844399c1dfa4
parent47d4e709887e5f7f9fdaf1e9961b2f806dfb827c (diff)
downloademacs-8da6c2f88823000244c6f8d2c5eb6d199bccbae6.tar.gz
emacs-8da6c2f88823000244c6f8d2c5eb6d199bccbae6.zip
(add-to-ordered-list): Rework to use list-order property of list-var.
-rw-r--r--lisp/subr.el41
1 files changed, 26 insertions, 15 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index fb48e578157..b67fc14a010 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -963,25 +963,36 @@ other hooks, such as major mode hooks, can do the job."
963The test for presence of ELEMENT is done with `equal'. 963The test for presence of ELEMENT is done with `equal'.
964 964
965The resulting list is reordered so that the elements are in the 965The resulting list is reordered so that the elements are in the
966order given by each element's `list-order' property (a number). 966order given by each element's numeric list order. Elements which
967Elements which are not symbols, and symbol elements without a 967are not symbols, and symbol elements without a numeric list order
968numeric `lisp-order' property are placed at the end of the list. 968are placed at the end of the list.
969 969
970If the third optional argument ORDER is non-nil and ELEMENT is 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. 971a symbol, set the symbol's list order to the given value.
972
973The list order for each symbol is stored in LIST-VAR's
974`list-order' property.
972 975
973The return value is the new value of LIST-VAR." 976The return value is the new value of LIST-VAR."
974 (when (and order (symbolp element)) 977 (let* ((ordering (get list-var 'list-order))
975 (put element 'list-order (and (numberp order) order))) 978 (cur (and (symbolp element) (assq element ordering))))
976 (add-to-list list-var element) 979 (when order
977 (set list-var (sort (symbol-value list-var) 980 (unless (symbolp element)
978 (lambda (a b) 981 (error "cannot specify order for non-symbols"))
979 (let ((oa (and (symbolp a) (get a 'list-order))) 982 (if cur
980 (ob (and (symbolp b) (get b 'list-order)))) 983 (setcdr cur order)
981 (cond 984 (setq cur (cons element order))
982 ((not oa) nil) 985 (setq ordering (cons cur ordering))
983 ((not ob) t) 986 (put list-var 'list-order ordering)))
984 (t (< oa ob)))))))) 987 (add-to-list list-var element)
988 (set list-var (sort (symbol-value list-var)
989 (lambda (a b)
990 (let ((oa (and (symbolp a) (assq a ordering)))
991 (ob (and (symbolp b) (assq b ordering))))
992 (cond
993 ((not oa) nil)
994 ((not ob) t)
995 (t (< (cdr oa) (cdr ob))))))))))
985 996
986 997
987;;; Load history 998;;; Load history