There was a post in this discourse many years ago on how to enable org-roam search with consult and ripgrep, the variable which enabled the function to work is now deprecated and will no longer work. Since the comments are many pages long and no activity has taken place for a certain amount of time I decided it would be better to open a new topic and post a working piece of code, since most users will not take the time to scroll to the end of the page.
Provided consult is installed inside Emacs, and ripgrep (rg) is available as a system package, the following code maybe used in the init file:
(defun org-roam-search ()
"Search org-roam directory using consult-ripgrep. With live-preview."
(interactive)
(let ((consult-ripgrep-args "rg --null --ignore-case --type org --line-buffered --color=never --max-columns=500 --no-heading --line-number"))
(consult-ripgrep org-roam-directory)))
(global-set-key (kbd "C-c f s") 'org-roam-search)
Explanations:
-
The original code used the variable
consult-ripgrep-command
: this is no longer valid. Instead we use the variable consult-ripgrep-args.
This variable is responsible for passing arguments to ripgrep (rg) -
The original code used
--color=always
, this causes the search to breakdown and show no matches. (why? idk), instead we may use either--color=auto
or--color=never
-
(let ((var "value")) --code to which this is visible)
allows us to temporarily change the value of a variable, we might as well have used setq
, but using let
has the upshot of allowing us to use M-x consult-ripgrep
in default-directory without these customisations - such as searching inside html/tex files and so on.
-
Customisations to the code can be easily done - look into
rg --help
in the system terminal and apply those options as may be required. For example:4.a) If we want to exclude our âjournalâ folder inside org-roam-directory we can use the option
--glob=!{journal/*}
as a argument toconsult-ripgrep-args
.4.b) If we want to exclude all sub-folders named âfoobarâ where-ever they exist inside
org-roam-directory
we can use--glob=!{foobar}
4.c) To exclude the âjournalâ folder & all folders named âfoobarâ we can use
--glob=!{journal/*,foobar}
and so on. -
If there is a PATTERN that exists in one file only, the auto-completion (live preview) may not work as intended. In that case, it is recommended to nest the PATTERN inside two #, for example #foo#, pressing âTabâ then will list all the instances inside that file as one would normally expect!