Use elgrep which is available on Melpa.
After a successful install, call M-x elgrep-menu
or you click on the menu entry Tools
→ Elgrep
.
There are two features that make elgrep
especially suited for that task:
- 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.
- 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
.