Hi there,

I use orgmode links extensively. In particular, I have hundreds (our thousands) of links to emails (in notmuch). I would very much like to add a tag to any email that is being referenced from org.

So, what I need to do first is be able to find all matches of a regular expression in all my org files. Non-interactively.

I have been playing around with xref-matches-in-directory but that would not cover when multiple emails are mentioned in the same line…

I have been looking and looking but everything I find missed the non-interactive part.

So: What is the function to “search for this REGEX in FILES in DIR and return the first capture group”? (the regex has a capture group for the msgid)

The regex:

  (rx-to-string
   (rx "notmuch:id:"
       (group (1+ (not "]")))))
      • telenieko@alien.topOPB
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        It’s an opportunity to learn more lisp!

        I do currently have a shell script using ripgrep & notmuch-tag, but felt it could be an interesting problem to solve within Emacs :)

        • mmaug@alien.topB
          link
          fedilink
          English
          arrow-up
          1
          ·
          11 months ago

          The lispy/emacs-like solution is to open each file, search it, and close it. Don’t optimize too early. Build the simplest most straightforward implementation and then worry about performance. But understand why the most emacs-like solution fails.