expanded iterator statuscodes and added inert project code

This commit is contained in:
ndwarshuis 2019-01-28 14:46:40 -08:00
parent 70b81d751b
commit 0a3b9d9d47
1 changed files with 89 additions and 31 deletions

120
conf.org
View File

@ -2165,7 +2165,7 @@ These are functions and variables exclusively for agenda block manipulation with
(defconst nd/inert-delay-days 90 (defconst nd/inert-delay-days 90
"The number of days to wait before tasks are considered inert.") "The number of days to wait before tasks are considered inert.")
(defconst nd/iter-statuscodes '(:uninit :empty :active) (defconst nd/iter-statuscodes '(:uninit :unscheduled :empty :project-error :active)
"Iterators can have these statuscodes.") "Iterators can have these statuscodes.")
(defconst nd/peri-future-time nd/iter-future-time (defconst nd/peri-future-time nd/iter-future-time
@ -2421,7 +2421,8 @@ Projects are tested according to their statuscodes, which in turn are a function
"Compare position of statuscodes SC1 and SC2 in SC-LIST using operator OP." "Compare position of statuscodes SC1 and SC2 in SC-LIST using operator OP."
`(,op (position ,sc1 ,sc-list) (position ,sc2 ,sc-list))) `(,op (position ,sc1 ,sc-list) (position ,sc2 ,sc-list)))
(defun nd/descend-into-project (allowed-statuscodes trans-tbl get-task-status) (defun nd/descend-into-project
(allowed-statuscodes trans-tbl get-task-status callback-fun)
"Loop through (sub)project and return overall statuscode. "Loop through (sub)project and return overall statuscode.
The returned statuscode is chosen from list ALLOWED-STATUSCODES where The returned statuscode is chosen from list ALLOWED-STATUSCODES where
@ -2441,7 +2442,7 @@ obtain a statuscode-equivalent of the status of the tasks."
;; when this is encountered the loop is broken because we are done ;; when this is encountered the loop is broken because we are done
;; (the last entry trumps all others) ;; (the last entry trumps all others)
(let ((project-status (first allowed-statuscodes)) (let ((project-status (first allowed-statuscodes))
(breaker-status (car (last allowed-statuscodes))) (breaker-status (-last-item allowed-statuscodes))
(previous-point)) (previous-point))
(save-excursion (save-excursion
(setq previous-point (point)) (setq previous-point (point))
@ -2454,7 +2455,7 @@ obtain a statuscode-equivalent of the status of the tasks."
(let ((new-status (let ((new-status
;; if project then descend recursively ;; if project then descend recursively
(if (nd/heading-has-children 'nd/is-todoitem-p) (if (nd/heading-has-children 'nd/is-todoitem-p)
(let ((n (nd/get-project-status))) (let ((n (funcall callback-fun)))
;; if project returns an allowed status ;; if project returns an allowed status
;; then use that ;; then use that
(or (and (member n allowed-statuscodes) n) (or (and (member n allowed-statuscodes) n)
@ -2485,7 +2486,8 @@ obtain a statuscode-equivalent of the status of the tasks."
((nd/is-scheduled-heading-p) :scheduled-project) ((nd/is-scheduled-heading-p) :scheduled-project)
;; held projects do not care what is underneath them ;; held projects do not care what is underneath them
((equal keyword "HOLD") :held) ;; only need to test if they are inert
((equal keyword "HOLD") (if (nd/is-inert-p) :inert :held))
;; projects with invalid todostates are nonsense ;; projects with invalid todostates are nonsense
((member keyword nd/project-invalid-todostates) ((member keyword nd/project-invalid-todostates)
@ -2501,6 +2503,7 @@ obtain a statuscode-equivalent of the status of the tasks."
(nd/descend-into-project (nd/descend-into-project
'(:archivable :complete) '(:archivable :complete)
'((:stuck . 1) '((:stuck . 1)
(:inert . 1)
(:held . 1) (:held . 1)
(:waiting . 1) (:waiting . 1)
(:active . 1) (:active . 1)
@ -2510,13 +2513,15 @@ obtain a statuscode-equivalent of the status of the tasks."
(:done-incomplete . 1)) (:done-incomplete . 1))
(lambda (k) (lambda (k)
(if (and (member k org-done-keywords) (if (and (member k org-done-keywords)
(nd/is-archivable-heading-p)) 0 1)))) (nd/is-archivable-heading-p)) 0 1))
#'nd/get-project-status))
;; done projects are like canceled projects but can also be incomplete ;; done projects are like canceled projects but can also be incomplete
((equal keyword "DONE") ((equal keyword "DONE")
(nd/descend-into-project (nd/descend-into-project
'(:archivable :complete :done-incomplete) '(:archivable :complete :done-incomplete)
'((:stuck . 2) '((:stuck . 2)
(:inert . 2)
(:held . 2) (:held . 2)
(:waiting . 2) (:waiting . 2)
(:active . 2) (:active . 2)
@ -2526,55 +2531,104 @@ obtain a statuscode-equivalent of the status of the tasks."
(lambda (k) (lambda (k)
(if (member k org-done-keywords) (if (member k org-done-keywords)
(if (nd/is-archivable-heading-p) 0 1) (if (nd/is-archivable-heading-p) 0 1)
2)))) 2))
#'nd/get-project-status))
;; project with TODO states could be basically any status ;; project with TODO states could be basically any status
((equal keyword "TODO") ((equal keyword "TODO")
(nd/descend-into-project (nd/descend-into-project
'(:undone-complete :stuck :held :waiting :active) '(:undone-complete :stuck :held :waiting :active :inert)
'((:complete . 0) '((:complete . 0)
(:archivable . 0) (:archivable . 0)
(:scheduled-project . 1) (:scheduled-project . 1)
(:invalid-todostate . 1) (:invalid-todostate . 1)
(:done-incomplete . 1)) (:done-incomplete . 1))
(lambda (k) (lambda (k)
(cond ((equal k "TODO") (if (nd/is-scheduled-heading-p) 4 1)) (cond ((nd/is-inert-p) 5)
((equal k "TODO") (if (nd/is-scheduled-heading-p) 4 1))
((equal k "HOLD") 2) ((equal k "HOLD") 2)
((equal k "WAIT") 3) ((equal k "WAIT") 3)
((equal k "NEXT") 4) ((equal k "NEXT") 4)
(t 0))))) (t 0)))
#'nd/get-project-status))
(t (error (concat "invalid keyword detected: " keyword)))))) (t (error (concat "invalid keyword detected: " keyword))))))
#+END_SRC #+END_SRC
****** repeater testing ****** repeater testing
Iterators and periodicals are tested similarly to projects in that they have statuscodes. Iterators and periodicals are tested similarly to projects in that they have statuscodes.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun nd/get-iterator-project-status (kw)
(cond
((or (nd/is-scheduled-heading-p)
(member kw nd/project-invalid-todostates) :project-error))
;; canceled tasks add nothing
((equal kw "CANC") :empty)
;;
;; these require descending into the project subtasks
;;
;; done projects either add nothing (empty) or are not actually
;; done (project error)
((equal kw "DONE")
(nd/descend-into-project
'(:empty :project-error)
'((:unscheduled . 1)
(:active . 1))
(lambda (k)
(if (member k org-done-keywords) 0 1))
#'nd/get-iterator-project-status))
;; project with TODO states could be basically any status
((equal kw "TODO")
(nd/descend-into-project
'(:unscheduled :empty :active)
'(:project-error . 0)
(lambda (k)
(let ((ts (nd/is-scheduled-heading-p)))
(cond
((not ts) 1)
((< nd/iter-future-time (- ts (float-time))) 2)
(t 0))))
#'nd/get-iterator-project-status))
(t (error (concat "invalid keyword detected: " kw)))))
(defun nd/get-iterator-status () (defun nd/get-iterator-status ()
"Get the status of an iterator where allowed statuscodes are in list "Get the status of an iterator where allowed statuscodes are in list
`nd/get-iter-statuscodes.' where latter codes in the list trump `nd/get-iter-statuscodes.' where latter codes in the list trump
earlier ones." earlier ones."
(let ((iter-status (first nd/iter-statuscodes)) (let ((cur-status (first nd/iter-statuscodes))
(subtree-end (save-excursion (org-end-of-subtree t)))) (breaker-status (-last-item nd/iter-statuscodes))
(subtree-end (save-excursion (org-end-of-subtree t)))
(prev-point (point)))
(save-excursion (save-excursion
(setq previous-point (point))
(outline-next-heading) (outline-next-heading)
(while (and (not (eq iter-status :active)) (while (and (not (eq cur-status breaker-status))
(< (point) subtree-end)) (< prev-point (point) subtree-end))
(let ((keyword (nd/is-atomic-task-p)) (let ((kw (nd/is-todoitem-p))
(new-status)) (new-status))
(if keyword (when kw
(progn ;; test if project of atomic task
(setq new-status (if (nd/heading-compare-timestamp ;; assume that there are no todoitems above this headline
(lambda () ;; to make checking easier
(or (nd/is-scheduled-heading-p) (setq
(nd/is-deadlined-heading-p))) new-status
nd/iter-future-time t) (if (nd/heading-has-children 'nd/is-todoitem-p)
:active (nd/get-iterator-project-status kw)
:empty)) (let ((ts (or (nd/is-scheduled-heading-p)
(if (nd/compare-statuscodes > new-status iter-status nd/iter-statuscodes) (nd/is-deadlined-heading-p))))
(setq iter-status new-status))))) (cond
(outline-next-heading))) ((member kw org-done-keywords) :empty)
iter-status)) ((not ts) :unscheduled)
((< nd/iter-future-time (- ts (float-time))) :active)
(t :empty)))))
(when (nd/compare-statuscodes > new-status cur-status nd/iter-statuscodes)
(setq cur-status new-status))))
(setq prev-point (point))
(org-forward-heading-same-level 1 t)))
cur-status))
(defun nd/get-periodical-status () (defun nd/get-periodical-status ()
"Get the status of a periodical where allowed statuscodes are in list "Get the status of a periodical where allowed statuscodes are in list
@ -3009,7 +3063,11 @@ These agenda commands are the center of the gtd workflow. Some are slower than d
("t" ("t"
"Task View" "Task View"
(,(nd/agenda-base-task-cmd* (,(nd/agenda-base-task-cmd*
act-no-rep-match ;; TODO, this can be better optimized if this view is split,
;; right now need to include DONE because may have
;; done-unclosed
(concat actionable "-" periodical "-" habit "-" iterator)
;; act-no-rep-match
"Tasks" "Tasks"
''nd/skip-non-tasks ''nd/skip-non-tasks
''(:undone-closed :done-unclosed :active :inert) ''(:undone-closed :done-unclosed :active :inert)
@ -3022,7 +3080,7 @@ These agenda commands are the center of the gtd workflow. Some are slower than d
'(concat (and nd/agenda-limit-project-toplevel "Toplevel ") "Projects") '(concat (and nd/agenda-limit-project-toplevel "Toplevel ") "Projects")
''nd/skip-non-projects ''nd/skip-non-projects
''(:scheduled-project :invalid-todostate :undone-complete :done-incomplete ''(:scheduled-project :invalid-todostate :undone-complete :done-incomplete
:stuck :waiting :held :active) :stuck :waiting :held :active :inert)
''nd/get-project-status t t))) ''nd/get-project-status t t)))
("i" ("i"