summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2021-06-27 16:13:46 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2021-06-27 16:21:08 +0200
commit8e3e2f667f0b28b85845204b708c3f0aebc9152b (patch)
treefe31fcf2da7583eaf6559fb9ad59613406b36b98
parente2550506ebfec0c1a7892dfa5ef948435be1c7f4 (diff)
downloadorg-mode-8e3e2f667f0b28b85845204b708c3f0aebc9152b.tar.gz
clock: Prevent "before first headline" error on clock-out note
* lisp/org-clock.el (org-clock-out): Possibly create a note at the very end of the process, when there's no need for point to be on the correct headline. Also call `org-clock-remove-empty-clock-drawer' unconditionally instead of putting it in `org-clock-out-hook'. Reported-by: Dave Dai <wenlong.dai@gmail.com> <https://yhetil.org/orgmode/87pmwaang6.fsf@HUE.i-did-not-set--mail-host-address--so-tickle-me/ยป
-rw-r--r--lisp/org-clock.el31
1 files changed, 15 insertions, 16 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 5480a37..cd930e8 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1676,17 +1676,13 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(insert " => " (format "%2d:%02d" h m))
(move-marker org-clock-marker nil)
(move-marker org-clock-hd-marker nil)
- ;; Possibly remove zero time clocks. However, do not add
- ;; a note associated to the CLOCK line in this case.
- (cond ((and org-clock-out-remove-zero-time-clocks
- (= 0 h m))
- (setq remove t)
- (delete-region (line-beginning-position)
- (line-beginning-position 2)))
- (org-log-note-clock-out
- (org-add-log-setup
- 'clock-out nil nil nil
- (concat "# Task: " (org-get-heading t) "\n\n"))))
+ ;; Possibly remove zero time clocks.
+ (when (and org-clock-out-remove-zero-time-clocks
+ (= 0 h m))
+ (setq remove t)
+ (delete-region (line-beginning-position)
+ (line-beginning-position 2)))
+ (org-clock-remove-empty-clock-drawer)
(when org-clock-mode-line-timer
(cancel-timer org-clock-mode-line-timer)
(setq org-clock-mode-line-timer nil))
@@ -1717,11 +1713,14 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
"Clock stopped at %s after %s => LINE REMOVED"
"Clock stopped at %s after %s")
te (org-duration-from-minutes (+ (* 60 h) m)))
- (run-hooks 'org-clock-out-hook)
- (unless (org-clocking-p)
- (setq org-clock-current-task nil)))))))
-
-(add-hook 'org-clock-out-hook #'org-clock-remove-empty-clock-drawer)
+ (unless (org-clocking-p)
+ (setq org-clock-current-task nil))
+ (run-hooks 'org-clock-out-hook)
+ ;; Add a note, but only if we didn't remove the clock line.
+ (when (and org-log-note-clock-out (not remove))
+ (org-add-log-setup
+ 'clock-out nil nil nil
+ (concat "# Task: " (org-get-heading t) "\n\n"))))))))
(defun org-clock-remove-empty-clock-drawer ()
"Remove empty clock drawers in current subtree."