Add function to sort entries by urgency

This commit is contained in:
Patrick Winter 2018-10-23 22:13:43 +02:00
parent 24bf81685d
commit 52d17476ed

View file

@ -92,12 +92,19 @@ the front and focus it. Otherwise, create one and load the data."
(while (not (equal (overlays-at (point)) nil)) (while (not (equal (overlays-at (point)) nil))
(forward-char))))) (forward-char)))))
(defun taskwarrior--sort-by-urgency (entries &optional asc)
(let ((cmp (if asc '< '>)))
(sort entries #'(lambda (x y)
(> (alist-get 'urgency x)
(alist-get 'urgency y))))))
(defun vector-to-list (vector) (defun vector-to-list (vector)
"Convert a vector to a list" "Convert a vector to a list"
(append vector nil)) (append vector nil))
(defun taskwarrior-write-entries () (defun taskwarrior-write-entries ()
(let ((entries (append (taskwarrior-export "1-1000") nil))) (let ((entries (taskwarrior--sort-by-urgency (taskwarrior-export "1-1000"))))
(dolist (entry entries) (dolist (entry entries)
(let ((id (alist-get 'id entry)) (let ((id (alist-get 'id entry))
(urgency (alist-get 'urgency entry)) (urgency (alist-get 'urgency entry))