5 ;; The following lines are always needed. Choose your own keys.
6 (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
8 (global-set-key "\C-cl" 'org-store-link)
9 (global-set-key "\C-ca" 'org-agenda)
10 (global-set-key "\C-cb" 'org-iswitchb)
11 (setq-default org-log-done 'time)
12 (setq-default org-agenda-ndays 5)
14 ;; agenda configuration
15 ;; Do not dim blocked tasks
16 (setq org-agenda-dim-blocked-tasks nil)
18 ;; Compact the block agenda view
19 (setq org-agenda-compact-blocks t)
21 ;; Custom agenda command definitions
22 (setq org-agenda-custom-commands
23 (quote (("N" "Notes" tags "NOTE"
24 ((org-agenda-overriding-header "Notes")
25 (org-tags-match-list-sublevels t)))
26 ("h" "Habits" tags-todo "STYLE=\"habit\""
27 ((org-agenda-overriding-header "Habits")
28 (org-agenda-sorting-strategy
29 '(todo-state-down effort-up category-keep))))
33 ((org-agenda-overriding-header "Tasks to Refile")
34 (org-tags-match-list-sublevels nil)))
35 (tags-todo "-CANCELLED/!"
36 ((org-agenda-overriding-header "Stuck Projects")
37 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
38 (org-agenda-sorting-strategy
40 (tags-todo "-HOLD-CANCELLED/!"
41 ((org-agenda-overriding-header "Projects")
42 (org-agenda-skip-function 'bh/skip-non-projects)
43 (org-tags-match-list-sublevels 'indented)
44 (org-agenda-sorting-strategy
46 (tags-todo "-CANCELLED/!NEXT"
47 ((org-agenda-overriding-header (concat "Project Next Tasks"
48 (if bh/hide-scheduled-and-waiting-next-tasks
50 " (including WAITING and SCHEDULED tasks)")))
51 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
52 (org-tags-match-list-sublevels t)
53 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
54 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
55 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
56 (org-agenda-sorting-strategy
57 '(todo-state-down effort-up category-keep))))
58 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
59 ((org-agenda-overriding-header (concat "Project Subtasks"
60 (if bh/hide-scheduled-and-waiting-next-tasks
62 " (including WAITING and SCHEDULED tasks)")))
63 (org-agenda-skip-function 'bh/skip-non-project-tasks)
64 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
65 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
66 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
67 (org-agenda-sorting-strategy
69 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
70 ((org-agenda-overriding-header (concat "Standalone Tasks"
71 (if bh/hide-scheduled-and-waiting-next-tasks
73 " (including WAITING and SCHEDULED tasks)")))
74 (org-agenda-skip-function 'bh/skip-project-tasks)
75 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
76 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
77 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
78 (org-agenda-sorting-strategy
80 (tags-todo "-CANCELLED+WAITING|HOLD/!"
81 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
82 (org-agenda-skip-function 'bh/skip-stuck-projects)
83 (org-tags-match-list-sublevels nil)
84 (org-agenda-todo-ignore-scheduled t)
85 (org-agenda-todo-ignore-deadlines t)))
87 ((org-agenda-overriding-header "Tasks to Archive")
88 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
89 (org-tags-match-list-sublevels nil))))
92 ; org mode agenda files
93 (setq org-agenda-files
94 (quote ("~/projects/debbugs/debbugs.org"
95 "~/projects/org-notes/notes.org"
96 "~/projects/org-notes/refile.org"
97 "~/projects/org-notes/diary.org"
98 "~/projects/org-notes/ool.org"
99 "~/projects/org-notes/sndservers.org"
100 "~/projects/org-notes/chaim.org"
101 "~/projects/org-notes/wildman.org"
102 "~/projects/org-notes/uddin.org"
103 "~/projects/reviews/reviews.org"
104 "~/projects/org-notes/fh.org")))
106 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
107 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
108 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
109 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
110 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
111 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
112 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
113 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
114 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
116 (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")))
117 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
119 (setq org-default-notes-file "~/projects/org-notes/notes.org")
120 (setq org-capture-templates ;; mail-specific note template, identified by "m"
121 '(("m" "Mail" entry (file+headline "~/projects/org-notes/refile.org" "Mail")
122 "* %?\n\n Source: %u, %c\n %i")
123 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
124 "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
125 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
126 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
127 ("n" "note" entry (file "~/projects/org-notes/refile.org")
128 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
129 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
130 "* %? \n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
131 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
132 "* %?\n%U\n" :clock-in t :clock-resume t)
133 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
134 "* TODO Review %c\n%U\n" :immediate-finish t)
135 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
136 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
137 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
138 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
139 ("J" "job" entry (file "~/projects/org-notes/refile.org")
140 "* TODO Apply for %a%? :job:\nSCHEDULED: %(format-time-string \"<%Y-%m-%d %a 17:00-17:30>\")\n%U\n" :clock-in t :clock-resume t)
141 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
142 "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"<%Y-%m-%d %a .+1d/3d>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n")
146 ;; Remove empty LOGBOOK drawers on clock out
147 (defun bh/remove-empty-drawer-on-clock-out ()
150 (beginning-of-line 0)
151 (org-remove-empty-drawer-at "LOGBOOK" (point))))
153 (defun my/org-add-id ()
156 (if (org-current-level)
164 ; org mode configuration from http://doc.norang.ca/org-mode.html
165 ;; Custom Key Bindings
166 (global-set-key (kbd "<f12>") 'org-agenda)
167 (global-set-key (kbd "<f5>") 'bh/org-todo)
168 (global-set-key (kbd "<S-f5>") 'bh/widen)
169 (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
170 (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
171 (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
172 (global-set-key (kbd "<f9> b") 'bbdb)
173 (global-set-key (kbd "<f9> c") 'calendar)
174 (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
175 (global-set-key (kbd "<f9> h") 'bh/hide-other)
176 (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
177 (global-set-key (kbd "<f9> w") 'widen)
179 ; change the outline mode prefix from C-c @ to C-c C-2
180 (setq outline-minor-mode-prefix "C-c C-2")
181 (add-hook 'outline-minor-mode-hook
182 (lambda () (local-set-key (kbd "C-c C-2")
183 outline-mode-prefix-map)))
185 (global-set-key (kbd "<f9> I") 'bh/punch-in)
186 (global-set-key (kbd "<f9> O") 'bh/punch-out)
188 (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
190 (global-set-key (kbd "<f9> r") 'boxquote-region)
191 (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
193 (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
194 (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
196 (global-set-key (kbd "<f9> v") 'visible-mode)
197 (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
198 (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
199 (global-set-key (kbd "C-<f9>") 'previous-buffer)
200 (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
201 (global-set-key (kbd "C-x n r") 'narrow-to-region)
202 (global-set-key (kbd "C-<f10>") 'next-buffer)
203 (global-set-key (kbd "<f11>") 'org-clock-goto)
204 (global-set-key (kbd "C-<f11>") 'org-clock-in)
205 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
206 (global-set-key (kbd "C-c c") 'org-capture)
208 (defun bh/hide-other ()
211 (org-back-to-heading 'invisible-ok)
217 (defun bh/set-truncate-lines ()
218 "Toggle value of truncate-lines and refresh window display."
220 (setq truncate-lines (not truncate-lines))
221 ;; now refresh window display (an idiom from simple.el):
223 (set-window-start (selected-window)
224 (window-start (selected-window)))))
226 (defun bh/make-org-scratch ()
228 (find-file "/tmp/publish/scratch.org")
229 (gnus-make-directory "/tmp/publish"))
231 (defun bh/switch-to-scratch ()
233 (switch-to-buffer "*scratch*"))
235 (setq org-use-fast-todo-selection t)
236 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
238 (setq org-todo-keywords
239 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
240 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
242 (setq org-todo-keyword-faces
243 (quote (("TODO" :foreground "red" :weight bold)
244 ("NEXT" :foreground "blue" :weight bold)
245 ("DONE" :foreground "forest green" :weight bold)
246 ("WAITING" :foreground "orange" :weight bold)
247 ("HOLD" :foreground "magenta" :weight bold)
248 ("CANCELLED" :foreground "forest green" :weight bold)
249 ("MEETING" :foreground "forest green" :weight bold)
250 ("PHONE" :foreground "forest green" :weight bold))))
252 (setq org-todo-state-tags-triggers
253 (quote (("CANCELLED" ("CANCELLED" . t))
254 ("WAITING" ("WAITING" . t))
255 ("HOLD" ("WAITING") ("HOLD" . t))
256 (done ("WAITING") ("HOLD"))
257 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
258 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
259 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
263 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
264 ; add ids on creation of nodes
265 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
266 ; create function to create headlines in file. This comes from
267 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
268 (defun my/org-add-ids-to-headlines-in-file ()
269 "Add ID properties to all headlines in the current file which
270 do not already have one."
272 (org-map-entries 'org-id-get-create))
273 ; if we wanted to do this to every buffer, do the following:
274 ; (add-hook 'org-mode-hook
276 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
279 ; resolve clocks after 10 minutes of idle; use xprintidle
280 ; (setq org-clock-idle-time 10)
281 ; (setq org-clock-x11idle-program-name "xprintidle")
283 ; this is from http://doc.norang.ca/org-mode.html#Capture
284 ; use C-M-r for org mode capture
285 (global-set-key (kbd "C-M-r") 'org-capture)
287 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
288 (setq org-refile-targets (quote ((nil :maxlevel . 9)
289 (org-agenda-files :maxlevel . 9))))
291 ; Use full outline paths for refile targets - we file directly with IDO
292 (setq org-refile-use-outline-path t)
294 ; Targets complete directly with IDO
295 (setq org-outline-path-complete-in-steps nil)
297 ; Allow refile to create parent tasks with confirmation
298 (setq org-refile-allow-creating-parent-nodes (quote confirm))
300 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
301 ; (setq org-completion-use-ido t)
302 ; (setq ido-everywhere t)
303 ; (setq ido-max-directory-size 100000)
304 ; (ido-mode (quote both))
305 ; ; Use the current window when visiting files and buffers with ido
306 ; (setq ido-default-file-method 'selected-window)
307 ; (setq ido-default-buffer-method 'selected-window)
308 ; ; Use the current window for indirect buffer display
309 ; (setq org-indirect-buffer-display 'current-window)
313 ; Exclude DONE state tasks from refile targets
314 (defun bh/verify-refile-target ()
315 "Exclude todo keywords with a done state from refile targets"
316 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
318 (setq org-refile-target-verify-function 'bh/verify-refile-target)
320 ;; ensure that emacsclient will show just the note to be edited when invoked
321 ;; from Mutt, and that it will shut down emacsclient once finished;
322 ;; fallback to legacy behavior when not invoked via org-protocol.
323 (require 'org-protocol)
324 (add-hook 'org-capture-mode-hook 'delete-other-windows)
325 (setq my-org-protocol-flag nil)
326 (defadvice org-capture-finalize (after delete-frame-at-end activate)
327 "Delete frame at remember finalization"
328 (progn (if my-org-protocol-flag (delete-frame))
329 (setq my-org-protocol-flag nil)))
330 (defadvice org-capture-refile (around delete-frame-after-refile activate)
331 "Delete frame at remember refile"
332 (if my-org-protocol-flag
334 (setq my-org-protocol-flag nil)
339 (defadvice org-capture-kill (after delete-frame-at-end activate)
340 "Delete frame at remember abort"
341 (progn (if my-org-protocol-flag (delete-frame))
342 (setq my-org-protocol-flag nil)))
343 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
344 (setq my-org-protocol-flag t))
346 (defadvice org-insert-todo-heading (after dla/create-id activate)
351 (add-to-list 'org-modules 'org-habit)
353 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
354 (defun open-mail-in-mutt (message)
355 "Open a mail message in Mutt, using an external terminal.
357 Message can be specified either by a path pointing inside a
358 Maildir, or by Message-ID."
359 (interactive "MPath or Message-ID: ")
361 (format "faf xterm -e \"%s %s\""
362 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
364 ;; add support for "mutt:ID" links
365 (org-add-link-type "mutt" 'open-mail-in-mutt)
367 (defun my-org-mode-setup ()
368 (load-library "reftex")
369 (and (buffer-file-name)
370 (file-exists-p (buffer-file-name))
373 (reftex-set-cite-format
374 '((?b . "[[bib:%l][%l-bib]]")
375 (?n . "[[notes:%l][%l-notes]]")
377 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
379 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
380 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
381 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
382 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
384 (add-hook 'org-mode-hook 'my-org-mode-setup)
386 (defun org-mode-reftex-search ()
388 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
390 (defun open-research-paper (bibtexkey)
391 "Open a paper by bibtex key"
392 (interactive "bibtex key: ")
395 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
396 (org-add-link-type "papers" 'open-research-paper)
397 (defun open-research-paper-pdf (bibtexkey)
398 "Open a paper pdf by bibtex key"
399 (interactive "bibtex key: ")
401 (format "%s -p evince %s"
402 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
403 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
405 (add-to-list 'org-link-abbrev-alist
407 "~/projects/research/paper_notes.org::#%s"))
409 ; I pretty much always want hiearchical checkboxes
410 (setq org-hierachical-checkbox-statistics nil)
413 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
414 (defun my-rtcite-export-handler (path desc format)
415 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
416 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
417 (match-string 1 path)))
418 (path (substring path 0 (match-beginning 0))))
419 (cond ((eq format 'latex)
421 (equal 0 (search "rtcite:" desc)))
422 (format "\\cite{%s}" search)
423 (format "\\cite[%s]{%s}" desc search))))))
425 (org-add-link-type "rtcite"
427 'my-rtcite-export-handler)
430 (setq-default org-mobile-directory "/rzlab.ucr.edu:/sites/dav.donarmstrong.com/root/org/")
431 (setq-default org-directory "/home/don/org-mode/")
432 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
434 ;; org mode ical export
435 (setq org-icalendar-timezone "America/Los_Angeles")
436 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
437 ;; we already add the id manually
438 ;; (setq org-icalendar-store-UID t)
441 (org-babel-do-load-languages
442 'org-babel-load-languages
448 ;; org-babel-by-backend
449 (defmacro org-babel-by-backend (&rest body)
450 `(case (if (boundp 'backend)
451 (org-export-backend-name backend)
457 ;; ;; stolen from http://kieranhealy.org/esk/kjhealy.html
458 ;; (require 'org-latex)
459 ;; ;; Choose either listings or minted for exporting source code blocks.
460 ;; ;; Using minted (as here) requires pygments be installed. To use the
461 ;; ;; default listings package instead, use
462 ;; ;; (setq org-latex-listings t)
463 ;; ;; and change references to "minted" below to "listings"
464 ;; ; (setq org-latex-listings 'minted)
466 ;; ;; default settings for minted code blocks
467 ;; (setq org-latex-minted-options
468 ;; '(;("frame" "single")
469 ;; ("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.
470 ;; ("fontsize" "\\small")
472 ;; ;; turn off the default toc behavior; deal with it properly in headers to files.
473 ;; (defun org-latex-no-toc (depth)
475 ;; (format "%% Org-mode is exporting headings to %s levels.\n"
477 ;; (setq org-latex-format-toc-function 'org-latex-no-toc)
480 (add-to-list 'org-latex-classes
482 "\\documentclass[11pt,oneside,article]{memoir}\n"
483 ("\\section{%s}" . "\\section*{%s}")
484 ("\\subsection{%s}" . "\\subsection*{%s}")
485 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
486 ("\\paragraph{%s}" . "\\paragraph*{%s}")
487 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
489 (setq org-beamer-outline-frame-options "")
491 (add-to-list 'org-latex-classes
493 "\\documentclass[ignorenonframetext]{beamer}
494 [NO-DEFAULT-PACKAGES]
497 ("\\section{%s}" . "\\section*{%s}")
498 ("\\subsection{%s}" . "\\subsection*{%s}")
499 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
500 ("\\paragraph{%s}" . "\\paragraph*{%s}")
501 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
503 (add-to-list 'org-latex-classes
505 "\\documentclass[11pt,oneside]{memoir}\n"
506 ("\\chapter{%s}" . "\\chapter*{%s}")
507 ("\\section{%s}" . "\\section*{%s}")
508 ("\\subsection{%s}" . "\\subsection*{%s}")
509 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
511 (add-to-list 'org-latex-classes
513 "\\documentclass[11pt]{letter}
514 [NO-DEFAULT-PACKAGES]
517 ("\\section{%s}" . "\\section*{%s}")
518 ("\\subsection{%s}" . "\\subsection*{%s}")
519 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
520 ("\\paragraph{%s}" . "\\paragraph*{%s}")
521 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
523 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
524 ;; but adapted to use latexmk 4.22 or higher.
525 (setq org-latex-pdf-process '("latexmk -pdflatex=xelatex -bibtex -use-make -pdf %f"))
527 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
528 (setq org-latex-default-packages-alist
530 (setq org-latex-packages-alist
540 (defun org-create-formula--latex-header ()
541 "Return LaTeX header appropriate for previewing a LaTeX snippet."
542 (let ((info (org-combine-plists (org-export--get-global-options
543 (org-export-get-backend 'latex))
544 (org-export--get-inbuffer-options
545 (org-export-get-backend 'latex)))))
546 (org-latex-guess-babel-language
547 (org-latex-guess-inputenc
548 (org-splice-latex-header
549 org-format-latex-header
550 org-latex-default-packages-alist
552 (plist-get info :latex-header)))
556 ; support ignoring headers in org mode export to latex
557 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
558 (defadvice org-latex-headline (around my-latex-skip-headlines
559 (headline contents info) activate)
560 (if (member "ignoreheading" (org-element-property :tags headline))
561 (setq ad-return-value contents)
564 ;; keep latex logfiles
566 (setq org-latex-remove-logfiles nil)
569 (defun bh/is-project-p ()
570 "Any task with a todo keyword subtask"
574 (subtree-end (save-excursion (org-end-of-subtree t)))
575 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
578 (while (and (not has-subtask)
579 (< (point) subtree-end)
580 (re-search-forward "^\*+ " subtree-end t))
581 (when (member (org-get-todo-state) org-todo-keywords-1)
582 (setq has-subtask t))))
583 (and is-a-task has-subtask))))
585 (defun bh/is-project-subtree-p ()
586 "Any task with a todo keyword that is in a project subtree.
587 Callers of this function already widen the buffer view."
588 (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
591 (bh/find-project-task)
592 (if (equal (point) task)
596 (defun bh/is-task-p ()
597 "Any task with a todo keyword and no subtask"
601 (subtree-end (save-excursion (org-end-of-subtree t)))
602 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
605 (while (and (not has-subtask)
606 (< (point) subtree-end)
607 (re-search-forward "^\*+ " subtree-end t))
608 (when (member (org-get-todo-state) org-todo-keywords-1)
609 (setq has-subtask t))))
610 (and is-a-task (not has-subtask)))))
612 (defun bh/is-subproject-p ()
613 "Any task which is a subtask of another project"
614 (let ((is-subproject)
615 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
617 (while (and (not is-subproject) (org-up-heading-safe))
618 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
619 (setq is-subproject t))))
620 (and is-a-task is-subproject)))
622 (defun bh/list-sublevels-for-projects-indented ()
623 "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
624 This is normally used by skipping functions where this variable is already local to the agenda."
625 (if (marker-buffer org-agenda-restrict-begin)
626 (setq org-tags-match-list-sublevels 'indented)
627 (setq org-tags-match-list-sublevels nil))
630 (defun bh/list-sublevels-for-projects ()
631 "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
632 This is normally used by skipping functions where this variable is already local to the agenda."
633 (if (marker-buffer org-agenda-restrict-begin)
634 (setq org-tags-match-list-sublevels t)
635 (setq org-tags-match-list-sublevels nil))
638 (defvar bh/hide-scheduled-and-waiting-next-tasks t)
640 (defun bh/toggle-next-task-display ()
642 (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
643 (when (equal major-mode 'org-agenda-mode)
645 (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
647 (defun bh/skip-stuck-projects ()
648 "Skip trees that are not stuck projects"
651 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
652 (if (bh/is-project-p)
653 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
657 (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
658 (unless (member "WAITING" (org-get-tags-at))
662 next-headline)) ; a stuck project, has subtasks but no next task
665 (defun bh/skip-non-stuck-projects ()
666 "Skip trees that are not stuck projects"
667 ;; (bh/list-sublevels-for-projects-indented)
670 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
671 (if (bh/is-project-p)
672 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
676 (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
677 (unless (member "WAITING" (org-get-tags-at))
681 nil)) ; a stuck project, has subtasks but no next task
684 (defun bh/skip-non-projects ()
685 "Skip trees that are not projects"
686 ;; (bh/list-sublevels-for-projects-indented)
687 (if (save-excursion (bh/skip-non-stuck-projects))
690 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
694 ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
698 (save-excursion (org-end-of-subtree t))))
700 (defun bh/skip-project-trees-and-habits ()
701 "Skip trees that are projects"
704 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
713 (defun bh/skip-projects-and-habits-and-single-tasks ()
714 "Skip trees that are projects, tasks that are habits, single non-project tasks"
717 (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
721 ((and bh/hide-scheduled-and-waiting-next-tasks
722 (member "WAITING" (org-get-tags-at)))
726 ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
731 (defun bh/skip-project-tasks-maybe ()
732 "Show tasks related to the current restriction.
733 When restricted to a project, skip project and sub project tasks, habits, NEXT tasks, and loose tasks.
734 When not restricted, skip project and sub-project tasks, habits, and project related tasks."
737 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
738 (next-headline (save-excursion (or (outline-next-heading) (point-max))))
739 (limit-to-project (marker-buffer org-agenda-restrict-begin)))
745 ((and (not limit-to-project)
746 (bh/is-project-subtree-p))
748 ((and limit-to-project
749 (bh/is-project-subtree-p)
750 (member (org-get-todo-state) (list "NEXT")))
755 (defun bh/skip-project-tasks ()
756 "Show non-project tasks.
757 Skip project and sub-project tasks, habits, and project related tasks."
760 (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
766 ((bh/is-project-subtree-p)
771 (defun bh/skip-non-project-tasks ()
773 Skip project and sub-project tasks, habits, and loose non-project tasks."
776 (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
777 (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
783 ((and (bh/is-project-subtree-p)
784 (member (org-get-todo-state) (list "NEXT")))
786 ((not (bh/is-project-subtree-p))
791 (defun bh/skip-projects-and-habits ()
792 "Skip trees that are projects and tasks that are habits"
795 (let ((subtree-end (save-excursion (org-end-of-subtree t))))
804 (defun bh/skip-non-subprojects ()
805 "Skip trees that are not projects"
806 (let ((next-headline (save-excursion (outline-next-heading))))
807 (if (bh/is-subproject-p)
811 ;; Resume clocking task when emacs is restarted
812 (org-clock-persistence-insinuate)
814 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
815 (setq org-clock-history-length 23)
816 ;; Resume clocking task on clock-in if the clock is open
817 (setq org-clock-in-resume t)
818 ;; Change tasks to NEXT when clocking in
819 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
820 ;; Separate drawers for clocking and logs
821 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
822 ;; Save clock data and state changes and notes in the LOGBOOK drawer
823 (setq org-clock-into-drawer t)
824 (setq org-log-into-drawer t)
825 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
826 (setq org-clock-out-remove-zero-time-clocks t)
827 ;; Clock out when moving task to a done state
828 (setq org-clock-out-when-done t)
829 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
830 (setq org-clock-persist t)
831 ;; Do not prompt to resume an active clock
832 (setq org-clock-persist-query-resume nil)
833 ;; Enable auto clock resolution for finding open clocks
834 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
835 ;; Include current clocking task in clock reports
836 (setq org-clock-report-include-clocking-task t)
839 (defvar bh/keep-clock-running nil)
841 (defun bh/clock-in-to-next (kw)
842 "Switch a task from TODO to NEXT when clocking in.
843 Skips capture tasks, projects, and subprojects.
844 Switch projects and subprojects from NEXT back to TODO"
845 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
847 ((and (member (org-get-todo-state) (list "TODO"))
850 ((and (member (org-get-todo-state) (list "NEXT"))
854 (defun bh/find-project-task ()
855 "Move point to the parent (project) task if any"
858 (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
859 (while (org-up-heading-safe)
860 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
861 (setq parent-task (point))))
862 (goto-char parent-task)
865 (defun bh/punch-in (arg)
866 "Start continuous clocking and set the default task to the
867 selected task. If no task is selected set the Organization task
868 as the default task."
870 (setq bh/keep-clock-running t)
871 (if (equal major-mode 'org-agenda-mode)
873 ;; We're in the agenda
875 (let* ((marker (org-get-at-bol 'org-hd-marker))
876 (tags (org-with-point-at marker (org-get-tags-at))))
877 (if (and (eq arg 4) tags)
878 (org-agenda-clock-in '(16))
879 (bh/clock-in-organization-task-as-default)))
881 ;; We are not in the agenda
885 ; Find the tags on the current task
886 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
888 (bh/clock-in-organization-task-as-default)))))
890 (defun bh/punch-out ()
892 (setq bh/keep-clock-running nil)
893 (when (org-clock-is-active)
895 (org-agenda-remove-restriction-lock))
897 (defun bh/clock-in-default-task ()
899 (org-with-point-at org-clock-default-task
902 (defun bh/clock-in-parent-task ()
903 "Move point to the parent (project) task if any and clock in"
908 (while (and (not parent-task) (org-up-heading-safe))
909 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
910 (setq parent-task (point))))
912 (org-with-point-at parent-task
914 (when bh/keep-clock-running
915 (bh/clock-in-default-task)))))))
917 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
919 (defun bh/clock-in-organization-task-as-default ()
921 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
922 (org-clock-in '(16))))
924 (defun bh/clock-out-maybe ()
925 (when (and bh/keep-clock-running
926 (not org-clock-clocking-in)
927 (marker-buffer org-clock-default-task)
928 (not org-clock-resolving-clocks-due-to-idleness))
929 (bh/clock-in-parent-task)))
931 (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
934 (defun bh/clock-in-task-by-id (id)
935 "Clock in a task by id"
936 (org-with-point-at (org-id-find id 'marker)
939 (defun bh/clock-in-last-task (arg)
940 "Clock in the interrupted task if there is one
941 Skip the default task and get the next one.
942 A prefix arg forces clock in of the default task."
944 (let ((clock-in-to-task
946 ((eq arg 4) org-clock-default-task)
947 ((and (org-clock-is-active)
948 (equal org-clock-default-task (cadr org-clock-history)))
949 (caddr org-clock-history))
950 ((org-clock-is-active) (cadr org-clock-history))
951 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
952 (t (car org-clock-history)))))
954 (org-with-point-at clock-in-to-task
955 (org-clock-in nil))))
958 ; allow for zero-width-space to be a break in regexp too
959 (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
960 (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
961 (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)