hand next tasks better
authorJames Richardson <james@jamestechnotes.com>
Mon, 27 Nov 2017 22:59:39 +0000 (17:59 -0500)
committerJames Richardson <james@jamestechnotes.com>
Mon, 27 Nov 2017 22:59:39 +0000 (17:59 -0500)
.emacs.d/config/org.el

index 995ed9fd372dd00e8a35b15569d3a9af26ebc74b..ec84d077085fbd1c89c81a5bd251796f30b9ab1a 100644 (file)
 ;; I want to get all org files in a directory
 ;; http://stackoverflow.com/questions/17215868/recursively-adding-org-files-in-a-top-level-directory-for-org-agenda-files-take
 
+(defvar bh/hide-scheduled-and-waiting-next-tasks t)
+;;(setq bh/hide-scheduled-and-waiting-next-tasks t)
+
+
 (defun jr/load-org-agenda-files-recursively (dir)
   "Find all directories in DIR."
   (unless (file-directory-p dir) (error "Not a directory `%s'" dir))
@@ -36,7 +40,9 @@
 ;;(jr/load-org-agenda-files-recursively "~/src/" ) ; trailing slash required
 ;;(jr/load-org-agenda-files-recursively "~/src01/" ) ; trailing slash required
 (when (file-directory-p "~/doc/org")
-  (setq org-directory "~/doc/org"))
+  (setq org-directory "~/doc/org")
+  (setq org-default-notes-file "~/doc/org/refile.org"))
+
 
 ;; (if (file-exists-p "~/doc/org")
 ;;     (if (boundp 'org-agenda-files)
        (sequence "NEW" "IN-PROGRESS" "|" "DONE") ;; jira
         (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE")))
 
+(setq org-todo-keyword-faces
+      (quote (("TODO" :foreground "red" :weight bold)
+              ("NEXT" :foreground "blue" :weight bold)
+             ("NEW" :foreground "red" :weight bold)
+              ("IN-PROGRESS" :foreground "blue" :weight bold)
+              ("DONE" :foreground "forest green" :weight bold)
+              ("WAITING" :foreground "orange" :weight bold)
+              ("HOLD" :foreground "magenta" :weight bold)
+              ("CANCELLED" :foreground "forest green" :weight bold)
+              ("MEETING" :foreground "forest green" :weight bold)
+              ("PHONE" :foreground "forest green" :weight bold))))
+
 (setq org-use-fast-todo-selection t)
 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
 
 
 (setq org-fast-tag-selection-single-key (quote expert))
 
+; For tag searches ignore tasks with scheduled and deadline datas
+
 (setq org-agenda-tags-todo-honor-ignore-options t)
 (setq org-agenda-span 1) ;; show day to start
 (setq org-deadline-warning-days 14)
 (setq org-icalendar-store-UID t)
 (setq org-icalendar-alarm-time 15)
 
-(setq org-default-notes-file "~/doc/org/refile.org")
-
 (require 'org-contacts nil 'noerror)
 (setq org-contacts-files '("~/doc/org/contacts.org"))
 
-
-
 (setq org-capture-templates
       (quote (("t" "todo" entry (file "~/doc/org/refile.org")
                "* TODO %?\n%a\n  %i")
                        (org-tags-match-list-sublevels nil)))
                 (tags-todo "-CANCELLED/!"
                            ((org-agenda-overriding-header "Stuck Projects")
+                            (org-agenda-skip-function 'bh/skip-non-stuck-projects)
+                            (org-agenda-sorting-strategy
+                             '(category-keep))))
+                (tags-todo "-HOLD-CANCELLED/!"
+                           ((org-agenda-overriding-header "Projects")
+                            (org-agenda-skip-function 'bh/skip-non-projects)
                             (org-tags-match-list-sublevels 'indented)
-                            (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
-                (tags-todo "-WAITING-CANCELLED/!NEXT"
-                           ((org-agenda-overriding-header "Next Tasks")
+                            (org-agenda-sorting-strategy
+                             '(category-keep))))
+                (tags-todo "-CANCELLED/!NEXT"
+                           ((org-agenda-overriding-header (concat "Project Next Tasks"
+                                                                  (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                      ""
+                                                                    " (including WAITING and SCHEDULED tasks)")))
                             (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
-                            (org-agenda-todo-ignore-scheduled t)
-                            (org-agenda-todo-ignore-deadlines t)
                             (org-tags-match-list-sublevels t)
+                            (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
                             (org-agenda-sorting-strategy
                              '(todo-state-down effort-up category-keep))))
-               (tags-todo "jira"
-                     ((org-agenda-overriding-header "Jira Tasks")
-                      (org-tags-match-list-sublevel)))
-                (tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
-                           ((org-agenda-overriding-header "Tasks")
-                            (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
-                            (org-agenda-todo-ignore-scheduled t)
-                            (org-agenda-todo-ignore-deadlines t)
+                (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
+                           ((org-agenda-overriding-header (concat "Project Subtasks"
+                                                                  (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                      ""
+                                                                    " (including WAITING and SCHEDULED tasks)")))
+                            (org-agenda-skip-function 'bh/skip-non-project-tasks)
+                            (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
                             (org-agenda-sorting-strategy
                              '(category-keep))))
-                (tags-todo "-CANCELLED/!"
-                           ((org-agenda-overriding-header "Projects")
-                            (org-agenda-skip-function 'bh/skip-non-projects)
+                (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
+                           ((org-agenda-overriding-header (concat "Standalone Tasks"
+                                                                  (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                      ""
+                                                                    " (including WAITING and SCHEDULED tasks)")))
+                            (org-agenda-skip-function 'bh/skip-project-tasks)
+                            (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
                             (org-agenda-sorting-strategy
                              '(category-keep))))
-                (tags-todo "-CANCELLED/!WAITING|HOLD"
-                           ((org-agenda-overriding-header "Waiting and Postponed Tasks")
-                            (org-agenda-skip-function 'bh/skip-projects-and-habits)
-                            (org-agenda-todo-ignore-scheduled t)
-                            (org-agenda-todo-ignore-deadlines t)))
+                (tags-todo "-CANCELLED+WAITING|HOLD/!"
+                           ((org-agenda-overriding-header (concat "Waiting and Postponed Tasks"
+                                                                  (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                      ""
+                                                                    " (including WAITING and SCHEDULED tasks)")))
+                            (org-agenda-skip-function 'bh/skip-non-tasks)
+                            (org-tags-match-list-sublevels nil)
+                            (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)))
                 (tags "-REFILE/"
                       ((org-agenda-overriding-header "Tasks to Archive")
-                       (org-agenda-skip-function 'bh/skip-non-archivable-tasks))))
-               nil)
-              ("r" "Tasks to Refile" tags "REFILE"
-               ((org-agenda-overriding-header "Tasks to Refile")
-                (org-tags-match-list-sublevels nil)))
-              ("#" "Stuck Projects" tags-todo "-CANCELLED/!"
-               ((org-agenda-overriding-header "Stuck Projects")
-                (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
-              ("n" "Next Tasks" tags-todo "-WAITING-CANCELLED/!NEXT"
-               ((org-agenda-overriding-header "Next Tasks")
-                (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
-                (org-agenda-todo-ignore-scheduled t)
-                (org-agenda-todo-ignore-deadlines t)
-                (org-tags-match-list-sublevels t)
+                       (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
+                       (org-tags-match-list-sublevels nil))))
+               nil))))
+
+(setq org-agenda-custom-commands1
+      (quote (("N" "Notes" tags "NOTE"
+               ((org-agenda-overriding-header "Notes")
+                (org-tags-match-list-sublevels t)))
+              ("h" "Habits" tags-todo "STYLE=\"habit\""
+               ((org-agenda-overriding-header "Habits")
                 (org-agenda-sorting-strategy
                  '(todo-state-down effort-up category-keep))))
-              ("R" "Tasks" tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
-               ((org-agenda-overriding-header "Tasks")
-                (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
-                (org-agenda-sorting-strategy
-                 '(category-keep))))
-              ("p" "Projects" tags-todo "-CANCELLED/!"
-               ((org-agenda-overriding-header "Projects")
-                (org-agenda-skip-function 'bh/skip-non-projects)
-                (org-agenda-sorting-strategy
-                 '(category-keep))))
-              ("w" "Waiting Tasks" tags-todo "-CANCELLED/!WAITING|HOLD"
-               ((org-agenda-overriding-header "Waiting and Postponed tasks"))
-               (org-agenda-skip-function 'bh/skip-projects-and-habits)
-               (org-agenda-todo-ignore-scheduled 'future)
-               (org-agenda-todo-ignore-deadlines 'future))
-              ("A" "Tasks to Archive" tags "-REFILE/"
-               ((org-agenda-overriding-header "Tasks to Archive")
-                (org-agenda-skip-function 'bh/skip-non-archivable-tasks))))))
-
-
+              (" " "Agenda"
+               ((agenda "" nil)
+                (tags "REFILE"
+                      ((org-agenda-overriding-header "Tasks to Refile")
+                       (org-tags-match-list-sublevels nil)))
+                (tags-todo "-CANCELLED/!"
+                           ((org-agenda-overriding-header "Stuck Projects")
+                           (org-agenda-skip-function 'bh/skip-non-stuck-projects)
+                           (org-agenda-sorting-strategy
+                            '(category-keep))))
+               (tags-todo "-HOLD-CANCELLED/!"
+                          ((org-agenda-overriding-header "Projects")
+                           (org-agenda-skip-function 'bh/skip-non-projects)
+                           (org-tags-match-list-sublevels 'indented)
+                           (org-agenda-sorting-strategy
+                            '(category-keep))))
+               (tags-todo "-CANCELLED/!NEXT"
+                          ((org-agenda-overriding-header (concat "Project Next Tasks"
+                                                                 (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                     ""
+                                                                   " (including WAITING and SCHEDULED tasks)")))
+                           (org-agenda-skip-function 'bh/skip-projects-and-habbits-and-single-tasks)
+                           (org-tags-match-list-sublevels t)
+                           (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-sorting-strategy
+                            '(todo-state-down effort-up category-keep))))
+               (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
+                           ((org-agenda-overriding-header (concat "Standalone Tasks"
+                                                                  (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                      ""
+                                                                    " (including WAITING and SCHEDULED tasks)")))
+                            (org-agenda-skip-function 'bh/skip-non-project-tasks)
+                            (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
+                            (org-agenda-sorting-strategy
+                             '(category-keep))))
+               (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
+                          ((org-agenda-overriding-header (concat "Project Subtasks"
+                                                                 (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                     ""
+                                                                   " (including WAITING and SCHEDULED tasks)")))
+                           (org-agenda-skip-function 'bh/skip-non-project-tasks)
+                           (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-sorting-strategy
+                            '(category-keep))))
+               (tags-todo "-CANCELLED+WAITING|HOLD/!"
+                          ((org-agenda-overriding-header (concat "Waiting and Postponed Tasks"
+                                                                 (if bh/hide-scheduled-and-waiting-next-tasks
+                                                                     ""
+                                                                   " (including WAITING and SCHEDULED tasks)")))
+                           (org-agenda-skip-function 'bh/skip-non-tasks)
+                           (org-tags-match-list-sublevels nil)
+                           (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
+                           (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)))
+                (tags "-REFILE/"
+                      ((org-agenda-overriding-header "Tasks to Archive")
+                       (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
+                      (org-tags-match-list-sublevels nill)))
+               nil)))))
 
+(defun bh/org-auto-exclude-function (tag)
+  "Automatic task exclusion in the agenda with / RET"
+  (and (cond
+        ((string= tag "hold")
+         t)
+        ((string= tag "farm")
+         t))
+       (concat "-" tag)))
 
+(setq org-agenda-auto-exclude-function 'bh/org-auto-exclude-function)
 
 (setq org-modules (quote (org-habit org-id)))
 (setq org-habit-graph-column 50)
@@ -408,6 +495,32 @@ Callers of this function already widen the buffer view."
     (setq org-tags-match-list-sublevels nil))
   nil)
 
+
+(defun bh/toggle-next-task-display ()
+  (interactive)
+  (setq bh/hide-scheduled-and-waiting-next-tasks (not bh/hide-scheduled-and-waiting-next-tasks))
+  (when  (equal major-mode 'org-agenda-mode)
+    (org-agenda-redo))
+  (message "%s WAITING and SCHEDULED NEXT Tasks" (if bh/hide-scheduled-and-waiting-next-tasks "Hide" "Show")))
+
+(defun bh/skip-stuck-projects ()
+  "Skip trees that are not stuck projects"
+  (save-restriction
+    (widen)
+    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
+      (if (bh/is-project-p)
+          (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
+                 (has-next ))
+            (save-excursion
+              (forward-line 1)
+              (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
+                (unless (member "WAITING" (org-get-tags-at))
+                  (setq has-next t))))
+            (if has-next
+                nil
+              next-headline)) ; a stuck project, has subtasks but no next task
+        nil))))
+
 (defun bh/skip-non-stuck-projects ()
   "Skip trees that are not stuck projects"
   (save-restriction
@@ -415,10 +528,12 @@ Callers of this function already widen the buffer view."
     (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
       (if (bh/is-project-p)
           (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
-                 (has-next (save-excursion
-                             (forward-line 1)
-                             (and (< (point) subtree-end)
-                                  (re-search-forward "^\\*+ \\(NEXT\\) " subtree-end t)))))
+                (has-next ))
+           (save-excursion
+             (forward-line 1)
+             (while (and (not has-next) (< (point) subtree-end) (re-search-forward "^\\*+ NEXT " subtree-end t))
+               (unless (member "WAITING" (org-get-tags-at))
+                 (setq has-next t))))
             (if has-next
                 next-headline
               nil)) ; a stuck project, has subtasks but no next task
@@ -426,15 +541,31 @@ Callers of this function already widen the buffer view."
 
 (defun bh/skip-non-projects ()
   "Skip trees that are not projects"
-  (bh/list-sublevels-for-projects-indented)
+  ;;(bh/list-sublevels-for-projects-indented)
   (if (save-excursion (bh/skip-non-stuck-projects))
       (save-restriction
         (widen)
         (let ((subtree-end (save-excursion (org-end-of-subtree t))))
-          (if (bh/is-project-p)
-              nil
-            subtree-end)))
-    (org-end-of-subtree t)))
+          (cond
+          ((bh/is-project-p)
+           nil)
+          ((and (bh/is-project-subtree-p) (not (bh/is-task-p)))
+           nil)
+           (t
+           subtree-end))))
+    (save-excursion (org-end-of-subtree t))))
+
+(defun bh/skip-non-tasks ()
+  "Show non-project tasks.
+Skip project and sub-project tasks, habits, and project related tasks."
+  (save-restriction
+    (widen)
+    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
+      (cond
+       ((bh/is-task-p)
+        nil)
+       (t
+        next-headline)))))
 
 (defun bh/skip-project-trees-and-habits ()
   "Skip trees that are projects"
@@ -457,8 +588,11 @@ Callers of this function already widen the buffer view."
       (cond
        ((org-is-habit-p)
         next-headline)
-       ((bh/is-project-p)
+       ((and bh/hide-scheduled-and-waiting-next-tasks
+            (member "WAITING" (org-get-tags-at)))
         next-headline)
+       ((bh/is-project-p)
+       next-headline)
        ((and (bh/is-task-p) (not (bh/is-project-subtree-p)))
         next-headline)
        (t
@@ -488,6 +622,42 @@ When not restricted, skip project and sub-project tasks, habits, and project rel
        (t
         nil)))))
 
+(defun bh/skip-project-tasks ()
+  "Show non-project tasks.
+Skip project and sub-project tasks, habits, and project related tasks."
+  (save-restriction
+    (widen)
+    (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
+      (cond
+       ((bh/is-project-p)
+        subtree-end)
+       ((org-is-habit-p)
+        subtree-end)
+       ((bh/is-project-subtree-p)
+        subtree-end)
+       (t
+        nil)))))
+
+(defun bh/skip-non-project-tasks ()
+  "Show project tasks.
+Skip project and sub-project tasks, habits, and loose non-project tasks."
+  (save-restriction
+    (widen)
+    (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
+           (next-headline (save-excursion (or (outline-next-heading) (point-max)))))
+      (cond
+       ((bh/is-project-p)
+        next-headline)
+       ((org-is-habit-p)
+        subtree-end)
+       ((and (bh/is-project-subtree-p)
+             (member (org-get-todo-state) (list "NEXT")))
+        subtree-end)
+       ((not (bh/is-project-subtree-p))
+        subtree-end)
+       (t
+        nil)))))
+
 (defun bh/skip-projects-and-habits ()
   "Skip trees that are projects and tasks that are habits"
   (save-restriction
@@ -507,6 +677,7 @@ When not restricted, skip project and sub-project tasks, habits, and project rel
     (if (bh/is-subproject-p)
         nil
       next-headline)))
+
 (setq org-archive-mark-done nil)
 (setq org-archive-location "%s_archive::* Archived Tasks")
 
@@ -514,24 +685,26 @@ When not restricted, skip project and sub-project tasks, habits, and project rel
   "Skip trees that are not available for archiving"
   (save-restriction
     (widen)
-    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
-      ;; Consider only tasks with done todo headings as archivable candidates
-      (if (member (org-get-todo-state) org-done-keywords)
-          (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
-                 (daynr (string-to-int (format-time-string "%d" (current-time))))
-                 (a-month-ago (* 60 60 24 (+ daynr 1)))
-                 (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
-                 (this-month (format-time-string "%Y-%m-" (current-time)))
-                 (subtree-is-current (save-excursion
-                                       (forward-line 1)
-                                       (and (< (point) subtree-end)
-                                            (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
-            (if subtree-is-current
-                next-headline ; Has a date in this month or last month, skip it
-              nil))  ; available to archive
-        (or next-headline (point-max))))))
-
-;;(setq org-log-done t)
+    ;; Consider only tasks with done todo headings as archivable candidates
+    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max))))
+         (subtree-end (save-excursion (org-end-of-subtree t))))
+      (if (member (org-get-todo-state) org-todo-keywords-1)
+         (if (member (org-get-todo-state) org-done-keywords)
+             (let* ((daynr (string-to-int (format-time-string "%d" (current-time))))
+                    (a-month-ago (* 60 60 24 (+ daynr 1)))
+                    (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
+                    (this-month (format-time-string "%Y-%m-" (current-time)))
+                    (subtree-is-current (save-excursion
+                                          (forward-line 1)
+                                          (and (< (point) subtree-end)
+                                               (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
+               (if subtree-is-current
+                   next-headline ; Has a date in this month or last month, skip it
+                 nil))  ; available to archive
+           (or subtree-end (point-max)))
+       next-headline))))
+
+(setq org-alphabetical-lists t)
 
 ; Erase all reminders and rebuilt reminders for today from the agenda
 (defun bh/org-agenda-to-appt ()
@@ -712,7 +885,7 @@ Late deadlines first, then scheduled, then non-late deadlines"
 (setq org-log-into-drawer "LOGBOOK")
 
 
-;;(setq org-ditaa-jar-path "~/java/ditaa0_6b.jar")
+(setq org-ditaa-jar-path "~/java/ditaa0_6b.jar")
 (setq org-plantuml-jar-path "/usr/share/plantuml/plantuml.jar")
 
 (add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)
@@ -740,8 +913,7 @@ Late deadlines first, then scheduled, then non-late deadlines"
          (org . t)
          (plantuml . t)
          (latex . t)
-         (makefile . t)
-))
+         (makefile . t)))
 
 ; Do not prompt to confirm evaluation
 ; This may be dangerous - make sure you understand the consequences