Is there a function to search for a heading in all org-mode files in all known Projectile projects?
I see that I can search for a string, but can I restrict it to an org-mode heading?;)
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityOne way to achieve it is by taking inspiration from the project-find-regexp
function. Instead of using files from the project, or from a directory, we give it all org files from all projectile-known-projects
:
(defun my-search-heading-across-projects ()
(interactive)
(let ((files (seq-filter (lambda (b) (string-match "org$" b))
(mapcan (lambda (root)
(mapcar (lambda (f)
(concat root f))
(projectile-project-files root)))
projectile-known-projects))))
(xref-show-xrefs
(apply-partially #'project--find-regexp-in-files "^\\*+" files)
nil)))
This function will list all headings. You can then search for the heading using isearch
(or narrow down if you use some completion framework like ivy/helm i.c.w. helm-xref / ivy-xref), and subsequently jump to the 'selected' heading by pressing RET
.
Projectile
provides a way to list all its projects, but Org mode certainly does not provide a way to list all Org mode files - AFAIK the only exception is the set of Org mode files that contribute to the agenda, which is stored inorg-agenda-files
. So you will probably have to collect the set of files in other ways. Once you have that set, you can loop over them and e.g. doC-c / m ITEM={foo}
on each one: this command creates a sparse tree with the matching headlines unfolded. It's probably OK as an interactive method, but it might be awkward as a bulk method.