5 ;; The following lines are always needed. Choose your own keys.
6 (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
12 (global-set-key "\C-cl" 'org-store-link)
13 (global-set-key "\C-ca" 'org-agenda)
14 (global-set-key "\C-cb" 'org-iswitchb)
15 (setq-default org-log-done 'time)
16 (setq-default org-agenda-ndays 5)
18 ;; agenda configuration
19 ;; Do not dim blocked tasks
20 (setq org-agenda-dim-blocked-tasks nil)
22 ;; Compact the block agenda view
23 (setq org-agenda-compact-blocks t)
25 ;; Custom agenda command definitions
26 (setq org-agenda-custom-commands
27 (quote (("N" "Notes" tags "NOTE"
28 ((org-agenda-overriding-header "Notes")
29 (org-tags-match-list-sublevels t)))
30 ("h" "Habits" tags-todo "STYLE=\"habit\""
31 ((org-agenda-overriding-header "Habits")
32 (org-agenda-sorting-strategy
33 '(todo-state-down effort-up category-keep))))
37 ((org-agenda-overriding-header "Tasks to Refile")
38 (org-tags-match-list-sublevels nil)))
39 (tags-todo "-CANCELLED/!"
40 ((org-agenda-overriding-header "Stuck Projects")
41 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
42 (org-agenda-sorting-strategy
44 (tags-todo "-HOLD-CANCELLED/!"
45 ((org-agenda-overriding-header "Projects")
46 (org-agenda-skip-function 'bh/skip-non-projects)
47 (org-tags-match-list-sublevels 'indented)
48 (org-agenda-sorting-strategy
50 (tags-todo "-CANCELLED/!NEXT"
51 ((org-agenda-overriding-header (concat "Project Next Tasks"
52 (if bh/hide-scheduled-and-waiting-next-tasks
54 " (including WAITING and SCHEDULED tasks)")))
55 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
56 (org-tags-match-list-sublevels t)
57 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
58 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
59 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
60 (org-agenda-sorting-strategy
61 '(todo-state-down effort-up category-keep))))
62 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
63 ((org-agenda-overriding-header (concat "Project Subtasks"
64 (if bh/hide-scheduled-and-waiting-next-tasks
66 " (including WAITING and SCHEDULED tasks)")))
67 (org-agenda-skip-function 'bh/skip-non-project-tasks)
68 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
69 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
70 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
71 (org-agenda-sorting-strategy
73 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
74 ((org-agenda-overriding-header (concat "Standalone Tasks"
75 (if bh/hide-scheduled-and-waiting-next-tasks
77 " (including WAITING and SCHEDULED tasks)")))
78 (org-agenda-skip-function 'bh/skip-project-tasks)
79 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
80 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
81 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
82 (org-agenda-sorting-strategy
84 (tags-todo "-CANCELLED+WAITING|HOLD/!"
85 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
86 (org-agenda-skip-function 'bh/skip-stuck-projects)
87 (org-tags-match-list-sublevels nil)
88 (org-agenda-todo-ignore-scheduled t)
89 (org-agenda-todo-ignore-deadlines t)))
91 ((org-agenda-overriding-header "Tasks to Archive")
92 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
93 (org-tags-match-list-sublevels nil))))
96 ; org mode agenda files
97 (setq org-agenda-files
98 (quote ("~/projects/org-notes/debbugs.org"
99 "~/projects/org-notes/notes.org"
100 "~/projects/org-notes/refile.org"
101 "~/projects/org-notes/diary.org"
102 "~/projects/org-notes/ool.org"
103 "~/projects/org-notes/sndservers.org"
104 "~/projects/org-notes/chaim.org"
105 "~/projects/org-notes/wildman.org"
106 "~/projects/org-notes/uddin.org"
107 "~/projects/org-notes/reviews.org"
108 "~/projects/org-notes/hpcbio.org"
109 "~/projects/org-notes/fh.org")))
111 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
112 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
113 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
114 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
115 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
116 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
117 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
118 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
119 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
121 (setq org-global-properties '(("Effort_ALL 0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
122 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
124 (setq org-default-notes-file "~/projects/org-notes/notes.org")
125 (setq org-capture-templates ;; mail-specific note template, identified by "m"
126 '(("m" "Mail" entry (file+headline "~/projects/org-notes/refile.org" "Mail")
127 "* %?\n\n Source: %u, %c\n %i")
128 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
129 "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
130 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
131 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
132 ("n" "note" entry (file "~/projects/org-notes/refile.org")
133 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
134 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
135 "* %? \n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
136 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
137 "* %?\n%U\n" :clock-in t :clock-resume t)
138 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
139 "* TODO Review %c\n%U\n" :immediate-finish t)
140 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
141 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
142 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
143 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
144 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
145 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
146 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
147 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
148 ("J" "job" entry (file "~/projects/org-notes/refile.org")
149 "* TODO Apply for %a%? :job:\nSCHEDULED: %(format-time-string \"<%Y-%m-%d 17:00-17:30>\")\n%U\n%a\n" :clock-in t :clock-resume t)
150 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
151 "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"<%Y-%m-%d .+1d/3d>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n%a\n")
155 ;; Remove empty LOGBOOK drawers on clock out
156 (defun bh/remove-empty-drawer-on-clock-out ()
159 (beginning-of-line 0)
160 (org-remove-empty-drawer-at (point))))
162 (defun my/org-add-id ()
165 (if (org-current-level)
173 ; org mode configuration from http://doc.norang.ca/org-mode.html
174 ;; Custom Key Bindings
175 (global-set-key (kbd "<f12>") 'org-agenda)
176 (global-set-key (kbd "<f5>") 'bh/org-todo)
177 (global-set-key (kbd "<S-f5>") 'bh/widen)
178 (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
179 (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
180 (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
181 (global-set-key (kbd "<f9> b") 'bbdb)
182 (global-set-key (kbd "<f9> c") 'calendar)
183 (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
184 (global-set-key (kbd "<f9> h") 'bh/hide-other)
185 (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
186 (global-set-key (kbd "<f9> w") 'widen)
188 ; change the outline mode prefix from C-c @ to C-c C-2
189 (setq outline-minor-mode-prefix "C-c C-2")
190 (add-hook 'outline-minor-mode-hook
191 (lambda () (local-set-key (kbd "C-c C-2")
192 outline-mode-prefix-map)))
194 (global-set-key (kbd "<f9> I") 'bh/punch-in)
195 (global-set-key (kbd "<f9> O") 'bh/punch-out)
197 (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
199 (global-set-key (kbd "<f9> r") 'boxquote-region)
200 (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
202 (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
203 (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
205 (global-set-key (kbd "<f9> v") 'visible-mode)
206 (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
207 (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
208 (global-set-key (kbd "C-<f9>") 'previous-buffer)
209 (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
210 (global-set-key (kbd "C-x n r") 'narrow-to-region)
211 (global-set-key (kbd "C-<f10>") 'next-buffer)
212 (global-set-key (kbd "<f11>") 'org-clock-goto)
213 (global-set-key (kbd "C-<f11>") 'org-clock-in)
214 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
215 (global-set-key (kbd "C-c c") 'org-capture)
217 (defun bh/hide-other ()
220 (org-back-to-heading 'invisible-ok)
226 (defun bh/set-truncate-lines ()
227 "Toggle value of truncate-lines and refresh window display."
229 (setq truncate-lines (not truncate-lines))
230 ;; now refresh window display (an idiom from simple.el):
232 (set-window-start (selected-window)
233 (window-start (selected-window)))))
235 (defun bh/make-org-scratch ()
237 (find-file "/tmp/publish/scratch.org")
238 (gnus-make-directory "/tmp/publish"))
240 (defun bh/switch-to-scratch ()
242 (switch-to-buffer "*scratch*"))
244 (setq org-use-fast-todo-selection t)
245 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
247 (setq org-todo-keywords
248 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
249 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
251 (setq org-todo-keyword-faces
252 (quote (("TODO" :foreground "red" :weight bold)
253 ("NEXT" :foreground "blue" :weight bold)
254 ("DONE" :foreground "forest green" :weight bold)
255 ("WAITING" :foreground "orange" :weight bold)
256 ("HOLD" :foreground "magenta" :weight bold)
257 ("CANCELLED" :foreground "forest green" :weight bold)
258 ("MEETING" :foreground "forest green" :weight bold)
259 ("PHONE" :foreground "forest green" :weight bold))))
261 (setq org-todo-state-tags-triggers
262 (quote (("CANCELLED" ("CANCELLED" . t))
263 ("WAITING" ("WAITING" . t))
264 ("HOLD" ("WAITING") ("HOLD" . t))
265 (done ("WAITING") ("HOLD"))
266 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
267 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
268 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
272 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
273 ; add ids on creation of nodes
274 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
275 ; create function to create headlines in file. This comes from
276 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
277 (defun my/org-add-ids-to-headlines-in-file ()
278 "Add ID properties to all headlines in the current file which
279 do not already have one."
281 (org-map-entries 'org-id-get-create))
282 ; if we wanted to do this to every buffer, do the following:
283 ; (add-hook 'org-mode-hook
285 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
288 ; resolve clocks after 10 minutes of idle; use xprintidle
289 ; (setq org-clock-idle-time 10)
290 ; (setq org-clock-x11idle-program-name "xprintidle")
292 ; this is from http://doc.norang.ca/org-mode.html#Capture
293 ; use C-M-r for org mode capture
294 (global-set-key (kbd "C-M-r") 'org-capture)
296 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
297 (setq org-refile-targets (quote ((nil :maxlevel . 9)
298 (org-agenda-files :maxlevel . 9))))
300 ; Use full outline paths for refile targets - we file directly with IDO
301 (setq org-refile-use-outline-path t)
303 ; Targets complete directly with IDO
304 (setq org-outline-path-complete-in-steps nil)
306 ; Allow refile to create parent tasks with confirmation
307 (setq org-refile-allow-creating-parent-nodes (quote confirm))
309 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
310 ; (setq org-completion-use-ido t)
311 ; (setq ido-everywhere t)
312 ; (setq ido-max-directory-size 100000)
313 ; (ido-mode (quote both))
314 ; ; Use the current window when visiting files and buffers with ido
315 ; (setq ido-default-file-method 'selected-window)
316 ; (setq ido-default-buffer-method 'selected-window)
317 ; ; Use the current window for indirect buffer display
318 ; (setq org-indirect-buffer-display 'current-window)
322 ; Exclude DONE state tasks from refile targets
323 (defun bh/verify-refile-target ()
324 "Exclude todo keywords with a done state from refile targets"
325 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
327 (setq org-refile-target-verify-function 'bh/verify-refile-target)
329 ;; ensure that emacsclient will show just the note to be edited when invoked
330 ;; from Mutt, and that it will shut down emacsclient once finished;
331 ;; fallback to legacy behavior when not invoked via org-protocol.
332 (require 'org-protocol)
333 (add-hook 'org-capture-mode-hook 'delete-other-windows)
334 (setq my-org-protocol-flag nil)
335 (defadvice org-capture-finalize (after delete-frame-at-end activate)
336 "Delete frame at remember finalization"
337 (progn (if my-org-protocol-flag (delete-frame))
338 (setq my-org-protocol-flag nil)))
339 (defadvice org-capture-refile (around delete-frame-after-refile activate)
340 "Delete frame at remember refile"
341 (if my-org-protocol-flag
343 (setq my-org-protocol-flag nil)
348 (defadvice org-capture-kill (after delete-frame-at-end activate)
349 "Delete frame at remember abort"
350 (progn (if my-org-protocol-flag (delete-frame))
351 (setq my-org-protocol-flag nil)))
352 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
353 (setq my-org-protocol-flag t))
355 (defadvice org-insert-todo-heading (after dla/create-id activate)
360 (add-to-list 'org-modules 'org-habit)
362 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
363 (defun open-mail-in-mutt (message)
364 "Open a mail message in Mutt, using an external terminal.
366 Message can be specified either by a path pointing inside a
367 Maildir, or by Message-ID."
368 (interactive "MPath or Message-ID: ")
370 (format "faf xterm -e \"%s %s\""
371 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
373 ;; add support for "mutt:ID" links
374 (org-add-link-type "mutt" 'open-mail-in-mutt)
376 (defun my-org-mode-setup ()
377 (load-library "reftex")
378 (and (buffer-file-name)
379 (file-exists-p (buffer-file-name))
382 (reftex-set-cite-format
383 '((?b . "[[bib:%l][%l-bib]]")
384 (?n . "[[notes:%l][%l-notes]]")
386 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
388 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
389 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
390 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
391 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
393 (add-hook 'org-mode-hook 'my-org-mode-setup)
395 (defun org-mode-reftex-search ()
397 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
399 (defun open-research-paper (bibtexkey)
400 "Open a paper by bibtex key"
401 (interactive "bibtex key: ")
404 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
405 (org-add-link-type "papers" 'open-research-paper)
406 (defun open-research-paper-pdf (bibtexkey)
407 "Open a paper pdf by bibtex key"
408 (interactive "bibtex key: ")
410 (format "%s -p evince %s"
411 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
412 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
414 (add-to-list 'org-link-abbrev-alist
416 "~/projects/research/paper_notes.org::#%s"))
418 ; I pretty much always want hiearchical checkboxes
419 (setq org-hierachical-checkbox-statistics nil)
421 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
422 (add-to-list 'org-structure-template-alist
423 '("E" "\\begin{equation}\n?\n\\end{equation}"))
426 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
427 (defun my-rtcite-export-handler (path desc format)
428 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
429 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
430 (match-string 1 path)))
431 (path (substring path 0 (match-beginning 0))))
432 (cond ((eq format 'latex)
434 (equal 0 (search "rtcite:" desc)))
435 (format "\\cite{%s}" search)
436 (format "\\cite[%s]{%s}" desc search))))))
438 (org-add-link-type "rtcite"
440 'my-rtcite-export-handler)
443 (setq-default org-mobile-directory "/rzlab.ucr.edu:/sites/dav.donarmstrong.com/root/org/")
444 (when (string= system-name "rzlab.ucr.edu")
445 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
446 (setq-default org-directory "/home/don/org-mode/")
447 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
449 ;; org mode ical export
450 (setq org-icalendar-timezone "America/Los_Angeles")
451 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
452 ;; we already add the id manually
453 ;; (setq org-icalendar-store-UID t)
456 (org-babel-do-load-languages
457 'org-babel-load-languages
463 ;; org-babel-by-backend
464 (defmacro org-babel-by-backend (&rest body)
465 `(case (if (boundp 'backend)
466 (org-export-backend-name backend)
472 ;; ;; stolen from http://kieranhealy.org/esk/kjhealy.html
473 ;; (require 'org-latex)
474 ;; ;; Choose either listings or minted for exporting source code blocks.
475 ;; ;; Using minted (as here) requires pygments be installed. To use the
476 ;; ;; default listings package instead, use
477 ;; ;; (setq org-latex-listings t)
478 ;; ;; and change references to "minted" below to "listings"
479 ;; ; (setq org-latex-listings 'minted)
481 ;; ;; default settings for minted code blocks
482 ;; (setq org-latex-minted-options
483 ;; '(;("frame" "single")
484 ;; ("bgcolor" "bg") ; bg will need to be defined in the preamble of your document. It's defined in org-preamble-pdflatex.sty and org-preamble-xelatex.sty below.
485 ;; ("fontsize" "\\small")
487 ;; ;; turn off the default toc behavior; deal with it properly in headers to files.
488 ;; (defun org-latex-no-toc (depth)
490 ;; (format "%% Org-mode is exporting headings to %s levels.\n"
492 ;; (setq org-latex-format-toc-function 'org-latex-no-toc)
495 (add-to-list 'org-latex-classes
497 "\\documentclass[11pt,oneside,article]{memoir}\n"
498 ("\\section{%s}" . "\\section*{%s}")
499 ("\\subsection{%s}" . "\\subsection*{%s}")
500 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
501 ("\\paragraph{%s}" . "\\paragraph*{%s}")
502 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
504 (setq org-beamer-outline-frame-options "")
506 (add-to-list 'org-latex-classes
508 "\\documentclass[ignorenonframetext]{beamer}
509 [NO-DEFAULT-PACKAGES]
512 ("\\section{%s}" . "\\section*{%s}")
513 ("\\subsection{%s}" . "\\subsection*{%s}")
514 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
515 ("\\paragraph{%s}" . "\\paragraph*{%s}")
516 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
518 (add-to-list 'org-latex-classes
520 "\\documentclass[11pt,oneside]{memoir}\n"
521 ("\\chapter{%s}" . "\\chapter*{%s}")
522 ("\\section{%s}" . "\\section*{%s}")
523 ("\\subsection{%s}" . "\\subsection*{%s}")
524 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
526 (add-to-list 'org-latex-classes
528 "\\documentclass[11pt]{letter}
529 [NO-DEFAULT-PACKAGES]
532 ("\\section{%s}" . "\\section*{%s}")
533 ("\\subsection{%s}" . "\\subsection*{%s}")
534 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
535 ("\\paragraph{%s}" . "\\paragraph*{%s}")
536 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
538 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
539 ;; but adapted to use latexmk 4.22 or higher.
540 (setq org-latex-pdf-process '("latexmk -pdflatex=xelatex -bibtex -use-make -pdf %f"))
542 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
543 (setq org-latex-default-packages-alist
545 (setq org-latex-packages-alist
555 (defun org-create-formula--latex-header ()
556 "Return LaTeX header appropriate for previewing a LaTeX snippet."
557 (let ((info (org-combine-plists (org-export--get-global-options
558 (org-export-get-backend 'latex))
559 (org-export--get-inbuffer-options
560 (org-export-get-backend 'latex)))))
561 (org-latex-guess-babel-language
562 (org-latex-guess-inputenc
563 (org-splice-latex-header
564 org-format-latex-header
565 org-latex-default-packages-alist
567 (plist-get info :latex-header)))
571 ; support ignoring headers in org mode export to latex
572 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
573 (defadvice org-latex-headline (around my-latex-skip-headlines
574 (headline contents info) activate)
575 (if (member "ignoreheading" (org-element-property :tags headline))
576 (setq ad-return-value contents)
579 ;; keep latex logfiles
581 (setq org-latex-remove-logfiles nil)
584 (defun bh/is-project-p ()
585 "Any task with a todo keyword subtask"
589 (subtree-end (save-excursion (org-end-of-subtree t)))
590 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
593 (while (and (not has-subtask)
594 (< (point) subtree-end)
595 (re-search-forward "^\*+ " subtree-end t))
596 (when (member (org-get-todo-state) org-todo-keywords-1)
597 (setq has-subtask t))))
598 (and is-a-task has-subtask))))
600 (defun bh/is-project-subtree-p ()
601 "Any task with a todo keyword that is in a project subtree.
602 Callers of this function already widen the buffer view."
603 (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
606 (bh/find-project-task)
607 (if (equal (point) task)
611 (defun bh/is-task-p ()
612 "Any task with a todo keyword and no subtask"
616 (subtree-end (save-excursion (org-end-of-subtree t)))
617 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
620 (while (and (not has-subtask)
621 (< (point) subtree-end)
622 (re-search-forward "^\*+ " subtree-end t))
623 (when (member (org-get-todo-state) org-todo-keywords-1)
624 (setq has-subtask t))))
625 (and is-a-task (not has-subtask)))))
627 (defun bh/is-subproject-p ()
628 "Any task which is a subtask of another project"
629 (let ((is-subproject)
630 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
632 (while (and (not is-subproject) (org-up-heading-safe))
633 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
634 (setq is-subproject t))))
635 (and is-a-task is-subproject)))
637 (defun bh/list-sublevels-for-projects-indented ()
638 "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
639 This is normally used by skipping functions where this variable is already local to the agenda."
640 (if (marker-buffer org-agenda-restrict-begin)
641 (setq org-tags-match-list-sublevels 'indented)
642 (setq org-tags-match-list-sublevels nil))
645 (defun bh/list-sublevels-for-projects ()
646 "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
647 This is normally used by skipping functions where this variable is already local to the agenda."
648 (if (marker-buffer org-agenda-restrict-begin)
649 (setq org-tags-match-list-sublevels t)
650 (setq org-tags-match-list-sublevels nil))
653 (defvar bh/hide-scheduled-and-waiting-next-tasks t)
655 (defun bh/toggle-next-task-display ()
657 (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
658 (when (equal major-mode 'org-agenda-mode)
660 (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
662 (defun bh/skip-stuck-projects ()
663 "Skip trees that are not stuck projects"
666 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
667 (if (bh/is-project-p)
668 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
672 (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
673 (unless (member "WAITING" (org-get-tags-at))
677 next-headline)) ; a stuck project, has subtasks but no next task
680 (defun bh/skip-non-stuck-projects ()
681 "Skip trees that are not stuck projects"
682 ;; (bh/list-sublevels-for-projects-indented)
685 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
686 (if (bh/is-project-p)
687 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
691 (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
692 (unless (member "WAITING" (org-get-tags-at))
696 nil)) ; a stuck project, has subtasks but no next task
699 (defun bh/skip-non-projects ()
700 "Skip trees that are not projects"
701 ;; (bh/list-sublevels-for-projects-indented)
702 (if (save-excursion (bh/skip-non-stuck-projects))
705 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
709 ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
713 (save-excursion (org-end-of-subtree t))))
715 (defun bh/skip-project-trees-and-habits ()
716 "Skip trees that are projects"
719 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
728 (defun bh/skip-projects-and-habits-and-single-tasks ()
729 "Skip trees that are projects, tasks that are habits, single non-project tasks"
732 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
736 ((and bh/hide-scheduled-and-waiting-next-tasks
737 (member "WAITING" (org-get-tags-at)))
741 ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
746 (defun bh/skip-project-tasks-maybe ()
747 "Show tasks related to the current restriction.
748 When restricted to a project, skip project and sub project tasks, habits, NEXT tasks, and loose tasks.
749 When not restricted, skip project and sub-project tasks, habits, and project related tasks."
752 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
753 (next-headline (save-excursion (or (outline-next-heading) (point-max))))
754 (limit-to-project (marker-buffer org-agenda-restrict-begin)))
760 ((and (not limit-to-project)
761 (bh/is-project-subtree-p))
763 ((and limit-to-project
764 (bh/is-project-subtree-p)
765 (member (org-get-todo-state) (list "NEXT")))
770 (defun bh/skip-project-tasks ()
771 "Show non-project tasks.
772 Skip project and sub-project tasks, habits, and project related tasks."
775 (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
781 ((bh/is-project-subtree-p)
786 (defun bh/skip-non-project-tasks ()
788 Skip project and sub-project tasks, habits, and loose non-project tasks."
791 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
792 (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
798 ((and (bh/is-project-subtree-p)
799 (member (org-get-todo-state) (list "NEXT")))
801 ((not (bh/is-project-subtree-p))
806 (defun bh/skip-projects-and-habits ()
807 "Skip trees that are projects and tasks that are habits"
810 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
819 (defun bh/skip-non-subprojects ()
820 "Skip trees that are not projects"
821 (let ((next-headline (save-excursion (outline-next-heading))))
822 (if (bh/is-subproject-p)
826 ;; Resume clocking task when emacs is restarted
827 (org-clock-persistence-insinuate)
829 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
830 (setq org-clock-history-length 23)
831 ;; Resume clocking task on clock-in if the clock is open
832 (setq org-clock-in-resume t)
833 ;; Change tasks to NEXT when clocking in
834 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
835 ;; Separate drawers for clocking and logs
836 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
837 ;; Save clock data and state changes and notes in the LOGBOOK drawer
838 (setq org-clock-into-drawer t)
839 (setq org-log-into-drawer t)
840 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
841 (setq org-clock-out-remove-zero-time-clocks t)
842 ;; Clock out when moving task to a done state
843 (setq org-clock-out-when-done t)
844 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
845 (setq org-clock-persist t)
846 ;; Do not prompt to resume an active clock
847 (setq org-clock-persist-query-resume nil)
848 ;; Enable auto clock resolution for finding open clocks
849 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
850 ;; Include current clocking task in clock reports
851 (setq org-clock-report-include-clocking-task t)
854 (defvar bh/keep-clock-running nil)
856 (defun bh/clock-in-to-next (kw)
857 "Switch a task from TODO to NEXT when clocking in.
858 Skips capture tasks, projects, and subprojects.
859 Switch projects and subprojects from NEXT back to TODO"
860 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
862 ((and (member (org-get-todo-state) (list "TODO"))
865 ((and (member (org-get-todo-state) (list "NEXT"))
869 (defun bh/find-project-task ()
870 "Move point to the parent (project) task if any"
873 (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
874 (while (org-up-heading-safe)
875 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
876 (setq parent-task (point))))
877 (goto-char parent-task)
880 (defun bh/punch-in (arg)
881 "Start continuous clocking and set the default task to the
882 selected task. If no task is selected set the Organization task
883 as the default task."
885 (setq bh/keep-clock-running t)
886 (if (equal major-mode 'org-agenda-mode)
888 ;; We're in the agenda
890 (let* ((marker (org-get-at-bol 'org-hd-marker))
891 (tags (org-with-point-at marker (org-get-tags-at))))
892 (if (and (eq arg 4) tags)
893 (org-agenda-clock-in '(16))
894 (bh/clock-in-organization-task-as-default)))
896 ;; We are not in the agenda
900 ; Find the tags on the current task
901 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
903 (bh/clock-in-organization-task-as-default)))))
905 (defun bh/punch-out ()
907 (setq bh/keep-clock-running nil)
908 (when (org-clock-is-active)
910 (org-agenda-remove-restriction-lock))
912 (defun bh/clock-in-default-task ()
914 (org-with-point-at org-clock-default-task
917 (defun bh/clock-in-parent-task ()
918 "Move point to the parent (project) task if any and clock in"
923 (while (and (not parent-task) (org-up-heading-safe))
924 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
925 (setq parent-task (point))))
927 (org-with-point-at parent-task
929 (when bh/keep-clock-running
930 (bh/clock-in-default-task)))))))
932 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
934 (defun bh/clock-in-organization-task-as-default ()
936 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
937 (org-clock-in '(16))))
939 (defun bh/clock-out-maybe ()
940 (when (and bh/keep-clock-running
941 (not org-clock-clocking-in)
942 (marker-buffer org-clock-default-task)
943 (not org-clock-resolving-clocks-due-to-idleness))
944 (bh/clock-in-parent-task)))
946 (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
949 (defun bh/clock-in-task-by-id (id)
950 "Clock in a task by id"
951 (org-with-point-at (org-id-find id 'marker)
954 (defun bh/clock-in-last-task (arg)
955 "Clock in the interrupted task if there is one
956 Skip the default task and get the next one.
957 A prefix arg forces clock in of the default task."
959 (let ((clock-in-to-task
961 ((eq arg 4) org-clock-default-task)
962 ((and (org-clock-is-active)
963 (equal org-clock-default-task (cadr org-clock-history)))
964 (caddr org-clock-history))
965 ((org-clock-is-active) (cadr org-clock-history))
966 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
967 (t (car org-clock-history)))))
969 (org-with-point-at clock-in-to-task
970 (org-clock-in nil))))
973 ; allow for zero-width-space to be a break in regexp too
974 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
975 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
976 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
978 ;; support inserting screen shots
979 (defun my/org-insert-screenshot ()
980 "Take a screenshot into a time stamped unique-named file in the
981 same directory as the org-buffer and insert a link to this file."
983 (defvar my/org-insert-screenshot/filename)
984 (setq my/org-insert-screenshot/filename
986 "Screenshot to insert: "
988 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
993 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
994 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
995 (org-display-inline-images))