emacs: tweak the xref and grep settings for using ripgrep

This commit is contained in:
Protesilaos 2026-08-24 12:26:21 +03:00
parent bf391c6eb1
commit 3ac5eafdf7
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 36 additions and 38 deletions

View file

@ -76,30 +76,29 @@
(prot-emacs-configure
(setq reb-re-syntax 'read)
(let ((ripgrep (or (executable-find "rg") (executable-find "ripgrep"))))
;; All those have been changed for Emacs 28
(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-file-name-display 'project-relative)
(setq xref-file-name-display 'project-relative)
(setq xref-search-program (if ripgrep 'ripgrep 'grep))
(setq grep-save-buffers nil)
(setq grep-use-headings nil) ; Emacs 30
(setq grep-program (or ripgrep (executable-find "grep")))
(setq grep-template
(if ripgrep
"/usr/bin/rg -nH --null -e <R> <F>"
"/usr/bin/grep <X> <C> -nH --null -e <R> <F>")))
(add-hook 'grep-mode #'prot-common-truncate-lines-silently)
;; All those have been changed for Emacs 28
(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
;; The `outline-xref' is for Emacs 32
(with-eval-after-load 'outline
;; The `outline-xref' is for Emacs 32
(define-advice outline-xref (:around (&rest args) prot)
(let ((xref-show-xrefs-function #'xref-show-definitions-completing-read))
(apply args)))))
(apply args))))
(setq grep-save-buffers nil)
(setq grep-use-headings nil) ; Emacs 30
(if-let* ((ripgrep (or (executable-find "rg") (executable-find "ripgrep"))))
(progn
(setq grep-program ripgrep)
(setq xref-search-program 'ripgrep)
(setq grep-template (format "%s -nH --null -e <R> <F>" ripgrep)))
(error "You need to install RIPGREP"))
(add-hook 'grep-mode #'prot-common-truncate-lines-silently))
;;; wgrep (writable grep)
;; See the `grep-edit-mode' for the new built-in feature.

View file

@ -5842,30 +5842,29 @@ Note the use of the ~let~ to decide whether I use the ~grep~ or ~rg~
(prot-emacs-configure
(setq reb-re-syntax 'read)
(let ((ripgrep (or (executable-find "rg") (executable-find "ripgrep"))))
;; All those have been changed for Emacs 28
(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-file-name-display 'project-relative)
(setq xref-file-name-display 'project-relative)
(setq xref-search-program (if ripgrep 'ripgrep 'grep))
(setq grep-save-buffers nil)
(setq grep-use-headings nil) ; Emacs 30
(setq grep-program (or ripgrep (executable-find "grep")))
(setq grep-template
(if ripgrep
"/usr/bin/rg -nH --null -e <R> <F>"
"/usr/bin/grep <X> <C> -nH --null -e <R> <F>")))
(add-hook 'grep-mode #'prot-common-truncate-lines-silently)
;; All those have been changed for Emacs 28
(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
;; The `outline-xref' is for Emacs 32
(with-eval-after-load 'outline
;; The `outline-xref' is for Emacs 32
(define-advice outline-xref (:around (&rest args) prot)
(let ((xref-show-xrefs-function #'xref-show-definitions-completing-read))
(apply args)))))
(apply args))))
(setq grep-save-buffers nil)
(setq grep-use-headings nil) ; Emacs 30
(if-let* ((ripgrep (or (executable-find "rg") (executable-find "ripgrep"))))
(progn
(setq grep-program ripgrep)
(setq xref-search-program 'ripgrep)
(setq grep-template (format "%s -nH --null -e <R> <F>" ripgrep)))
(error "You need to install RIPGREP"))
(add-hook 'grep-mode #'prot-common-truncate-lines-silently))
#+end_src
*** The =prot-emacs-search.el= setup for editable grep buffers (~grep-edit-mode~ or ~wgrep~)