Browse Source

New option `org-clock-auto-clockout-timer'

* etc/ORG-NEWS (New option ~org-clock-auto-clockout-timer~):
Mention the new option `org-clock-auto-clockout-timer'.

* doc/org-manual.org (Clocking out automatically after some
idle time): Document `org-clock-auto-clockout-timer'.

* lisp/org.el (org-clock-auto-clockout-insinuate): New
function to add a hook for auto-clocking out the current tasks
after `org-clock-auto-clockout-timer' seconds.

* lisp/org-clock.el (org-clock-auto-clockout-timer): New option.
(org-clock-auto-clockout): New function, use the new option.
Bastien 5 years ago
parent
commit
88794cab06
4 changed files with 56 additions and 0 deletions
  1. 15 0
      doc/org-manual.org
  2. 9 0
      etc/ORG-NEWS
  3. 24 0
      lisp/org-clock.el
  4. 8 0
      lisp/org.el

+ 15 - 0
doc/org-manual.org

@@ -6886,6 +6886,21 @@ If you only want this from time to time, use three universal prefix
 arguments with ~org-clock-in~ and two {{{kbd(C-u C-u)}}} with
 arguments with ~org-clock-in~ and two {{{kbd(C-u C-u)}}} with
 ~org-clock-in-last~.
 ~org-clock-in-last~.
 
 
+**** Clocking out automatically after some idle time
+:PROPERTIES:
+:UNNUMBERED: notoc
+:END:
+#+cindex: auto clocking out after idle time
+
+#+vindex: org-clock-auto-clockout-timer
+When you often forget to clock out before being idle and you don't
+want to manually set the clocking time to take into account, you can
+set ~org-clock-auto-clockout-timer~ to a number of seconds and add
+=(org-clock-auto-clockout-insinuate)= to your =.emacs= file.
+
+When the clock is running and Emacs is idle for more than this number
+of seconds, the clock will be clocked out automatically.
+
 ** Effort Estimates
 ** Effort Estimates
 :PROPERTIES:
 :PROPERTIES:
 :DESCRIPTION: Planning work effort in advance.
 :DESCRIPTION: Planning work effort in advance.

+ 9 - 0
etc/ORG-NEWS

@@ -79,6 +79,15 @@ Babel Java blocks recognize header argument =:cmdargs= and pass its
 value in call to =java=.
 value in call to =java=.
 
 
 ** New options
 ** New options
+*** New option ~org-clock-auto-clockout-timer~
+
+When this option is set to a number and the user configuration
+contains =(org-clock-auto-clockout-insinuate)=, Org will clock out the
+currently clocked in task after that number of seconds of idle time.
+
+This is useful when you often forget to clock out before being idle
+and don't want to have to manually set the clocking time to take into
+account.
 
 
 *** New option ~org-table-header-line-p~
 *** New option ~org-table-header-line-p~
 
 

+ 24 - 0
lisp/org-clock.el

@@ -468,6 +468,19 @@ Valid values are: `today', `yesterday', `thisweek', `lastweek',
 		 (const :tag "Select range interactively" interactive))
 		 (const :tag "Select range interactively" interactive))
   :safe #'symbolp)
   :safe #'symbolp)
 
 
+(defcustom org-clock-auto-clockout-timer nil
+  "Timer for auto clocking out when Emacs is idle.
+When set to a number, auto clock out the currently clocked in
+task after this number of seconds of idle time.
+
+This is only effective when `org-clock-auto-clockout-insinuate'
+is added to the user configuration."
+  :group 'org-clock
+  :package-version '(Org . "9.4")
+  :type '(choice
+	  (integer :tag "Clock out after Emacs is idle for X seconds")
+	  (const :tag "Never auto clock out" nil)))
+
 (defvar org-clock-in-prepare-hook nil
 (defvar org-clock-in-prepare-hook nil
   "Hook run when preparing the clock.
   "Hook run when preparing the clock.
 This hook is run before anything happens to the task that
 This hook is run before anything happens to the task that
@@ -1397,6 +1410,17 @@ the default behavior."
 	 (message "Clock starts at %s - %s" ts org--msg-extra)
 	 (message "Clock starts at %s - %s" ts org--msg-extra)
 	 (run-hooks 'org-clock-in-hook))))))
 	 (run-hooks 'org-clock-in-hook))))))
 
 
+(defun org-clock-auto-clockout ()
+  "Clock out the currently clocked in task if Emacs is idle.
+See `org-clock-auto-clockout-timer' to set the idle time span.
+
+Thie is only effective when `org-clock-auto-clockout-insinuate'
+is present in the user configuration."
+  (when (and (numberp org-clock-auto-clockout-timer)
+	     org-clock-current-task)
+    (run-with-idle-timer
+     org-clock-auto-clockout-timer nil #'org-clock-out)))
+
 ;;;###autoload
 ;;;###autoload
 (defun org-clock-in-last (&optional arg)
 (defun org-clock-in-last (&optional arg)
   "Clock in the last closed clocked item.
   "Clock in the last closed clocked item.

+ 8 - 0
lisp/org.el

@@ -3766,6 +3766,14 @@ If yes, offer to stop it and to save the buffer with the changes."
   (add-hook 'org-mode-hook 'org-clock-load)
   (add-hook 'org-mode-hook 'org-clock-load)
   (add-hook 'kill-emacs-hook 'org-clock-save))
   (add-hook 'kill-emacs-hook 'org-clock-save))
 
 
+(defun org-clock-auto-clockout-insinuate ()
+  "Set up hook for auto clocking out when Emacs is idle.
+See `org-clock-auto-clockout-timer'.
+
+This function is meant to be added to the user configuration."
+  (require 'org-clock)
+  (add-hook 'org-clock-in-hook #'org-clock-auto-clockout t))
+
 (defgroup org-archive nil
 (defgroup org-archive nil
   "Options concerning archiving in Org mode."
   "Options concerning archiving in Org mode."
   :tag "Org Archive"
   :tag "Org Archive"