From 82231fb4b11b780488c66b4e5f0ee6fcf6643f1d Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Wed, 19 Jun 2024 13:41:50 -0400 Subject: [PATCH] Warn about invalid clock lines --- lisp/org-element.el | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index d6ad9824a..113cd6059 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2312,6 +2312,25 @@ Return a new syntax node of `clock' type containing `:status', (unless (bolp) (skip-chars-forward " \t")) (count-lines before-blank (point)))) (end (point))) + (when (and value ;; Clock lines don't need timestamps + (or + (not + (and (org-element-property :year-start value) + (org-element-property :month-start value) + (org-element-property :day-start value) + (org-element-property :hour-start value) + (org-element-property :minute-start value))) + (and (eq status 'closed) + (not (and (org-element-property :year-end value) + (org-element-property :month-end value) + (org-element-property :day-end value) + (org-element-property :hour-end value) + (org-element-property :minute-end value)))))) + (setq value nil) + (org-element--cache-warn "Invalid clock element at %s:%d: \"%s\"" + (buffer-name) + (line-number-at-pos begin t) + (buffer-substring-no-properties begin end))) (org-element-create 'clock (list :status status @@ -4393,15 +4412,14 @@ Assume point is at the beginning of the timestamp." hour-start (nth 2 date) minute-start (nth 1 date)))) ;; Compute date-end. It can be provided directly in timestamp, - ;; or extracted from time range. Otherwise, it defaults to the - ;; same values as date-start. + ;; or extracted from time range. (unless diaryp (let ((date (and date-end (org-parse-time-string date-end t)))) - (setq year-end (or (nth 5 date) year-start) - month-end (or (nth 4 date) month-start) - day-end (or (nth 3 date) day-start) - hour-end (or (nth 2 date) (car time-range) hour-start) - minute-end (or (nth 1 date) (cdr time-range) minute-start)))) + (setq year-end (or (nth 5 date) (and time-range year-start)) + month-end (or (nth 4 date) (and time-range month-start)) + day-end (or (nth 3 date) (and time-range day-start)) + hour-end (or (nth 2 date) (car time-range)) + minute-end (or (nth 1 date) (cdr time-range))))) ;; Diary timestamp with time. (when (and diaryp (string-match "\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)?" date-start)) -- 2.45.1