diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 985488016..19117821a 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -308,6 +308,13 @@ The change is breaking when ~org-use-property-inheritance~ is set to ~t~. The =TEST= parameter is better served by Emacs debugging tools. ** New and changed options +*** New variable ~org-clock-out-removed-last-clock~ + +The variable is intended to be used by ~org-clock-out-hook~. It is a +flag used to signal when the =CLOCK= line has been removed. This can +happen when ~org-clock-out-remove-zero-time-clocks~ is customized to +be non-nil. + *** ~org-info-other-documents~ is now a custom option Users can now extend the value of ~org-info-other-documents~ to diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 44e63bf55..eda312d74 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -515,7 +515,10 @@ to add an effort property.") "Hook run when starting the clock.") (defvar org-clock-out-hook nil "Hook run when stopping the current clock. -The point is at the current clock line when the hook is executed.") +The point is at the current clock line when the hook is executed. + +The hook functions can access `org-clock-out-removed-last-clock' to +check whether the latest CLOCK line has been cleared.") (defvar org-clock-cancel-hook nil "Hook run when canceling the current clock.") @@ -1698,6 +1701,11 @@ and current `frame-title-format' is equal to `org-clock-frame-title-format'." (equal frame-title-format org-clock-frame-title-format)) (setq frame-title-format org-frame-title-format-backup))) +(defvar org-clock-out-removed-last-clock nil + "When non-nil, the last `org-clock-out' removed the clock line. +This can happen when `org-clock-out-remove-zero-time-clocks' is set to +non-nil and the latest clock took 0 minutes.") + ;;;###autoload (defun org-clock-out (&optional switch-to-state fail-quietly at-time) "Stop the currently running clock. @@ -1788,6 +1796,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'." te (org-duration-from-minutes (+ (* 60 h) m))) (unless (org-clocking-p) (setq org-clock-current-task nil)) + (setq org-clock-out-removed-last-clock remove) (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))