From 032f4036adf6aa36bf590a66b3da8c219c30c92d Mon Sep 17 00:00:00 2001 From: Patrick Winter Date: Tue, 4 Dec 2018 20:08:17 +0100 Subject: [PATCH] Turn taskwarrior-active-filters into buffer local variable --- taskwarrior.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/taskwarrior.el b/taskwarrior.el index 03ca94b..2f3de0a 100644 --- a/taskwarrior.el +++ b/taskwarrior.el @@ -12,8 +12,6 @@ (defconst taskwarrior-mutating-commands '("add" "modify")) -(defvar taskwarrior-active-filters '() 'taskwarrior-active-filters) - (defvar taskwarrior-description 'taskwarrior-description "Taskwarrior mode face used for tasks with a priority of C.") @@ -60,13 +58,23 @@ (string-match "^[0-9]*" line) (match-string 0 line))) +(defun taskwarrior--get-filter-as-string () + (if (local-variable-p 'taskwarrior-active-filters) + (mapconcat 'identity taskwarrior-active-filters " ") + "") + ) + +(defun taskwarrior--set-filter (filter) + (cond ((stringp filter) (setq-local taskwarrior-active-filters (split-string filter " "))) + ((listp filter) (setq-local taskwarrior-active-filters filter)) + (t (error "Filter did not match any supported type.")))) + (defun taskwarrior-filter () (interactive) - (let* ((current-filter-string (mapconcat 'identity taskwarrior-active-filters " ")) - (new-filter (read-from-minibuffer "Filter: " current-filter-string))) - (taskwarrior-update-buffer new-filter))) - - + (let ((new-filter (read-from-minibuffer "Filter: " (taskwarrior--get-filter-as-string)))) + (progn + (taskwarrior--set-filter new-filter) + (taskwarrior-update-buffer new-filter)))) (defun taskwarrior--shell-command (command &optional filter modifications miscellaneous) (shell-command-to-string