-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtaskwarrior.el
97 lines (77 loc) · 3.07 KB
/
taskwarrior.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;;; taskwarrior.el --- Taskwarrior client for Emacs
;; Copyright (C) 2015 Andrey Lisin <andrey.lisin@gmail.com>
;; Author: Andrey Lisin <andrey.lisin@gmail.com>
;; Keywords: taskwarrior
;; Version: 0.0.1
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Rule taskwarrior from Emacs
;;
;; Have a nice day!
;;; Code:
(defvar taskwarrior-mode-hook nil)
(defvar taskwarrior-buffer-name "*taskwarrior*"
"Name of the taskwarrior buffer.")
(defvar taskwarrior-map (make-sparse-keymap)
"The keymap to use with taskwarrior.")
(if taskwarrior-map
(progn
(define-key taskwarrior-map (kbd "g") 'taskwarrior)
(define-key taskwarrior-map (kbd "a") 'taskwarrior-add-task)
(define-key taskwarrior-map (kbd "d") 'taskwarrior-done-task)
(define-key taskwarrior-map (kbd "i") 'taskwarrior-task-info)))
(defun display-tasks ()
(let ((shell-output (shell-command-to-string "task"))
(taskwarrior-buffer (get-buffer-create taskwarrior-buffer-name)))
(switch-to-buffer taskwarrior-buffer)
(erase-buffer)
(insert shell-output)))
(defun taskwarrior-add-task (task-description)
"Add taskwarrior task."
(interactive "sTask description: ")
(shell-command (format "task add %s" task-description))
(display-tasks))
(defun filter-spaces (seq)
"Filter spaces from seq of strings."
(delq nil (mapcar (lambda (x) (if (string-equal x " ") nil x)) seq)))
(defun get-task-number (line)
(let ((tokens (split-string line)))
(string-to-number (nth 0 (filter-spaces tokens)))))
(defun delete-task ()
(interactive)
(let* ((current-line (thing-at-point 'line))
(task-number (get-task-number current-line)))
(message (format "task %i delete" (string-to-number task-number)))))
(defun taskwarrior-done-task ()
"Mark taskwarrior task as done."
(interactive)
(let* ((current-line (thing-at-point 'line))
(task-number (get-task-number current-line)))
(if (/= 0 task-number)
(shell-command (format "task %i done" task-number)))
(display-tasks)))
(defun taskwarrior-task-info ()
"Show task detailed information."
(interactive)
(let* ((current-line (thing-at-point 'line))
(task-number (get-task-number current-line)))
(if (/= 0 task-number)
(with-output-to-temp-buffer (shell-command (format "task %i info" task-number))))))
(defun taskwarrior ()
"The entry point for taskwarrior client."
(interactive)
(display-tasks)
(use-local-map taskwarrior-map)
)
(provide 'taskwarrior)
;;; taskwarrior.el ends here