Skip to content

Instantly share code, notes, and snippets.

@jthaman
Last active October 18, 2025 22:29
Show Gist options
  • Save jthaman/c4eb411defc98f82cfd85c8c0d4c67e0 to your computer and use it in GitHub Desktop.
Save jthaman/c4eb411defc98f82cfd85c8c0d4c67e0 to your computer and use it in GitHub Desktop.
Call ripgrep-all in emacs with consult
;; New versions of consult make this dramatically simpler than it used to be. Just one function that you can bind to a key:
;;;###autoload
(defun consult-ripgrep-all (&optional dir initial)
(interactive "P")
(let ((consult-ripgrep-args "rga --null --line-buffered --color=never --max-columns=1000 --smart-case --no-heading --with-filename --line-number"))
(consult-ripgrep dir initial)))
@arstum
Copy link

arstum commented Jan 3, 2023

Debugger entered--Lisp error: (void-function consult--ripgrep-builder)

@jthaman
Copy link
Author

jthaman commented Jan 4, 2023

The error means that you don't have `consult--ripgrep-builder' installed on your system. It is because the Consult author renamed it. I tried to fix plz check.

@arstum
Copy link

arstum commented Jan 5, 2023

What the script running version of consult?

@fountainer
Copy link

I tried the code and it works well. However, it would be better if it can jump to the specified page when selecting the candidate pdf file.

@jthaman
Copy link
Author

jthaman commented May 31, 2023

That would definitely be a usability improvement! I'm open to suggestions.

@fountainer
Copy link

That would definitely be a usability improvement! I'm open to suggestions.

I don't have much knowledge of elisp, consult or embark. So I don't have good suggestions. :)

@jthaman
Copy link
Author

jthaman commented Jun 2, 2023

same, same.

@g-simmons
Copy link

ty for posting! probably saved me an hour or more 👍

@gvalson
Copy link

gvalson commented Aug 5, 2025

Thanks for sharing this! This still works.

@Zaijab
Copy link

Zaijab commented Aug 21, 2025

@jthaman @fountainer

For the PDF page upon selection, you can try this (requires pdf-tools):

(defun pdf-consult-ripgrep-all (&optional dir initial)
  (interactive "P")
  (let* ((consult-ripgrep-args "rga --null --line-buffered --color=never --max-columns=1000 --smart-case --no-heading --with-filename --line-number")
	 (result (consult-ripgrep dir initial)))
    (when (and result (string-match "\\([^:]+\\.pdf\\).*page \\([0-9]+\\)" result))
      (pdf-view-goto-page (string-to-number (match-string 2 result))))))

There's still room for improvement. It does not take you to the page during the preview. I'll leave that for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment