From: "Samuel W. Flint" <swflint+orgmode@flintfam.org>
To: "Org-Mode" <emacs-orgmode@gnu.org>
Subject: [PATCH 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
Date: Sat, 22 Oct 2022 13:29:24 -0500 [thread overview]
Message-ID: <87sfjfvhiz.fsf@flintfam.org> (raw)
* lisp/org-clock.el (org-clock-in-next-state,
org-clock-out-next-state): Define and document customizeable variables
to describe the "next state" on clock-in/-out.
(org-clock-in-switch-to-state, org-clock-out-switch-to-state): Add
options to use the `org-clock-{in,out}-next-state' variables to change
on clock-in/-out.
(org-clock-in-next-state-function, org-clock-out-next-state-function):
Define functions which can be used to select the next TODO state on
clock-in/-out.
---
lisp/org-clock.el | 48 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 6332399bb..18cd83988 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -145,6 +145,16 @@ out time will be 14:50."
:group 'org-clock
:type 'boolean)
+(defcustom org-clock-in-next-state nil
+ "Alist of next TODO states for clocking out.
+The symbol `error' may be used to prevent clocking out on tasks."
+ :group 'org-clock
+ :group 'org-todo
+ :type '(alist :key-value (string :tag "Current State:")
+ :value-type (choice :tag "Next State :"
+ (string :tag "TODO Keyword")
+ (const :tag "Block Clock-In" 'error))))
+
(defcustom org-clock-in-switch-to-state nil
"Set task to a special todo state while clocking it.
The value should be the state to which the entry should be
@@ -156,7 +166,18 @@ state to switch it to."
:type '(choice
(const :tag "Don't force a state" nil)
(string :tag "State")
- (symbol :tag "Function")))
+ (const :tag "Use `org-clock-in-next-state'" 'org-clock-in-next-state-function)
+ (symbol :tag "Function")))
+
+(defcustom org-clock-out-next-state nil
+ "Alist of next TODO states for clocking out.
+The symbol `error' may be used to prevent clocking in on tasks."
+ :group 'org-clock
+ :group 'org-todo
+ :type '(alist :key-value (string :tag "Current State:")
+ :value-type (choice :tag "Next State :"
+ (string :tag "TODO Keyword")
+ (const :tag "Block Clock-Out" 'error))))
(defcustom org-clock-out-switch-to-state nil
"Set task to a special todo state after clocking out.
@@ -169,7 +190,8 @@ state to switch it to."
:type '(choice
(const :tag "Don't force a state" nil)
(string :tag "State")
- (symbol :tag "Function")))
+ (const :tag "Use `org-clock-out-next-state'" 'org-clock-out-next-state-function)
+ (symbol :tag "Function")))
(defcustom org-clock-history-length 5
"Number of clock tasks to remember in history.
@@ -1256,6 +1278,17 @@ so long."
(defvar org-clock-out-time nil) ; store the time of the last clock-out
(defvar org--msg-extra)
+(defun org-clock-in-next-state-function (state)
+ "Change state to the next logical TODO STATE on clock-in.
+
+Use `org-clock-in-next-state'."
+ (when-let ((state-pair (assoc state org-clock-in-next-state))
+ (next-state (cdr state-pair)))
+ (if (and (symbolp next-state)
+ (eq 'error next-state))
+ (user-error (format "Cannot clock into %s task, change to a valid TODO state." state))
+ next-state)))
+
;;;###autoload
(defun org-clock-in (&optional select start-time)
"Start the clock on the current item.
@@ -1650,6 +1683,17 @@ and current `frame-title-format' is equal to `org-clock-frame-title-format'."
(equal frame-title-format org-clock-frame-title-format))
(setq frame-title-format org-frame-title-format-backup)))
+(defun org-clock-out-next-state-function (state)
+ "Change state to the next logical TODO STATE on clock-out.
+
+Use `org-clock-out-next-state'."
+ (when-let ((state-pair (assoc state org-clock-out-next-state))
+ (next-state (cdr state-pair)))
+ (if (and (symbolp next-state)
+ (eq 'error next-state))
+ (user-error (format "Cannot clock into %s task, change to a valid TODO state." state))
+ next-state)))
+
;;;###autoload
(defun org-clock-out (&optional switch-to-state fail-quietly at-time)
"Stop the currently running clock.
--
2.37.3
--
Samuel W. Flint
4096R/FA13D704
(F50D 862B 4F65 5943 A8C2 EF0E 86C9 3E7A FA13 D704)
λs.(s s) λs.(s s)
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
next reply other threads:[~2022-10-24 5:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-22 18:29 Samuel W. Flint [this message]
2022-10-31 5:58 ` [PATCH 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfjfvhiz.fsf@flintfam.org \
--to=swflint+orgmode@flintfam.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).