From cf2b63e2762145bba19ad8ba76ac6c8dfd82c1b4 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 18 Apr 2021 18:41:43 -0400 Subject: [PATCH] REF rewrite iterator and periodical status functions with while macro --- local/lib/org-x/org-x.el | 60 +++++++++++++++------------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/local/lib/org-x/org-x.el b/local/lib/org-x/org-x.el index 661f922..aebf8d6 100644 --- a/local/lib/org-x/org-x.el +++ b/local/lib/org-x/org-x.el @@ -708,36 +708,28 @@ Allowed statuscodes are in list `nd/get-iter-statuscodes.' where latter codes in the list trump earlier ones." (let ((cur-status (first org-x-iter-statuscodes)) (breaker-status (-last-item org-x-iter-statuscodes)) - (subtree-end (save-excursion (org-end-of-subtree t))) - (prev-point (point)) (kw nil) (new-status nil) (ts nil)) - (save-excursion - (outline-next-heading) - (while (and (not (eq cur-status breaker-status)) - (< prev-point (point) subtree-end)) - (setq kw (org-x-is-todoitem-p) - new-status nil) - (when kw - ;; test if project of atomic task - ;; assume that there are no todoitems above this headline - ;; to make checking easier - (setq - new-status - (if (org-x-headline-has-children 'org-x-is-todoitem-p) - (org-x--clone-get-iterator-project-status kw) - (setq ts (or (org-x-is-scheduled-heading-p) - (org-x-is-deadlined-heading-p))) - (cond - ((member kw org-done-keywords) :empt) - ((not ts) :unscheduled) - ((< org-x-iter-future-time (- ts (float-time))) :actv) - (t :empt)))) - (when (org-x-compare-statuscodes > new-status cur-status org-x-iter-statuscodes) - (setq cur-status new-status))) - (setq prev-point (point)) - (org-forward-heading-same-level 1 t))) + (org-x-while-child-headlines (not (eq cur-status breaker-status)) + (setq kw (org-x-is-todoitem-p)) + (when kw + ;; test if project or atomic task + ;; assume that there are no todoitems above this headline + ;; to make checking easier + (setq + new-status + (if (org-x-headline-has-children 'org-x-is-todoitem-p) + (org-x--clone-get-iterator-project-status kw) + (setq ts (or (org-x-is-scheduled-heading-p) + (org-x-is-deadlined-heading-p))) + (cond + ((member kw org-done-keywords) :empt) + ((not ts) :unscheduled) + ((< org-x-iter-future-time (- ts (float-time))) :actv) + (t :empt)))) + (when (org-x-compare-statuscodes > new-status cur-status org-x-iter-statuscodes) + (setq cur-status new-status)))) cur-status)) ;; periodicals @@ -767,16 +759,9 @@ latter codes in the list trump earlier ones." new cur-status)))) (let ((cur-status (first org-x-peri-statuscodes)) - (breaker-status (-last-item org-x-peri-statuscodes)) - (subtree-end (save-excursion (org-end-of-subtree t))) - (prev-point (point))) - (save-excursion - (outline-next-heading) - (while (and (not (eq cur-status breaker-status)) - (< prev-point (point) subtree-end)) - (setq cur-status (->> (get-ts) (new-status cur-status))) - (setq prev-point (point)) - (org-forward-heading-same-level 1 t))) + (breaker-status (-last-item org-x-peri-statuscodes))) + (org-x-while-child-headlines (not (eq cur-status breaker-status)) + (setq cur-status (->> (get-ts) (new-status cur-status)))) cur-status))) ;; skip functions @@ -922,6 +907,7 @@ N is the number of clones to produce." ;; marking subtrees +;; put this in terms of org-ml (defun org-x-mark-subtree-keyword (new-keyword &optional exclude no-log) "Change the todo keyword of all tasks in a subtree to NEW-KEYWORD. If EXCLUDE is given, it should be a list of todo keywords; any headline