|
@@ -325,6 +325,12 @@ play with them."
|
|
|
:version "24.1"
|
|
|
:type 'boolean)
|
|
|
|
|
|
+(defcustom org-clock-continuously nil
|
|
|
+ "Non-nil means to start clocking from the last clock-out time, if any."
|
|
|
+ :type 'boolean
|
|
|
+ :version "24.1"
|
|
|
+ :group 'org-clock)
|
|
|
+
|
|
|
(defcustom org-clock-total-time-cell-format "*%s*"
|
|
|
"Format string for the total time cells."
|
|
|
:group 'org-clock
|
|
@@ -1054,7 +1060,10 @@ recently clocked tasks to
|
|
|
clock into. When SELECT is \\[universal-argument] \\[universal-argument], \
|
|
|
clock into the current task and mark
|
|
|
it as the default task, a special task that will always be offered in
|
|
|
-the clocking selection, associated with the letter `d'."
|
|
|
+the clocking selection, associated with the letter `d'.
|
|
|
+When SELECT is \\[universal-argument] \\[universal-argument] \\[universal-argument], \
|
|
|
+clock in by using the last clock-out time as the start time
|
|
|
+\(see `org-clock-continuously' to make this the default behavior.)"
|
|
|
(interactive "P")
|
|
|
(setq org-clock-notification-was-shown nil)
|
|
|
(catch 'abort
|
|
@@ -1073,6 +1082,11 @@ the clocking selection, associated with the letter `d'."
|
|
|
(let ((org-clock-clocking-in t))
|
|
|
(org-resolve-clocks))) ; check if any clocks are dangling
|
|
|
|
|
|
+ (when (equal select '(64))
|
|
|
+ ;; Set start-time to `org-clock-out-time'
|
|
|
+ (let ((org-clock-continuously t))
|
|
|
+ (org-clock-in nil org-clock-out-time)))
|
|
|
+
|
|
|
(when (equal select '(4))
|
|
|
(setq selected-task (org-clock-select-task "Clock-in on task: "))
|
|
|
(if selected-task
|
|
@@ -1191,7 +1205,8 @@ the clocking selection, associated with the letter `d'."
|
|
|
(setq org-clock-total-time (org-clock-sum-current-item
|
|
|
(org-clock-get-sum-start)))
|
|
|
(setq org-clock-start-time
|
|
|
- (or (and leftover
|
|
|
+ (or (and org-clock-continuously org-clock-out-time)
|
|
|
+ (and leftover
|
|
|
(y-or-n-p
|
|
|
(format
|
|
|
"You stopped another clock %d mins ago; start this one from then? "
|
|
@@ -1238,13 +1253,20 @@ the clocking selection, associated with the letter `d'."
|
|
|
;;;###autoload
|
|
|
(defun org-clock-in-last (&optional arg)
|
|
|
"Clock in the last closed clocked item.
|
|
|
-When already clocking in, send an warning."
|
|
|
+When already clocking in, send an warning.
|
|
|
+With a universal prefix argument, select the task you want to
|
|
|
+clock in from the last clocked in tasks.
|
|
|
+With two universal prefix arguments, start clocking using the
|
|
|
+last clock-out time, if any."
|
|
|
(interactive "P")
|
|
|
- (if arg (org-clock-select-task)
|
|
|
- (org-clock-clock-in (cons (car org-clock-history) (current-time)))
|
|
|
- (message "Now clocking in: %s (in %s)"
|
|
|
- org-clock-current-task
|
|
|
- (buffer-name (marker-buffer org-clock-marker)))))
|
|
|
+ (if (equal arg '(4)) (org-clock-in (org-clock-select-task))
|
|
|
+ (let ((start-time (if (or org-clock-continuously (equal arg '(16)))
|
|
|
+ (or org-clock-out-time (current-time))
|
|
|
+ (current-time))))
|
|
|
+ (org-clock-clock-in (list (car org-clock-history)) nil start-time)
|
|
|
+ (message "Now clocking in: %s (in %s)"
|
|
|
+ org-clock-current-task
|
|
|
+ (buffer-name (marker-buffer org-clock-marker))))))
|
|
|
|
|
|
(defun org-clock-mark-default-task ()
|
|
|
"Mark current task as default task."
|
|
@@ -1377,9 +1399,10 @@ line and position cursor in that line."
|
|
|
(and (re-search-forward org-property-end-re nil t)
|
|
|
(goto-char (match-beginning 0))))))))
|
|
|
|
|
|
+(defvar org-clock-out-time nil) ; store the time of the last clock-out
|
|
|
(defun org-clock-out (&optional fail-quietly at-time)
|
|
|
"Stop the currently running clock.
|
|
|
-If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
|
|
|
+Throw an error if there is no running clock and FAIL-QUIETLY is nil."
|
|
|
(interactive)
|
|
|
(catch 'exit
|
|
|
(when (not (org-clocking-p))
|
|
@@ -1388,7 +1411,8 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
|
|
|
(setq frame-title-format org-frame-title-format-backup)
|
|
|
(force-mode-line-update)
|
|
|
(if fail-quietly (throw 'exit t) (error "No active clock")))
|
|
|
- (let (ts te s h m remove)
|
|
|
+ (let ((now (current-time)) ts te s h m remove)
|
|
|
+ (setq org-clock-out-time now)
|
|
|
(save-excursion ; Do not replace this with `with-current-buffer'.
|
|
|
(org-no-warnings (set-buffer (org-clocking-buffer)))
|
|
|
(save-restriction
|
|
@@ -1402,8 +1426,7 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
|
|
|
(goto-char (match-end 0))
|
|
|
(delete-region (point) (point-at-eol))
|
|
|
(insert "--")
|
|
|
- (setq te (org-insert-time-stamp (or at-time (current-time))
|
|
|
- 'with-hm 'inactive))
|
|
|
+ (setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
|
|
|
(setq s (- (org-float-time (apply 'encode-time (org-parse-time-string te)))
|
|
|
(org-float-time (apply 'encode-time (org-parse-time-string ts))))
|
|
|
h (floor (/ s 3600))
|
|
@@ -1465,7 +1488,8 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
|
|
|
(when clock-drawer
|
|
|
(save-excursion
|
|
|
(org-back-to-heading t)
|
|
|
- (while (search-forward clock-drawer end t)
|
|
|
+ (while (and (< (point) end)
|
|
|
+ (search-forward clock-drawer end t))
|
|
|
(goto-char (match-beginning 0))
|
|
|
(org-remove-empty-drawer-at clock-drawer (point))
|
|
|
(forward-line 1))))))
|
|
@@ -1536,9 +1560,12 @@ UPDOWN tells whether to change 'up or 'down."
|
|
|
(save-excursion ; Do not replace this with `with-current-buffer'.
|
|
|
(org-no-warnings (set-buffer (org-clocking-buffer)))
|
|
|
(goto-char org-clock-marker)
|
|
|
- (delete-region (1- (point-at-bol)) (point-at-eol))
|
|
|
- ;; Just in case, remove any empty LOGBOOK left over
|
|
|
- (org-remove-empty-drawer-at "LOGBOOK" (point)))
|
|
|
+ (if (save-excursion (move-beginning-of-line 1)
|
|
|
+ (looking-at (concat "^[ \t]*" org-clock-string)))
|
|
|
+ (progn (delete-region (1- (point-at-bol)) (point-at-eol))
|
|
|
+ (org-remove-empty-drawer-at "LOGBOOK" (point)))
|
|
|
+ (message "Clock gone, cancel the timer anyway")
|
|
|
+ (sit-for 2)))
|
|
|
(move-marker org-clock-marker nil)
|
|
|
(move-marker org-clock-hd-marker nil)
|
|
|
(setq global-mode-string
|