TransWikia.com

Find clocking errors in org-mode entries: list/edit all clock entries with duration until next day(s)

Emacs Asked on December 28, 2021

I discovered the excellent org-analyzer tool and used it to analyze my clock entries in Emacs org-mode.

Unfortunately the results are not usable yet, because there are a lot (dozens) of faulty clock entries. Most of them are "over night", so I worked on something in the afternoon, forgot to clock out and then the clock-out was generated the next morning.

My question: how can I get a list of all clock intervals with 2 different dates, e. g.

CLOCK: [2020-07-24 Fri 15:38]–[2020-07-25 Sat 08:38] => 17:00

  • How can I create a search agenda to list all of them, so that I can fix them manually? Criteria would be 2 different days like in the example above. (Or is there some other way in Emacs to search all .org files in a directory for such entries and easily edit the faulty lines?)

  • or is there already a tool for cleaning up such clock entries in org-mode?

One Answer

Use elgrep which is available on Melpa.

After a successful install, call M-x elgrep-menu or you click on the menu entry ToolsElgrep.

There are two features that make elgrep especially suited for that task:

  1. Specify whole lines that start with CLOCK: as search records.
    • You can do so by setting Beginning of Record to Regexp and typing ^ *CLOCK: into the corresponding text field.
    • Also set End of Record to Regexp and set the text field to $ to specify the end of line as record end.
  2. Instead of a single regexp use a list of regexps with one positive regexp and one negative one.
    • You can leave the positive regexp empty. In that case also CLOCK-lines with missing time stamps or with only a single time stamp are detected.
    • An exclamation mark ! at the beginning of the second regexp negates the regexp. That means that only such records are listed that match the first regexp but not the second one. Behind the ! use a regexp that matches a time interval starting and ending on the same day, i.e., including the exclamation mark
      ![([0-9]{4}-[0-9]{2}-[0-9]{2}).*]--[1.*].

You get all the above settings automatically if you paste the following line into the first Form: line of the Elgrep call list and click the [SET] button above the input field.

(elgrep/i "~/" "\.org\'" ("" "!\[\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\).*\]--\[\1.*\]") :r-beg "^ *CLOCK:" :r-end "$" :async t)

You just need to replace ~/ in the text field for Directory with the right path. Completion by M-TAB works in that text field.

If you need that kind of search more often for a certain directory I suggest you run the search once and afterwards give the search a name in the Elgrep call list. Those named Elgrep calls are preserved in the call list and you can even directly run them with the [RUN] button.

The search results are listed in the *elgrep* buffer. That buffer has an Elgrep menu where you can activate Elgrep-edit (bound to C-c C-e). Afterwards you can edit the clock lines to your liking and save the buffer with C-x C-s. This modifies and saves the matching lines of the original buffers.

Background info: Named elgrep calls are automatically stored in the elgrep-data-file relative to the user-emacs-directory.

Answered by Tobias on December 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP