org-clock-override.el (1799B)
1 ;; -*- lexical-binding: t; -*- 2 3 (defun za/org-clock-resolve-clock 4 (clock resolve-to clock-out-time close restart fail-quietly) 5 "Resolve CLOCK given the time RESOLVE-TO, and the present. 6 CLOCK is a cons cell of the form (MARKER START-TIME)." 7 (let ((org-clock-resolving-clocks t) 8 ;; If the clocked entry contained only a clock and possibly 9 ;; the associated drawer, and we either cancel it or clock it 10 ;; out, `org-clock-out-remove-zero-time-clocks' may clear all 11 ;; contents, and leave point on the /next/ headline. We store 12 ;; the current entry location to be able to get back here when 13 ;; we need to clock in again the previously clocked task. 14 (heading (org-with-point-at (car clock) 15 (org-back-to-heading t) 16 (point-marker)))) 17 (pcase resolve-to 18 (`nil 19 (org-clock-clock-cancel clock) 20 (when (and restart (not org-clock-clocking-in)) 21 (org-with-point-at heading (org-clock-in)))) 22 (`now 23 (cond 24 (restart (error "RESTART is not valid here")) 25 ((or close org-clock-clocking-in) 26 (org-clock-clock-out clock fail-quietly)) 27 ((org-is-active-clock clock) nil) 28 (t (org-clock-clock-in clock t)))) 29 ((pred (time-less-p nil)) 30 (error "RESOLVE-TO must refer to a time in the past")) 31 (_ 32 (when restart (error "RESTART is not valid here")) 33 ;; I switched the or condition here because i want G to work the way I want 34 (org-clock-clock-out clock fail-quietly (or resolve-to clock-out-time)) 35 (cond 36 (org-clock-clocking-in nil) 37 (close 38 (setq org-clock-leftover-time (and (null clock-out-time) resolve-to))) 39 (t 40 (org-with-point-at heading 41 (org-clock-in nil (and clock-out-time resolve-to))))))))) 42 43 (advice-add 'org-clock-resolve-clock :override #'za/org-clock-resolve-clock) 44 45 (provide 'org-clock-override)