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