Updates to mirror new repository structure.
[james/home/home-etc.git] / .emacs.d / config / org.el
1 ;; org mode
2 (require 'org)
3 ;; required in upper level, before this file gets sourced.
4 ;; The idea is I don't need this if I don't have my org files.
5 (load-library "org-compat")
6 ;;(require 'org-install)
7 ;;(require 'org-protocol)
8 ;;(require 'org-publish)
9 (require 'org-feed)
10 ;; I manage org files myself.
11 ;; I really don't wish work files to end up on personal devices.
12 (add-hook 'org-mode-hook
13           (lambda()
14             (org-defkey org-mode-map "\C-c[" 'undefined)
15             (org-defkey org-mode-map "\C-c]" 'undefined))
16           'append)
17 (require 'ox-latex)
18 ;; I want to get all org files in a directory
19 ;; http://stackoverflow.com/questions/17215868/recursively-adding-org-files-in-a-top-level-directory-for-org-agenda-files-take
20
21 (defvar bh/hide-scheduled-and-waiting-next-tasks t)
22 ;;(setq bh/hide-scheduled-and-waiting-next-tasks t)
23
24
25 (defun jr/load-org-agenda-files-recursively (dir)
26   "Find all directories in DIR."
27   (unless (file-directory-p dir) (error "Not a directory `%s'" dir))
28   (unless (equal (directory-files dir nil org-agenda-file-regexp t) nil)
29     (add-to-list 'org-agenda-files dir))
30   (dolist (file (directory-files dir nil nil t))
31     (unless (member file '("." ".."))
32       (let ((file (concat dir file "/")))
33         (when (file-directory-p file)
34           (jr/load-org-agenda-files-recursively file))))))
35
36 (when (file-directory-p "~/doc/org")
37   (jr/load-org-agenda-files-recursively "~/doc/org/" )) ; trailing slash required
38 (when (file-directory-p "~/lib/finance")
39   (jr/load-org-agenda-files-recursively "~/lib/finance/"))
40 ;;(add-to-list 'org-agenda-files '"~/")
41 ;;(jr/load-org-agenda-files-recursively "~/.etc/")
42 ;;(jr/load-org-agenda-files-recursively "~/src/" ) ; trailing slash required
43 ;;(jr/load-org-agenda-files-recursively "~/src01/" ) ; trailing slash required
44 (when (file-directory-p "~/doc/org")
45   (setq org-directory "~/doc/org")
46   (setq org-default-notes-file "~/doc/org/refile.org"))
47
48
49 ;; (if (file-exists-p "~/doc/org")
50 ;;     (if (boundp 'org-agenda-files)
51 ;;         (add-to-list 'org-agenda-files '"~/doc/org")
52 ;;       (setq org-agenda-files  '("~/doc/org"))))
53 ;; (if (file-exists-p "~/doc/org/lowes")
54 ;;     (add-to-list 'org-agenda-files '"~/doc/org/lowes"))
55 ;; (if (file-exists-p "~/src/wiki/jamestechnotes.com")
56 ;;     (add-to-list 'org-agenda-files '"~/src/wiki/jamestechnotes.com"))
57 ;; (if (file-exists-p "~/src")
58 ;;     (add-to-list 'org-agenda-files '"~/src"))
59 ;; (if (file-exists-p "~/src01")
60 ;;     (add-to-list 'org-agenda-files '"~/src01"))
61 ;;k(setq org-mobile-files (org-agenda-files))
62
63 ;; setup for MobileOrg
64 ;;(cond ((file-exists-p "~/doc/org")
65 ;;       (setq org-directory "~/doc/org")
66 ;;       (setq org-mobile-directory "~/doc/MobileOrg")
67 ;;       (setq org-mobile-inbox-for-pull "~/doc/org/MobileInbox.org"))
68 ;;      (t
69 ;;       (setq org-directory "~")
70 ;;       (setq org-mobile-directory "~/tmp")
71 ;;       (setq org-mobile-inbox-for-pull "~/tmp/MobileInbox.org")))
72
73 ;;(setq org-file-apps org-file-apps-defaults-gnu)
74 ;;(delete '("\\.pdf\\'" . default) org-file-apps)
75 ;;(add-to-list 'org-file-apps '(("\\.pdf\\'" . "evince \"%s\"")))
76
77 ;; setup todo things.
78 (setq org-todo-keywords
79       '((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
80         (sequence "NEW" "IN-PROGRESS" "|" "DONE") ;; jira
81         (sequence "TASK" "|" "DONE") ;; will this work for others?
82         (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE")))
83
84 (setq org-todo-keyword-faces
85       (quote (("TODO" :foreground "red" :weight bold)
86               ("NEXT" :foreground "blue" :weight bold)
87               ("NEW" :foreground "red" :weight bold)
88               ("IN-PROGRESS" :foreground "blue" :weight bold)
89               ("DONE" :foreground "forest green" :weight bold)
90               ("WAITING" :foreground "orange" :weight bold)
91               ("HOLD" :foreground "magenta" :weight bold)
92               ("CANCELLED" :foreground "forest green" :weight bold)
93               ("MEETING" :foreground "forest green" :weight bold)
94               ("PHONE" :foreground "forest green" :weight bold)
95               ("TASK" :foreground "orange" :weight bold))))
96
97 (setq org-use-fast-todo-selection t)
98 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
99
100 (setq org-todo-state-tags-triggers
101       (quote (("CANCELLED" ("CANCELLED" . t))
102               ("WAITING" ("WAITING" . t))
103               ("HOLD" ("WAITING" . t) ("HOLD" . t))
104               (done ("WAITING") ("HOLD"))
105               ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
106               ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
107               ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
108
109 ; Tags
110 (setq org-tag-alist (quote ((:startgroup)
111                             ("@home" . ?H)
112                             ("@lowes" . ?l)
113                             (:endgroup)
114                             ("PHONE" . ?p)
115                             ("PERSONAL" . ?P)
116                             ("crypt" . ?E)
117                             ("WORK" . ?W)
118                             ("NOTE" . ?n)
119                             ("WIKI" . ?w)
120                             ("ONE" . ?O)
121                             ("TEAM" . ?T)
122                             ("FLAGGED" . ??))))
123
124 (setq org-fast-tag-selection-single-key (quote expert))
125
126 ; For tag searches ignore tasks with scheduled and deadline datas
127
128 (setq org-agenda-tags-todo-honor-ignore-options t)
129 (setq org-agenda-span 1) ;; show day to start
130 (setq org-deadline-warning-days 14)
131 (setq org-agenda-show-all-dates t)
132 (setq org-agenda-skip-deadline-if-done t)
133 (setq org-agenda-skip-scheduled-if-done t)
134 (setq org-agenda-start-on-weekday nil)
135
136 ;; setup for ics
137 (setq org-icalendar-use-scheduled '(event-if-todo event-if-not-todo todo-start))
138 (setq org-icalendar-use-deadline '(event-if-todo event-if-not-todo todo-start))
139 (setq org-icalendar-categories '(category todo-state all-tags))
140 (setq org-icalendar-store-UID t)
141 (setq org-icalendar-alarm-time 15)
142
143 (require 'org-contacts nil 'noerror)
144 (setq org-contacts-files '("~/doc/org/contacts.org"))
145
146 (setq org-capture-templates
147       (quote (("t" "todo" entry (file "~/doc/org/refile.org")
148                "* TODO %?\n%a\n  %i")
149               ("n" "note" entry (file "~/doc/org/refile.org")
150                "* %? :NOTE:\n%a\n  %i")
151               ("j" "Journal" entry (file+datetree "~/doc/org/diary.org")
152                "* %?\n  %i")
153               ("w" "org-protocol" entry (file "~/doc/org/refile.org")
154                "* TODO Review %c\n  %i")
155               ("p" "Phone call" entry (file "~/doc/org/refile.org")
156                "* PHONE %? :PHONE:")
157               ;; todo from email
158               ("m" "todo" entry (file+headline "~/doc/org/refile.org" "Taskss")
159                "* TODO %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")
160 ;              ("c" "Contacts" entry (file+headline "~/doc/org/contacts.org" "Contacts")
161               ("c" "Contacts" entry (file "~/doc/org/contacts.org")
162                "* %(org-contacts-template-name)
163 :PROPERTIES:%(org-contacts-template-email)
164 :Phone:
165 :Cell:
166 :Fax:
167 :Company:
168 :Street:
169 :City:
170 :State:
171 :Postal:
172 :URL:
173 :Notes:
174 :END:")
175               )))
176
177 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
178 (setq org-refile-targets (quote ((nil :maxlevel . 9)
179                                  (org-agenda-files :maxlevel . 9))))
180
181 ; Use full outline paths for refile targets - we file directly with IDO
182 (setq org-refile-use-outline-path t)
183
184 ; Targets complete directly with IDO
185 ;(setq org-outline-path-complete-in-steps nil) ido is broke for refile
186
187 ; Allow refile to create parent tasks with confirmation
188 ;;(setq org-refile-allow-creating-parent-nodes (quote confirm))
189
190 ; Use IDO for both buffer and file completion and ido-everywhere to t
191 (setq org-completion-use-ido nil) ;; this is broken 9 sept 15
192
193 (require 'org-crypt)
194 (org-crypt-use-before-save-magic)
195 (setq org-tags-exclude-from-inheritance (quote ("crypt")))
196 (setq org-crypt-key "D8467AFB")
197
198 ;; load EasyPG... be careful with autosave
199 (require 'epa-file)
200 (epa-file-enable)
201   
202 ;;;; Refile settings
203 ; Exclude DONE state tasks from refile targets
204 (defun bh/verify-refile-target ()
205   "Exclude todo keywords with a done state from refile targets"
206   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
207
208 (setq org-refile-target-verify-function 'bh/verify-refile-target)
209
210 ;;agenda
211 (setq org-agenda-dim-blocked-tasks t)
212 (setq org-agenda-compact-blocks t)
213
214 ;; Custom agenda command definitions
215 (setq org-agenda-custom-commands
216       (quote (("N" "Notes" tags "NOTE"
217                ((org-agenda-overriding-header "Notes")
218                 (org-tags-match-list-sublevels t)))
219               ("h" "Habits" tags-todo "STYLE=\"habit\""
220                ((org-agenda-overriding-header "Habits")
221                 (org-agenda-sorting-strategy
222                  '(todo-state-down priority-down effort-up category-keep))))
223               (" " "Agenda"
224                ((agenda "" nil)
225                 (tags "REFILE"
226                       ((org-agenda-overriding-header "Tasks to Refile")
227                        (org-tags-match-list-sublevels nil)))
228                 (tags-todo "-CANCELLED/!"
229                            ((org-agenda-overriding-header "Stuck Projects")
230                             (org-agenda-skip-function 'bh/skip-non-stuck-projects)
231                             (org-agenda-sorting-strategy
232                              '(priority-down category-keep))))
233                 (tags-todo "-CANCELLED/!NEXT"
234                            ((org-agenda-overriding-header (concat "Project Next Tasks"
235                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
236                                                                       ""
237                                                                     " (including WAITING and SCHEDULED tasks)")))
238                             (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
239                             (org-tags-match-list-sublevels t)
240                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
241                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
242                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
243                             (org-agenda-sorting-strategy
244                              '(todo-state-down priority-down effort-up category-keep))))
245                 (tags-todo "-HOLD-CANCELLED/!"
246                            ((org-agenda-overriding-header "Projects")
247                             (org-agenda-skip-function 'bh/skip-non-projects)
248                             (org-tags-match-list-sublevels 'indented)
249                             (org-agenda-sorting-strategy
250                              '(priority-down category-keep))))
251                 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
252                            ((org-agenda-overriding-header (concat "Project Subtasks"
253                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
254                                                                       ""
255                                                                     " (including WAITING and SCHEDULED tasks)")))
256                             (org-agenda-skip-function 'bh/skip-non-project-tasks)
257                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
258                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
259                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
260                             (org-agenda-sorting-strategy
261                              '(priority-down category-keep))))
262                 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
263                            ((org-agenda-overriding-header (concat "Standalone Tasks"
264                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
265                                                                       ""
266                                                                     " (including WAITING and SCHEDULED tasks)")))
267                             (org-agenda-skip-function 'bh/skip-project-tasks)
268                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
269                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
270                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
271                             (org-agenda-sorting-strategy
272                              '(priority-down category-keep))))
273                 (tags-todo "-CANCELLED+WAITING|HOLD/!"
274                            ((org-agenda-overriding-header (concat "Waiting and Postponed Tasks"
275                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
276                                                                       ""
277                                                                     " (including WAITING and SCHEDULED tasks)")))
278                             (org-agenda-skip-function 'bh/skip-non-tasks)
279                             (org-tags-match-list-sublevels nil)
280                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
281                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)))
282                 (tags "-REFILE/"
283                       ((org-agenda-overriding-header "Tasks to Archive")
284                        (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
285                        (org-tags-match-list-sublevels nil))))
286                nil))))
287
288 (setq org-agenda-custom-commands1
289       (quote (("N" "Notes" tags "NOTE"
290                ((org-agenda-overriding-header "Notes")
291                 (org-tags-match-list-sublevels t)))
292               ("h" "Habits" tags-todo "STYLE=\"habit\""
293                ((org-agenda-overriding-header "Habits")
294                 (org-agenda-sorting-strategy
295                  '(todo-state-down effort-up category-keep))))
296               (" " "Agenda"
297                ((agenda "" nil)
298                 (tags "REFILE"
299                       ((org-agenda-overriding-header "Tasks to Refile")
300                        (org-tags-match-list-sublevels nil)))
301                 (tags-todo "-CANCELLED/!"
302                            ((org-agenda-overriding-header "Stuck Projects")
303                             (org-agenda-skip-function 'bh/skip-non-stuck-projects)
304                             (org-agenda-sorting-strategy
305                              '(category-keep))))
306                 (tags-todo "-HOLD-CANCELLED/!"
307                            ((org-agenda-overriding-header "Projects")
308                             (org-agenda-skip-function 'bh/skip-non-projects)
309                             (org-tags-match-list-sublevels 'indented)
310                             (org-agenda-sorting-strategy
311                              '(category-keep))))
312                 (tags-todo "-CANCELLED/!NEXT"
313                            ((org-agenda-overriding-header (concat "Project Next Tasks"
314                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
315                                                                       ""
316                                                                     " (including WAITING and SCHEDULED tasks)")))
317                             (org-agenda-skip-function 'bh/skip-projects-and-habbits-and-single-tasks)
318                             (org-tags-match-list-sublevels t)
319                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
320                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
321                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
322                             (org-agenda-sorting-strategy
323                              '(todo-state-down effort-up category-keep))))
324                 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
325                            ((org-agenda-overriding-header (concat "Standalone Tasks"
326                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
327                                                                       ""
328                                                                     " (including WAITING and SCHEDULED tasks)")))
329                             (org-agenda-skip-function 'bh/skip-non-project-tasks)
330                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
331                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
332                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
333                             (org-agenda-sorting-strategy
334                              '(category-keep))))
335                 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
336                            ((org-agenda-overriding-header (concat "Project Subtasks"
337                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
338                                                                       ""
339                                                                     " (including WAITING and SCHEDULED tasks)")))
340                             (org-agenda-skip-function 'bh/skip-non-project-tasks)
341                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
342                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
343                             (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
344                             (org-agenda-sorting-strategy
345                              '(category-keep))))
346                 (tags-todo "-CANCELLED+WAITING|HOLD/!"
347                            ((org-agenda-overriding-header (concat "Waiting and Postponed Tasks"
348                                                                   (if bh/hide-scheduled-and-waiting-next-tasks
349                                                                       ""
350                                                                     " (including WAITING and SCHEDULED tasks)")))
351                             (org-agenda-skip-function 'bh/skip-non-tasks)
352                             (org-tags-match-list-sublevels nil)
353                             (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
354                             (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)))
355                 (tags "-REFILE/"
356                       ((org-agenda-overriding-header "Tasks to Archive")
357                        (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
358                        (org-tags-match-list-sublevels nill)))
359                nil)))))
360
361 (defun bh/org-auto-exclude-function (tag)
362   "Automatic task exclusion in the agenda with / RET"
363   (and (cond
364         ((string= tag "hold")
365          t)
366         ((string= tag "farm")
367          t))
368        (concat "-" tag)))
369
370 (setq org-agenda-auto-exclude-function 'bh/org-auto-exclude-function)
371
372 (setq org-modules (quote (org-habit org-id)))
373 (setq org-habit-graph-column 50)
374 (setq global-auto-revert-mode t)
375 (setq org-crypt-disable-auto-save nil)
376 (setq org-stuck-projects (quote ("" nil nil "")))
377
378 (setq org-list-demote-modify-bullet (quote (("+" . "-")
379                                             ("*" . "-")
380                                             ("1." . "-")
381                                             ("1)" . "-"))))
382 (setq org-tags-match-list-sublevels t)
383 (setq org-agenda-persistent-filter t)
384 (setq split-width-threshold 120)
385 (setq org-agenda-skip-additional-timestamps-same-entry t)
386 (setq org-table-use-standard-references (quote from))
387 (setq org-agenda-window-setup 'current-window)
388 (setq org-clone-delete-id t)
389 (setq org-cycle-include-plain-lists t)
390 ;; make fonts come out right in html
391 (setq org-src-fontify-natively t)
392 ;;(setq org-structure-template-alist
393 ;;      (quote (("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")
394 ;;              ("e" "#+begin_example\n?\n#+end_example" "<example>\n?\n</example>")
395 ;;              ("q" "#+begin_quote\n?\n#+end_quote" "<quote>\n?\n</quote>")
396 ;;              ("v" "#+begin_verse\n?\n#+end_verse" "<verse>\n?\n/verse>")
397 ;;              ("c" "#+begin_center\n?\n#+end_center" "<center>\n?\n/center>")
398 ;;              ("l" "#+begin_latex\n?\n#+end_latex" "<literal style=\"latex\">\n?\n</literal>")
399 ;;              ("L" "#+latex: " "<literal style=\"latex\">?</literal>")
400 ;;              ("h" "#+begin_html\n?\n#+end_html" "<literal style=\"html\">\n?\n</literal>")
401 ;;              ("H" "#+html: " "<literal style=\"html\">?</literal>")
402 ;;              ("a" "#+begin_ascii\n?\n#+end_ascii")
403 ;; ;;             ("A" "#+ascii: ")
404 ;;              ("i" "#+index: ?" "#+index: ?")
405 ;;              ("I" "#+include %file ?" "<include file=%file markup=\"?\">"))))
406
407 (setq org-startup-indented t
408       org-export-headline-levels 10)
409 (defun bh/mark-next-parent-tasks-todo ()
410   "Visit each parent task and change NEXT states to TODO"
411   (let ((mystate (or (and (fboundp 'state)
412                           state)
413                      (nth 2 (org-heading-components)))))
414     (when (equal mystate "NEXT")
415       (save-excursion
416         (while (org-up-heading-safe)
417           (when (member (nth 2 (org-heading-components)) (list "NEXT"))
418             (org-todo "TODO")))))))
419
420 (add-hook 'org-after-todo-state-change-hook 'bh/mark-next-parent-tasks-todo 'append)
421 (add-hook 'org-clock-in-hook 'bh/mark-next-parent-tasks-todo 'append)
422 (run-at-time "00:59" 3600 'org-save-all-org-buffers)
423
424 (defun bh/find-project-task ()
425   "Move point to the parent (project) task if any"
426   (save-restriction
427     (widen)
428     (let ((parent-task (save-excursion (org-back-to-heading 'invisible-ok) (point))))
429       (while (org-up-heading-safe)
430         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
431           (setq parent-task (point))))
432       (goto-char parent-task)
433       parent-task)))
434
435 (defun bh/is-project-p ()
436   "Any task with a todo keyword subtask"
437   (save-restriction
438     (widen)
439     (let ((has-subtask)
440           (subtree-end (save-excursion (org-end-of-subtree t)))
441           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
442       (save-excursion
443         (forward-line 1)
444         (while (and (not has-subtask)
445                     (< (point) subtree-end)
446                     (re-search-forward "^\*+ " subtree-end t))
447           (when (member (org-get-todo-state) org-todo-keywords-1)
448             (setq has-subtask t))))
449       (and is-a-task has-subtask))))
450
451 (defun bh/is-project-subtree-p ()
452   "Any task with a todo keyword that is in a project subtree.
453 Callers of this function already widen the buffer view."
454   (let ((task (save-excursion (org-back-to-heading 'invisible-ok)
455                               (point))))
456     (save-excursion
457       (bh/find-project-task)
458       (if (equal (point) task)
459           nil
460         t))))
461
462 (defun bh/is-task-p ()
463   "Any task with a todo keyword and no subtask"
464   (save-restriction
465     (widen)
466     (let ((has-subtask)
467           (subtree-end (save-excursion (org-end-of-subtree t)))
468           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
469       (save-excursion
470         (forward-line 1)
471         (while (and (not has-subtask)
472                     (< (point) subtree-end)
473                     (re-search-forward "^\*+" subtree-end t))
474           (when (member (org-get-todo-state) org-todo-keywords-1)
475             (setq has-subtask t))))
476       (and is-a-task (not has-subtask)))))
477
478 (defun bh/is-subproject-p ()
479   "Any task with is a subtask of another project"
480   (let ((is-subproject)
481         (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
482     (save-excursion
483       (while (and (not is-subproject) (org-up-heading-safe))
484         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
485           (setq is-subproject t))))
486     (and is-a-task is-subproject)))
487
488 (defun bh/list-sublevels-for-projects-indented ()
489   "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
490   This is normally used by skipping functions where this variable is already local to the agenda."
491   (if (marker-buffer org-agenda-restrict-begin)
492       (setq org-tags-match-list-sublevels 'indented)
493     (setq org-tags-match-list-sublevels nil))
494   nil)
495
496 (defun bh/list-sublevels-for-projects ()
497   "Set org-tags-match-list-sublevels so when restricted to a subtree we list all subtasks.
498   This is normally used by skipping functions where this variable is already local to the agenda."
499   (if (marker-buffer org-agenda-restrict-begin)
500       (setq org-tags-match-list-sublevels t)
501     (setq org-tags-match-list-sublevels nil))
502   nil)
503
504
505 (defun bh/toggle-next-task-display ()
506   (interactive)
507   (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
508   (when  (equal major-mode 'org-agenda-mode)
509     (org-agenda-redo))
510   (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
511
512 (defun bh/skip-stuck-projects ()
513   "Skip trees that are not stuck projects"
514   (save-restriction
515     (widen)
516     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
517       (if (bh/is-project-p)
518           (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
519                  (has-next ))
520             (save-excursion
521               (forward-line 1)
522               (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
523                 (unless (member "WAITING" (org-get-tags-at))
524                   (setq has-next t))))
525             (if has-next
526                 nil
527               next-headline)) ; a stuck project, has subtasks but no next task
528         nil))))
529
530 (defun bh/skip-non-stuck-projects ()
531   "Skip trees that are not stuck projects"
532   (save-restriction
533     (widen)
534     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
535       (if (bh/is-project-p)
536           (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
537                  (has-next ))
538             (save-excursion
539               (forward-line 1)
540               (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
541                 (unless (member "WAITING" (org-get-tags-at))
542                   (setq has-next t))))
543             (if has-next
544                 next-headline
545               nil)) ; a stuck project, has subtasks but no next task
546         next-headline))))
547
548 (defun bh/skip-non-projects ()
549   "Skip trees that are not projects"
550   ;;(bh/list-sublevels-for-projects-indented)
551   (if (save-excursion (bh/skip-non-stuck-projects))
552       (save-restriction
553         (widen)
554         (let ((subtree-end (save-excursion (org-end-of-subtree t))))
555           (cond
556            ((bh/is-project-p)
557             nil)
558            ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
559             nil)
560            (t
561             subtree-end))))
562     (save-excursion (org-end-of-subtree t))))
563
564 (defun bh/skip-non-tasks ()
565   "Show non-project tasks.
566 Skip project and sub-project tasks, habits, and project related tasks."
567   (save-restriction
568     (widen)
569     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
570       (cond
571        ((bh/is-task-p)
572         nil)
573        (t
574         next-headline)))))
575
576 (defun bh/skip-project-trees-and-habits ()
577   "Skip trees that are projects"
578   (save-restriction
579     (widen)
580     (let ((subtree-end (save-excursion (org-end-of-subtree t))))
581       (cond
582        ((bh/is-project-p)
583         subtree-end)
584        ((org-is-habit-p)
585         subtree-end)
586        (t
587         nil)))))
588
589 (defun bh/skip-projects-and-habits-and-single-tasks ()
590   "Skip trees that are projects, tasks that are habits, single non-project tasks"
591   (save-restriction
592     (widen)
593     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
594       (cond
595        ((org-is-habit-p)
596         next-headline)
597        ((and bh/hide-scheduled-and-waiting-next-tasks
598              (member "WAITING" (org-get-tags-at)))
599         next-headline)
600        ((bh/is-project-p)
601         next-headline)
602        ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
603         next-headline)
604        (t
605         nil)))))
606
607 (defun bh/skip-project-tasks-maybe ()
608   "Show tasks related to the current restriction.
609 When restricted to a project, skip project and sub project tasks, habits, NEXT tasks, and loose tasks.
610 When not restricted, skip project and sub-project tasks, habits, and project related tasks."
611   (save-restriction
612     (widen)
613     (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
614            (next-headline (save-excursion (or (outline-next-heading) (point-max))))
615            (limit-to-project (marker-buffer org-agenda-restrict-begin)))
616       (cond
617        ((bh/is-project-p)
618         next-headline)
619        ((org-is-habit-p)
620         subtree-end)
621        ((and (not limit-to-project)
622              (bh/is-project-subtree-p))
623         subtree-end)
624        ((and limit-to-project
625              (bh/is-project-subtree-p)
626              (member (org-get-todo-state) (list "NEXT")))
627         subtree-end)
628        (t
629         nil)))))
630
631 (defun bh/skip-project-tasks ()
632   "Show non-project tasks.
633 Skip project and sub-project tasks, habits, and project related tasks."
634   (save-restriction
635     (widen)
636     (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
637       (cond
638        ((bh/is-project-p)
639         subtree-end)
640        ((org-is-habit-p)
641         subtree-end)
642        ((bh/is-project-subtree-p)
643         subtree-end)
644        (t
645         nil)))))
646
647 (defun bh/skip-non-project-tasks ()
648   "Show project tasks.
649 Skip project and sub-project tasks, habits, and loose non-project tasks."
650   (save-restriction
651     (widen)
652     (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
653            (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
654       (cond
655        ((bh/is-project-p)
656         next-headline)
657        ((org-is-habit-p)
658         subtree-end)
659        ((and (bh/is-project-subtree-p)
660              (member (org-get-todo-state) (list "NEXT")))
661         subtree-end)
662        ((not (bh/is-project-subtree-p))
663         subtree-end)
664        (t
665         nil)))))
666
667 (defun bh/skip-projects-and-habits ()
668   "Skip trees that are projects and tasks that are habits"
669   (save-restriction
670     (widen)
671     (let ((subtree-end (save-excursion (org-end-of-subtree t))))
672       (cond
673        ((bh/is-project-p)
674         subtree-end)
675        ((org-is-habit-p)
676         subtree-end)
677        (t
678         nil)))))
679
680 (defun bh/skip-non-subprojects ()
681   "Skip trees that are not projects"
682   (let ((next-headline (save-excursion (outline-next-heading))))
683     (if (bh/is-subproject-p)
684         nil
685       next-headline)))
686
687 (setq org-archive-mark-done nil)
688 (setq org-archive-location "%s_archive::* Archived Tasks")
689
690 (defun bh/skip-non-archivable-tasks ()
691   "Skip trees that are not available for archiving"
692   (save-restriction
693     (widen)
694     ;; Consider only tasks with done todo headings as archivable candidates
695     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max))))
696           (subtree-end (save-excursion (org-end-of-subtree t))))
697       (if (member (org-get-todo-state) org-todo-keywords-1)
698           (if (member (org-get-todo-state) org-done-keywords)
699               (let* ((daynr (string-to-number (format-time-string "%d" (current-time))))
700                      (a-month-ago (* 60 60 24 (+ daynr 1)))
701                      (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
702                      (this-month (format-time-string "%Y-%m-" (current-time)))
703                      (subtree-is-current (save-excursion
704                                            (forward-line 1)
705                                            (and (< (point) subtree-end)
706                                                 (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
707                 (if subtree-is-current
708                     next-headline ; Has a date in this month or last month, skip it
709                   nil))  ; available to archive
710             (or subtree-end (point-max)))
711         next-headline))))
712
713 (setq org-alphabetical-lists t)
714
715 ; Erase all reminders and rebuilt reminders for today from the agenda
716 (defun bh/org-agenda-to-appt ()
717   (interactive)
718   (setq appt-time-msg-list nil)
719   (org-agenda-to-appt))
720
721 ; Rebuild the reminders everytime the agenda is displayed
722 (add-hook 'org-finalize-agenda-hook 'bh/org-agenda-to-appt 'append)
723
724 ; This is at the end of my .emacs - so appointments are set up when Emacs starts
725 (bh/org-agenda-to-appt)
726
727 ; Activate appointments so we get notifications
728 (appt-activate t)
729
730 ; If we leave Emacs running overnight - reset the appointments one minute after midnight
731 (run-at-time "24:01" nil 'bh/org-agenda-to-appt)
732
733
734 ;; Keep tasks with dates on the global todo lists
735 (setq org-agenda-todo-ignore-with-date nil)
736
737 ;; Keep tasks with deadlines on the global todo lists
738 (setq org-agenda-todo-ignore-deadlines nil)
739
740 ;; Keep tasks with scheduled dates on the global todo lists
741 (setq org-agenda-todo-ignore-scheduled nil)
742
743 ;; Keep tasks with timestamps on the global todo lists
744 (setq org-agenda-todo-ignore-timestamp nil)
745
746 ;; Remove completed deadline tasks from the agenda view
747 (setq org-agenda-skip-deadline-if-done t)
748
749 ;; Remove completed scheduled tasks from the agenda view
750 (setq org-agenda-skip-scheduled-if-done t)
751
752 ;; Remove completed items from search results
753 (setq org-agenda-skip-timestamp-if-done t)
754
755
756 (setq org-agenda-include-diary nil)
757 (setq org-agenda-diary-file "~/doc/org/diary.org")
758 (setq org-agenda-insert-diary-extract-time t)
759 (setq org-agenda-text-search-extra-files (quote (agenda-archives)))
760 (setq org-agenda-repeating-timestamp-show-all t)
761
762 ;; Show all agenda dates - even if they are empty
763 (setq org-agenda-show-all-dates t)
764
765 ;; let's try priorities
766 ;; org defaults to a b c, with b being the default.
767 ;; let's try a b c d e f g h i, or am I being silly.
768 ;; high is a b c, medium is d e f, low is g h i
769 (setq org-enable-priority-commands t
770       org-default-priority ?E
771       org-lowest-priority ?I)
772
773
774 ;; Sorting order for tasks on the agenda
775 (setq org-agenda-sorting-strategy
776       (quote ((agenda habit-down time-up user-defined-up priority-down effort-up category-keep)
777               (todo category-up priority-down effort-up)
778               (tags category-up priority-down effort-up)
779               (search category-up))))
780
781 ;; Start the weekly agenda on Monday
782 ;;(setq org-agenda-start-on-weekday 1)
783
784 ;; Enable display of the time grid so we can see the marker for the current time
785 (setq org-agenda-time-grid '((daily today remove-match)
786                               (0 300 600 800 1000 1200 1300 1500 1700 1900 2100 2300 2400)
787                               "......" "----------------"))
788
789 ;; Display tags farther right
790 (setq org-agenda-tags-column -102)
791
792 ;;
793 ;; Agenda sorting functions
794 ;;
795 (setq org-agenda-cmp-user-defined 'bh/agenda-sort)
796
797 (defun bh/agenda-sort (a b)
798   "Sorting strategy for agenda items.
799 Late deadlines first, then scheduled, then non-late deadlines"
800   (let (result num-a num-b)
801     (cond
802      ; time specific items are already sorted first by org-agenda-sorting-strategy
803
804      ; non-deadline and non-scheduled items next
805      ((bh/agenda-sort-test 'bh/is-not-scheduled-or-deadline a b))
806
807      ; deadlines for today next
808      ((bh/agenda-sort-test 'bh/is-due-deadline a b))
809
810      ; late deadlines next
811      ((bh/agenda-sort-test-num 'bh/is-late-deadline '< a b))
812
813      ; scheduled items for today next
814      ((bh/agenda-sort-test 'bh/is-scheduled-today a b))
815
816      ; late scheduled items next
817      ((bh/agenda-sort-test-num 'bh/is-scheduled-late '> a b))
818
819      ; pending deadlines last
820      ((bh/agenda-sort-test-num 'bh/is-pending-deadline '< a b))
821
822      ; finally default to unsorted
823      (t (setq result nil)))
824     result))
825
826 (defmacro bh/agenda-sort-test (fn a b)
827   "Test for agenda sort"
828   `(cond
829     ; if both match leave them unsorted
830     ((and (apply ,fn (list ,a))
831           (apply ,fn (list ,b)))
832      (setq result nil))
833     ; if a matches put a first
834     ((apply ,fn (list ,a))
835      (setq result -1))
836     ; otherwise if b matches put b first
837     ((apply ,fn (list ,b))
838      (setq result 1))
839     ; if none match leave them unsorted
840     (t nil)))
841
842 (defmacro bh/agenda-sort-test-num (fn compfn a b)
843   `(cond
844     ((apply ,fn (list ,a))
845      (setq num-a (string-to-number (match-string 1 ,a)))
846      (if (apply ,fn (list ,b))
847          (progn
848            (setq num-b (string-to-number (match-string 1 ,b)))
849            (setq result (if (apply ,compfn (list num-a num-b))
850                             -1
851                           1)))
852        (setq result -1)))
853     ((apply ,fn (list ,b))
854      (setq result 1))
855     (t nil)))
856
857 (defun bh/is-not-scheduled-or-deadline (date-str)
858   (and (not (bh/is-deadline date-str))
859        (not (bh/is-scheduled date-str))))
860
861 (defun bh/is-due-deadline (date-str)
862   (string-match "Deadline:" date-str))
863
864 (defun bh/is-late-deadline (date-str)
865   (string-match "In *\\(-.*\\)d\.:" date-str))
866
867 (defun bh/is-pending-deadline (date-str)
868   (string-match "In \\([^-]*\\)d\.:" date-str))
869
870 (defun bh/is-deadline (date-str)
871   (or (bh/is-due-deadline date-str)
872       (bh/is-late-deadline date-str)
873       (bh/is-pending-deadline date-str)))
874
875 (defun bh/is-scheduled (date-str)
876   (or (bh/is-scheduled-today date-str)
877       (bh/is-scheduled-late date-str)))
878
879 (defun bh/is-scheduled-today (date-str)
880   (string-match "Scheduled:" date-str))
881
882 (defun bh/is-scheduled-late (date-str)
883   (string-match "Sched\.\\(.*\\)x:" date-str))
884
885 (require 'org-git-link nil 'noerror)
886 (require 'org-checklist nil 'noerror)
887 (setq org-enforce-todo-dependencies t)
888 (setq org-hide-leading-stargs nil)
889 (setq org-startup-indented t)
890 (setq org-cycle-separator-lines 2)
891 (setq org-blank-before-new-entry (quote ((heading)
892                                          (plain-list-item . auto))))
893 (setq org-insert-heading-respect-content nil)
894 (setq org-reverse-note-order nil)
895 (setq org-show-following-heading t)
896 (setq org-show-hierarchy-above t)
897 (setq org-show-siblings (quote ((default))))
898 (setq org-deadline-warning-days 30)
899 (setq org-log-done (quote time))
900 (setq org-log-into-drawer "LOGBOOK")
901
902
903 (setq org-ditaa-jar-path "~/java/ditaa0_6b.jar")
904 (setq org-plantuml-jar-path "/usr/share/plantuml/plantuml.jar")
905
906 (add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)
907
908 ; Make babel results blocks lowercase
909 (setq org-babel-results-keyword "results")
910
911 (defun bh/display-inline-images ()
912   (condition-case nil
913       (org-display-inline-images)
914     (error nil)))
915
916 (org-babel-do-load-languages
917  'org-babel-load-languages
918  '((emacs-lisp . t)
919          (dot . t)
920          (ditaa . t)
921          (R . t)
922          (python . t)
923          (ruby . t)
924          (gnuplot . t)
925          (clojure . t)
926          ;;(sh . t)
927          (ledger . t)
928          (org . t)
929          (plantuml . t)
930          (latex . t)
931          (makefile . t)))
932
933 ; Do not prompt to confirm evaluation
934 ; This may be dangerous - make sure you understand the consequences
935 ; of setting this -- see the docstring for details
936 (setq org-confirm-babel-evaluate nil)
937
938 ; Cache all babel results blocks by default
939 ; For graphics generation this is way faster if nothing changes
940 (setq org-babel-default-header-args
941      (cons '(:cache . "yes")
942      (assq-delete-all :cache org-babel-default-header-args)))
943
944 ; Use fundamental mode when editing plantuml blocks with C-c '
945 (add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))
946
947 ; publishing
948
949 ; experimenting with docbook exports - not finished
950 (setq org-docbook-xsl-fo-proc-command "fop %s %s")
951 (setq org-docbook-xslt-proc-command "xsltproc --output %s /usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl %s")
952 ;
953 ; Inline images in HTML instead of producting links to the image
954 (setq org-html-inline-images t)
955 ; Do not use sub or superscripts - I currently don't need this functionality in my documents
956 ;(setq org-export-with-sub-superscripts nil)
957 ; Use org.css from the norang website for export document stylesheets
958 ;;(setq org-export-html-style-extra "<link rel=\"stylesheet\" href=\"http://doc.norang.ca/org.css\" type=\"text/css\" />")
959 (setq org-html-style-include-default nil)
960 ; Do not generate internal css formatting for HTML exports
961 (setq org-htmlize-output-type (quote inline-css))
962 ; Export with LaTeX fragments
963 (setq org-with-LaTeX-fragments t)
964 ; I wish to do abstracts nad lists...
965 (defun org-latex-no-toc (depth)
966   (when depth
967     (format "%% Org-mode is exporting headings to %s levels.\n"
968             depth)))
969 ;;(setq org-latex-format-toc-function 'org-latex-no-toc)
970 ;; now part of org-mode (require 'org-special-blocks)
971
972                                         ; use minted
973 (require 'ox-latex)
974 (add-to-list 'org-latex-packages-alist '("" "minted"))
975 (setq org-latex-listings 'minted)
976 (setq org-latex-minted-options
977       '(("frame" "single")
978         ("fontsize" "\\scriptsize")
979         ;("xleftmargin" "50pt")
980         ;("xrightmargin" "50pt")
981         ("linenos" "true")))
982 ;; cywin doesn't have texi2dvi
983 (if (eq system-type 'gnu/linux)
984     (setq org-latex-pdf-process '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
985                                   "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
986                                   "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
987   (setq org-latex-pdf-process '("texi2dvi --pdf --tidy --shell-escape --batch %f")))
988 ; List of projects
989 ; norang       - http://www.norang.ca/
990 ; doc          - http://doc.norang.ca/
991 ; org-mode-doc - http://doc.norang.ca/org-mode.html and associated files
992 ; org          - miscellaneous todo lists for publishing
993 (setq org-publish-project-alist
994       ;
995       ; http://www.norang.ca/  (norang website)
996       ; norang-org are the org-files that generate the content
997       ; norang-extra are images and css files that need to be included
998       ; norang is the top-level project that gets published
999       (quote (("norang-org"
1000                :base-directory "~/git/www.norang.ca"
1001                :publishing-directory "/ssh:www-data@www:~/www.norang.ca/htdocs"
1002                :recursive t
1003                :table-of-contents nil
1004                :base-extension "org"
1005                :publishing-function org-publish-org-to-html
1006                :style-include-default nil
1007                :section-numbers nil
1008                :table-of-contents nil
1009                :style "<link rel=\"stylesheet\" href=\"norang.css\" type=\"text/css\" />"
1010                :author-info nil
1011                :creator-info nil)
1012               ("norang-extra"
1013                :base-directory "~/git/www.norang.ca/"
1014                :publishing-directory "/ssh:www-data@www:~/www.norang.ca/htdocs"
1015                :base-extension "css\\|pdf\\|png\\|jpg\\|gif"
1016                :publishing-function org-publish-attachment
1017                :recursive t
1018                :author nil)
1019               ("norang"
1020                :components ("norang-org" "norang-extra"))
1021               ;
1022               ; http://doc.norang.ca/  (norang website)
1023               ; doc-org are the org-files that generate the content
1024               ; doc-extra are images and css files that need to be included
1025               ; doc is the top-level project that gets published
1026               ("doc-org"
1027                :base-directory "~/git/doc.norang.ca/"
1028                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs"
1029                :recursive nil
1030                :section-numbers nil
1031                :table-of-contents nil
1032                :base-extension "org"
1033                :publishing-function (org-publish-org-to-html org-publish-org-to-org)
1034                :style-include-default nil
1035                :style "<link rel=\"stylesheet\" href=\"/org.css\" type=\"text/css\" />"
1036                :author-info nil
1037                :creator-info nil)
1038               ("doc-extra"
1039                :base-directory "~/git/doc.norang.ca/"
1040                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs"
1041                :base-extension "css\\|pdf\\|png\\|jpg\\|gif"
1042                :publishing-function org-publish-attachment
1043                :recursive nil
1044                :author nil)
1045               ("doc"
1046                :components ("doc-org" "doc-extra"))
1047               ("doc-private-org"
1048                :base-directory "~/git/doc.norang.ca/private"
1049                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs/private"
1050                :recursive nil
1051                :section-numbers nil
1052                :table-of-contents nil
1053                :base-extension "org"
1054                :publishing-function (org-publish-org-to-html org-publish-org-to-org)
1055                :style-include-default nil
1056                :style "<link rel=\"stylesheet\" href=\"/org.css\" type=\"text/css\" />"
1057                :auto-sitemap t
1058                :sitemap-filename "index.html"
1059                :sitemap-title "Norang Private Documents"
1060                :sitemap-style "tree"
1061                :author-info nil
1062                :creator-info nil)
1063               ("doc-private-extra"
1064                :base-directory "~/git/doc.norang.ca/private"
1065                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs/private"
1066                :base-extension "css\\|pdf\\|png\\|jpg\\|gif"
1067                :publishing-function org-publish-attachment
1068                :recursive nil
1069                :author nil)
1070               ("doc-private"
1071                :components ("doc-private-org" "doc-private-extra"))
1072               ;
1073               ; Miscellaneous pages for other websites
1074               ; org are the org-files that generate the content
1075               ("org-org"
1076                :base-directory "~/git/org/"
1077                :publishing-directory "/ssh:www-data@www:~/org"
1078                :recursive t
1079                :section-numbers nil
1080                :table-of-contents nil
1081                :base-extension "org"
1082                :publishing-function org-publish-org-to-html
1083                :style-include-default nil
1084                :style "<link rel=\"stylesheet\" href=\"/org.css\" type=\"text/css\" />"
1085                :author-info nil
1086                :creator-info nil)
1087               ;
1088               ; http://doc.norang.ca/  (norang website)
1089               ; org-mode-doc-org this document
1090               ; org-mode-doc-extra are images and css files that need to be included
1091               ; org-mode-doc is the top-level project that gets published
1092               ; This uses the same target directory as the 'doc' project
1093               ("org-mode-doc-org"
1094                :base-directory "~/git/org-mode-doc/"
1095                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs"
1096                :recursive t
1097                :section-numbers nil
1098                :table-of-contents nil
1099                :base-extension "org"
1100                :publishing-function (org-publish-org-to-html org-publish-org-to-org)
1101                :plain-source t
1102                :htmlized-source t
1103                :style-include-default nil
1104                :style "<link rel=\"stylesheet\" href=\"/org.css\" type=\"text/css\" />"
1105                :author-info nil
1106                :creator-info nil)
1107               ("org-mode-doc-extra"
1108                :base-directory "~/git/org-mode-doc/"
1109                :publishing-directory "/ssh:www-data@www:~/doc.norang.ca/htdocs"
1110                :base-extension "css\\|pdf\\|png\\|jpg\\|gif"
1111                :publishing-function org-publish-attachment
1112                :recursive t
1113                :author nil)
1114               ("org-mode-doc"
1115                :components ("org-mode-doc-org" "org-mode-doc-extra"))
1116               ;
1117               ; http://doc.norang.ca/  (norang website)
1118               ; org-mode-doc-org this document
1119               ; org-mode-doc-extra are images and css files that need to be included
1120               ; org-mode-doc is the top-level project that gets published
1121               ; This uses the same target directory as the 'doc' project
1122               ("tmp-org"
1123                :base-directory "/tmp/publish/"
1124                :publishing-directory "/ssh:www-data@www:~/www.norang.ca/htdocs/tmp"
1125                :recursive t
1126                :section-numbers nil
1127                :table-of-contents nil
1128                :base-extension "org"
1129                :publishing-function (org-publish-org-to-html org-publish-org-to-org)
1130                :style "<link rel=\"stylesheet\" href=\"http://doc.norang.ca/org.css\" type=\"text/css\" />"
1131                :plain-source t
1132                :htmlized-source t
1133                :style-include-default nil
1134                :auto-sitemap t
1135                :sitemap-filename "index.html"
1136                :sitemap-title "Test Publishing Area"
1137                :sitemap-style "tree"
1138                :author-info t
1139                :creator-info t)
1140               ("tmp-extra"
1141                :base-directory "/tmp/publish/"
1142                :publishing-directory "/ssh:www-data@www:~/www.norang.ca/htdocs/tmp"
1143                :base-extension "css\\|pdf\\|png\\|jpg\\|gif"
1144                :publishing-function org-publish-attachment
1145                :recursive t
1146                :author nil)
1147               ("tmp"
1148                :components ("tmp-org" "tmp-extra")))))
1149
1150 (setq org-publish-project-alist
1151       '(
1152         ("doc-jtn-com-private"
1153          :base-directory "~/doc/doc.jamestechnotes.com-private"
1154          :base-extension "org"
1155          :publishing-directory "/ssh:chara.dreamhost.com:~/doc.jamestechnotes.com/private"
1156          :recursive t
1157          :publishing-functino org-publish-org-to-html
1158          :headline-levels 6
1159          :auto-preamble t
1160          )
1161         ("doc-jtn" :components ("doc-jtn-com-private"))
1162         ("jamestechnotes-com"
1163          :base-directory "~/src/wiki/jamestechnotes.com"
1164          :base-extension "org"
1165          :publishing-directory "~/public_html/"
1166          :recursive t
1167          :publishing-function (org-publish-org-to-html org-publish-org-to-org)
1168          :headline-levels 6
1169          :auto-preamble t
1170          :auto-sitemap nil
1171          :makeindex nil
1172          :style "<meta name=\"author\" content=\"James Richardson\" /><meta name=\"authorurl\" content=\"http://jamestechnotes.com\" /><link href=\"http://www.myopenid.com/server\" rel=\"openid.server\" /><link href=\"http://www.myopenid.com/server\" rel=\"openid2.provider\" /><link href=\"http://james-richardson-jr.myopenid.com/\" rel=\"openid.delegate\" /><link href=\"http://james-richardson-jr.myopenid.com/\" rel=\"openid2.local_id\" /><link href=\"https://plus.google.com/100087072360376597478\" rel=\"publisher\" /><link href=\"http://jamestechnotes.com\" rel=\"author\"/> <link rel=\"stylesheet\" title=\"Standard\" href=\"/css/org.css\" type=\"text/css\"/>"
1173          :html-preamble "<div id=\"menu\"><a href=\"index.html\">Home</a> | <a href=\"about.html\">About</a></div>"
1174          )
1175         ("jamestechnotes-com-static"
1176          :base-directory "~/src/wiki/jamestechnotes.com"
1177          :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|ogg\\|swf\\|txt"
1178          :publishing-directory "~/public_html"
1179          :recursive t
1180          :publishing-function org-publish-attachment
1181          )
1182         ("jamestechnotes" :components ("jamestechnotes-com" "jamestechnotes-com-static"))
1183         ))
1184 ; I'm lazy and don't want to remember the name of the project to publish when I modify
1185 ; a file that is part of a project.  So this function saves the file, and publishes
1186 ; the project that includes this file
1187 ;
1188 ; It's bound to C-S-F12 so I just edit and hit C-S-F12 when I'm done and move on to the next thing
1189 (defun bh/save-then-publish ()
1190   (interactive)
1191   (save-buffer)
1192   (org-save-all-org-buffers)
1193   (org-publish-current-project))
1194
1195 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
1196
1197 ;; push
1198 ;;(defvar org-mobile-push-timer nil
1199 ;;  "Timer that `org-mobile-push-timer' uses to reschedule itself, or nil")
1200
1201 ;;(defun org-mobile-push-with-delay (secs)
1202 ;;  (when org-mobile-push-timer
1203 ;;    (cancel-timer org-mobile-push-timer))
1204 ;;  (setq org-mobile-push-timer
1205 ;;      (run-with-idle-timer
1206 ;;       (* 1 secs) nil 'org-mobile-push)))
1207
1208 ;; (add-hook 'after-save-hook
1209 ;;        (lambda()
1210 ;;          (when (eq major-mode 'org-mode)
1211 ;;            (dolist (file (org-mobile-files-alist))
1212 ;;              (if (string= (expand-file-name (car file)) (buffer-file-name))
1213 ;;                  (org-mobile-push-with-delay 30))))))
1214
1215 ;;(run-at-time "00:05" 86400 '(lambda () (org-mobile-push-with-delay 1)))
1216
1217 ;; pul
1218 ;;(org-mobile-pull)
1219
1220 ;;(defun install-monitor (file secs)
1221 ;;  (run-with-timer 0 secs
1222 ;;    (lambda (f p)
1223 ;;      (unless (< p (second (time-since (elt (file-attributes f) 5))))
1224 ;;        (org-mobile-pull)))
1225 ;;    file secs))
1226
1227 ;; (install-monitor (file-truename
1228 ;;                   (concat
1229 ;;                    (file-name-as-directory org-mobile-directory)
1230 ;;                    org-mobile-capture-file))
1231 ;;                  5)
1232
1233 ;;(run-with-timer 0 (* 60 60) 'org-mobile-pull) ; pull every hour
1234
1235
1236 ;; ;; export org mode buffer as html w/o header crap
1237 ;; (global-set-key (kbd "<f9> x") 'jr/connections)
1238 ;; (defun jr/connections (arg)
1239 ;;   (interactive "P")
1240 ;;   (org-as-html arg nil nil t))
1241
1242 ;; rss feeds
1243 ;; (setq org-feed-alist
1244 ;;       '(("Armed and Dangerous"
1245 ;;       "http://esr.ibiblio.org/?feed=rss2"
1246 ;;       "~/doc/org/todo.org" "catb")
1247 ;;      ("Git Annex"
1248 ;;       "https://git-annex.branchable.com/forum/index.rss"
1249 ;;       "~/doc/org/todo.org" "gitannex")
1250 ;;      ("Ikiwki"
1251 ;;       "http://ikiwiki.info/news/index.rss"
1252 ;;       "~/doc/org/todo.org" "ikiwiki")
1253 ;;      ("myglpus"
1254 ;;       "http://gplusrss.com/rss/feed/2eec32c7a808ca3556325d3160b5ebd3546e7948ad7f8"
1255 ;;       "~/doc/org/todo.org" "mygplus")
1256 ;;      ("bofh"
1257 ;;       "http://www.theregister.co.uk/data_centre/bofh/headlines.rss"
1258 ;;       "~/doc/org/todo.org" "BOFH")
1259 ;;      ("reg-servers"
1260 ;;       "http://www.theregister.co.uk/data_centre/servers/headlines.rss"
1261 ;;       "~/doc/org/todo.org" "reg-servers")
1262 ;;      ("reg-os"
1263 ;;       "http://www.theregister.co.uk/software/os/headlines.rss"
1264 ;;       "~/doc/org/todo.org" "reg-os")
1265 ;;      ("reg-apps"
1266 ;;       "http://www.theregister.co.uk/software/apps/headlines.rss"
1267 ;;       "~/doc/org/todo.org" "reg-apps")
1268 ;;      ("reg-dev"
1269 ;;       "http://www.theregister.co.uk/software/developer/headlines.rss"
1270 ;;       "~/doc/org/todo.org" "reg-dev")
1271 ;;      ("reg-stob"
1272 ;;       "http://www.theregister.co.uk/software/stob/headlines.rss"
1273 ;;       "~/doc/org/todo.org" "reg-stob")
1274 ;;      ("reg-sci"
1275 ;;       "http://www.theregister.co.uk/science/special_projects_bureau/headlines.rss"
1276 ;;       "~/doc/org/todo.org" "reg-sci")
1277 ;;      ("sci-american"
1278 ;;       "http://rss.sciam.com/sciam/topic/quantum-physics"
1279 ;;       "~/doc/org/todo.org" "sci-american")
1280 ;;      ("roku"
1281 ;;       "http://blog.roku.com/feed/"
1282 ;;       "~/doc/org/todo.org" "roku")
1283 ;;      ("xkcd"
1284 ;;       "http://xkcd.com/rss.xml"
1285 ;;       "~/doc/org/todo.org" "xkcd")
1286 ;;      ("dilbert"
1287 ;;       "http://www.comicsyndicate.org/Feed/Dilbert"
1288 ;;       "~/doc/org/todo.org" "dilbert")
1289 ;;      ("bloom"
1290 ;;       "http://www.comicsyndicate.org/Feed/Bloom%20County"
1291 ;;       "~/doc/org/todo.org" "bloom")
1292 ;;      ("rush"
1293 ;;       "http://feeds.feedburner.com/rushLimbaugh-AllContent"
1294 ;;       "~/doc/org/todo.org" "rush")))
1295 (setq org-feed-default-template
1296       "\n* %h\n  SCHEDULED: %T\n  %description\n  %a\n")
1297
1298 ;; setup solar
1299 (setq calendar-latitude 35.6
1300       calendar-longitude -80.8
1301       calendar-location-name "Mooresville, NC"
1302       calendar-time-zone -300
1303       calendar-standard-time-zone-name "EST"
1304       calendar-daylight-time-zone-name "EDT")
1305
1306 ;; org-weather
1307 (when (require 'org-weather nil 'noerror)
1308   (setq org-weather-location "4480125"
1309         org-weather-api-url "http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&mode=json&units=imperial&cnt=7&APPID=%s"
1310         org-weather-temperature-unit "°F"
1311         org-weather-speed-unit "mph")
1312   (org-weather-refresh))
1313
1314 ;; effort and clocking
1315 ; Set default column view headings: Task Effort Clock_Summary
1316 (setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")
1317
1318 ; global Effort estimate values
1319 ; global STYLE property values for completion
1320 (setq org-global-properties (quote (("Effort_ALL" . "0:15 0:30 0:45 1:00 2:00 3:00 4:00 5:00 6:00 8:00")
1321                                     ("STYLE_ALL" . "habit"))))
1322
1323
1324 ;; org-jira
1325 ;; set defcustom before loading
1326 (setq jiralib-url "https://tools.lowes.com/jira"
1327       ;;jiralib-wsdl-descriptor-url "https://tools.lowes.com/jira/rpc/soap/jirasoapservice-v2?wsdl"
1328       org-jira-working-dir "~/doc/org/lowes"
1329       org-jira-use-status-as-todo t)
1330 (require 'org-jira nil 'noerror)
1331 (setq request-message-level 'debug
1332       request-log-level 'debug)
1333
1334 (defun jr/insert-latex-boilerplate ()
1335     "Insert boilerplate into current buffer"
1336   (interactive)
1337   (insert "#+LATEX_CLASS: article
1338 #+LATEX_CLASS_OPTIONS:
1339 #+LATEX_HEADER:
1340 #+LATEX_HEADER_EXTRA:
1341 #+DESCRIPTION:
1342 #+KEYWORDS:
1343 #+SUBTITLE:
1344 #+LATEX_COMPILER: pdflatex
1345 #+DATE: \\today
1346
1347 #+OPTIONS: ':nil *:t -:t ::t <:t H:10 \\n:nil ^:t arch:headline
1348 #+OPTIONS: author:t broken-links:nil c:nil creator:nil
1349 #+OPTIONS: d:(not \"LOGBOOK\") date:t e:t email:nil f:t inline:t num:t
1350 #+OPTIONS: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t
1351 #+OPTIONS: timestamp:t title:t toc:nil todo:t |:t
1352 #+TITLE: set this
1353 #+AUTHOR: James Richardson
1354 #+EMAIL: james.richardson@lowes.com
1355 #+LANGUAGE: en
1356 #+SELECT_TAGS: export
1357 #+EXCLUDE_TAGS: noexport
1358 #+CREATOR: Emacs 25.1.1 (Org mode 9.0.5)
1359
1360 #+LaTeX: \\thispagestyle{empty}
1361
1362 #+BEGIN_abstract
1363 #+END_abstract
1364
1365 #+LaTeX: \\newpage
1366 #+LaTex: \\twocolumn
1367 #+LaTeX: \\pagestyle{plain}
1368 #+LaTeX: \\setcounter{page}{1}
1369 #+LaTeX: \\pagenumbering{roman}
1370
1371 #+LATEX: \\tableofcontents
1372 #+LATEX: \\listoftables
1373 #+LATEX: \\listoffigures
1374 #+LATEX: \\listoflistings
1375 #+LaTeX: \\onecolumn
1376 #+LaTeX: \\pagestyle{headings}
1377 #+LaTeX: \\setcounter{page}{1}
1378 #+LaTeX: \\pagenumbering{arabic}
1379
1380 Text here
1381
1382 #+LaTeX: \\newpage
1383 #+LaTeX: \\appendix
1384
1385 Appendices here"))