Set the default xref-search-program to ripgrep

This commit is contained in:
Vedang Manerikar 2024-11-23 09:40:28 +05:30
parent 32dcfd850d
commit 7394e7395e
2 changed files with 38 additions and 30 deletions

View file

@ -2323,7 +2323,7 @@ Here I am making some minor tweaks to =*occur*= buffer (remember to
read the introduction to this section ([[#h:e0f9c30e-3a98-4479-b709-7008277749e4][The =unravel-search.el= module]])). read the introduction to this section ([[#h:e0f9c30e-3a98-4479-b709-7008277749e4][The =unravel-search.el= module]])).
I always want (i) the cursor to be at the top of the buffer, (ii) the I always want (i) the cursor to be at the top of the buffer, (ii) the
current line to be highlighted, as it is easier for selection current line to be highlighted, as it is easier for selection
purposes ... purposes ...
#+end_quote #+end_quote
#+begin_src emacs-lisp :tangle "unravel-modules/unravel-search.el" #+begin_src emacs-lisp :tangle "unravel-modules/unravel-search.el"
@ -2360,37 +2360,41 @@ purposes ...
:END: :END:
#+begin_src emacs-lisp :tangle "unravel-modules/unravel-search.el" #+begin_src emacs-lisp :tangle "unravel-modules/unravel-search.el"
;;; grep and xref ;;; grep and xref
(use-package re-builder (use-package re-builder
:ensure nil :ensure nil
:commands (re-builder regexp-builder) :commands (re-builder regexp-builder)
:config :config
(setq reb-re-syntax 'read)) (setq reb-re-syntax 'read))
(use-package xref (use-package xref
:ensure nil :ensure nil
:commands (xref-find-definitions xref-go-back) :commands (xref-find-definitions xref-go-back)
:config :config
;; All those have been changed for Emacs 28 ;; All those have been changed for Emacs 28
(setq xref-show-definitions-function #'xref-show-definitions-completing-read) ; for M-. (setq xref-show-definitions-function #'xref-show-definitions-completing-read) ; for M-.
(setq xref-show-xrefs-function #'xref-show-definitions-buffer) ; for grep and the like (setq xref-show-xrefs-function #'xref-show-definitions-buffer) ; for grep and the like
(setq xref-file-name-display 'project-relative)) (setq xref-file-name-display 'project-relative)
(setq xref-search-program (if (or (executable-find "rg")
(executable-find "ripgrep"))
'ripgrep
'grep)))
(use-package grep (use-package grep
:ensure nil :ensure nil
:commands (grep lgrep rgrep) :commands (grep lgrep rgrep)
:config :config
(setq grep-save-buffers nil) (setq grep-save-buffers nil)
(setq grep-use-headings t) ; Emacs 30 (setq grep-use-headings t) ; Emacs 30
(let ((executable (or (executable-find "rg") "grep")) (let ((executable (or (executable-find "rg") "grep"))
(rgp (string-match-p "rg" grep-program))) (rgp (string-match-p "rg" grep-program)))
(setq grep-program executable) (setq grep-program executable)
(setq grep-template (setq grep-template
(if rgp (if rgp
"/usr/bin/rg -nH --null -e <R> <F>" "/usr/bin/rg -nH --null -e <R> <F>"
"/usr/bin/grep <X> <C> -nH --null -e <R> <F>")) "/usr/bin/grep <X> <C> -nH --null -e <R> <F>"))
(setq xref-search-program (if rgp 'ripgrep 'grep)))) (setq xref-search-program (if rgp 'ripgrep 'grep))))
#+end_src #+end_src
** The =unravel-search.el= setup for editable grep buffers (~grep-edit-mode~ or ~wgrep~) ** The =unravel-search.el= setup for editable grep buffers (~grep-edit-mode~ or ~wgrep~)

View file

@ -64,7 +64,11 @@
;; All those have been changed for Emacs 28 ;; All those have been changed for Emacs 28
(setq xref-show-definitions-function #'xref-show-definitions-completing-read) ; for M-. (setq xref-show-definitions-function #'xref-show-definitions-completing-read) ; for M-.
(setq xref-show-xrefs-function #'xref-show-definitions-buffer) ; for grep and the like (setq xref-show-xrefs-function #'xref-show-definitions-buffer) ; for grep and the like
(setq xref-file-name-display 'project-relative)) (setq xref-file-name-display 'project-relative)
(setq xref-search-program (if (or (executable-find "rg")
(executable-find "ripgrep"))
'ripgrep
'grep)))
(use-package grep (use-package grep
:ensure nil :ensure nil