Using consult-ripgrep with org-roam for searching notes

Hey, sorry for taking a while and thanks for coming back to this!

Unfortunately, this function doesn’t work for me. I don’t know if I’m doing something wrong, but the multiline flag seems to have no impact.

If I have a file like this

foo
bar

and I query by either #foo bar or #foo#bar it doesn’t return the result. Seems to me like it’s still a line-based search.

Thinking about the flag, I suppose it makes sense that that is what it would indeed do.

The solution, I think would be to somehow call ripgrep recursively, while still retaining the Emacs-grep-interface “sugar”.

I think it’s not unclear how to do that in principle, but it may be non-trivial in practice.

Thanks, really cool :slight_smile:

Leaving this snippet here for all spacemacs users:

  (defun tim/counsel-search-org-roam ()
    "Use spacemacs/counsel-search to search the org-roam directory"
    (interactive)
    (spacemacs/counsel-search dotspacemacs-search-tools nil org-roam-directory))
  (spacemacs/set-leader-keys "aors" 'tim/counsel-search-org-roam)

How should consult-ripgrep be installed with doom? It is not mentioned in the documentation of consult.

I think it’s included. Can’t remember having had to install it manually and couldn’t find anything in my config.

I think it comes with the vertico module in init.el.

This is correct.

Then I do not understand why when I do M-x consult I don’t see any of the available functions… Should I enable something? (I did not find vertico anywhere in the init.el).

That’s probably because loading consult is deferred in the vertico module config.

Try any one of the commands that appear, or directly loading it by M-x load-library or evaluating require

What completion module are you using then? Ivy?

You can comment that out, and add “vertico” below it, and then doom sync.

Has consult-ripgrep-command been replaced with consult-ripgrep-args? I am trying to get rg to search only .org files but hitting a roadblock.

UPDATE: in the end, I used the following and it seems to work:
(setq consult-ripgrep-args "rg --null --type org --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number .")

For those of you using a locked down windows environment, if you have access to VS Code it includes ripgrep.
Search for rg.exe

2 Likes

I am using company. Does it mean that if I add vertico it will interfere with company? I do not want to break anything.

No.

I want to try this setup, but I am not sure how to.
I have doom emacs, with a pretty standard configuration, and by looking at the docs it seems that vertico is already installed.
How should I install the proper things?
From what I understand I need to put in my init.el:

(doom! :input
       ;;chinese
       ;;japanese
       ;;layout            ; auie,ctsrnm is the superior home row

       :completion
       company           ; the ultimate code completion backend
       vertico  ;; THIS IS WHAT I NEED TO ADD?
       ;;helm              ; the *other* search engine for love and life
       ;;ido               ; the other *other* search engine...
       ivy               ; a search engine for love and life

and then just use the function defined bms/org-roam-rg-search?

Could you please show me a config example? I am afraid to break things…

Yes, just add that line to your init.el.

But I’m not sure; you may also need to comment out ivy.

1 Like

This is great, thanks for sharing. Does anyone know how I could modify this config to initially narrow the results to exclude certain lines? That is, there are certain lines in my notes that I generally don’t need to see in results (e.g. properties drawers), which end up cluttering the results.

How do I get the completions to show in the minibuffer like the video example shown?

Right now, ‘C-c rr’ will throw a separate Completions list/buffer and I lose the ability to navigate and preview.

I believe it depends on what completion framework you use. I use Vertico and consult-ripgrep just works in a similar way shown in the video as expected – the custom funtion bms/org-roam-rg-research above is a thin wrapper around consult-ripgrep anyway.

If you are using Ivy or Helm, it may not work as expected.