2

I'm clocking the time spent on daily tasks like email and for that I have a "Daily Routine" TODO entry. Clocking in this task adds a new clock line everyday, leading to a very populated CLOCK drawer. I'd like to limit its size by either a maximum number of clock entries by removing the older ones or better, removing the entries older than some date. Ideally, I'd like to find a function that tidies the clock drawer of an entry, to be added to the clock-in or clock-out hook.

Any idea how to achieve that ?

1

Have a look at org-clock-remove-empty-clock-drawer. It uses org-map-tree and a regular expression based on org-clock-drawer-name to find the :LOGBOOK: drawers.

You can use the same logic to get point to the start of :LOGBOOK: and then handle all CLOCK: entries on a line-by-line basis. To parse the timestamps, you can use org-ts-regexp-both and org-element-timestamp-parser. Afterwards, you can use kill-whole-line to get rid of the entry.

So in short:

  1. Find the next :LOGBOOK: via re-search-forward
  2. Go forward a single line
  3. Check the start of the line.
    • If it starts with :END:, stop the clock handling for the current drawer
    • If it starts with CLOCK:, search for the next timestamp.
      1. If it's too old, remove the whole line with kill-whole-line.
      2. Otherwise continue to the next line
    • goto 3.
1
  • Thanks, those are very good pointers. I'll try and come up with something. – wilk Mar 24 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.