-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
org-gtd-skip.el
160 lines (138 loc) · 6.11 KB
/
org-gtd-skip.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
;;; org-gtd-skip.el --- various org-agenda-skip-functions -*- lexical-binding: t; coding: utf-8 -*-
;;
;; Copyright © 2019-2023 Aldric Giacomoni
;; Author: Aldric Giacomoni <[email protected]>
;; This file is not part of GNU Emacs.
;; This file 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, or (at your option)
;; any later version.
;; This file 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 file. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Building agenda views is complex, and filtering them effectively can truly
;; require its own language. This is that language.
;;
;;; Code:
(defun org-gtd-skip-AND (funcs)
"Ensure all of the functions FUNCS want to skip the current entry."
(let ((non-nil-funcs (seq-drop-while (lambda (x) (not (funcall x))) funcs)))
(if non-nil-funcs
(funcall (car non-nil-funcs)))))
(defun org-gtd-skip-unless-calendar ()
"Skip-function: only keep this if it's an org-gtd calendar entry."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (and (string-equal (org-entry-get (point) "ORG_GTD" t)
org-gtd-calendar)
(org-entry-get (point) "ORG_GTD_TIMESTAMP"))
nil
subtree-end)))
(defun org-gtd-skip-unless-project-heading ()
"Skip-function: only keep this if it's an org-gtd project heading entry."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (and (equal 2 (org-element-property :level (org-element-at-point)))
(string-equal (org-entry-get (point) "ORG_GTD" t)
org-gtd-projects))
nil
subtree-end)))
(defun org-gtd-skip-unless-delegated ()
"Skip entry unless it is delegated."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (org-entry-get (point) "DELEGATED_TO")
nil
subtree-end)))
(defun org-gtd-skip-unless-scheduled-start-in-the-past ()
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(scheduled-start (org-entry-get (point) "SCHEDULED"))
(start-of-day (org-gtd-skip--start-of-day (current-time))))
(if (and scheduled-start
(time-less-p (org-time-string-to-time scheduled-start)
start-of-day))
nil
subtree-end)))
(defun org-gtd-skip-unless-deadline-in-the-past ()
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(deadline (org-entry-get (point) "DEADLINE"))
(start-of-day (org-gtd-skip--start-of-day (current-time))))
(if (and deadline
(time-less-p (org-time-string-to-time deadline)
start-of-day))
nil
subtree-end)))
(defun org-gtd-skip-unless-timestamp-in-the-past ()
"Skip unless ORG_GTD_TIMESTAMP is in the past."
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(timestamp (org-entry-get (point) "ORG_GTD_TIMESTAMP"))
(start-of-day (org-gtd-skip--start-of-day (current-time))))
(if (and timestamp
(time-less-p (org-time-string-to-time timestamp)
start-of-day))
nil
subtree-end)))
(defun org-gtd-skip-unless-habit ()
"Skip-function: only keep this if it's a habit."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (string-equal "habit" (org-entry-get (point) "STYLE"))
nil
subtree-end)))
(defun org-gtd-skip-unless-delegated-to-empty ()
"Skip-function: only keep this if it's a habit."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (org-entry-get (point) org-gtd-delegate-property)
nil
subtree-end)))
(defun org-gtd-skip-unless-timestamp-empty-or-invalid ()
"Return non-nil if the current headline's ORG_GTD_TIMESTAMP property is not set, null, or not a date."
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(prop (org-entry-get nil org-gtd-timestamp)))
(if (and prop
(org-string-match-p org-ts-regexp-both prop))
subtree-end
nil)))
(defun org-gtd-skip-unless-habit-invalid ()
"Return non-nil if the current headline's ORG_GTD_TIMESTAMP property is not set, null, or not a date."
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(style (or (org-entry-get nil "STYLE") ""))
(timestamp (or (org-entry-get nil "SCHEDULED") "")))
(if (and (string-equal style "habit")
(org-string-match-p org-repeat-re timestamp))
subtree-end
nil)))
(defun org-gtd-skip-unless-action-invalid ()
"Return non-nil if the action wouldn't show up in the agenda."
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
(invalidp (or (not (org-entry-is-todo-p))
(org-entry-get nil "TODO" org-gtd-todo)))
)
(if invalidp
nil
subtree-end)))
(defun org-gtd-skip-unless-area-of-focus-func (area)
"Return a skip-function to only keep if it's a specific GTD AREA of focus."
(apply-partially #'org-gtd-skip-unless-area-of-focus area))
(defun org-gtd-skip-unless-area-of-focus (area)
"Skip-function: only keep this if it's a specific GTD AREA of focus."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (string-equal (downcase area)
(downcase (org-entry-get (point) "CATEGORY")))
nil
subtree-end)))
(defun org-gtd-skip-if-habit ()
"Skip-function: only keep this if it's a habit."
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
(if (string-equal "habit" (org-entry-get (point) "STYLE"))
subtree-end
nil)))
(defun org-gtd-skip--start-of-day (timestamp)
(let ((decoded (decode-time timestamp)))
(setf (nth 0 decoded) 0)
(setf (nth 1 decoded) 0)
(setf (nth 2 decoded) 0)
(apply #'encode-time decoded)))
(provide 'org-gtd-skip)
;;; org-gtd-skip.el ends here