diff options
| author | Kim F. Storm | 2005-06-14 08:14:06 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2005-06-14 08:14:06 +0000 |
| commit | 8da6c2f88823000244c6f8d2c5eb6d199bccbae6 (patch) | |
| tree | c489bdb8c68d95233d7f002d30ca844399c1dfa4 | |
| parent | 47d4e709887e5f7f9fdaf1e9961b2f806dfb827c (diff) | |
| download | emacs-8da6c2f88823000244c6f8d2c5eb6d199bccbae6.tar.gz emacs-8da6c2f88823000244c6f8d2c5eb6d199bccbae6.zip | |
(add-to-ordered-list): Rework to use list-order property of list-var.
| -rw-r--r-- | lisp/subr.el | 41 |
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." | |||
| 963 | The test for presence of ELEMENT is done with `equal'. | 963 | The test for presence of ELEMENT is done with `equal'. |
| 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 `list-order' property (a number). | 966 | order given by each element's numeric list order. Elements which |
| 967 | Elements which are not symbols, and symbol elements without a | 967 | are not symbols, and symbol elements without a numeric list order |
| 968 | numeric `lisp-order' property are placed at the end of the list. | 968 | are placed at the end of the list. |
| 969 | 969 | ||
| 970 | If the third optional argument ORDER is non-nil and ELEMENT is | 970 | If the third optional argument ORDER is non-nil and ELEMENT is |
| 971 | a symbol, set the symbol's `list-order' property to the given value. | 971 | a symbol, set the symbol's list order to the given value. |
| 972 | |||
| 973 | The list order for each symbol is stored in LIST-VAR's | ||
| 974 | `list-order' property. | ||
| 972 | 975 | ||
| 973 | The return value is the new value of LIST-VAR." | 976 | The 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 |