improve erc-sasl
[Emacs.git] / lisp / init-org.el
blobcbe14091bf984c45176900b8d17c04449fdd50ff
1 ;;; init-org.el --- Org-mode config -*- lexical-binding: t -*-
2 ;;; Commentary:
3 ;;; Code:
5 (when *is-a-mac*
6 (maybe-require-package 'grab-mac-link))
8 (maybe-require-package 'org-cliplink)
10 (define-key global-map (kbd "C-c l") 'org-store-link)
11 (define-key global-map (kbd "C-c a") 'org-agenda)
13 (defvar sanityinc/org-global-prefix-map (make-sparse-keymap)
14 "A keymap for handy global access to org helpers, particularly clocking.")
16 (define-key sanityinc/org-global-prefix-map (kbd "j") 'org-clock-goto)
17 (define-key sanityinc/org-global-prefix-map (kbd "l") 'org-clock-in-last)
18 (define-key sanityinc/org-global-prefix-map (kbd "i") 'org-clock-in)
19 (define-key sanityinc/org-global-prefix-map (kbd "o") 'org-clock-out)
20 (define-key global-map (kbd "C-c o") sanityinc/org-global-prefix-map)
23 ;; Various preferences
24 (setq org-log-done t
25 org-edit-timestamp-down-means-later t
26 org-hide-emphasis-markers t
27 org-catch-invisible-edits 'show
28 org-export-coding-system 'utf-8
29 org-fast-tag-selection-single-key 'expert
30 org-html-validation-link nil
31 org-export-kill-product-buffer-when-displayed t
32 org-tags-column 80)
35 ;; Lots of stuff from http://doc.norang.ca/org-mode.html
37 ;; Re-align tags when window shape changes
38 (with-eval-after-load 'org-agenda
39 (add-hook 'org-agenda-mode-hook
40 (lambda () (add-hook 'window-configuration-change-hook 'org-agenda-align-tags nil t))))
43 (setq org-support-shift-select t)
46 ;;; Refiling
48 (setq org-refile-use-cache nil)
50 ;; Targets include this file and any file contributing to the agenda - up to 5 levels deep
51 (setq org-refile-targets '((nil :maxlevel . 5) (org-agenda-files :maxlevel . 5)))
53 (with-eval-after-load 'org-agenda
54 (add-to-list 'org-agenda-after-show-hook 'org-show-entry))
56 (advice-add 'org-refile :after (lambda (&rest _) (org-save-all-org-buffers)))
58 ;; Exclude DONE state tasks from refile targets
59 (defun sanityinc/verify-refile-target ()
60 "Exclude todo keywords with a done state from refile targets."
61 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
62 (setq org-refile-target-verify-function 'sanityinc/verify-refile-target)
64 (defun sanityinc/org-refile-anywhere (&optional goto default-buffer rfloc msg)
65 "A version of `org-refile' which allows refiling to any subtree."
66 (interactive "P")
67 (let ((org-refile-target-verify-function))
68 (org-refile goto default-buffer rfloc msg)))
70 (defun sanityinc/org-agenda-refile-anywhere (&optional goto rfloc no-update)
71 "A version of `org-agenda-refile' which allows refiling to any subtree."
72 (interactive "P")
73 (let ((org-refile-target-verify-function))
74 (org-agenda-refile goto rfloc no-update)))
76 ;; Targets start with the file name - allows creating level 1 tasks
77 ;;(setq org-refile-use-outline-path (quote file))
78 (setq org-refile-use-outline-path t)
79 (setq org-outline-path-complete-in-steps nil)
81 ;; Allow refile to create parent tasks with confirmation
82 (setq org-refile-allow-creating-parent-nodes 'confirm)
85 ;;; To-do settings
87 (setq org-todo-keywords
88 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
89 (sequence "PROJECT(p)" "|" "DONE(d!/!)" "CANCELLED(c@/!)")
90 (sequence "WAITING(w@/!)" "DELEGATED(e!)" "HOLD(h)" "|" "CANCELLED(c@/!)")))
91 org-todo-repeat-to-state "NEXT")
93 (setq org-todo-keyword-faces
94 (quote (("NEXT" :inherit warning)
95 ("PROJECT" :inherit font-lock-string-face))))
99 ;;; Agenda views
101 (setq-default org-agenda-clockreport-parameter-plist '(:link t :maxlevel 3))
104 (let ((active-project-match "-INBOX/PROJECT"))
106 (setq org-stuck-projects
107 `(,active-project-match ("NEXT")))
109 (setq org-agenda-compact-blocks t
110 org-agenda-sticky t
111 org-agenda-start-on-weekday nil
112 org-agenda-span 'day
113 org-agenda-include-diary nil
114 org-agenda-sorting-strategy
115 '((agenda habit-down time-up user-defined-up effort-up category-keep)
116 (todo category-up effort-up)
117 (tags category-up effort-up)
118 (search category-up))
119 org-agenda-window-setup 'current-window
120 org-agenda-custom-commands
121 `(("N" "Notes" tags "NOTE"
122 ((org-agenda-overriding-header "Notes")
123 (org-tags-match-list-sublevels t)))
124 ("g" "GTD"
125 ((agenda "" nil)
126 (tags "INBOX"
127 ((org-agenda-overriding-header "Inbox")
128 (org-tags-match-list-sublevels nil)))
129 (stuck ""
130 ((org-agenda-overriding-header "Stuck Projects")
131 (org-agenda-tags-todo-honor-ignore-options t)
132 (org-tags-match-list-sublevels t)
133 (org-agenda-todo-ignore-scheduled 'future)))
134 (tags-todo "-INBOX"
135 ((org-agenda-overriding-header "Next Actions")
136 (org-agenda-tags-todo-honor-ignore-options t)
137 (org-agenda-todo-ignore-scheduled 'future)
138 (org-agenda-skip-function
139 '(lambda ()
140 (or (org-agenda-skip-subtree-if 'todo '("HOLD" "WAITING"))
141 (org-agenda-skip-entry-if 'nottodo '("NEXT")))))
142 (org-tags-match-list-sublevels t)
143 (org-agenda-sorting-strategy
144 '(todo-state-down effort-up category-keep))))
145 (tags-todo ,active-project-match
146 ((org-agenda-overriding-header "Projects")
147 (org-tags-match-list-sublevels t)
148 (org-agenda-sorting-strategy
149 '(category-keep))))
150 (tags-todo "-INBOX/-NEXT"
151 ((org-agenda-overriding-header "Orphaned Tasks")
152 (org-agenda-tags-todo-honor-ignore-options t)
153 (org-agenda-todo-ignore-scheduled 'future)
154 (org-agenda-skip-function
155 '(lambda ()
156 (or (org-agenda-skip-subtree-if 'todo '("PROJECT" "HOLD" "WAITING" "DELEGATED"))
157 (org-agenda-skip-subtree-if 'nottododo '("TODO")))))
158 (org-tags-match-list-sublevels t)
159 (org-agenda-sorting-strategy
160 '(category-keep))))
161 (tags-todo "/WAITING"
162 ((org-agenda-overriding-header "Waiting")
163 (org-agenda-tags-todo-honor-ignore-options t)
164 (org-agenda-todo-ignore-scheduled 'future)
165 (org-agenda-sorting-strategy
166 '(category-keep))))
167 (tags-todo "/DELEGATED"
168 ((org-agenda-overriding-header "Delegated")
169 (org-agenda-tags-todo-honor-ignore-options t)
170 (org-agenda-todo-ignore-scheduled 'future)
171 (org-agenda-sorting-strategy
172 '(category-keep))))
173 (tags-todo "-INBOX"
174 ((org-agenda-overriding-header "On Hold")
175 (org-agenda-skip-function
176 '(lambda ()
177 (or (org-agenda-skip-subtree-if 'todo '("WAITING"))
178 (org-agenda-skip-entry-if 'nottodo '("HOLD")))))
179 (org-tags-match-list-sublevels nil)
180 (org-agenda-sorting-strategy
181 '(category-keep))))
182 ;; (tags-todo "-NEXT"
183 ;; ((org-agenda-overriding-header "All other TODOs")
184 ;; (org-match-list-sublevels t)))
185 )))))
188 (add-hook 'org-agenda-mode-hook 'hl-line-mode)
191 ;;; Org clock
193 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
194 (with-eval-after-load 'org
195 (org-clock-persistence-insinuate))
196 (setq org-clock-persist t)
197 (setq org-clock-in-resume t)
199 ;; Save clock data and notes in the LOGBOOK drawer
200 (setq org-clock-into-drawer t)
201 ;; Save state changes in the LOGBOOK drawer
202 (setq org-log-into-drawer t)
203 ;; Removes clocked tasks with 0:00 duration
204 (setq org-clock-out-remove-zero-time-clocks t)
206 ;; Show clock sums as hours and minutes, not "n days" etc.
207 (setq org-time-clocksum-format
208 '(:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t))
212 ;;; Show the clocked-in task - if any - in the header line
213 (defun sanityinc/show-org-clock-in-header-line ()
214 (setq-default header-line-format '((" " org-mode-line-string " "))))
216 (defun sanityinc/hide-org-clock-from-header-line ()
217 (setq-default header-line-format nil))
219 (add-hook 'org-clock-in-hook 'sanityinc/show-org-clock-in-header-line)
220 (add-hook 'org-clock-out-hook 'sanityinc/hide-org-clock-from-header-line)
221 (add-hook 'org-clock-cancel-hook 'sanityinc/hide-org-clock-from-header-line)
223 (with-eval-after-load 'org-clock
224 (define-key org-clock-mode-line-map [header-line mouse-2] 'org-clock-goto)
225 (define-key org-clock-mode-line-map [header-line mouse-1] 'org-clock-menu))
229 ;;; Archiving
231 (setq org-archive-mark-done nil)
232 (setq org-archive-location "%s_archive::* Archive")
236 (with-eval-after-load 'org
237 (org-babel-do-load-languages
238 'org-babel-load-languages
239 (seq-filter
240 (lambda (pair)
241 (locate-library (concat "ob-" (symbol-name (car pair)))))
242 '((R . t)
243 (ditaa . t)
244 (dot . t)
245 (emacs-lisp . t)
246 (gnuplot . t)
247 (haskell . nil)
248 (latex . t)
249 (ledger . t)
250 (ocaml . nil)
251 (octave . t)
252 (plantuml . t)
253 (python . t)
254 (ruby . t)
255 (screen . nil)
256 (sh . t) ;; obsolete
257 (shell . t)
258 (sql . t)
259 (sqlite . t)))))
262 (provide 'init-org)
263 ;;; init-org.el ends here