Mercurial > emacs
comparison lisp/subr.el @ 63605:99743da5284f
(add-to-ordered-list): Test membership with eq. Simplify.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 20 Jun 2005 21:41:34 +0000 |
parents | a89b059224fb |
children | ec5194493ae9 5b54039912f4 |
comparison
equal
deleted
inserted
replaced
63604:4ca64c59b88b | 63605:99743da5284f |
---|---|
958 (cons element (symbol-value list-var)))))) | 958 (cons element (symbol-value list-var)))))) |
959 | 959 |
960 | 960 |
961 (defun add-to-ordered-list (list-var element &optional order) | 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. | 962 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |
963 The test for presence of ELEMENT is done with `equal'. | 963 The test for presence of ELEMENT is done with `eq'. |
964 | 964 |
965 The resulting list is reordered so that the elements are in the | 965 The resulting list is reordered so that the elements are in the |
966 order given by each element's numeric list order. | 966 order given by each element's numeric list order. Elements |
967 Elements without a numeric list order are placed at the end of | 967 without a numeric list order are placed at the end of the list. |
968 the list. | |
969 | 968 |
970 If the third optional argument ORDER is non-nil, set the | 969 If the third optional argument ORDER is non-nil, set the |
971 element's list order to the given value. | 970 element's list order to the given value. |
972 | 971 |
973 The list order for each element is stored in LIST-VAR's | 972 The list order for each element is stored in LIST-VAR's |
977 (let ((ordering (get list-var 'list-order))) | 976 (let ((ordering (get list-var 'list-order))) |
978 (unless ordering | 977 (unless ordering |
979 (put list-var 'list-order | 978 (put list-var 'list-order |
980 (setq ordering (make-hash-table :weakness 'key :test 'eq)))) | 979 (setq ordering (make-hash-table :weakness 'key :test 'eq)))) |
981 (when order | 980 (when order |
982 (puthash element order ordering)) | 981 (puthash element (and (numberp order) order) ordering)) |
983 (add-to-list list-var element) | 982 (unless (memq element (symbol-value list-var)) |
983 (set list-var (cons element (symbol-value list-var)))) | |
984 (set list-var (sort (symbol-value list-var) | 984 (set list-var (sort (symbol-value list-var) |
985 (lambda (a b) | 985 (lambda (a b) |
986 (let ((oa (gethash a ordering)) | 986 (let ((oa (gethash a ordering)) |
987 (ob (gethash b ordering))) | 987 (ob (gethash b ordering))) |
988 (cond | 988 (if (and oa ob) |
989 ((not oa) nil) | 989 (< oa ob) |
990 ((not ob) t) | 990 oa))))))) |
991 (t (< oa ob))))))))) | |
992 | 991 |
993 | 992 |
994 ;;; Load history | 993 ;;; Load history |
995 | 994 |
996 ;;; (defvar symbol-file-load-history-loaded nil | 995 ;;; (defvar symbol-file-load-history-loaded nil |