-
Notifications
You must be signed in to change notification settings - Fork 0
/
howm-gtd.el
196 lines (167 loc) · 7.25 KB
/
howm-gtd.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
;;; howm-gtd.el --- GTD with howm
;; Copyright (C) 2010 Takahiro HIMURA
;; Author: Takahiro HIMURA <[email protected]>
;; Keywords: calendar, docs
;; 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:
;;
;;; Code:
(require 'howm)
(require 'action-lock)
(require 'cl)
(eval-after-load "action-lock"
'(progn
;; monkey patch to action-lock-font-lock
(defun action-lock-font-lock ()
(cheat-font-lock-mode action-lock-silent)
(if (null action-lock-original-font-lock-keywords)
(setq action-lock-original-font-lock-keywords font-lock-keywords)
(setq font-lock-keywords action-lock-original-font-lock-keywords))
(when action-lock-rules
(let* ((entries (mapcar (lambda (pair)
(let* ((regexp (car pair))
(matcher (action-lock-matcher regexp))
(pos (or (caddr pair) 0))
(face (or (cadddr (cdr pair)) 'action-lock-face))
(hilit (list pos face
'prepend)))
(cons matcher hilit)))
action-lock-rules)))
(cheat-font-lock-append-keywords entries)
;; (cheat-font-lock-prepend-keywords entries)
(cheat-font-lock-fontify t)
)))))
(defvar howm-gtd-type-spec
'(("NEXT" (:face howm-gtd-face-next :keys (?n) :order 0))
("INBOX" (:face howm-gtd-face-inbox :keys (?i) :order -1))
("WAIT" (:face howm-gtd-face-misc :keys (?w) :order -2))
("PROJECT" (:face howm-gtd-face-misc :keys (?p) :order -3))
("SOMEDAY" (:face howm-gtd-face-misc :keys (?s) :order -4))
("REVIEW" (:face howm-gtd-face-misc :keys (?r) :order -5))
("CANCEL" (:face howm-gtd-face-done :keys (?c ?x) :order nil))
("DONE" (:face howm-gtd-face-done :keys (?d) :order nil)))
"")
(defvar howm-gtd-default-type "DONE"
"")
(defvar action-lock-switch-time-default-tag ""
"")
(howm-defun-memoize howm-gtd-all-types ()
(mapcar #'car howm-gtd-type-spec))
(howm-defun-memoize howm-gtd-activated-type-regexp ()
(regexp-opt
(delq nil
(mapcar (lambda (x) (if (howm-gtd-get-parameter x :order) x nil))
(howm-gtd-all-types)))
t))
(howm-defun-memoize howm-gtd-get-parameter (type key)
(cadr (member key (cadr (assoc type howm-gtd-type-spec)))))
(howm-defun-memoize howm-gtd-menu-key-list ()
(apply 'append
(mapcar (lambda (type)
(mapcar (lambda (k) (cons k type))
(howm-gtd-get-parameter type :keys)))
(howm-gtd-all-types))))
(defface howm-gtd-face-misc
'((t
(:foreground "ForestGreen" :weight bold)))
"howm howm-gtd misc face")
(defface howm-gtd-face-inbox
'((t
(:foreground "Firebrick" :weight bold)))
"howm howm-gtd inbox face")
(defface howm-gtd-face-next
'((t
(:foreground "Blue" :weight bold)))
"howm howm-gtd next face")
(defface howm-gtd-face-done
'((t
(:foreground "gray" :weight bold)))
"howm howm-gtd done face")
(defun howm-gtd-create-action-lock-regexp (label-list)
(let
((time-regexp (let ((dd "[0-9]\\{2\\}"))
(format "\\(\\[%s%s-%s-%s %s:%s\\]\\(.*\\) \\)?"
dd dd dd dd dd dd))))
(concat time-regexp (regexp-opt label-list t))))
(defun howm-gtd-create-action-lock (label-list)
(let ((time-format "[%Y-%m-%d %H:%M]"))
(list (howm-gtd-create-action-lock-regexp label-list)
`(lambda (&optional dummy)
(if (eq major-mode 'howm-menu-mode)
(howm-action-lock-forward (match-beginning 0))
(let* ((b (match-beginning 0))
(e (match-end 0))
(s (match-string-no-properties 3))
(tag (or (match-string-no-properties 2) action-lock-switch-time-default-tag))
(next (or (howm-gtd-item-menu (howm-gtd-menu-key-list)) howm-gtd-default-type)))
(delete-region b e)
(insert (format-time-string (concat ,time-format tag)) " " next)
(goto-char b))))
3 nil #'(howm-gtd-action-lock-face 3))))
(defun howm-gtd-action-lock-face (kwd)
(if (numberp kwd) (setq kwd (match-string kwd)))
(or (howm-gtd-get-parameter kwd :face) 'gtd-face-misc))
(defun howm-gtd-item-menu (itemlist)
(interactive "P")
(message (mapconcat (lambda (item) (format "(%c)%s" (car item) (cdr item))) itemlist ", "))
(let* ((sw (selected-window)) (c (read-char)))
(select-window sw)
(cdr (assoc c itemlist))))
(setq action-lock-default-rules
(cons (howm-gtd-create-action-lock (howm-gtd-all-types))
action-lock-default-rules))
(defun howm-gtd-menu-all ()
(let* ((types (concat "[+]? " (howm-gtd-activated-type-regexp)))
(r (howm-reminder-regexp types))
(rg (howm-reminder-regexp-grep types))
(summarizer (howm-reminder-summarizer r))
(folder (howm-reminder-search-path-folder)))
(howm-menu-general "todo" 'todo
(howm-sort #'howm-gtd-priority #'howm-gtd-priority-gt
(howm-view-search-folder-items rg folder summarizer)))))
(setq howm-menu-allow (cons 'howm-gtd-menu-all howm-menu-allow))
(defun howm-gtd-get-type (str)
(let* ((rx (regexp-opt (howm-gtd-all-types) t)))
(if (string-match rx str)
(match-string 1 str)
nil)))
(defun howm-gtd-priority (item)
(let* ((p (howm-todo-parse item))
(late (car p))
(type (second p))
(lazy (third p))
(description (fifth p))
(f (or (cdr (assoc type howm-todo-priority-func))
#'howm-todo-priority-unknown))
(priority (funcall f late lazy item))
(type (howm-gtd-get-type description)))
(cons type priority)))
(defun howm-gtd-priority-gt (e1 e2)
(let ((e1t (howm-gtd-get-parameter (car e1) :order)) ; FIXME
(e2t (howm-gtd-get-parameter (car e2) :order)))
(if (and e1t e2t)
(cond ((> e1t e2t) t)
((< e1t e2t) nil)
((> (cdr e1) (cdr e2)) t) ; FIXME
(t nil))
nil)))
(defun howm-gtd-menu (gtdtype)
(let* ((types (format "[+]? %s" gtdtype))
(r (howm-reminder-regexp types))
(rg (howm-reminder-regexp-grep types))
(summarizer (howm-reminder-summarizer r))
(folder (howm-reminder-search-path-folder)))
(howm-menu-general "todo" 'todo
(howm-view-search-folder-items rg folder summarizer))))
(setq howm-menu-allow (cons 'howm-gtd-menu howm-menu-allow))
(provide 'howm-gtd)
;;; howm-gtd.el ends here