[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
clock-table and hooking that into org-capture file+olp+datetree
From: |
Christopher Causer |
Subject: |
clock-table and hooking that into org-capture file+olp+datetree |
Date: |
Sat, 30 Jan 2021 08:40:12 +0000 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-84-gfc141fe8b8-fm-20210125.001-gfc141fe8 |
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.
An example tree would be
#+BEGIN_QUOTE
* Work
** 2021
*** 2021-01 January
**** 2021-01-07 Thursday
***** Ate some chips
***** Drank some soda
#+END_QUOTE
I tried looking at the org-mode source, and it is too advanced for me to
follow. The closest I can get (or at least here's a scrap of code to prove I
did actually try) is as follows:
#+BEGIN_SRC emacs-lisp
(defun cc/create-or-update-effort-table ()
(save-excursion
(find-file (concat org-directory "/diary.org"))
(goto-char (org-find-olp (list (concat org-directory "/diary.org" ) "Work"
"2021" "2021-01 January" "2021-01-07 Thursday")))
(beginning-of-line)
(next-line)
(if (looking-at-p "[[:space:]]*#\\+BEGIN: clocktable") (forward-word 3)
(progn (insert "\n")(previous-line)))
(org-clock-report)))
#+END_SRC
A lot of beginner missteps there that I'm sure people can correct, but
hopefully you can see the intent. If you see anything amiss please let me know,
but my main problems are:
1. I hardcoded the datetree part whereas I'd like this to be today's date or
even the date picker built into org-mode. I am very far off using the
datepicker to generate ("%Y" "%Y-%m %B" "%Y-%m-%d %A") [3]. This would also be
needed for point 4.
2. I obviously don't understand how markers work well enough because I had to
add the ~find-file~ whereas I would imagine you could just do it all in the
goto-char line, if I knew how to use markers better.
3. The function would fail if the tree doesn't exist. I'd like it created like
org-capture would. Not all clocked items are in my diary, so I may want to run
the function before any diary items exist for today.
4. I would like to customize the variables org-clock-report uses to generate
the report. It looks to be assigned by the defaults ~org-clocktable-defaults~.
The ~:block~ option is the obvious option I'd like to change to a set date. In
other words, I want to change the options in the function above but not use
org-clocktable-defaults unless it reverts after the function is finished.
5. Even if the function above worked, I have no idea how to hook that into
file+olp+datetree. Would I need to switch to file+function and add the clock
table as a side-effect?
The function cc/create-or-update-effort-table has to use olp, not headline, as
the headline "2021-01-07 Thursday" is not unique in the file.
Thank you for taking the time to read this far, and thank you to all the people
who've contributed to Emacs and Org-Mode. I wish I'd discovered them sooner.
Christopher.
[1] https://orgmode.org/manual/Template-elements.html
[2] https://orgmode.org/manual/The-clock-table.html
[3] https://man7.org/linux/man-pages/man1/date.1.html
The links are for my benefit when I come back to this email, rather than anyone
else's, but I guess it doesn't hurt to include them for other people new to
org-mode like myself.