Add functionality to filter task output

This commit is contained in:
Patrick Winter 2018-12-04 18:42:26 +01:00
parent 5d64ae379c
commit e15f66a06d

View file

@ -12,6 +12,8 @@
(defconst taskwarrior-mutating-commands '("add" "modify")) (defconst taskwarrior-mutating-commands '("add" "modify"))
(defvar taskwarrior-active-filters '() 'taskwarrior-active-filters)
(defvar taskwarrior-description 'taskwarrior-description (defvar taskwarrior-description 'taskwarrior-description
"Taskwarrior mode face used for tasks with a priority of C.") "Taskwarrior mode face used for tasks with a priority of C.")
@ -34,6 +36,7 @@
(define-key taskwarrior-mode-map (kbd "a") 'taskwarrior-add) (define-key taskwarrior-mode-map (kbd "a") 'taskwarrior-add)
(define-key taskwarrior-mode-map (kbd "d") 'taskwarrior-done) (define-key taskwarrior-mode-map (kbd "d") 'taskwarrior-done)
(define-key taskwarrior-mode-map (kbd "D") 'taskwarrior-delete) (define-key taskwarrior-mode-map (kbd "D") 'taskwarrior-delete)
(define-key taskwarrior-mode-map (kbd "f") 'taskwarrior-filter)
(define-key taskwarrior-mode-map (kbd "P") 'taskwarrior-change-project)) (define-key taskwarrior-mode-map (kbd "P") 'taskwarrior-change-project))
(defun taskwarrior--display-task-details-in-echo-area () (defun taskwarrior--display-task-details-in-echo-area ()
@ -57,6 +60,14 @@
(string-match "^[0-9]*" line) (string-match "^[0-9]*" line)
(match-string 0 line))) (match-string 0 line)))
(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)))
(defun taskwarrior--shell-command (command &optional filter modifications miscellaneous) (defun taskwarrior--shell-command (command &optional filter modifications miscellaneous)
(shell-command-to-string (shell-command-to-string
(format "task %s %s %s %s" (format "task %s %s %s %s"
@ -145,7 +156,7 @@ the front and focus it. Otherwise, create one and load the data."
(interactive) (interactive)
(taskwarrior-update-buffer)) (taskwarrior-update-buffer))
(defun taskwarrior-update-buffer () (defun taskwarrior-update-buffer (&optional filter)
(interactive) (interactive)
(let* ((buf (get-buffer-create "taskwarrior"))) (let* ((buf (get-buffer-create "taskwarrior")))
(progn (progn
@ -155,7 +166,7 @@ the front and focus it. Otherwise, create one and load the data."
(goto-char (point-min)) (goto-char (point-min))
(toggle-read-only) (toggle-read-only)
(erase-buffer) (erase-buffer)
(taskwarrior-load-tasks "1-1000") (taskwarrior-load-tasks (concat "1-1000 " filter))
(taskwarrior-write-entries) (taskwarrior-write-entries)
(toggle-read-only) (toggle-read-only)
(hl-line-mode) (hl-line-mode)