From 52d17476ed37ed92744c0b20383cf8a28efc8aea Mon Sep 17 00:00:00 2001 From: Patrick Winter Date: Tue, 23 Oct 2018 22:13:43 +0200 Subject: [PATCH] Add function to sort entries by urgency --- taskwarrior.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/taskwarrior.el b/taskwarrior.el index 3f8cc8a..72ac6a7 100644 --- a/taskwarrior.el +++ b/taskwarrior.el @@ -92,12 +92,19 @@ the front and focus it. Otherwise, create one and load the data." (while (not (equal (overlays-at (point)) nil)) (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) "Convert a vector to a list" (append vector nil)) (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) (let ((id (alist-get 'id entry)) (urgency (alist-get 'urgency entry))