aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-org-agenda.el
blob: 8bdf8d5ee1c5122bcdf6bbda45625173fba1f7c8 (plain)
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
(gx/maybe-require-package 'org-ql)

(defvar gx/org-agenda-block--today-schedule
  '(agenda "" ((org-agenda-span 1)
	       (org-agenda-overriding-header "Today's Schedule")))
  "A block showing today's schedule.")

(defvar gx/org-agenda-block--weekly-log
  '(agenda "" ((org-agenda-overriding-header "Weekly Log")
	       (org-agenda-span 7)
	       (org-agenda-show-log t)
	       (org-agenda-log-mode-items '(state clock closed))))
  "A block showing my schedule and logged tasks for this week.")

(defvar gx/org-agenda-block--stuck-projects
  '(org-ql-block '(and (or (tags "PROJECT")
			   (not (ancestors (todo))))
		       (todo)
		       (not (done))
		       (not (todo "SOMEDAY"))
		       (not (todo "NEXT"))
		       (not (scheduled))
		       (not (descendants (todo "NEXT")))
		       (not (descendants (scheduled))))
		 ((org-ql-block-header "Stuck Projects")))
  "A block showing stuck projects.")

(defvar gx/org-agenda-block--unwilling-to-do
  '(tags-todo "UNWILLING"
	      ((org-agenda-overriding-header "Unwilling to do")))
  "A block showing tasks I am not willing to do ...")

(defvar gx/org-agenda-block--week-at-a-glance
  '(agenda ""
	   ((org-agenda-span 7)
	    (org-agenda-repeating-timestamp-show-all t)
	    (org-agenda-entry-types '(:deadline :scheduled))
	    (org-agenda-overriding-header "Week at a Glance")))
  "A block showing the tasks scheduled or due this week.")

(defvar gx/org-agenda-block--attention
  '(org-ql-block '(and (not (todo "WAITING"))
		       (or (tags "URGENT" "FLAGGED")
			   (priority "A"))
		       (not (done)))
		 ((org-ql-block-header "ATTENTION")))
  "A block showing tasks require attention.")

(defvar gx/org-agenda-block--waiting-not-scheduled
  '(org-ql-block '(and (todo "WAITING")
		       (not (scheduled)))
		 ((org-ql-block-header "Waiting unscheduled tasks")))
  "A block showing waiting and not scheduled tasks.")

(defvar gx/org-agenda-block--next-not-scheduled
  '(org-ql-block '(and (todo "NEXT")
		       (not (scheduled)))
		 ((org-ql-block-header "Next unscheduled tasks")))
  "A block showing next unscheduled tasks.")

(defvar gx/org-agenda-block--display-settings
  '((org-agenda-todo-ignore-deadlines 'near)
    (org-agenda-todo-ignore-scheduled t))
  "Display settings for all agenda views.")

(defun gx/org-agenda-quit (fn)
  (org-save-all-org-buffers)
  (funcall fn))
(advice-add 'org-agenda-quit :around 'gx/org-agenda-quit)

(with-eval-after-load 'evil
  (evil-set-initial-state 'org-agenda-mode 'motion)
  (evil-define-key 'motion org-agenda-mode-map

    ;; motion
    (kbd "j") 'org-agenda-next-line
    (kbd "k") 'org-agenda-previous-line
    (kbd "gg") 'evil-goto-first-line
    (kbd "G") 'evil-goto-line
    (kbd "C-n") 'org-agenda-next-item
    (kbd "C-p") 'org-agenda-previous-item
    (kbd "[[") 'org-agenda-earlier
    (kbd "]]") 'org-agenda-later

    ;; actions
    (kbd "RET") 'org-agenda-switch-to
    (kbd "TAB") 'org-agenda-goto
    (kbd "t") 'org-agenda-todo
    (kbd "r") 'org-agenda-refile
    (kbd "+") 'org-agenda-priority-up
    (kbd "-") 'org-agenda-priority-down
    (kbd "H") 'org-agenda-do-date-earlier
    (kbd "L") 'org-agenda-do-date-later
    (kbd "o") 'org-agenda-add-note
    (kbd "A") 'org-agenda-append-agenda
    (kbd "C") 'org-agenda-capture
    (kbd "R") 'org-agenda-redo

    (kbd "dd") 'org-agenda-kill

    ;; bulk
    (kbd "m") 'org-agenda-bulk-toggle
    (kbd "x") 'org-agenda-bulk-action

    ;; set
    (kbd "ss") 'org-agenda-schedule
    (kbd "sd") 'org-agenda-deadline
    (kbd "st") 'org-agenda-set-tags
    (kbd "sT") 'org-timer-set-timer
    (kbd "se") 'org-agenda-set-effort

    ;; filter
    (kbd "fc") 'org-agenda-filter-by-category
    (kbd "fr") 'org-agenda-filter-by-regexp
    (kbd "fe") 'org-agenda-filter-by-effort
    (kbd "ft") 'org-agenda-filter-by-tag
    (kbd "F") 'org-agenda-filter-remove-all

    ;; clock
    (kbd "ci") 'org-agenda-clock-in
    (kbd "co") 'org-agenda-clock-out
    (kbd "cc") 'org-agenda-clock-cancel
    (kbd "cg") 'org-agenda-clock-goto
    (kbd "cr") 'org-agenda-clockreport-mode

    ;; goto
    (kbd "gc") 'org-agenda-goto-calendar

    ;; display
    (kbd "vE") 'org-agenda-entry-text-mode

    (kbd "u") 'org-agenda-undo))

(setq org-agenda-dim-blocked-tasks nil)
(setq org-agenda-skip-deadline-prewarning-if-scheduled t)
(setq org-deadline-warning-days 30)
(setq org-agenda-window-setup 'current-window)
;; (setq org-agenda-prefix-format
;; 	'((agenda . "%i %-12:c%?-12t% s %b")
;; 	  (timeline . "  % s")
;; 	  (todo . "%i %-12:c %b")
;; 	  (tags . "%i %-12:c")
;; 	  (search . " %i %-12:c")))
(setq org-agenda-custom-commands
    `((" " "Daily agenda and all important TODOs"
       (,gx/org-agenda-block--today-schedule
	,gx/org-agenda-block--attention
	,gx/org-agenda-block--unwilling-to-do
	;; (tags-todo "computer|@office|phone")
	;; (tags "PROJECT+CATEGORY=\"elephants\"")
	,gx/org-agenda-block--stuck-projects
	,gx/org-agenda-block--next-not-scheduled
	,gx/org-agenda-block--waiting-not-scheduled
	,gx/org-agenda-block--week-at-a-glance)
       ,gx/org-agenda-block--display-settings)
      ("l" "Weekly Log"
       (,gx/org-agenda-block--weekly-log)
       ,gx/org-agenda-block--display-settings)
      ("d" "Upcoming deadlines" agenda ""
       ((org-agenda-time-grid nil)
	(org-deadline-warning-days 365)
	(org-agenda-entry-types '(:deadline))))
      ("g" . "GTD contexts")
      ("gh" "Home" tags-todo "home")
      ("p" . "Priorities")
      ("pa" "A items" tags-todo "+PRIORITIES=\"A\"")
      ("pb" "B items" tags-todo "+PRIORITIES=\"B\"")
      ("pc" "C items" tags-todo "+PRIORITIES=\"C\"")))

(provide 'init-org-agenda)