Function: todo-sort
todo-sort is a byte-compiled function defined in todo-mode.el.gz.
Signature
(todo-sort LIST &optional KEY)
Documentation
Return a copy of LIST, possibly sorted according to KEY.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-sort (list &optional key)
"Return a copy of LIST, possibly sorted according to KEY."
(let* ((l (copy-sequence list))
(fn (if (eq key 'alpha)
(lambda (x) (upcase x)) ; Alphabetize case insensitively.
(lambda (x) (todo-get-count key x))))
;; Keep track of whether the last sort by key was descending or
;; ascending.
(descending (member key todo-descending-counts))
(cmp (if (eq key 'alpha)
'string<
(if descending '< '>)))
(pred (lambda (s1 s2) (let ((t1 (funcall fn (car s1)))
(t2 (funcall fn (car s2))))
(funcall cmp t1 t2)))))
(when key
(setq l (sort l pred))
;; Switch between descending and ascending sort order.
(if descending
(setq todo-descending-counts
(delete key todo-descending-counts))
(push key todo-descending-counts)))
l))