From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gLFrJpdKWWNJewAAbAwnHQ (envelope-from ) for ; Wed, 26 Oct 2022 16:56:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id mBlaJpdKWWMLSgEAauVa8A (envelope-from ) for ; Wed, 26 Oct 2022 16:56:23 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1DD431F7A3 for ; Wed, 26 Oct 2022 16:56:23 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onhnG-0005Z7-Cv; Wed, 26 Oct 2022 10:54:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onhnE-0005Cu-UA for emacs-orgmode@gnu.org; Wed, 26 Oct 2022 10:54:09 -0400 Received: from mx.flintfam.org ([107.191.44.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onhnC-0006sm-0Q for emacs-orgmode@gnu.org; Wed, 26 Oct 2022 10:54:08 -0400 Received: by mx.flintfam.org (Postfix, from userid 114) id 5BC341F594; Wed, 26 Oct 2022 14:53:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.9.2 mx.flintfam.org 5BC341F594 Received: from hilbert.flintfam.org (unknown [129.93.161.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.flintfam.org (Postfix) with ESMTPSA id 32C401F54C for ; Wed, 26 Oct 2022 14:53:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.9.2 mx.flintfam.org 32C401F54C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flintfam.org; s=mail; t=1666796031; bh=Azn0H5sgXo/ed+ZJmhkgcuV/IVjwKLQPAs9zpHLisoQ=; h=From:To:Subject:Reply-To:Date:From; b=jEyo4V38PzyJQpDnQ0gVC7CE6WI4pS9NZ22F9ScydZy5V++KLes15HlVxiGVQfWx2 htcj9D2yUKwCNSg01u2kYwUD/i+Ii6qG0eD63Z9GlL9gzwDyClqkW+iqR0/X8iOORX ZdAK4HOFHIsOfJ/ItPwEsZiBn54/vAL59Ik77hI+WHuZYdeosJlx3WSuKAIvushgdJ 1Sb3+Nd01puWrxN/tBDrjZtLjMMJPO0xygpwveXwOUsUBu005HrCgQP1/Cj+Ouu7zI cQfXEd7M5du9nkzkJUqy9772OVcW9Km+Bwk705NebR5D9/wYzN1YDgywgAiBD0emYF hMB/1E3tA/2rw== From: "Samuel W. Flint" To: "Org-Mode" 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 Message-ID: <87eduud4ap.fsf@flintfam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=107.191.44.89; envelope-from=swflint+orgmode@flintfam.org; helo=mx.flintfam.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: 875yg6elmh.fsf@flintfam.org Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666796183; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Azn0H5sgXo/ed+ZJmhkgcuV/IVjwKLQPAs9zpHLisoQ=; b=JAEP8Pp8a4YDWqZgZwNymo+CaG31uEBNOiKJffbI76Mx4GSpc3/1yjt0L1QcjLogNDNLPB N7T9nSkwUyFf0zHdkcXCMyZJ1MifTq3qEQt8fvPWlX/WmyovceWQqGY23j3cpgqe9oXKoG 8454t/x2g6ODqTsJtGAncMAnDIKn6ymhKB51m8tXR7GaMGbGO3nHz+xo6SuhyVyzccSbnN u1DjOAac8F6T01ELyxO9Q+dufgoZSwM2wJamPeD3eWfn9BstgJh5MkjdMjnbK2gtKP6kDX s2pQHC6CAPVve7wl5fK/5aeuZO+Iy78W/XQ74AJJ+gKHo7tUTzNwOdBClBQl7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666796183; a=rsa-sha256; cv=none; b=vBK8l+kE2voGCn3Mca9F+KZ3dEHwzlAC1v3Cy56ddV6WHiSRNYM/iiZoWgsRw+AR66GlZS dUNRkr7bU8rI8W+ts49DhHWJ6nHTcH4jrbh9QEjhoDC51PFnDsh4pIOqvEakOzgi3OBzD7 5OzvaB6vN9UzmNLPixxUU5BdLTxdhHN94ZFU1etBNSOd/HW7eq4m1wdV6laQRlcrHbSRSb TjDVziy0bcmgzB89HUXqWUZZ1U3Cq8srVdE2O2yhQmg6p1aM+P4lnhBCfwdjKoc89Ktt81 CP42pm5g6muLxlVeG40x/ZtlTCwRalRkJmwsCsaEUZsuR6ZCp18shIS62MDh7w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=flintfam.org header.s=mail header.b=jEyo4V38; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.78 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=flintfam.org header.s=mail header.b=jEyo4V38; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1DD431F7A3 X-Spam-Score: 2.78 X-Migadu-Scanner: scn1.migadu.com X-TUID: MUBJBJk/Upj7 * 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"))) =20 (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"))) =20 (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-i= n-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 --=20 2.37.0 --=20 Samuel W. Flint 4096R/FA13D704 (F50D 862B 4F65 5943 A8C2 EF0E 86C9 3E7A FA13 D704) =CE=BBs.(s s) =CE=BBs.(s s) O< ascii ribbon campaign - stop html mail - www.asciiribbon.org