aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/init-org.el
blob: ac376acd15b50ec5c8a42fe84fed01f5ac969a8c (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
171
172
173
174
175
176
177
178
179
180
181
(defun gx/org-refile (fn &optional arg default-buffer rfloc msg)
  (funcall-interactively fn arg default-buffer rfloc msg)
  (org-save-all-org-buffers))
(advice-add 'org-refile :around 'gx/org-refile)

(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-hook 'org-capture-after-finalize-hook 'org-save-all-org-buffers)

;; evil
(when (gx/maybe-require-package 'evil-org)
  (autoload #'evil-org-mode "evil-org" nil t)
  (add-hook 'org-mode-hook 'evil-org-mode)
  (add-hook 'org-agenda-mode-hook 'evil-org-mode))
(with-eval-after-load 'evil-org
  (evil-org-set-key-theme '(navigation insert textobjects additional calendar todo))
  (gx/diminish 'evil-org-mode))

;; keybinds
(with-eval-after-load 'evil
  (evil-define-key 'normal 'global
    (kbd "<leader>a") 'org-agenda
    (kbd "<leader>l") 'org-store-link
    (kbd "<leader>C") 'org-capture)
  (evil-define-key 'normal org-mode-map
    (kbd "TAB") 'org-cycle
    (kbd "RET") 'org-open-at-point
    (kbd "H") 'org-toggle-heading

    (kbd "<leader>r") 'org-refile

    ;; toggle
    (kbd "<leader><SPC>l") 'org-toggle-link-display

    ;; set
    (kbd "<leader>ss") 'org-schedule
    (kbd "<leader>sd") 'org-deadline
    (kbd "<leader>sp") 'org-set-property
    (kbd "<leader>st") 'org-set-tags-command
    (kbd "<leader>se") 'org-set-effort

    ;; insert
    (kbd "<leader>il") 'org-insert-link
    (kbd "<leader>ih") 'org-i
    (kbd "<leader>ii") 'org-id-get-create

    ;; clock
    (kbd "<leader>ci") 'org-clock-in
    (kbd "<leader>co") 'org-clock-out
    (kbd "<leader>cr") 'org-clock-report
    (kbd "<leader>cc") 'org-clock-cancel

    ;; priority
    (kbd "+") 'org-priority-up
    (kbd "-") 'org-priority-down))

(add-hook 'org-mode-hook
	  (lambda ()
	    (setq truncate-lines nil)
	    (setq tab-width 4)))

(setq org-default-notes-file "~/words/journals/inbox.org")
(setq org-agenda-start-on-weekday 0)

;; appearance
(setq org-src-tab-acts-natively t)
(setq org-adapt-indentation nil)
(setq org-startup-indented t)
(setq org-descriptive-links t)
(setq org-tags-column (- fill-column))
(setq org-agenda-tags-column org-tags-column)
(setq org-startup-folded 'showall)

(with-eval-after-load 'org-indent
  (gx/diminish 'org-indent-mode))

;; todo
(setq org-todo-keywords
    '((sequence "TODO(t)" ; to do later
		"NEXT(n)" ; doing now or to do soon
		"WAITING(w)" "SOMEDAY(s)"
		"|" "DONE(d)" "CANCELLED(c)")))
(setq org-log-done t)
(setq org-log-into-drawer t)

;; tags
(setq org-tags-exclude-from-inheritance
    '("PROJECT"))
(setq org-tag-alist '((:startgroup . nil)
		      ("@work" . ?w) ("@home" . ?h) ("errants" . ?e)
		      (:endgroup . nil)
		      ("phone" . ?m)
		      ("FLAGGED" . ?f)
		      ("URGENT" . ?u)
		      ("UNWILLING" . ?x)
		      ("PROJECT" . ?p)
		      ("REFILE" . ?r)))

;; refile
(setq org-refile-targets '((nil :maxlevel . 9)
			   (org-agenda-files :maxlevel . 9))
      org-outline-path-complete-in-steps nil
      org-refile-use-outline-path 'file)

;; capture
(setq org-capture-templates
    '(("t" "TODO" entry (file+headline org-default-notes-file "Tasks")
	"* TODO %?\nCaptured on %U\n  %i\n  %a")
	("j" "Journal" entry (file+datetree org-default-notes-file)
	"* %?\nCaptured on %U\n  %i\n  %a")))

;; clock
(setq org-clock-persist 'history)
(with-eval-after-load 'org
  (org-clock-persistence-insinuate))

;; modules
(with-eval-after-load 'org
  (add-to-list 'org-modules 'org-habit t)
  (add-to-list 'org-modules 'org-tempo t))
(setq org-confirm-babel-evaluate nil)

;; babel
(with-eval-after-load 'org
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((shell . t)
     (plantuml . t))))

;; roam
(when (gx/maybe-require-package 'org-roam)
  (autoload 'org-roam-node-find "org-roam-node")
  (autoload 'org-roam-dailies-goto-today "org-roam-dailies")
  (add-hook 'org-mode-hook 'org-roam-db-autosync-mode))
(with-eval-after-load 'evil
  (evil-define-key 'normal 'global
    (kbd "<leader>fn") 'org-roam-node-find
    (kbd "<leader>cn") 'org-roam-dailies-goto-today)
  (evil-define-key 'normal org-mode-map
    (kbd "<leader><SPC>b") 'org-roam-buffer-toggle
    (kbd "<leader>in") 'org-roam-node-insert
    (kbd "[d") 'org-roam-dailies-goto-previous-note
    (kbd "]d") 'org-roam-dailies-goto-next-note))
(setq org-roam-directory (file-truename "~/words"))
(setq org-roam-db-gc-threshold most-positive-fixnum)
(setq org-roam-dailies-directory "journals/")
(setq org-roam-dailies-capture-templates
      '(("d" "daily" entry
	 "* %?"
	 :target (file+head "%<%Y/%Y-%m-%d>.org"
			    "#+title: %<%a %d %b %Y>\n"))
	("w" "weekly" entry
	 "* %?"
	 :target (file+head "%<%Y/week%V>.org"
			    "#+title: Week %<%V %Y>\n"))
	("m" "monthly" entry
	 "* %?"
	 :target (file+head "%<%Y/%Y-%m>.org"
			    "#+title: %<%B %Y>\n"))
	("y" "yearly" entry
	 "* %?"
	 :target (file+head "%<%Y/%Y>.org"
			    "#+title: %<%Y>\n"))))

;; roam ui
(gx/maybe-require-package 'org-roam-ui)
(setq org-roam-ui-follow t
      org-roam-ui-sync-theme t
      org-roam-ui-update-on-save t
      org-roam-ui-open-at-start t)

;; alert
(when (gx/maybe-require-package 'org-alert)
  (autoload 'org-alert-enable "org-alert"))
(when *is-a-linux*
  (setq alert-default-style 'libnotify))
(when *is-a-mac*
  (setq alert-default-style 'osx-notifier))
(setq org-alert-interval 60)

(require 'init-org-agenda)
(provide 'init-org)