From 1ffe30ca105e25446de145ac8977ec3128275a09 Mon Sep 17 00:00:00 2001 From: Patrick Winter Date: Sun, 4 Nov 2018 21:13:32 +0100 Subject: [PATCH] Refactor setting of an attribute into internal helper function --- taskwarrior.el | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/taskwarrior.el b/taskwarrior.el index 10ed6a5..aea7b08 100644 --- a/taskwarrior.el +++ b/taskwarrior.el @@ -79,22 +79,27 @@ (error "Seems like two task have the same id.") (car task)))) -(defun taskwarrior-change-description () - (interactive) - (save-excursion - (let* ((id (taskwarrior-id-at-point)) - (task (taskwarrior-export-task id)) - (new-text (read-from-minibuffer "Description: " (alist-get 'description task)))) - (taskwarrior--shell-command "modify" id new-text) - (taskwarrior-update-buffer)))) - -(defun taskwarrior-change-project (project) - (interactive "sProject: ") - (let ((filter (taskwarrior-id-at-point)) - (modifications (concat "project:" project))) - (taskwarrior--shell-command "modify" filter modifications) +(defun taskwarrior--change-attribute (attribute) + "Change an attribute of a task" + (let* ((prefix (concat (upcase attribute) ": ")) + (id (taskwarrior-id-at-point)) + (task (taskwarrior-export-task id)) + (key (make-symbol attribute)) + (old-value (alist-get key task)) + (new-value (read-from-minibuffer prefix old-value))) + (taskwarrior--shell-command "modify" id new-value) (taskwarrior-update-buffer))) +(defun taskwarrior-change-description () + "Change the description of a task" + (interactive) + (taskwarrior--change-attribute "description")) + +(defun taskwarrior-change-project () + "Change the project of a task" + (interactive) + (taskwarrior--change-attribute "project")) + (defun taskwarrior-add (description) (interactive "sDescription: ") (taskwarrior--shell-command "add" "" description))