]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/org-mode-configuration.el
just file org mode configuration directly
[lib.git] / emacs_el / configuration / org-mode-configuration.el
1 (require 'org-id)
2 (require 'reftex)
3 (require 'gnus)
4
5 (require 'org)
6 (require 'org-agenda)
7 (require 'org-habit)
8 ;; The following lines are always needed. Choose your own keys.
9 (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
10 (eval-when-compile
11   (require 'cl))
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)
17
18 ;; agenda configuration
19 ;; Do not dim blocked tasks
20 (setq org-agenda-dim-blocked-tasks nil)
21
22 ;; Compact the block agenda view
23 (setq org-agenda-compact-blocks t)
24
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))))
34               (" " "Agenda"
35                ((agenda "" nil)
36                 (tags "REFILE"
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
43                              '(category-keep))))
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
49                              '(category-keep))))
50                 (tags-todo "-CANCELLED/!NEXT"
51                            ((org-agenda-overriding-header (concat "Project Next Tasks"
52                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
53                                                                       ""
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
65                                                                       ""
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
72                              '(category-keep))))
73                 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
74                            ((org-agenda-overriding-header (concat "Standalone Tasks"
75                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
76                                                                       ""
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
83                              '(category-keep))))
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)))
90                 (tags "-REFILE/"
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))))
94                nil))))
95
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/holidays.org"
101               "~/projects/org-notes/refile.org"
102               "~/projects/org-notes/diary.org"
103               "~/projects/org-notes/ool.org"
104               "~/projects/org-notes/sndservers.org"
105               "~/projects/org-notes/chaim.org"
106               "~/projects/org-notes/wildman.org"
107               "~/projects/org-notes/uddin.org"
108           "~/projects/org-notes/reviews.org"
109           "~/projects/org-notes/hpcbio.org"
110           "~/org-mode/from-mobile.org"
111               "~/projects/org-notes/fh.org")))
112
113 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
114 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
115 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
116 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
117 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
118 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
119 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
120 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
121 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
122
123 (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")))
124 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
125
126 ;; add automatic reminders for appointments
127 (defadvice  org-agenda-redo (after org-agenda-redo-add-appts)
128   "Pressing `r' on the agenda will also add appointments."
129   (progn 
130     (setq appt-time-msg-list nil)
131     (org-agenda-to-appt)))
132
133 (setq org-default-notes-file "~/projects/org-notes/notes.org")
134 (setq org-id-link-to-org-use-id t)
135 (setq org-capture-templates  ;; mail-specific note template, identified by "m"
136       '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
137          "* %?\n\n  Source: %u, [[%:link][%:description]]\n  %:initial")
138         ("t" "todo" entry (file "~/projects/org-notes/refile.org")
139          "* TODO %?\n  :PROPERTIES:\n  :END:\n  :LOGBOOK:\n  :END:\n%U\n%a\n" :clock-in t :clock-resume t)
140         ("r" "respond" entry (file "~/projects/org-notes/refile.org")
141          "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
142         ("n" "note" entry (file "~/projects/org-notes/refile.org")
143          "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
144         ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
145          "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
146         ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
147          "* %?\n%U\n" :clock-in t :clock-resume t)
148         ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
149          "* TODO Review %c\n%U\n" :immediate-finish t)
150         ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
151          "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
152         ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
153          "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
154         ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
155          "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
156         ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
157          "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
158         ("J" "job" entry (file "~/projects/org-notes/refile.org")
159          "* 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)
160         ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
161          "* 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")
162         )
163       )
164
165 ;; Remove empty LOGBOOK drawers on clock out
166 (defun bh/remove-empty-drawer-on-clock-out ()
167   (interactive)
168   (save-excursion
169     (beginning-of-line 0)
170     (org-remove-empty-drawer-at (point))))
171
172 (defun my/org-add-id ()
173   (interactive)
174   (save-excursion
175     (if (org-current-level)
176         ()
177       (forward-char 1)
178       )
179     (org-id-get-create)
180     )
181 )
182
183 ; org mode configuration from http://doc.norang.ca/org-mode.html
184 ;; Custom Key Bindings
185 (global-set-key (kbd "<f12>") 'org-agenda)
186 (global-set-key (kbd "<f5>") 'bh/org-todo)
187 (global-set-key (kbd "<S-f5>") 'bh/widen)
188 (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
189 (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
190 (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
191 (global-set-key (kbd "<f9> b") 'bbdb)
192 (global-set-key (kbd "<f9> c") 'calendar)
193 (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
194 (global-set-key (kbd "<f9> h") 'bh/hide-other)
195 (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
196 (global-set-key (kbd "<f9> w") 'widen)
197
198 ; change the outline mode prefix from C-c @ to C-c C-2
199 (setq outline-minor-mode-prefix "C-c C-2")
200 ;(add-hook 'outline-minor-mode-hook
201 ;          (lambda () (local-set-key (kbd "C-c C-2")
202 ;                                    outline-mode-prefix-map)))
203
204 (global-set-key (kbd "<f9> I") 'bh/punch-in)
205 (global-set-key (kbd "<f9> O") 'bh/punch-out)
206
207 (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
208
209 (global-set-key (kbd "<f9> r") 'boxquote-region)
210 (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
211
212 (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
213 (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
214
215 (global-set-key (kbd "<f9> v") 'visible-mode)
216 (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
217 (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
218 (global-set-key (kbd "C-<f9>") 'previous-buffer)
219 (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
220 (global-set-key (kbd "C-x n r") 'narrow-to-region)
221 (global-set-key (kbd "C-<f10>") 'next-buffer)
222 (global-set-key (kbd "<f11>") 'org-clock-goto)
223 (global-set-key (kbd "C-<f11>") 'org-clock-in)
224 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
225 (global-set-key (kbd "C-c c") 'org-capture)
226
227 (defun bh/hide-other ()
228   (interactive)
229   (save-excursion
230     (org-back-to-heading 'invisible-ok)
231     (hide-other)
232     (org-cycle)
233     (org-cycle)
234     (org-cycle)))
235
236 (defun bh/set-truncate-lines ()
237   "Toggle value of truncate-lines and refresh window display."
238   (interactive)
239   (setq truncate-lines (not truncate-lines))
240   ;; now refresh window display (an idiom from simple.el):
241   (save-excursion
242     (set-window-start (selected-window)
243                       (window-start (selected-window)))))
244
245 (defun bh/make-org-scratch ()
246   (interactive)
247   (find-file "/tmp/publish/scratch.org")
248   (gnus-make-directory "/tmp/publish"))
249
250 (defun bh/switch-to-scratch ()
251   (interactive)
252   (switch-to-buffer "*scratch*"))
253
254 (setq org-use-fast-todo-selection t)
255 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
256
257 (setq org-todo-keywords
258       (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
259               (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
260
261 (setq org-todo-keyword-faces
262       (quote (("TODO" :foreground "red" :weight bold)
263               ("NEXT" :foreground "blue" :weight bold)
264               ("DONE" :foreground "forest green" :weight bold)
265               ("WAITING" :foreground "orange" :weight bold)
266               ("HOLD" :foreground "magenta" :weight bold)
267               ("CANCELLED" :foreground "forest green" :weight bold)
268               ("MEETING" :foreground "forest green" :weight bold)
269               ("PHONE" :foreground "forest green" :weight bold))))
270
271 (setq org-todo-state-tags-triggers
272       (quote (("CANCELLED" ("CANCELLED" . t))
273               ("WAITING" ("WAITING" . t))
274               ("HOLD" ("WAITING") ("HOLD" . t))
275               (done ("WAITING") ("HOLD"))
276               ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
277               ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
278               ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
279
280
281
282 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
283 ; add ids on creation of nodes
284 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
285 ; create function to create headlines in file. This comes from
286 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
287 (defun my/org-add-ids-to-headlines-in-file ()
288   "Add ID properties to all headlines in the current file which
289 do not already have one."
290   (interactive)
291   (org-map-entries 'org-id-get-create))
292 ; if we wanted to do this to every buffer, do the following:
293 ; (add-hook 'org-mode-hook
294 ;           (lambda ()
295 ;             (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
296
297
298 ; resolve clocks after 10 minutes of idle; use xprintidle
299 ; (setq org-clock-idle-time 10)
300 ; (setq org-clock-x11idle-program-name "xprintidle")
301
302 ; this is from http://doc.norang.ca/org-mode.html#Capture
303 ; use C-M-r for org mode capture
304 (global-set-key (kbd "C-M-r") 'org-capture)
305
306 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
307 (setq org-refile-targets (quote ((nil :maxlevel . 9)
308                                  (org-agenda-files :maxlevel . 9))))
309
310 ; Use full outline paths for refile targets - we file directly with IDO
311 (setq org-refile-use-outline-path t)
312
313 ; Targets complete directly with IDO
314 (setq org-outline-path-complete-in-steps nil)
315
316 ; Allow refile to create parent tasks with confirmation
317 (setq org-refile-allow-creating-parent-nodes (quote confirm))
318
319 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
320 ; (setq org-completion-use-ido t)
321 ; (setq ido-everywhere t)
322 ; (setq ido-max-directory-size 100000)
323 ; (ido-mode (quote both))
324 ; ; Use the current window when visiting files and buffers with ido
325 ; (setq ido-default-file-method 'selected-window)
326 ; (setq ido-default-buffer-method 'selected-window)
327 ; ; Use the current window for indirect buffer display
328 ; (setq org-indirect-buffer-display 'current-window)
329
330
331 ;;;; Refile settings
332 ; Exclude DONE state tasks from refile targets
333 (defun bh/verify-refile-target ()
334   "Exclude todo keywords with a done state from refile targets"
335   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
336
337 (setq org-refile-target-verify-function 'bh/verify-refile-target)
338
339 ;; ensure that emacsclient will show just the note to be edited when invoked
340 ;; from Mutt, and that it will shut down emacsclient once finished;
341 ;; fallback to legacy behavior when not invoked via org-protocol.
342 (require 'org-protocol)
343 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
344 (setq my-org-protocol-flag nil)
345 (defadvice org-capture-finalize (after delete-frame-at-end activate)
346   "Delete frame at remember finalization"
347   (progn (if my-org-protocol-flag (delete-frame))
348          (setq my-org-protocol-flag nil)))
349 (defadvice org-capture-refile (around delete-frame-after-refile activate)
350   "Delete frame at remember refile"
351   (if my-org-protocol-flag
352       (progn
353         (setq my-org-protocol-flag nil)
354         ad-do-it
355         (delete-frame))
356     ad-do-it)
357   )
358 (defadvice org-capture-kill (after delete-frame-at-end activate)
359   "Delete frame at remember abort"
360   (progn (if my-org-protocol-flag (delete-frame))
361          (setq my-org-protocol-flag nil)))
362 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
363   (setq my-org-protocol-flag t))
364
365 (defadvice org-insert-todo-heading (after dla/create-id activate)
366   (org-id-get-create)
367   )
368
369 ;; org modules
370 (add-to-list 'org-modules 'org-habit)
371
372 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
373 (defun open-mail-in-mutt (message)
374   "Open a mail message in Mutt, using an external terminal.
375
376 Message can be specified either by a path pointing inside a
377 Maildir, or by Message-ID."
378   (interactive "MPath or Message-ID: ")
379   (shell-command
380    (format "faf xterm -e \"%s %s\""
381        (substitute-in-file-name "$HOME/bin/mutt_open") message)))
382
383 ;; add support for "mutt:ID" links
384 (org-add-link-type "mutt" 'open-mail-in-mutt)
385
386 (defun my-org-mode-setup ()
387   (load-library "reftex")
388   (and (buffer-file-name)
389        (file-exists-p (buffer-file-name))
390        (progn
391          (reftex-parse-all)
392          (reftex-set-cite-format
393           '((?b . "[[bib:%l][%l-bib]]")
394             (?n . "[[notes:%l][%l-notes]]")
395             (?c . "\\cite{%l}")
396             (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
397          ))
398   (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
399   (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
400   (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
401   (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
402   )
403 (add-hook 'org-mode-hook 'my-org-mode-setup)
404
405 (defun org-mode-reftex-search ()
406   (interactive)
407   (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
408
409 (defun open-research-paper (bibtexkey)
410   "Open a paper by bibtex key"
411   (interactive "bibtex key: ")
412   (shell-command
413    (format "%s %s"
414        (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
415 (org-add-link-type "papers" 'open-research-paper)
416 (defun open-research-paper-pdf (bibtexkey)
417   "Open a paper pdf by bibtex key"
418   (interactive "bibtex key: ")
419   (shell-command
420    (format "%s -p evince_annot %s"
421        (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
422 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
423
424 (add-to-list 'org-link-abbrev-alist
425              '("notes" .
426                "~/projects/research/paper_notes.org::#%s"))
427
428 ; I pretty much always want hiearchical checkboxes
429 (setq org-hierachical-checkbox-statistics nil)
430
431 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
432 (add-to-list 'org-structure-template-alist
433              '("E" "\\begin{equation}\n?\n\\end{equation}"))
434
435  ;; stolen from
436 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
437 (defun my-rtcite-export-handler (path desc format)
438   (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
439   (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
440                    (match-string 1 path)))
441          (path (substring path 0 (match-beginning 0))))
442     (cond ((eq format 'latex)
443            (if (or (not desc) 
444                    (equal 0 (search "rtcite:" desc)))
445                (format "\\cite{%s}" search)
446              (format "\\cite[%s]{%s}" desc search))))))
447
448 (org-add-link-type "rtcite" 
449                    'org-bibtex-open
450                    'my-rtcite-export-handler)
451
452
453 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
454 (when (string= system-name "linnode")
455   (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
456 (setq-default org-directory "/home/don/org-mode/")
457 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
458
459 ;; org mode ical export
460 (setq org-icalendar-timezone "America/Los_Angeles")
461 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
462 ;; we already add the id manually
463 ;; (setq org-icalendar-store-UID t)
464
465 ;; org babel support
466 (org-babel-do-load-languages
467  'org-babel-load-languages
468  '((emacs-lisp . t )
469    (R . t)
470    (latex . t)
471    (ditaa . t)
472    (dot . t)
473    ))
474 ;; use graphviz-dot for dot things
475 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
476 ;; org-babel-by-backend
477 (defmacro org-babel-by-backend (&rest body)
478    `(case (if (boundp 'backend) 
479               (org-export-backend-name backend)
480             nil) ,@body))
481
482 (defun my/fix-inline-images ()
483   (when org-inline-image-overlays
484     (org-redisplay-inline-images)))
485
486 (add-hook 'org-babel-after-execute-hook
487            'my/fix-inline-images)
488
489 ;; ;; org latex
490 ;; ;; stolen from http://kieranhealy.org/esk/kjhealy.html
491 ;; (require 'org-latex)   
492 ;; ;; Choose either listings or minted for exporting source code blocks.
493 ;; ;; Using minted (as here) requires pygments be installed. To use the
494 ;; ;; default listings package instead, use
495 ;; ;; (setq org-latex-listings t)
496 ;; ;; and change references to "minted" below to "listings"
497 ;; ; (setq org-latex-listings 'minted)
498 ;; 
499 ;; ;; default settings for minted code blocks
500 ;; (setq org-latex-minted-options
501 ;;       '(;("frame" "single")
502 ;;         ("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.
503 ;;         ("fontsize" "\\small")
504 ;;         ))
505 ;; ;; turn off the default toc behavior; deal with it properly in headers to files.
506 ;; (defun org-latex-no-toc (depth)  
507 ;;   (when depth
508 ;;     (format "%% Org-mode is exporting headings to %s levels.\n"
509 ;;             depth)))
510 ;; (setq org-latex-format-toc-function 'org-latex-no-toc)
511
512 (require 'ox-latex)
513 (add-to-list 'org-latex-classes
514              '("memarticle"
515                "\\documentclass[11pt,oneside,article]{memoir}\n"
516                ("\\section{%s}" . "\\section*{%s}")
517                ("\\subsection{%s}" . "\\subsection*{%s}")
518                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
519                ("\\paragraph{%s}" . "\\paragraph*{%s}")
520                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
521
522 (setq org-beamer-outline-frame-options "")
523 (require 'ox-beamer)
524 (add-to-list 'org-latex-classes
525              '("beamer"
526                "\\documentclass[ignorenonframetext]{beamer}
527 [NO-DEFAULT-PACKAGES]
528 [PACKAGES]
529 [EXTRA]"
530                ("\\section{%s}" . "\\section*{%s}")
531                ("\\subsection{%s}" . "\\subsection*{%s}")
532                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
533                ("\\paragraph{%s}" . "\\paragraph*{%s}")
534                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
535
536 (add-to-list 'org-latex-classes
537              '("membook"
538                "\\documentclass[11pt,oneside]{memoir}\n"
539                ("\\chapter{%s}" . "\\chapter*{%s}")
540                ("\\section{%s}" . "\\section*{%s}")
541                ("\\subsection{%s}" . "\\subsection*{%s}")
542                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
543
544 (add-to-list 'org-latex-classes
545              '("letter"
546                "\\documentclass[11pt]{letter}
547 [NO-DEFAULT-PACKAGES]
548 [PACKAGES]
549 [EXTRA]"
550        ("\\section{%s}" . "\\section*{%s}")
551                ("\\subsection{%s}" . "\\subsection*{%s}")
552                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
553                ("\\paragraph{%s}" . "\\paragraph*{%s}")
554                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
555
556 (add-to-list 'org-latex-classes
557              '("dlacv"
558                "\\documentclass{dlacv}
559 [NO-DEFAULT-PACKAGES]
560 [NO-PACKAGES]
561 [NO-EXTRA]"
562                ("\\section{%s}" . "\\section*{%s}")
563                ("\\subsection{%s}" . "\\subsection*{%s}")
564                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
565                ("\\paragraph{%s}" . "\\paragraph*{%s}")
566                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
567
568
569 (add-to-list 'org-latex-classes
570              '("dlaresume"
571                "\\documentclass{dlaresume}
572 [NO-DEFAULT-PACKAGES]
573 [NO-PACKAGES]
574 [NO-EXTRA]"
575                ("\\section{%s}" . "\\section*{%s}")
576                ("\\subsection{%s}" . "\\subsection*{%s}")
577                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
578                ("\\paragraph{%s}" . "\\paragraph*{%s}")
579                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
580
581
582 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
583 ;; but adapted to use latexmk 4.22 or higher.  
584 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
585
586 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
587 (setq org-latex-default-packages-alist
588       '(("" "amsmath" t)
589         ("" "unicode-math" t)
590         ))
591 (setq org-latex-packages-alist
592       '(("" "graphicx" t)
593         ("" "fontspec" t)
594         ("" "xunicode" t)
595         ("" "hyperref" t)
596         ("" "url" t)
597         ("" "rotating" t)
598         ("" "longtable" nil)
599         ("" "float" )))
600
601 ;; make equations larger
602 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
603
604 (defun org-create-formula--latex-header ()
605   "Return LaTeX header appropriate for previewing a LaTeX snippet."
606   (let ((info (org-combine-plists (org-export--get-global-options
607                                    (org-export-get-backend 'latex))
608                                   (org-export--get-inbuffer-options
609                                    (org-export-get-backend 'latex)))))
610     (org-latex-guess-babel-language
611      (org-latex-guess-inputenc
612       (org-splice-latex-header
613        org-format-latex-header
614        org-latex-default-packages-alist
615        nil t
616        (plist-get info :latex-header)))
617      info)))
618
619
620 ; support ignoring headers in org mode export to latex
621 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
622 (defadvice org-latex-headline (around my-latex-skip-headlines
623                                       (headline contents info) activate)
624   (if (member "ignoreheading" (org-element-property :tags headline))
625       (setq ad-return-value contents)
626     ad-do-it))
627
628 ;; keep latex logfiles
629
630 (setq org-latex-remove-logfiles nil)
631
632 ;; helper functions
633 (defun bh/is-project-p ()
634   "Any task with a todo keyword subtask"
635   (save-restriction
636     (widen)
637     (let ((has-subtask)
638           (subtree-end (save-excursion (org-end-of-subtree t)))
639           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
640       (save-excursion
641         (forward-line 1)
642         (while (and (not has-subtask)
643                     (< (point) subtree-end)
644                     (re-search-forward "^\*+ " subtree-end t))
645           (when (member (org-get-todo-state) org-todo-keywords-1)
646             (setq has-subtask t))))
647       (and is-a-task has-subtask))))
648
649 (defun bh/is-project-subtree-p ()
650   "Any task with a todo keyword that is in a project subtree.
651 Callers of this function already widen the buffer view."
652   (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
653                               (point))))
654     (save-excursion
655       (bh/find-project-task)
656       (if (equal (point) task)
657           nil
658         t))))
659
660 (defun bh/is-task-p ()
661   "Any task with a todo keyword and no subtask"
662   (save-restriction
663     (widen)
664     (let ((has-subtask)
665           (subtree-end (save-excursion (org-end-of-subtree t)))
666           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
667       (save-excursion
668         (forward-line 1)
669         (while (and (not has-subtask)
670                     (< (point) subtree-end)
671                     (re-search-forward "^\*+ " subtree-end t))
672           (when (member (org-get-todo-state) org-todo-keywords-1)
673             (setq has-subtask t))))
674       (and is-a-task (not has-subtask)))))
675
676 (defun bh/is-subproject-p ()
677   "Any task which is a subtask of another project"
678   (let ((is-subproject)
679         (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
680     (save-excursion
681       (while (and (not is-subproject) (org-up-heading-safe))
682         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
683           (setq is-subproject t))))
684     (and is-a-task is-subproject)))
685
686 (defun bh/list-sublevels-for-projects-indented ()
687   "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
688   This is normally used by skipping functions where this variable is already local to the agenda."
689   (if (marker-buffer org-agenda-restrict-begin)
690       (setq org-tags-match-list-sublevels 'indented)
691     (setq org-tags-match-list-sublevels nil))
692   nil)
693
694 (defun bh/list-sublevels-for-projects ()
695   "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
696   This is normally used by skipping functions where this variable is already local to the agenda."
697   (if (marker-buffer org-agenda-restrict-begin)
698       (setq org-tags-match-list-sublevels t)
699     (setq org-tags-match-list-sublevels nil))
700   nil)
701
702 (defvar bh/hide-scheduled-and-waiting-next-tasks t)
703
704 (defun bh/toggle-next-task-display ()
705   (interactive)
706   (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
707   (when  (equal major-mode 'org-agenda-mode)
708     (org-agenda-redo))
709   (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
710
711 (defun bh/skip-stuck-projects ()
712   "Skip trees that are not stuck projects"
713   (save-restriction
714     (widen)
715     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
716       (if (bh/is-project-p)
717           (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
718                  (has-next ))
719             (save-excursion
720               (forward-line 1)
721               (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
722                 (unless (member "WAITING" (org-get-tags-at))
723                   (setq has-next t))))
724             (if has-next
725                 nil
726               next-headline)) ; a stuck project, has subtasks but no next task
727         nil))))
728
729 (defun bh/skip-non-stuck-projects ()
730   "Skip trees that are not stuck projects"
731   ;; (bh/list-sublevels-for-projects-indented)
732   (save-restriction
733     (widen)
734     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
735       (if (bh/is-project-p)
736           (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
737                  (has-next ))
738             (save-excursion
739               (forward-line 1)
740               (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
741                 (unless (member "WAITING" (org-get-tags-at))
742                   (setq has-next t))))
743             (if has-next
744                 next-headline
745               nil)) ; a stuck project, has subtasks but no next task
746         next-headline))))
747
748 (defun bh/skip-non-projects ()
749   "Skip trees that are not projects"
750   ;; (bh/list-sublevels-for-projects-indented)
751   (if (save-excursion (bh/skip-non-stuck-projects))
752       (save-restriction
753         (widen)
754         (let ((subtree-end (save-excursion (org-end-of-subtree t))))
755           (cond
756            ((bh/is-project-p)
757             nil)
758            ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
759             nil)
760            (t
761             subtree-end))))
762     (save-excursion (org-end-of-subtree t))))
763
764 (defun bh/skip-project-trees-and-habits ()
765   "Skip trees that are projects"
766   (save-restriction
767     (widen)
768     (let ((subtree-end (save-excursion (org-end-of-subtree t))))
769       (cond
770        ((bh/is-project-p)
771         subtree-end)
772        ((org-is-habit-p)
773         subtree-end)
774        (t
775         nil)))))
776
777 (defun bh/skip-projects-and-habits-and-single-tasks ()
778   "Skip trees that are projects, tasks that are habits, single non-project tasks"
779   (save-restriction
780     (widen)
781     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
782       (cond
783        ((org-is-habit-p)
784         next-headline)
785        ((and bh/hide-scheduled-and-waiting-next-tasks
786              (member "WAITING" (org-get-tags-at)))
787         next-headline)
788        ((bh/is-project-p)
789         next-headline)
790        ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
791         next-headline)
792        (t
793         nil)))))
794
795 (defun bh/skip-project-tasks-maybe ()
796   "Show tasks related to the current restriction.
797 When restricted to a project, skip project and sub project tasks, habits, NEXT tasks, and loose tasks.
798 When not restricted, skip project and sub-project tasks, habits, and project related tasks."
799   (save-restriction
800     (widen)
801     (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
802            (next-headline (save-excursion (or (outline-next-heading) (point-max))))
803            (limit-to-project (marker-buffer org-agenda-restrict-begin)))
804       (cond
805        ((bh/is-project-p)
806         next-headline)
807        ((org-is-habit-p)
808         subtree-end)
809        ((and (not limit-to-project)
810              (bh/is-project-subtree-p))
811         subtree-end)
812        ((and limit-to-project
813              (bh/is-project-subtree-p)
814              (member (org-get-todo-state) (list "NEXT")))
815         subtree-end)
816        (t
817         nil)))))
818
819 (defun bh/skip-project-tasks ()
820   "Show non-project tasks.
821 Skip project and sub-project tasks, habits, and project related tasks."
822   (save-restriction
823     (widen)
824     (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
825       (cond
826        ((bh/is-project-p)
827         subtree-end)
828        ((org-is-habit-p)
829         subtree-end)
830        ((bh/is-project-subtree-p)
831         subtree-end)
832        (t
833         nil)))))
834
835 (defun bh/skip-non-project-tasks ()
836   "Show project tasks.
837 Skip project and sub-project tasks, habits, and loose non-project tasks."
838   (save-restriction
839     (widen)
840     (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
841            (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
842       (cond
843        ((bh/is-project-p)
844         next-headline)
845        ((org-is-habit-p)
846         subtree-end)
847        ((and (bh/is-project-subtree-p)
848              (member (org-get-todo-state) (list "NEXT")))
849         subtree-end)
850        ((not (bh/is-project-subtree-p))
851         subtree-end)
852        (t
853         nil)))))
854
855 (defun bh/skip-projects-and-habits ()
856   "Skip trees that are projects and tasks that are habits"
857   (save-restriction
858     (widen)
859     (let ((subtree-end (save-excursion (org-end-of-subtree t))))
860       (cond
861        ((bh/is-project-p)
862         subtree-end)
863        ((org-is-habit-p)
864         subtree-end)
865        (t
866         nil)))))
867
868 (defun bh/skip-non-subprojects ()
869   "Skip trees that are not projects"
870   (let ((next-headline (save-excursion (outline-next-heading))))
871     (if (bh/is-subproject-p)
872         nil
873       next-headline)))
874 ;
875 ;; Resume clocking task when emacs is restarted
876 (org-clock-persistence-insinuate)
877 ;;
878 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
879 (setq org-clock-history-length 23)
880 ;; Resume clocking task on clock-in if the clock is open
881 (setq org-clock-in-resume t)
882 ;; Change tasks to NEXT when clocking in
883 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
884 ;; (setq org-clock-in-switch-to-state "NEXT")
885 ;; Separate drawers for clocking and logs
886 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
887 ;; Save clock data and state changes and notes in the LOGBOOK drawer
888 (setq org-clock-into-drawer t)
889 (setq org-log-into-drawer t)
890 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
891 (setq org-clock-out-remove-zero-time-clocks t)
892 ;; Clock out when moving task to a done state
893 (setq org-clock-out-when-done t)
894 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
895 (setq org-clock-persist t)
896 ;; Do not prompt to resume an active clock
897 (setq org-clock-persist-query-resume nil)
898 ;; Enable auto clock resolution for finding open clocks
899 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
900 ;; Include current clocking task in clock reports
901 (setq org-clock-report-include-clocking-task t)
902
903 ;; the cache seems to be broken
904 (setq org-element-use-cache nil)
905
906 (defvar bh/keep-clock-running nil)
907
908 (defun bh/clock-in-to-next (kw)
909   "Switch a task from TODO to NEXT when clocking in.
910 Skips capture tasks, projects, and subprojects.
911 Switch projects and subprojects from NEXT back to TODO"
912   (when (not (and (boundp 'org-capture-mode) org-capture-mode))
913     (cond
914      ((and (member (org-get-todo-state) (list "TODO"))
915            (bh/is-task-p))
916       "NEXT")
917      ((and (member (org-get-todo-state) (list "NEXT"))
918            (bh/is-project-p))
919       "TODO"))))
920
921 (defun bh/find-project-task ()
922   "Move point to the parent (project) task if any"
923   (save-restriction
924     (widen)
925     (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
926       (while (org-up-heading-safe)
927         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
928           (setq parent-task (point))))
929       (goto-char parent-task)
930       parent-task)))
931
932 (defun bh/punch-in (arg)
933   "Start continuous clocking and set the default task to the
934 selected task.  If no task is selected set the Organization task
935 as the default task."
936   (interactive "p")
937   (setq bh/keep-clock-running t)
938   (if (equal major-mode 'org-agenda-mode)
939       ;;
940       ;; We're in the agenda
941       ;;
942       (let* ((marker (org-get-at-bol 'org-hd-marker))
943              (tags (org-with-point-at marker (org-get-tags-at))))
944         (if (and (eq arg 4) tags)
945             (org-agenda-clock-in '(16))
946           (bh/clock-in-organization-task-as-default)))
947     ;;
948     ;; We are not in the agenda
949     ;;
950     (save-restriction
951       (widen)
952       ; Find the tags on the current task
953       (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
954           (org-clock-in '(16))
955         (bh/clock-in-organization-task-as-default)))))
956
957 (defun bh/punch-out ()
958   (interactive)
959   (setq bh/keep-clock-running nil)
960   (when (org-clock-is-active)
961     (org-clock-out))
962   (org-agenda-remove-restriction-lock))
963
964 (defun bh/clock-in-default-task ()
965   (save-excursion
966     (org-with-point-at org-clock-default-task
967       (org-clock-in))))
968
969 (defun bh/clock-in-parent-task ()
970   "Move point to the parent (project) task if any and clock in"
971   (let ((parent-task))
972     (save-excursion
973       (save-restriction
974         (widen)
975         (while (and (not parent-task) (org-up-heading-safe))
976           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
977             (setq parent-task (point))))
978         (if parent-task
979             (org-with-point-at parent-task
980               (org-clock-in))
981           (when bh/keep-clock-running
982             (bh/clock-in-default-task)))))))
983
984 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
985
986 (defun bh/clock-in-organization-task-as-default ()
987   (interactive)
988   (org-with-point-at (org-id-find bh/organization-task-id 'marker)
989     (org-clock-in '(16))))
990
991 (defun bh/clock-out-maybe ()
992   (when (and bh/keep-clock-running
993              (not org-clock-clocking-in)
994              (marker-buffer org-clock-default-task)
995              (not org-clock-resolving-clocks-due-to-idleness))
996     (bh/clock-in-parent-task)))
997
998 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
999
1000 (require 'org-id)
1001 (defun bh/clock-in-task-by-id (id)
1002   "Clock in a task by id"
1003   (org-with-point-at (org-id-find id 'marker)
1004     (org-clock-in nil)))
1005
1006 (defun bh/clock-in-last-task (arg)
1007   "Clock in the interrupted task if there is one
1008 Skip the default task and get the next one.
1009 A prefix arg forces clock in of the default task."
1010   (interactive "p")
1011   (let ((clock-in-to-task
1012          (cond
1013           ((eq arg 4) org-clock-default-task)
1014           ((and (org-clock-is-active)
1015                 (equal org-clock-default-task (cadr org-clock-history)))
1016            (caddr org-clock-history))
1017           ((org-clock-is-active) (cadr org-clock-history))
1018           ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1019           (t (car org-clock-history)))))
1020     (widen)
1021     (org-with-point-at clock-in-to-task
1022       (org-clock-in nil))))
1023
1024
1025 (defun org-export-to-ods ()
1026   (interactive)
1027   (let ((csv-file "data.csv"))
1028     (org-table-export csv-file "orgtbl-to-csv")
1029     (org-odt-convert csv-file "ods" 'open)))
1030
1031 ; allow for zero-width-space to be a break in regexp too
1032 ; (setcar org-emphasis-regexp-components "​ [:space:] \t('\"{")
1033 ; (setcar (nthcdr 1 org-emphasis-regexp-components) "​ [:space:]- \t.,:!?;'\")}\\")
1034 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1035
1036 ;; support inserting screen shots
1037 (defun my/org-insert-screenshot ()
1038   "Take a screenshot into a time stamped unique-named file in the
1039 same directory as the org-buffer and insert a link to this file."
1040   (interactive)
1041   (defvar my/org-insert-screenshot/filename)
1042   (setq my/org-insert-screenshot/filename
1043         (read-file-name
1044          "Screenshot to insert: "
1045          nil
1046          (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
1047          )
1048         )
1049   (call-process "import" nil nil nil my/org-insert-screenshot/filename)
1050   (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
1051   (org-display-inline-images))
1052
1053 (defun my/fix-inline-images ()
1054   (when org-inline-image-overlays
1055     (org-redisplay-inline-images)))
1056
1057 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
1058
1059 ;; use xelatex to preview with imagemagick
1060 (add-to-list 'org-preview-latex-process-alist
1061              '(xelateximagemagick
1062               :programs ("xelatex" "convert")
1063               :description "pdf > png"
1064               :message "you need to install xelatex and imagemagick"
1065               :use-xcolor t
1066               :image-input-type "pdf"
1067               :image-output-type "png"
1068               :image-size-adjust (1.0 . 1.0)
1069               :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
1070               :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
1071              )
1072 ;; use xelatex by default
1073 (setq org-preview-latex-default-process 'xelateximagemagick)
1074
1075 ; from http://orgmode.org/Changes.html
1076 (defun my/org-repair-property-drawers ()
1077   "Fix properties drawers in current buffer.
1078  Ignore non Org buffers."
1079   (interactive)
1080   (when (eq major-mode 'org-mode)
1081     (org-with-wide-buffer
1082      (goto-char (point-min))
1083      (let ((case-fold-search t)
1084            (inline-re (and (featurep 'org-inlinetask)
1085                            (concat (org-inlinetask-outline-regexp)
1086                                    "END[ \t]*$"))))
1087        (org-map-entries
1088         (lambda ()
1089           (unless (and inline-re (org-looking-at-p inline-re))
1090             (save-excursion
1091               (let ((end (save-excursion (outline-next-heading) (point))))
1092                 (forward-line)
1093                 (when (org-looking-at-p org-planning-line-re) (forward-line))
1094                 (when (and (< (point) end)
1095                            (not (org-looking-at-p org-property-drawer-re))
1096                            (save-excursion
1097                              (and (re-search-forward org-property-drawer-re end t)
1098                                   (eq (org-element-type
1099                                        (save-match-data (org-element-at-point)))
1100                                       'drawer))))
1101                   (insert (delete-and-extract-region
1102                            (match-beginning 0)
1103                            (min (1+ (match-end 0)) end)))
1104                   (unless (bolp) (insert "\n"))))))))))))
1105
1106 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1107 (defun org-agenda-timeline-all (&optional arg)
1108   (interactive "P")
1109   (with-temp-buffer
1110     (dolist (org-agenda-file org-agenda-files)
1111       (insert-file-contents org-agenda-file nil)
1112       (end-of-buffer)
1113       (newline))
1114     (write-file "/tmp/timeline.org")
1115     (org-agenda arg "L")))
1116 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1117
1118 (provide 'org-mode-configuration)