emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
@ 2022-10-26 14:53 Samuel W. Flint
  2022-10-27  4:11 ` Max Nikulin
  2022-10-27  4:45 ` Ihor Radchenko
  0 siblings, 2 replies; 10+ messages in thread
From: Samuel W. Flint @ 2022-10-26 14:53 UTC (permalink / raw)
  To: Org-Mode

* 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-26 14:53 [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier Samuel W. Flint
@ 2022-10-27  4:11 ` Max Nikulin
  2022-10-27  4:45 ` Ihor Radchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Max Nikulin @ 2022-10-27  4:11 UTC (permalink / raw)
  To: 875yg6elmh.fsf, Org-Mode

On 26/10/2022 21:53, Samuel W. Flint wrote:
> * 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.

Samuel, please, consider using --in-reply-to and perhaps --thread 
options of git format-patch while preparing messages. It should help 
mail user agents to group all versions of your patches.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-26 14:53 [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier Samuel W. Flint
  2022-10-27  4:11 ` Max Nikulin
@ 2022-10-27  4:45 ` Ihor Radchenko
  2022-10-28 15:03   ` Samuel W. Flint
  2023-07-16  8:22   ` Ihor Radchenko
  1 sibling, 2 replies; 10+ messages in thread
From: Ihor Radchenko @ 2022-10-27  4:45 UTC (permalink / raw)
  To: 875yg6elmh.fsf; +Cc: Org-Mode

"Samuel W. Flint" <swflint+orgmode@flintfam.org> writes:

> * 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.

Thanks!

Before we continue, could you please confirm if you have FSF copyright
assignment? My records show that you have made two commits to Org mode
previously, and they total LOC is 15, which is maximum allowed
contribution that does not require copyright assignment. See
https://orgmode.org/worg/org-contribute.html#copyright

>    "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.

Maybe "`(CURRENT . NEXT)' TODO state pairs"? It will be slightly more
clear.

>  (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."

Same here.

The rest looks good.

If you can, please also add tests.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-27  4:45 ` Ihor Radchenko
@ 2022-10-28 15:03   ` Samuel W. Flint
  2022-10-29  3:51     ` Ihor Radchenko
  2023-07-16  8:22   ` Ihor Radchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Samuel W. Flint @ 2022-10-28 15:03 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org-Mode

>>>>> Ihor Radchenko writes:

    IR> "Samuel W. Flint" <swflint+orgmode@flintfam.org> writes:
    >> * 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.

    IR> Thanks!

    IR> Before we continue, could you please confirm if you have FSF copyright
    IR> assignment? My records show that you have made two commits to Org mode
    IR> previously, and they total LOC is 15, which is maximum allowed
    IR> contribution that does not require copyright assignment. See
    IR> https://orgmode.org/worg/org-contribute.html#copyright

I've sent in the assignment, but I'm waiting on the FSF's response & a
waiver/documentation from my employer.

    >> "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.

    IR> Maybe "`(CURRENT . NEXT)' TODO state pairs"? It will be slightly more
    IR> clear.

    >> (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."

    IR> Same here.

I can adjust that as well.  That would definitely clarify the documentation

    IR> The rest looks good.

    IR> If you can, please also add tests.

I'll try my hand at it!

    IR> -- 
    IR> Ihor Radchenko // yantar92,
    IR> Org mode contributor,
    IR> Learn more about Org mode at <https://orgmode.org/>.
    IR> Support Org development at <https://liberapay.com/org-mode>,
    IR> or support my work at <https://liberapay.com/yantar92>

Sam

-- 
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-28 15:03   ` Samuel W. Flint
@ 2022-10-29  3:51     ` Ihor Radchenko
  2022-11-21  9:06       ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2022-10-29  3:51 UTC (permalink / raw)
  To: Samuel W. Flint; +Cc: Org-Mode

"Samuel W. Flint" <swflint@flintfam.org> writes:

>     IR> Before we continue, could you please confirm if you have FSF copyright
>     IR> assignment? My records show that you have made two commits to Org mode
>     IR> previously, and they total LOC is 15, which is maximum allowed
>     IR> contribution that does not require copyright assignment. See
>     IR> https://orgmode.org/worg/org-contribute.html#copyright
>
> I've sent in the assignment, but I'm waiting on the FSF's response & a
> waiver/documentation from my employer.

Good to hear. Note that FSF should reply within 5 working days.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-29  3:51     ` Ihor Radchenko
@ 2022-11-21  9:06       ` Ihor Radchenko
  2022-11-21 14:53         ` Samuel W. Flint
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2022-11-21  9:06 UTC (permalink / raw)
  To: Samuel W. Flint; +Cc: Org-Mode

Ihor Radchenko <yantar92@posteo.net> writes:

>> I've sent in the assignment, but I'm waiting on the FSF's response & a
>> waiver/documentation from my employer.
>
> Good to hear. Note that FSF should reply within 5 working days.

May I know if you got any reply from FSF?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-11-21  9:06       ` Ihor Radchenko
@ 2022-11-21 14:53         ` Samuel W. Flint
  2022-11-22  3:36           ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Samuel W. Flint @ 2022-11-21 14:53 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org-Mode

>>>>> Ihor Radchenko writes:

    IR> Ihor Radchenko <yantar92@posteo.net> writes:
    >>> I've sent in the assignment, but I'm waiting on the FSF's response & a
    >>> waiver/documentation from my employer.
    >> 
    >> Good to hear. Note that FSF should reply within 5 working days.

    IR> May I know if you got any reply from FSF?

I'm still waiting for final confirmation.  Having some issues getting
confirmation from the University.

Sam


    IR> -- 
    IR> Ihor Radchenko // yantar92,
    IR> Org mode contributor,
    IR> Learn more about Org mode at <https://orgmode.org/>.
    IR> Support Org development at <https://liberapay.com/org-mode>,
    IR> or support my work at <https://liberapay.com/yantar92>


-- 
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-11-21 14:53         ` Samuel W. Flint
@ 2022-11-22  3:36           ` Ihor Radchenko
  2023-01-27 10:38             ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2022-11-22  3:36 UTC (permalink / raw)
  To: Samuel W. Flint; +Cc: Org-Mode

"Samuel W. Flint" <swflint+orgmode@flintfam.org> writes:

>     IR> May I know if you got any reply from FSF?
>
> I'm still waiting for final confirmation.  Having some issues getting
> confirmation from the University.

Thanks for the update. Let us know when the process is done.

Note that universities usually don't have issues with FSF copyright,
maybe unless you are working on a grant related to Emacs/Org
development.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-11-22  3:36           ` Ihor Radchenko
@ 2023-01-27 10:38             ` Ihor Radchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2023-01-27 10:38 UTC (permalink / raw)
  To: Samuel W. Flint; +Cc: Org-Mode

Ihor Radchenko <yantar92@posteo.net> writes:

>> I'm still waiting for final confirmation.  Having some issues getting
>> confirmation from the University.
>
> Thanks for the update. Let us know when the process is done.
>
> Note that universities usually don't have issues with FSF copyright,
> maybe unless you are working on a grant related to Emacs/Org
> development.

Hi,

It has been a while since your last update.
May I know if you managed to get the university approval?
Maybe you need some assistance?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier
  2022-10-27  4:45 ` Ihor Radchenko
  2022-10-28 15:03   ` Samuel W. Flint
@ 2023-07-16  8:22   ` Ihor Radchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2023-07-16  8:22 UTC (permalink / raw)
  To: 875yg6elmh.fsf; +Cc: Org-Mode

Ihor Radchenko <yantar92@posteo.net> writes:

> Before we continue, could you please confirm if you have FSF copyright
> assignment? My records show that you have made two commits to Org mode
> previously, and they total LOC is 15, which is maximum allowed
> contribution that does not require copyright assignment. See
> https://orgmode.org/worg/org-contribute.html#copyright

Unfortunately, the copyright assignment got stuck in the process because
of university bureaucracy.

Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-16  8:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 14:53 [PATCH v2 1/2] lisp/org-clock.el: Make switching states on clock-in/-out easier Samuel W. Flint
2022-10-27  4:11 ` Max Nikulin
2022-10-27  4:45 ` Ihor Radchenko
2022-10-28 15:03   ` Samuel W. Flint
2022-10-29  3:51     ` Ihor Radchenko
2022-11-21  9:06       ` Ihor Radchenko
2022-11-21 14:53         ` Samuel W. Flint
2022-11-22  3:36           ` Ihor Radchenko
2023-01-27 10:38             ` Ihor Radchenko
2023-07-16  8:22   ` Ihor Radchenko

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).