summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-12-06 00:25:45 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-12-06 00:25:45 +0100
commitb423a6187a1ece2977846245a4c25808a9d443c6 (patch)
tree1facdad24cae0660eabcaf08db52cdb453cb6bb8
parent6f8347a834cdd3c4b514e1482e424f33c01606c0 (diff)
parent503ede74bc0a1db59fd2fb7bac0bf1ba7352d15b (diff)
downloadorg-mode-b423a6187a1ece2977846245a4c25808a9d443c6.tar.gz
Merge branch 'master' into next
-rw-r--r--lisp/org-clock.el69
1 files changed, 36 insertions, 33 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 9e4ca89..1ebfa02 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -916,39 +916,42 @@ If necessary, clock-out of the currently active clock."
(defvar org-clock-resolving-clocks nil)
(defvar org-clock-resolving-clocks-due-to-idleness nil)
-(defun org-clock-resolve-clock (clock resolve-to clock-out-time
- &optional close-p restart-p fail-quietly)
- "Resolve `CLOCK' given the time `RESOLVE-TO', and the present.
-`CLOCK' is a cons cell of the form (MARKER START-TIME)."
- (let ((org-clock-resolving-clocks t))
- (cond
- ((null resolve-to)
- (org-clock-clock-cancel clock)
- (if (and restart-p (not org-clock-clocking-in))
- (org-clock-clock-in clock)))
-
- ((eq resolve-to 'now)
- (if restart-p
- (error "RESTART-P is not valid here"))
- (if (or close-p org-clock-clocking-in)
- (org-clock-clock-out clock fail-quietly)
- (unless (org-is-active-clock clock)
- (org-clock-clock-in clock t))))
-
- ((not (time-less-p resolve-to (current-time)))
- (error "RESOLVE-TO must refer to a time in the past"))
-
- (t
- (if restart-p
- (error "RESTART-P is not valid here"))
- (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-resolve-clock
+ (clock resolve-to clock-out-time close restart fail-quietly)
+ "Resolve CLOCK given the time RESOLVE-TO, and the present.
+CLOCK is a cons cell of the form (MARKER START-TIME)."
+ (let ((org-clock-resolving-clocks t)
+ ;; If the clocked entry contained only a clock and possibly
+ ;; 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)
+ (when (and restart (not org-clock-clocking-in))
+ (org-with-point-at heading (org-clock-in))))
+ (`now
+ (cond
+ (restart (error "RESTART is not valid here"))
+ ((or close org-clock-clocking-in)
+ (org-clock-clock-out clock fail-quietly))
+ ((org-is-active-clock clock) nil)
+ (t (org-clock-clock-in clock t))))
+ ((pred (time-less-p (current-time)))
+ (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
+ (org-with-point-at heading
+ (org-clock-in nil (and clock-out-time resolve-to)))))))))
(defun org-clock-jump-to-current-clock (&optional effective-clock)
"When an Org clock is running, jump to it."