emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] capture: Fix handling of time range for :time-prompt


From: Kyle Meyer
Subject: [PATCH] capture: Fix handling of time range for :time-prompt
Date: Mon, 18 Jan 2021 21:25:27 -0500

Kyle Meyer writes:

> I'm okay with the minimal fix to the regexp, though I wonder if we can
> avoid the follow-up call to org-read-date-analyze entirely.  I'm running
> out of time to test thoroughly tonight, but perhaps something like this
> (ignoring the potential cond->if cleanup):

Testing that against the cases in your initial report, I believe it
leads to the same results as your patch, so here's a cleaned-up version.

-- >8 --
Subject: [PATCH] capture: Fix handling of time range for :time-prompt

* lisp/org-capture.el (org-capture-set-target-location): Bind
org-end-time-was-given around the org-read-date call to get a return
value that uses the start time rather than doing custom adjustment of
the return value.

If org-capture-set-target-location detects that the answer to
org-read-date has a time range, it strips the end time from the answer
and calls org-read-date-analyze again.  (org-read-date already calls
it underneath.)  The regexp it uses, however, can easily match a date,
leading to a bogus result.

org-read-date-analyze is already capable of processing the time range
in a way that matches org-capture-set-target-location's intent: when
org-end-time-was-given is bound, org-read-date-analyze splits off the
end value of the range and stores it in org-end-time-was-given.  Drop
the custom logic and let org-read-date-analyze handle the range.

Reported-by: Richard Lawrence <richard.lawrence@berkeley.edu>
Ref: https://orgmode.org/list/87h7obh4ct.fsf@aquinas
---
 lisp/org-capture.el | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index f40f2b335..d7b69f228 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1025,28 +1025,23 @@ (defun org-capture-set-target-location (&optional 
target)
               (time-to-days org-overriding-default-time))
              ((or (org-capture-get :time-prompt)
                   (equal current-prefix-arg 1))
-              ;; Prompt for date.
-              (let ((prompt-time (org-read-date
-                                  nil t nil "Date for tree entry:")))
+               ;; Prompt for date.  Bind `org-end-time-was-given' so
+               ;; that `org-read-date-analyze' handles the time range
+               ;; case and returns `prompt-time' with the start value.
+               (let* ((org-time-was-given nil)
+                      (org-end-time-was-given nil)
+                      (prompt-time (org-read-date
+                                   nil t nil "Date for tree entry:")))
                 (org-capture-put
                  :default-time
-                 (cond ((and (or (not (boundp 'org-time-was-given))
-                                 (not org-time-was-given))
-                             (not (= (time-to-days prompt-time) (org-today))))
-                        ;; Use 00:00 when no time is given for another
-                        ;; date than today?
-                        (apply #'encode-time 0 0
-                               org-extend-today-until
-                               (cl-cdddr (decode-time prompt-time))))
-                       ((string-match "\\([^ ]+\\)-[^ ]+[ ]+\\(.*\\)"
-                                      org-read-date-final-answer)
-                        ;; Replace any time range by its start.
-                        (apply #'encode-time
-                               (org-read-date-analyze
-                                (replace-match "\\1 \\2" nil nil
-                                               org-read-date-final-answer)
-                                prompt-time (decode-time prompt-time))))
-                       (t prompt-time)))
+                  (if (and (or (not org-time-was-given))
+                           (not (= (time-to-days prompt-time) (org-today))))
+                      ;; Use 00:00 when no time is given for another
+                      ;; date than today?
+                      (apply #'encode-time 0 0
+                             org-extend-today-until
+                             (cl-cdddr (decode-time prompt-time)))
+                    prompt-time))
                 (time-to-days prompt-time)))
              (t
               ;; Current date, possibly corrected for late night

base-commit: 9e8215f4a5df7d03ac787da78d28f69a4c18e7d3
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]