From 08e595f312d1400371b846ff3676c0e13df7e1b7 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 25 Nov 2021 18:15:22 +0800 Subject: [PATCH] org-agenda-get-scheduled: Fix wrong matches when WITH-HOUR is non-nil * lisp/org-agenda.el (org-agenda-get-scheduled): Do not rely on regex match to judge that current headline is scheduled with time when WITH-HOUR argument is non-nil. Limit regexp search when looking for scheduled timestamp in current headline and intentionally signal search error if something went wrong (headline without scheduled timestamp in planning line must not be encountered at this point in the code). This commit continues 77a9932b0 and 82197761. --- lisp/org-agenda.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 2a73816ca..dfab7b700 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -6398,7 +6398,14 @@ scheduled items with an hour specification like [h]h:mm." (if (org-element--cache-active-p) (org-element-cache-map (lambda (el) - (when (org-element-property :scheduled el) + (when (and (org-element-property :scheduled el) + (or (not with-hour) + (org-element-property + :hour-start + (org-element-property :scheduled el)) + (org-element-property + :hour-end + (org-element-property :scheduled el)))) (goto-char (org-element-property :contents-begin el)) (catch :skip (org-agenda-skip el) @@ -6408,7 +6415,12 @@ scheduled items with an hour specification like [h]h:mm." 1 -1)) (pos (save-excursion (goto-char (org-element-property :contents-begin el)) - (re-search-forward regexp nil t) + ;; We intentionally leave NOERROR + ;; argument in `re-search-forward' nil. If + ;; the search fails here, something went + ;; wrong and we are looking at + ;; non-matching headline. + (re-search-forward regexp (line-end-position)) (1- (match-beginning 1)))) (todo-state (org-element-property :todo-keyword el)) (donep (eq 'done (org-element-property :todo-type el)))