summaryrefslogtreecommitdiff
path: root/config/org.el
blob: 88be8e827f1edf0f6d9e649e95dce9b4d60e6745 (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
;; Org Mode Configuration

;; =====================================
;; Core Org Settings
;; =====================================

(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)

(setq org-directory "~/Notes")

;; Recursively find all .org files under ~/Notes
(setq org-agenda-files
	  (directory-files-recursively "~/Notes" "\\.org$"))

;; Open agenda in column view (table) by default
(setq org-agenda-view-columns-initially t)

;; TODO workflow states
(setq org-todo-keywords
	  '((sequence "TODO" "DOING" "|" "DONE")))

;; Log timestamp when task is marked DONE
(setq org-log-done 'time)

;; =====================================
;; Deadline Tracker (auto-computed)
;; =====================================

(defun org-update-deadline-properties ()
  "Update DAYS and URGENCY properties for all TODO entries with deadlines."
  (interactive)
  (org-map-entries
   (lambda ()
	 (let ((deadline (org-get-deadline-time (point))))
	   (when deadline
		 (let* ((days (- (time-to-days deadline) (time-to-days (current-time))))
				(urgency (cond
						  ((< days 0) "OVERDUE")
						  ((<= days 7) "CLOSE")
						  (t "OK"))))
		   (org-set-property "DAYS" (number-to-string days))
		   (org-set-property "URGENCY" urgency)))))
   "/!TODO|DOING" 'file))

;; Auto-update when opening org files
(add-hook 'org-mode-hook
		  (lambda ()
			(when (and buffer-file-name
					   (string-match-p "tasks\\.org$" buffer-file-name))
			  (org-update-deadline-properties))))

;; =====================================
;; Org Super Agenda
;; =====================================

(use-package org-super-agenda
  :after org
  :config
  (org-super-agenda-mode 1))

;; =====================================
;; CalDAV Sync
;; =====================================

;; Load CalDAV credentials from gitignored file
(let ((caldav-secrets (expand-file-name "caldav.el" user-emacs-directory)))
  (when (file-exists-p caldav-secrets)
	(load caldav-secrets)))

(use-package org-caldav
  :after org
  :config
  (setq org-caldav-inbox "~/Notes/caldav-inbox.org"
		org-caldav-files '("~/Notes/tasks.org")))

;; =====================================
;; Calendar Framework (calfw)
;; =====================================

(use-package calfw
  :commands cfw:open-calendar-buffer)

(use-package calfw-org
  :after calfw
  :commands cfw:open-org-calendar)