From 027bb89373fadb83ad11fa727641a7a14e1d09e5 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Mon, 19 Aug 2019 13:31:13 -0500 Subject: [PATCH] Fix: (deadline-warning) Handle plain timestamp elements Sometimes org-element-context returns an element like: (planning (:closed (timestamp (:type inactive ...)) :deadline (timestamp (:type active ...)) :scheduled (timestamp (:type active ...)) :begin 93706 ...)) Other times it returns just: (timestamp (:type active ...)) Even with point in the same position, immediately after the deadline timestamp. I don't know why, and it might even be a bug that's been fixed in newer version of Org. Anyway, this handles both. --- org-ql.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/org-ql.el b/org-ql.el index e1fd0a8..3913985 100644 --- a/org-ql.el +++ b/org-ql.el @@ -827,11 +827,15 @@ parseable by `parse-time-string' which may omit the time value." (forward-line 1) (when (re-search-forward org-deadline-time-regexp (line-end-position) t) (-let* ((context (org-element-context)) - ;; Since we need to handle warning periods, we parse the - ;; Org timestamp as an org-element rather than as a string. - ((_planning (_closed _nil _deadline element . _rest)) context) - ((_timestamp (&keys :warning-value :warning-unit)) element) - (ts (ts-parse-org-element element)) + ;; Since we need to handle warning periods, we parse the Org timestamp + ;; as an org-element rather than as a string. Unfortunately, sometimes + ;; `org-element-context' returns a timestamp nested inside a `planning' + ;; element, other times just the timestamp, so we have to handle both. + (deadline-ts-element (pcase context + (`(planning ,tss) (plist-get tss :deadline)) + (`(timestamp . ,_) context))) + ((_timestamp (&keys :warning-value :warning-unit)) deadline-ts-element) + (ts (ts-parse-org-element deadline-ts-element)) (ts (pcase warning-unit ('nil ts) ((and unit (or 'year 'month 'day))