From cc16dd6a8c59312a75b8e25669a7e4eb3d9f9ef4 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Tue, 11 Oct 2022 11:44:26 -0400 Subject: [PATCH 1/2] lisp/org-habit.el: Use time as a history cutoff point * lisp/org-habit.el (org-habit-parse-todo): Use time as a cutoff point instead of using a count. This allows viewing the full history of habits that are completed multiple times a day. Previously we would miss some days and show an incorrect history --- lisp/org-habit.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/org-habit.el b/lisp/org-habit.el index 677b7adb6..fe5f4fe63 100644 --- a/lisp/org-habit.el +++ b/lisp/org-habit.el @@ -212,11 +212,11 @@ This list represents a \"habit\" for the rest of this module." habit-entry scheduled-repeat)) (setq deadline (+ scheduled (- dr-days sr-days)))) (org-back-to-heading t) - (let* ((maxdays (+ org-habit-preceding-days org-habit-following-days)) + (let* ((firstday (- (org-today) org-habit-preceding-days)) (reversed org-log-states-order-reversed) (search (if reversed 're-search-forward 're-search-backward)) (limit (if reversed end (point))) - (count 0) + (done nil) (re (format "^[ \t]*-[ \t]+\\(?:State \"%s\".*%s%s\\)" (regexp-opt org-done-keywords) @@ -235,13 +235,14 @@ This list represents a \"habit\" for the rest of this module." ("%u" . ".*?") ("%U" . ".*?"))))))))) (unless reversed (goto-char end)) - (while (and (< count maxdays) (funcall search re limit t)) + (while (and (not done) (funcall search re limit t)) (push (time-to-days (org-time-string-to-time (or (match-string-no-properties 1) (match-string-no-properties 2)))) closed-dates) - (setq count (1+ count)))) + (when (< (car closed-dates) firstday) + (setq done t)))) (list scheduled sr-days deadline dr-days closed-dates sr-type)))) (defsubst org-habit-scheduled (habit) -- 2.38.0