aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <id@rbenencia.name>2026-01-04 11:55:44 -0300
committerRaúl Benencia <id@rbenencia.name>2026-01-04 11:55:44 -0300
commit49bcc434004d6b5ef3f414588846834b175f7439 (patch)
tree5e61765b463ee7ea24d3ed1c71d0f5bb993bfe40
parent75ee87d3b1c66198f6abba75fec405f40dc4cce0 (diff)
Allow setting a default task to auto-clock in
-rw-r--r--org-tempus.el45
1 files changed, 35 insertions, 10 deletions
diff --git a/org-tempus.el b/org-tempus.el
index 1ce00bb..bcbe3f8 100644
--- a/org-tempus.el
+++ b/org-tempus.el
@@ -30,6 +30,7 @@
;;; Code:
(require 'org-clock)
+(require 'org-id)
(defgroup org-tempus ()
"Display mode line indicator with information about clocked time."
@@ -193,7 +194,12 @@ The value is a string like:
:type 'integer
:group 'org-tempus)
-(defcustom org-tempus-idle-auto-clock-out-seconds 0
+(defcustom org-tempus-auto-clock-enabled nil
+ "When non-nil, allow Org Tempus auto clock in/out."
+ :type 'boolean
+ :group 'org-tempus)
+
+(defcustom org-tempus-idle-auto-clock-out-seconds 300
"Idle seconds after which to auto clock out.
Set to 0 to disable auto clock-out."
:type 'integer
@@ -204,21 +210,24 @@ Set to 0 to disable auto clock-out."
:type 'boolean
:group 'org-tempus)
-(defcustom org-tempus-idle-auto-clock-in nil
+(defcustom org-tempus-idle-auto-clock-in t
"When non-nil, auto clock in after activity if Org Tempus auto clocked out."
:type 'boolean
:group 'org-tempus)
-(defcustom org-tempus-auto-clock-enabled t
- "When non-nil, allow Org Tempus auto clock in/out."
- :type 'boolean
- :group 'org-tempus)
-
(defcustom org-tempus-idle-auto-clock-in-window-minutes 120
- "Minutes after auto clock-out during which auto clock-in is allowed."
+ "Minutes after auto clock-out during which auto clock-in to old task is
+allowed."
:type 'integer
:group 'org-tempus)
+(defcustom org-tempus-default-task-id nil
+ "Org ID of the default task used for auto clock-in.
+You can set this by running `org-id-get-create' on a heading and
+assigning the resulting ID to this variable."
+ :type '(choice (const :tag "None" nil) string)
+ :group 'org-tempus)
+
(defcustom org-tempus-idle-provider 'emacs
"Provider used to query idle time.
Known providers are `emacs' (activity inside Emacs),
@@ -575,7 +584,8 @@ A session does not reset when switching tasks within
(when (and (>= org-tempus--idle-active-streak
org-tempus-idle-active-streak-seconds)
(not (org-clock-is-active)))
- (unless (org-tempus--maybe-auto-clock-in)
+ (unless (or (org-tempus--maybe-auto-clock-in)
+ (org-tempus--maybe-auto-clock-in-default))
(when (org-tempus--notification-allowed-p)
(org-tempus--record-notification)
(org-tempus--notify
@@ -600,6 +610,21 @@ Return non-nil when an auto clock-in occurs."
(org-tempus--notify "Auto clocked in to your last task.")
t))))
+(defun org-tempus--maybe-auto-clock-in-default ()
+ "Auto clock in to the default task if eligible.
+Return non-nil when an auto clock-in occurs."
+ (when (and org-tempus-auto-clock-enabled
+ org-tempus-default-task-id
+ (not (org-clock-is-active)))
+ (let ((marker (org-id-find org-tempus-default-task-id 'marker)))
+ (when (and marker (marker-buffer marker))
+ (with-current-buffer (marker-buffer marker)
+ (org-with-point-at marker
+ (org-clock-in)))
+ (org-tempus--reset-auto-clock-state)
+ (org-tempus--notify "Auto clocked in to your default task.")
+ t))))
+
(defun org-tempus--maybe-update-dconf (&optional value)
"Update dconf with VALUE when `org-tempus-dconf-path' is set."
(when (and org-tempus-dconf-path
@@ -638,7 +663,7 @@ Return non-nil when an auto clock-in occurs."
(org-tempus--mode-line-separator)
(org-tempus--format-mode-line-item
"T" total-display)
- "] ("
+ "] "
(org-tempus--current-task-name)
(let* ((task-minutes (org-tempus--current-task-time-minutes))
(task-time (org-duration-from-minutes task-minutes))
nihil fit ex nihilo