[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out
From: |
Samuel W. Flint |
Subject: |
[PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier |
Date: |
Wed, 26 Oct 2022 09:53:50 -0500 |
* lisp/org-clock.el (org-clock-in-switch-to-state,
org-clock-out-switch-to-state): Allow
`org-clock-{in,out}-switch-to-state` to be an alist of
current/next-state pairs.
(org-clock-in, org-clock-out): Add logic to handle
`org-clock-{in,out}-switch-to-state` as alists.
---
lisp/org-clock.el | 60 ++++++++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 21 deletions(-)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 6332399bb..f5ffb515f 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -148,28 +148,34 @@ out time will be 14:50."
(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
-switched. If the value is a function, it must take one
-parameter (the current TODO state of the item) and return the
-state to switch it to."
+switched. It may also be an alist of `(CURRENT . NEXT)' pairs.
+If the value is a function, it must take one parameter (the
+current TODO state of the item) and return the state to switch it
+to."
:group 'org-clock
:group 'org-todo
:type '(choice
(const :tag "Don't force a state" nil)
(string :tag "State")
- (symbol :tag "Function")))
+ (alist :key-value (string :tag "Current State:")
+ :value-type (string :tag "Next State :"))
+ (symbol :tag "Function")))
(defcustom org-clock-out-switch-to-state nil
"Set task to a special todo state after clocking out.
The value should be the state to which the entry should be
-switched. If the value is a function, it must take one
-parameter (the current TODO state of the item) and return the
-state to switch it to."
+switched. It may also be an alist of `(CURRENT . NEXT)' pairs.
+If the value is a function, it must take one parameter (the
+current TODO state of the item) and return the state to switch it
+to."
:group 'org-clock
:group 'org-todo
:type '(choice
(const :tag "Don't force a state" nil)
(string :tag "State")
- (symbol :tag "Function")))
+ (alist :key-value (string :tag "Current State:")
+ :value-type (string :tag "Next State :"))
+ (symbol :tag "Function")))
(defcustom org-clock-history-length 5
"Number of clock tasks to remember in history.
@@ -1348,17 +1354,23 @@ the default behavior."
(run-hooks 'org-clock-in-prepare-hook)
(org-clock-history-push)
(setq org-clock-current-task (org-get-heading t t t t))
- (cond ((functionp org-clock-in-switch-to-state)
- (let ((case-fold-search nil))
- (looking-at org-complex-heading-regexp))
- (let ((newstate (funcall org-clock-in-switch-to-state
- (match-string 2))))
- (when newstate (org-todo newstate))))
+ (cond ((listp org-clock-in-switch-to-state)
+ (let ((case-fold-search nil))
+ (looking-at org-complex-heading-regexp))
+ (when-let ((state-pair (assoc (match-string 2)
org-clock-in-switch-to-state))
+ (new-state (cdr state-pair)))
+ (org-todo new-state)))
+ ((functionp org-clock-in-switch-to-state)
+ (let ((case-fold-search nil))
+ (looking-at org-complex-heading-regexp))
+ (let ((newstate (funcall org-clock-in-switch-to-state
+ (match-string 2))))
+ (when newstate (org-todo newstate))))
((and org-clock-in-switch-to-state
(not (looking-at (concat org-outline-regexp "[ \t]*"
- org-clock-in-switch-to-state
- "\\>"))))
- (org-todo org-clock-in-switch-to-state)))
+ org-clock-in-switch-to-state
+ "\\>"))))
+ (org-todo org-clock-in-switch-to-state)))
(setq org-clock-heading (org-clock--mode-line-heading))
(org-clock-find-position org-clock-in-resume)
(cond
@@ -1720,6 +1732,12 @@ to, overriding the existing value of
`org-clock-out-switch-to-state'."
(org-back-to-heading t)
(let ((org-clock-out-when-done nil))
(cond
+ ((listp org-clock-out-switch-to-state)
+ (let ((case-fold-search nil))
+ (looking-at org-complex-heading-regexp))
+ (when-let ((state-pair (assoc (match-string 2)
org-clock-out-switch-to-state))
+ (new-state (cdr state-pair)))
+ (org-todo new-state)))
((functionp org-clock-out-switch-to-state)
(let ((case-fold-search nil))
(looking-at org-complex-heading-regexp))
@@ -1728,10 +1746,10 @@ to, overriding the existing value of
`org-clock-out-switch-to-state'."
(when newstate (org-todo newstate))))
((and org-clock-out-switch-to-state
(not (looking-at
- (concat
- org-outline-regexp "[ \t]*"
- org-clock-out-switch-to-state
- "\\>"))))
+ (concat
+ org-outline-regexp "[ \t]*"
+ org-clock-out-switch-to-state
+ "\\>"))))
(org-todo org-clock-out-switch-to-state))))))
(force-mode-line-update)
(message (if remove
--
2.37.0
--
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
- [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier,
Samuel W. Flint <=