emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Christopher Causer" <ml-emacs-orgmode@chyc.co.uk>
To: orgmode <emacs-orgmode@gnu.org>
Subject: clock-table and hooking that into org-capture file+olp+datetree
Date: Sat, 30 Jan 2021 08:40:12 +0000	[thread overview]
Message-ID: <85e0ac65-f4b6-4212-95bf-2bc24671de06@www.fastmail.com> (raw)
In-Reply-To: <79daebf0-5bda-473a-b289-392fd0c8df18@www.fastmail.com>

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.


  reply	other threads:[~2021-01-30  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=85e0ac65-f4b6-4212-95bf-2bc24671de06@www.fastmail.com \
    --to=ml-emacs-orgmode@chyc.co.uk \
    --cc=emacs-orgmode@gnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).