dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

org-clock-override.el (1767B)


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