Store tasks in buffer local variable

This commit is contained in:
Patrick Winter 2018-10-24 21:11:46 +02:00
parent 52d17476ed
commit d1bf77d3b8

View file

@ -49,6 +49,10 @@
(json-read-from-string (json-read-from-string
(taskwarrior--shell-command "export" filter)))) (taskwarrior--shell-command "export" filter))))
(defun taskwarrior-load-tasks (filter)
"Load tasks into buffer-local variable"
(setq-local taskwarrior-tasks (taskwarrior-export filter)))
(defun taskwarrior-change-project (project) (defun taskwarrior-change-project (project)
(interactive "sProject: ") (interactive "sProject: ")
(let ((filter (taskwarrior-id-at-point)) (let ((filter (taskwarrior-id-at-point))
@ -81,30 +85,31 @@ the front and focus it. Otherwise, create one and load the data."
(let* ((buf (get-buffer-create "taskwarrior"))) (let* ((buf (get-buffer-create "taskwarrior")))
(progn (progn
(switch-to-buffer buf) (switch-to-buffer buf)
(taskwarrior-mode)
(setq font-lock-defaults '(taskwarrior-highlight-regexps)) (setq font-lock-defaults '(taskwarrior-highlight-regexps))
(goto-char (point-min)) (goto-char (point-min))
(toggle-read-only) (toggle-read-only)
(erase-buffer) (erase-buffer)
(taskwarrior-load-tasks "1-1000")
(taskwarrior-write-entries) (taskwarrior-write-entries)
(taskwarrior-mode)
(hl-line-mode) (hl-line-mode)
(goto-char (point-min)) (goto-char (point-min))
(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) (defun taskwarrior--sort-by-urgency (entries &optional asc)
;; TODO: Figure out how to store a function in the cmp variable.
(let ((cmp (if asc '< '>))) (let ((cmp (if asc '< '>)))
(sort entries #'(lambda (x y) (sort entries #'(lambda (x y)
(> (alist-get 'urgency x) (> (alist-get 'urgency x)
(alist-get 'urgency y)))))) (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 (taskwarrior--sort-by-urgency (taskwarrior-export "1-1000")))) (let ((entries (taskwarrior--sort-by-urgency taskwarrior-tasks)))
(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))