From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 8IPeNI1XFWB9VwAA0tVLHw (envelope-from ) for ; Sat, 30 Jan 2021 12:56:45 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id uDiOMI1XFWDpVQAAbx9fmQ (envelope-from ) for ; Sat, 30 Jan 2021 12:56:45 +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 1B8CB9403C8 for ; Sat, 30 Jan 2021 12:56:44 +0000 (UTC) Received: from localhost ([::1]:35648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5pnu-0003pL-Rr for larch@yhetil.org; Sat, 30 Jan 2021 07:56:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5pnF-0003p6-Hl for emacs-orgmode@gnu.org; Sat, 30 Jan 2021 07:56:01 -0500 Received: from forward5-smtp.messagingengine.com ([66.111.4.239]:47887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5pnD-0005AC-CG for emacs-orgmode@gnu.org; Sat, 30 Jan 2021 07:56:01 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailforward.nyi.internal (Postfix) with ESMTP id 063431947560; Sat, 30 Jan 2021 07:55:56 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 30 Jan 2021 07:55:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=oNgY7w nRE6+FpniDnTpVWlCRsnwqRog4mvjjtQd9slc=; b=rc9WAAGuuK38sweW7p5j4O lQrthCUhNzVvEWgCMqGSpyNh0oo4b7HScgR3IksNIiA4WHgRB0Eh6yIdodZ7a0oG QfyyK9a1fMh4lt2d0ocbd+uVhTxHrVQCpUqPS0aBhC/5yyVutBpe9brOi5hzCbSh JDFjDy2it7WakdjRqvZoq2mjprXbSJZhVjVEdlkcj80dZeGZr8AEDvboeOTsWZgc +IYlKYkctLdMpqK5gNbCWXXKms6XSt1TQB58xFyCFDYUgAidodsKPErLmQZ3nqKi Ijy2CBcQA6Tkh6UIuyySOiQIV8HzrkMngW2eY6x5EMY30plcc+0See6PdVNacCIg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeggdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufgjfhffkfggtgesthdtredttd dttdenucfhrhhomheptfhitghhrghrugcunfgrfihrvghntggvuceorhhitghhrghrugdr lhgrfihrvghntggvsehunhhiqdhtuhgvsghinhhgvghnrdguvgeqnecuggftrfgrthhtvg hrnhepveekieekgeegtdefuddtfeduleffueejueekheelvefhffffheehgeevtdefveel necuffhomhgrihhnpeguihgrrhihrdhorhhgnecukfhppeegiedruddugedrudehuddrud eggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehr fihlsehfrghsthhmrghilhdrtghomh X-ME-Proxy: Received: from aquinas (dynamic-046-114-151-144.46.114.pool.telefonica.de [46.114.151.144]) by mail.messagingengine.com (Postfix) with ESMTPA id 5369B1080057; Sat, 30 Jan 2021 07:55:55 -0500 (EST) Received: from rwl by aquinas with local (Exim 4.92) (envelope-from ) id 1l5pky-0000YI-NT; Sat, 30 Jan 2021 13:53:40 +0100 From: Richard Lawrence To: Christopher Causer , orgmode Subject: Re: clock-table and hooking that into org-capture file+olp+datetree In-Reply-To: <85e0ac65-f4b6-4212-95bf-2bc24671de06@www.fastmail.com> References: <79daebf0-5bda-473a-b289-392fd0c8df18@www.fastmail.com> <85e0ac65-f4b6-4212-95bf-2bc24671de06@www.fastmail.com> Date: Sat, 30 Jan 2021 13:53:40 +0100 Message-ID: <87mtwqziuj.fsf@aquinas> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: neutral client-ip=66.111.4.239; envelope-from=rwl@fastmail.com; helo=forward5-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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.05 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=rc9WAAGu; 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: 1B8CB9403C8 X-Spam-Score: -2.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: kH/NbP2XrD97 Hi Christopher, "Christopher Causer" writes: > Hello everyone! Here's a reasonably easy (I think) question because I'm quite new to Emacs and org-mode. > > I have an org-capture template using file+olp+datetree[1], which works great at filing my thoughts for the day. Separately I know I can generate clock tables[2] based on dynamic blocks to show me what I've been doing with my time for any given period. What I'm struggling with is to glue parts of these together to achieve the following: > > 1. I org-capture to a subheading of datetree. When it does so it either creates or updates an org-clock-report just below the datetree header (the bit that says "2020-11-12 Thursday", for example.) I guess this would be the parent of what I'm capturing. > > 2. For all my historical journal entries, if I could move point to a headline with a date such as the example below and it would pull the date out and add a clocktable below via an interactive function that would be my ideal. This is less of a problem for me as I don't have much in the way of history in my diary yet or my other org files. > If I understand right, what you need for both of these things is a function to jump to a date in your diary datetree and update the clocktable there. Right? Some functions that will help with this: - org-datetree-find-date-create - org-narrow-to-subtree So, something like this should get you started: #+begin_src emacs-lisp (defun org-update-clocktable-on-date (date) (save-excursion ;; open the file containing the datetree: (find-file (concat org-directory "/diary.org")) ;; jump to the subtree for the given date: ;; note: date must look like (m d y) where all three values are integers (org-datetree-find-date-create date) ;; narrow to the subtree for this date, so we don't update ;; any other clocktables (org-narrow-to-subtree) ;; update the clock report, or create it if it doesn't exist ;; note: we pass a prefix argument to tell org-clock-report to ;; update the first clocktable it finds in the (narrowed) buffer (org-clock-report t) ;; widen to the whole buffer again (widen))) #+end_src Then you can call this function, providing the date, in different contexts where you want to create or update the clocktable. Note that org-datetree-find-date has a slightly annoying interface, in that you need to provide a list of three integers representing a calendar date. One easy way to do that interactively is with calendar-read-date, which prompts you for the year, month and day, so you could say (org-update-clocktable-on-date (calendar-read-date)) calendar-read-date is not as nice to use interactively as org-read-date, but as far as I know, there is no easy way to get the calendar (m d y) format out of its return value, which is either a string like "2021-01-30" or a value in Emacs' internal time representation format. But you can do something like (let* ;; prompt for the date and decode the resulting internal time as a list: ((decoded (decode-time (org-read-date nil t nil "Update on date:"))) ;; unpack the date as a list (m d y) from the decoded time: (date (list (nth 4 decoded) ; month (nth 3 decoded) ; day (nth 5 decoded)))) ; year (org-update-clocktable-on-date date)) Hope that helps get you to your next step! -- Best, Richard