/[emacs]/emacs/lisp/subr.el
ViewVC logotype

Diff of /emacs/lisp/subr.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.465 by monnier, Wed Jun 15 20:58:20 2005 UTC revision 1.466 by kfstorm, Mon Jun 20 21:41:34 2005 UTC
# Line 960  other hooks, such as major mode hooks, c Line 960  other hooks, such as major mode hooks, c
960    
961  (defun add-to-ordered-list (list-var element &optional order)  (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.    "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'.  The test for presence of ELEMENT is done with `eq'.
964    
965  The resulting list is reordered so that the elements are in the  The resulting list is reordered so that the elements are in the
966  order given by each element's numeric list order.  order given by each element's numeric list order.  Elements
967  Elements without a numeric list order are placed at the end of  without a numeric list order are placed at the end of the list.
 the list.  
968    
969  If the third optional argument ORDER is non-nil, set the  If the third optional argument ORDER is non-nil, set the
970  element's list order to the given value.  element's list order to the given value.
# Line 979  The return value is the new value of LIS Line 978  The return value is the new value of LIS
978        (put list-var 'list-order        (put list-var 'list-order
979             (setq ordering (make-hash-table :weakness 'key :test 'eq))))             (setq ordering (make-hash-table :weakness 'key :test 'eq))))
980      (when order      (when order
981        (puthash element order ordering))        (puthash element (and (numberp order) order) ordering))
982      (add-to-list list-var element)      (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)      (set list-var (sort (symbol-value list-var)
985                          (lambda (a b)                          (lambda (a b)
986                            (let ((oa (gethash a ordering))                            (let ((oa (gethash a ordering))
987                                  (ob (gethash b ordering)))                                  (ob (gethash b ordering)))
988                              (cond                              (if (and oa ob)
989                               ((not oa) nil)                                  (< oa ob)
990                               ((not ob) t)                                oa)))))))
                              (t (< oa ob)))))))))  
991    
992    
993  ;;; Load history  ;;; Load history

Legend:
Removed from v.1.465  
changed lines
  Added in v.1.466

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26