From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id II8/DHCUFmAzIAAA0tVLHw (envelope-from ) for ; Sun, 31 Jan 2021 11:28:48 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id KDEhCHCUFmBEWQAA1q6Kng (envelope-from ) for ; Sun, 31 Jan 2021 11:28:48 +0000 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 5FBFE9404C2 for ; Sun, 31 Jan 2021 11:28:47 +0000 (UTC) Received: from localhost ([::1]:39646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6AuM-00014g-7u for larch@yhetil.org; Sun, 31 Jan 2021 06:28:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6AhL-0005F3-5q for emacs-orgmode@gnu.org; Sun, 31 Jan 2021 06:15:19 -0500 Received: from wforward3-smtp.messagingengine.com ([64.147.123.22]:44761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6AhH-0007L2-Ts for emacs-orgmode@gnu.org; Sun, 31 Jan 2021 06:15:18 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailforward.west.internal (Postfix) with ESMTP id 14DD2C55; Sun, 31 Jan 2021 06:15:14 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 31 Jan 2021 06:15:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=bDlKJV wVsKE3jq5oz/LgqZkqFPOfFq+eXdZq7MB6qpk=; b=C9lxa4QAfgu5PS5UnAN5Pq eBnaxnSDZVm6492oUJjCmLcONVXoaCuXFh34deLaB+hS7H7wxeSRjufnJ7oD85IB AwdfcM8aUfkm+cuGh9z+bczuIgZ4n90rxlFHMb8/16fMtqDworQf8KCjYszVD9DE 7oQoEURzOb58eOElaZtvqV6GiC+BG0yEZelE955A2a/5d19nX+XW8erFXc1GscOC Nj5TqUxNPvsrbT/ZshH6SrQ2Ero/ak/YrJe/grmyWlAAh3tVMT8neNiJWem3USN+ kpRn8+LUKdM65qV3dvou4oZe6Tjs4ZNVhmjb0X5fi80HA3zzBktorNNYleh+t+2Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeigddvvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffujghffffkgggtsehttdertddttddtnecuhfhrohhmpeftihgthhgrrhgu ucfnrgifrhgvnhgtvgcuoehrihgthhgrrhgurdhlrgifrhgvnhgtvgesuhhnihdqthhuvg gsihhnghgvnhdruggvqeenucggtffrrghtthgvrhhnpeegtdejtdeggeeuffegtefgudfh geegjeeiiedvheegieevfeehleeiudevueekffenucffohhmrghinheprghgrghinhdroh hrghdprhgvshhulhhtrdhorhhgpdhorhhgmhhouggvrdhorhhgnecukfhppeegiedruddu gedrudegkedrvdehtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehrfihlsehfrghsthhmrghilhdrtghomh X-ME-Proxy: Received: from aquinas (dynamic-046-114-148-250.46.114.pool.telefonica.de [46.114.148.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 1B4AF240057; Sun, 31 Jan 2021 06:15:13 -0500 (EST) Received: from rwl by aquinas with local (Exim 4.92) (envelope-from ) id 1l6AhC-0007kf-5E; Sun, 31 Jan 2021 12:15:10 +0100 From: Richard Lawrence To: Kyle Meyer Subject: Re: [PATCH] capture: Fix handling of time range for :time-prompt In-Reply-To: <878s8pll2g.fsf@kyleam.com> References: <878s8pll2g.fsf@kyleam.com> Date: Sun, 31 Jan 2021 12:15:10 +0100 Message-ID: <87a6spz7b5.fsf@aquinas> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: neutral client-ip=64.147.123.22; envelope-from=rwl@fastmail.com; helo=wforward3-smtp.messagingengine.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.06 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=C9lxa4QA; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 5FBFE9404C2 X-Spam-Score: -2.06 X-Migadu-Scanner: scn1.migadu.com X-TUID: 0VuDAVAv70Rb Dear Kyle and all, Thanks for following up! Sorry it's taken me so long to reply. Kyle Meyer writes: > Testing that against the cases in your initial report, I believe it > leads to the same results as your patch, so here's a cleaned-up version. I confirm that this cleaned up version works for me and gets the same results for my test cases. I think it should be applied (modulo one nitpick below). Are you willing to apply it, Kyle? I don't have commit rights myself. > -- >8 -- > Subject: [PATCH] capture: Fix handling of time range for :time-prompt > > * lisp/org-capture.el (org-capture-set-target-location): Bind > org-end-time-was-given around the org-read-date call to get a return > value that uses the start time rather than doing custom adjustment of > the return value. > > If org-capture-set-target-location detects that the answer to > org-read-date has a time range, it strips the end time from the answer > and calls org-read-date-analyze again. (org-read-date already calls > it underneath.) The regexp it uses, however, can easily match a date, > leading to a bogus result. > > org-read-date-analyze is already capable of processing the time range > in a way that matches org-capture-set-target-location's intent: when > org-end-time-was-given is bound, org-read-date-analyze splits off the > end value of the range and stores it in org-end-time-was-given. Drop > the custom logic and let org-read-date-analyze handle the range. > > Reported-by: Richard Lawrence > Ref: https://orgmode.org/list/87h7obh4ct.fsf@aquinas > --- > lisp/org-capture.el | 35 +++++++++++++++-------------------- > 1 file changed, 15 insertions(+), 20 deletions(-) > > diff --git a/lisp/org-capture.el b/lisp/org-capture.el > index f40f2b335..d7b69f228 100644 > --- a/lisp/org-capture.el > +++ b/lisp/org-capture.el > @@ -1025,28 +1025,23 @@ (defun org-capture-set-target-location (&optional target) > (time-to-days org-overriding-default-time)) > ((or (org-capture-get :time-prompt) > (equal current-prefix-arg 1)) > - ;; Prompt for date. > - (let ((prompt-time (org-read-date > - nil t nil "Date for tree entry:"))) > + ;; Prompt for date. Bind `org-end-time-was-given' so > + ;; that `org-read-date-analyze' handles the time range > + ;; case and returns `prompt-time' with the start value. > + (let* ((org-time-was-given nil) > + (org-end-time-was-given nil) > + (prompt-time (org-read-date > + nil t nil "Date for tree entry:"))) > (org-capture-put > :default-time > - (cond ((and (or (not (boundp 'org-time-was-given)) > - (not org-time-was-given)) > - (not (= (time-to-days prompt-time) (org-today)))) > - ;; Use 00:00 when no time is given for another > - ;; date than today? > - (apply #'encode-time 0 0 > - org-extend-today-until > - (cl-cdddr (decode-time prompt-time)))) > - ((string-match "\\([^ ]+\\)-[^ ]+[ ]+\\(.*\\)" > - org-read-date-final-answer) > - ;; Replace any time range by its start. > - (apply #'encode-time > - (org-read-date-analyze > - (replace-match "\\1 \\2" nil nil > - org-read-date-final-answer) > - prompt-time (decode-time prompt-time)))) > - (t prompt-time))) > + (if (and (or (not org-time-was-given)) Nitpick: (or (not org-time-was-given)) is equivalent to (not org-time-was-given) > + (not (= (time-to-days prompt-time) (org-today)))) > + ;; Use 00:00 when no time is given for another > + ;; date than today? > + (apply #'encode-time 0 0 > + org-extend-today-until > + (cl-cdddr (decode-time prompt-time))) > + prompt-time)) > (time-to-days prompt-time))) > (t > ;; Current date, possibly corrected for late night > > base-commit: 9e8215f4a5df7d03ac787da78d28f69a4c18e7d3 As for this: > The original change came in b61ff117b (org-capture.el: > Set a correct time value with file+datetree+prompt, 2012-09-24), and I > believe the related thread is > . Thanks for the reference to this thread. I would like to be able to do exactly what Gregor mentioned there: - be prompted when capturing for the date and time / time range of the event/appointment. - record the event/appointment in a date tree under the date entered at the prompt - have a timestamp with the full time information entered at the prompt appear in the resulting heading In short: enter the full date and time information *once*, and use this both to place the entry in the datetree and to give it a timestamp. As far as I can tell, that is not fully possible today, even with this patch. The reason is that time *range* information entered at the prompt generated by :time-prompt gets thrown away. The reason for *that* is that org-read-date is called with t as its to-time argument (the second argument), so that the date is returned in Emacs' internal time representation, which doesn't represent ranges. Bastien's recommended solution back then was to use %^t and %^T in the capture template instead of %t and %T. The problem with that is that it requires entering the date twice: once at the prompt generated by :time-prompt, and once at the prompt to replace the %^T in the template. Could we instead save, say, :start-time and :end-time values in org-capture-plist after the :time-prompt, and use them to populate %T, %U, etc. in the template? This seems like the right solution to me, but it might require modifying org-read-date, which is a hairy piece of code. What do others think about this? Should I come up with a patch for this, or is there a different solution that the community and maintainers would prefer? -- Best, Richard