Refactor buffer update logic into wrapper function

After most task shell commands the taskwarrior buffer needs to be rewritten. Instead of handling
this in every interactive command use a wrapper function to do this.
This commit is contained in:
Patrick Winter 2019-04-09 14:40:01 +02:00
parent 3de77fb049
commit 777434aef5

View file

@ -157,9 +157,7 @@
(defun taskwarrior-add (description) (defun taskwarrior-add (description)
(interactive "sDescription: ") (interactive "sDescription: ")
(taskwarrior--shell-command "add" "" description) (taskwarrior--mutable-shell-command "add" "" description))
(when (eq (buffer-name) taskwarrior-buffer-name)
(taskwarrior-update-buffer)))
(defun taskwarrior-done () (defun taskwarrior-done ()
"Mark current task as done." "Mark current task as done."
@ -167,8 +165,7 @@
(let ((id (taskwarrior-id-at-point)) (let ((id (taskwarrior-id-at-point))
(confirmation (yes-or-no-p "Done?"))) (confirmation (yes-or-no-p "Done?")))
(when confirmation (when confirmation
(taskwarrior--shell-command "done" id) (taskwarrior--mutable-shell-command "done" id))))
(taskwarrior-update-buffer))))
(defun taskwarrior-delete () (defun taskwarrior-delete ()
"Delete current task." "Delete current task."
@ -176,8 +173,15 @@
(let ((id (taskwarrior-id-at-point)) (let ((id (taskwarrior-id-at-point))
(confirmation (yes-or-no-p "Delete?"))) (confirmation (yes-or-no-p "Delete?")))
(when confirmation (when confirmation
(taskwarrior--shell-command "delete" id "" "" "yes") (taskwarrior--mutable-shell-command "delete" id "" "" "yes"))))
(taskwarrior-update-buffer))))
(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)))
(taskwarrior--shell-command command filter modifications misc confirm)
(taskwarrior-update-buffer)
(goto-line line-number)))
;; Setup a major mode for taskwarrior ;; Setup a major mode for taskwarrior
;;;###autoload ;;;###autoload