Extract taskwarrior-add logic into pure function

This make unit testing alot easier
This commit is contained in:
Patrick Winter 2019-10-22 18:52:29 +02:00
parent e8914d0308
commit 0fa25884f9

View file

@ -290,7 +290,14 @@
(defun taskwarrior-add (description)
(interactive "sDescription: ")
(taskwarrior--mutable-shell-command "add" "" description))
(progn
(taskwarrior--add description)
(taskwarrior--revert-buffer)))
(defun taskwarrior--add (description)
(let ((output (taskwarrior--shell-command "add" "" description)))
(when (string-match "Created task \\([[:digit:]]+\\)." output)
(match-string 1 output))))
(defun taskwarrior-mark-p ()
"Whether there are any marked tasks"
@ -328,6 +335,12 @@
(let ((id (taskwarrior-id-at-point)))
(taskwarrior--mutable-shell-command "annotate" id annotation)))
(defun taskwarrior--revert-buffer ()
"Revert taskwarrior buffer."
(let ((line-number (line-number-at-pos)))
(taskwarrior-update-buffer)
(goto-line line-number)))
(defun taskwarrior--mutable-shell-command (command &optional filter modifications misc confirm)
"Run shell command and restore taskwarrior buffer."
(let ((line-number (line-number-at-pos)))