From 0fa25884f948b33491581d58c487d4978e3c1e61 Mon Sep 17 00:00:00 2001 From: Patrick Winter Date: Tue, 22 Oct 2019 18:52:29 +0200 Subject: [PATCH] Extract taskwarrior-add logic into pure function This make unit testing alot easier --- taskwarrior.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/taskwarrior.el b/taskwarrior.el index 38151cf..7d0629e 100644 --- a/taskwarrior.el +++ b/taskwarrior.el @@ -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)))