org-clock: Fix resolving clocks
* lisp/org-clock.el (org-clock-resolve-clock): Fix resolving clocks when the entry is empty barring the clock itself and possibly the clock drawer, and `org-clock-out-remove-zero-time-clocks' is non-nil.
This commit is contained in:
parent
04641c4bbe
commit
503ede74bc
|
@ -917,39 +917,42 @@ If necessary, clock-out of the currently active clock."
|
||||||
(defvar org-clock-resolving-clocks nil)
|
(defvar org-clock-resolving-clocks nil)
|
||||||
(defvar org-clock-resolving-clocks-due-to-idleness nil)
|
(defvar org-clock-resolving-clocks-due-to-idleness nil)
|
||||||
|
|
||||||
(defun org-clock-resolve-clock (clock resolve-to clock-out-time
|
(defun org-clock-resolve-clock
|
||||||
&optional close-p restart-p fail-quietly)
|
(clock resolve-to clock-out-time close restart fail-quietly)
|
||||||
"Resolve `CLOCK' given the time `RESOLVE-TO', and the present.
|
"Resolve CLOCK given the time RESOLVE-TO, and the present.
|
||||||
`CLOCK' is a cons cell of the form (MARKER START-TIME)."
|
CLOCK is a cons cell of the form (MARKER START-TIME)."
|
||||||
(let ((org-clock-resolving-clocks t))
|
(let ((org-clock-resolving-clocks t)
|
||||||
(cond
|
;; If the clocked entry contained only a clock and possibly
|
||||||
((null resolve-to)
|
;; the associated drawer, and we either cancel it or clock it
|
||||||
|
;; out, `org-clock-out-remove-zero-time-clocks' may clear all
|
||||||
|
;; contents, and leave point on the /next/ headline. We store
|
||||||
|
;; the current entry location to be able to get back here when
|
||||||
|
;; we need to clock in again the previously clocked task.
|
||||||
|
(heading (org-with-point-at (car clock) (org-back-to-heading t))))
|
||||||
|
(pcase resolve-to
|
||||||
|
(`nil
|
||||||
(org-clock-clock-cancel clock)
|
(org-clock-clock-cancel clock)
|
||||||
(if (and restart-p (not org-clock-clocking-in))
|
(when (and restart (not org-clock-clocking-in))
|
||||||
(org-clock-clock-in clock)))
|
(org-with-point-at heading (org-clock-in))))
|
||||||
|
(`now
|
||||||
((eq resolve-to 'now)
|
(cond
|
||||||
(if restart-p
|
(restart (error "RESTART is not valid here"))
|
||||||
(error "RESTART-P is not valid here"))
|
((or close org-clock-clocking-in)
|
||||||
(if (or close-p org-clock-clocking-in)
|
(org-clock-clock-out clock fail-quietly))
|
||||||
(org-clock-clock-out clock fail-quietly)
|
((org-is-active-clock clock) nil)
|
||||||
(unless (org-is-active-clock clock)
|
(t (org-clock-clock-in clock t))))
|
||||||
(org-clock-clock-in clock t))))
|
((pred (time-less-p (current-time)))
|
||||||
|
|
||||||
((not (time-less-p resolve-to (current-time)))
|
|
||||||
(error "RESOLVE-TO must refer to a time in the past"))
|
(error "RESOLVE-TO must refer to a time in the past"))
|
||||||
|
(_
|
||||||
|
(when restart (error "RESTART is not valid here"))
|
||||||
|
(org-clock-clock-out clock fail-quietly (or clock-out-time resolve-to))
|
||||||
|
(cond
|
||||||
|
(org-clock-clocking-in nil)
|
||||||
|
(close
|
||||||
|
(setq org-clock-leftover-time (and (null clock-out-time) resolve-to)))
|
||||||
(t
|
(t
|
||||||
(if restart-p
|
(org-with-point-at heading
|
||||||
(error "RESTART-P is not valid here"))
|
(org-clock-in nil (and clock-out-time resolve-to)))))))))
|
||||||
(org-clock-clock-out clock fail-quietly (or clock-out-time
|
|
||||||
resolve-to))
|
|
||||||
(unless org-clock-clocking-in
|
|
||||||
(if close-p
|
|
||||||
(setq org-clock-leftover-time (and (null clock-out-time)
|
|
||||||
resolve-to))
|
|
||||||
(org-clock-clock-in clock nil (and clock-out-time
|
|
||||||
resolve-to))))))))
|
|
||||||
|
|
||||||
(defun org-clock-jump-to-current-clock (&optional effective-clock)
|
(defun org-clock-jump-to-current-clock (&optional effective-clock)
|
||||||
"When an Org clock is running, jump to it."
|
"When an Org clock is running, jump to it."
|
||||||
|
|
Loading…
Reference in New Issue