Fix filter of tabulated list entries
This commit is contained in:
parent
a1f836972d
commit
5ad8fee1a9
1 changed files with 30 additions and 40 deletions
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
(defvar taskwarrior-buffer-name "*taskwarrior*")
|
(defvar taskwarrior-buffer-name "*taskwarrior*")
|
||||||
|
|
||||||
|
(defvar taskwarrior-filter nil)
|
||||||
(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.")
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@
|
||||||
(define-key taskwarrior-mode-map (kbd "D") 'taskwarrior-delete)
|
(define-key taskwarrior-mode-map (kbd "D") 'taskwarrior-delete)
|
||||||
(define-key taskwarrior-mode-map (kbd "m") 'taskwarrior-mark-task)
|
(define-key taskwarrior-mode-map (kbd "m") 'taskwarrior-mark-task)
|
||||||
(define-key taskwarrior-mode-map (kbd "u") 'taskwarrior-unmark-task)
|
(define-key taskwarrior-mode-map (kbd "u") 'taskwarrior-unmark-task)
|
||||||
(define-key taskwarrior-mode-map (kbd "f") 'taskwarrior-filter)
|
(define-key taskwarrior-mode-map (kbd "f") 'taskwarrior-set-filter)
|
||||||
(define-key taskwarrior-mode-map (kbd "r") 'taskwarrior-reset-filter)
|
(define-key taskwarrior-mode-map (kbd "r") 'taskwarrior-reset-filter)
|
||||||
(define-key taskwarrior-mode-map (kbd "t") 'taskwarrior-edit-tags)
|
(define-key taskwarrior-mode-map (kbd "t") 'taskwarrior-edit-tags)
|
||||||
(define-key taskwarrior-mode-map (kbd "RET") 'taskwarrior-info)
|
(define-key taskwarrior-mode-map (kbd "RET") 'taskwarrior-info)
|
||||||
|
@ -164,28 +165,18 @@
|
||||||
(string-match "^ [0-9]*" line)
|
(string-match "^ [0-9]*" line)
|
||||||
(string-trim-left (match-string 0 line))))
|
(string-trim-left (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-reset-filter ()
|
(defun taskwarrior-reset-filter ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(progn
|
(progn
|
||||||
(taskwarrior--set-filter "")
|
(setq-local taskwarrior-filter nil)
|
||||||
(taskwarrior-update-buffer "")))
|
(taskwarrior-update-buffer)))
|
||||||
|
|
||||||
(defun taskwarrior-filter ()
|
(defun taskwarrior-set-filter ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((new-filter (read-from-minibuffer "Filter: " (taskwarrior--get-filter-as-string))))
|
(let ((new-filter (read-from-minibuffer "Filter: " taskwarrior-filter)))
|
||||||
(progn
|
(progn
|
||||||
(taskwarrior--set-filter new-filter)
|
(setq-local taskwarrior-filter new-filter)
|
||||||
(taskwarrior-update-buffer new-filter))))
|
(taskwarrior-update-buffer))))
|
||||||
|
|
||||||
(defun taskwarrior--shell-command (command &optional filter modifications miscellaneous confirm)
|
(defun taskwarrior--shell-command (command &optional filter modifications miscellaneous confirm)
|
||||||
(let* ((confirmation (if confirm (concat "echo " confirm " |") ""))
|
(let* ((confirmation (if confirm (concat "echo " confirm " |") ""))
|
||||||
|
@ -209,8 +200,9 @@
|
||||||
(vector-to-list tags)
|
(vector-to-list tags)
|
||||||
" "))
|
" "))
|
||||||
|
|
||||||
(defun taskwarrior-export ()
|
(defun taskwarrior-export (&optional filter)
|
||||||
"Turn task export into the tabulated list entry form"
|
"Turn task export into the tabulated list entry form"
|
||||||
|
(let ((filter (concat filter " id.not:0")))
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (entry)
|
(lambda (entry)
|
||||||
(let* ((id (format "%s" (alist-get 'id entry)))
|
(let* ((id (format "%s" (alist-get 'id entry)))
|
||||||
|
@ -223,18 +215,16 @@
|
||||||
`(,id [,id ,urgency ,priority ,annotations ,project ,tags ,description])))
|
`(,id [,id ,urgency ,priority ,annotations ,project ,tags ,description])))
|
||||||
(vector-to-list
|
(vector-to-list
|
||||||
(json-read-from-string
|
(json-read-from-string
|
||||||
(taskwarrior--shell-command "export" "id.not:0")))))
|
(taskwarrior--shell-command "export" filter))))))
|
||||||
|
|
||||||
(defun taskwarrior-update-buffer (&optional filter)
|
(defun taskwarrior-update-buffer ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((filter (taskwarrior--get-filter-as-string)))
|
|
||||||
(progn
|
(progn
|
||||||
(setq tabulated-list-entries (taskwarrior-export))
|
(setq tabulated-list-entries
|
||||||
(tabulated-list-print t)
|
(if taskwarrior-filter
|
||||||
(goto-char (point-min))
|
(taskwarrior-export taskwarrior-filter)
|
||||||
(while (not (equal (overlays-at (point)) nil))
|
(taskwarrior-export)))
|
||||||
(forward-char))
|
(tabulated-list-print t)))
|
||||||
(taskwarrior--set-filter filter))))
|
|
||||||
|
|
||||||
(defun taskwarrior-export-task (id)
|
(defun taskwarrior-export-task (id)
|
||||||
(let ((task (vector-to-list
|
(let ((task (vector-to-list
|
||||||
|
@ -362,7 +352,7 @@
|
||||||
("Description" 100 nil)])
|
("Description" 100 nil)])
|
||||||
(setq tabulated-list-padding 2)
|
(setq tabulated-list-padding 2)
|
||||||
(setq tabulated-list-sort-key (cons "Urg" nil)) (tabulated-list-init-header)
|
(setq tabulated-list-sort-key (cons "Urg" nil)) (tabulated-list-init-header)
|
||||||
(taskwarrior-update-buffer ""))
|
(taskwarrior-update-buffer))
|
||||||
|
|
||||||
;;; Externally visible functions
|
;;; Externally visible functions
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Reference in a new issue