From: Richard Lawrence <firstname.lastname@example.org> To: Christopher Causer <email@example.com>, orgmode <firstname.lastname@example.org> Subject: Re: clock-table and hooking that into org-capture file+olp+datetree Date: Sat, 30 Jan 2021 13:53:40 +0100 [thread overview] Message-ID: <87mtwqziuj.fsf@aquinas> (raw) In-Reply-To: <email@example.com> Hi Christopher, "Christopher Causer" <firstname.lastname@example.org> 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, which works great at filing my thoughts for the day. Separately I know I can generate clock tables 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
next prev parent reply other threads:[~2021-01-30 12:56 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-29 22:32 Christopher Causer 2021-01-30 8:40 ` Christopher Causer 2021-01-30 12:53 ` Richard Lawrence [this message] 2021-01-30 16:32 ` Christopher Causer 2021-01-30 17:09 ` Richard Lawrence 2021-01-30 22:40 ` Christopher Causer 2021-02-02 5:15 ` Kyle Meyer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=87mtwqziuj.fsf@aquinas \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: clock-table and hooking that into org-capture file+olp+datetree' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this 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).