On 03/04/2025 15:15, Mayuresh Kathe wrote:
Would you be in a position to suggest a search tool (inside Emacs) for
going through my content produced and managed via Orgmode and/or Roam?
Something like Google search, but only limited to my local information?
I have never tried the following tool announced on this mailing list
earlier:
org-fts: full text search of your org-mode files with ivy integration
<https://www.reddit.com/r/orgmode/comments/klyzjv/new_package_orgfts_full_text_search_of_your/>
Perhaps some LLM should be tried nowadays instead of trigram indexers,
but I have not experimented yet as well.
For simple searches "git grep" my be more convenient than other grep
successors recursively walking through directories. The point is to
configure git diff tool to recognize Org headings, see
<https://protesilaos.com/codelog/2021-01-26-git-diff-hunk-elisp-org/>
Protesilaos Stavrou. Informative diff hunks for Emacs Lisp and Org.
~/.config/git/config:
[diff "org"]
xfuncname = "^(\\*+ .*|\\s*#\\+[Tt][Ii][Tt][Ll][Ee]:\\s+.*)"
~/.config/git/attributes
*.org diff=org
And you can run
git grep -p PATTERN
More context lines may be added using "-C 5" or even "-W" for whole
heading. To search outside of git repository use the following trick
git -c grep.fallbackToNoIndex=1 grep -p PATTERN
I am experimenting with the following "gigr" wrapper:
#!/bin/sh
# git grep convenience wrapper to show function name or document section
#
# Unfortunately `git grep` has no option to ignore `.git` directory
# completely. Absolute paths and parent directories `..` cause errors.
#
# Recursive by default. The `pathspec` argument is more flexible
# than file or directory argument of grep-like tools.
#
# See git-grep(1) for additional options, for example
# `-C 5` for several context lines or `-W` for whole headings
# text.
# See gitattributes(5) how to set custom patterns
# for function names or section titles.
# TODO:
# $ git grep --no-index -p PATTERN ../OUTSIDE
# fatal: ../OUTSIDE: '../OUTSIDE' is outside repository at
'/CURRENT/GIT/DIR'
# A workaround:
# $ git -C ../OUTSIDE grep --no-index -p PATTERN
# TODO: consider --no-pager
# Make behavior similar to ag(1) (Silver Searcher).
! [ -t 1 ] || set -- --heading --break "$@"
# Use by default
# --show-function
# --ignore-case
# --line-number
exec git -c grep.fallbackToNoIndex=1 grep -pin "$@"