all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* clock-table and hooking that into org-capture file+olp+datetree
@ 2021-01-29 22:32 Christopher Causer
  2021-01-30  8:40 ` Christopher Causer
  0 siblings, 1 reply; 7+ messages in thread
From: Christopher Causer @ 2021-01-29 22:32 UTC (permalink / raw)
  To: orgmode

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 the datetree. When it does so it either creates or updates an org-clock-report at the top of 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] or even from today's date.

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-02  5:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-29 22:32 clock-table and hooking that into org-capture file+olp+datetree Christopher Causer
2021-01-30  8:40 ` Christopher Causer
2021-01-30 12:53   ` Richard Lawrence
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.