Fork me on GitHub
#emacs
<
2022-02-15
>
vemv12:02:30

What do you all use for "project-wide search and replace"? I hacked something highly to my liking based on helm-ag back in 2017 (which worked with ag and rg alike). However that only works in Emacs 25 (or 26 sometimes), which I managed to keep using quite flawlessly until these days - now it's much less of a viable option. I reckon my requirements are simple: • Search project-wide, ideally honoring rg ignore rules or at least .gitignore • Preview each found match as a single line in some sort of UI • I can adjust my search query, and results/preview are updated real-time • Replace all occurrences with an input that is asked interactively, after I got to see the preview of the found results Ideas welcome!

pavlosmelissinos13:02:27

deadgrep is awesome for "project-wide search", the replace part I still do manually 😄 Apparently it has https://github.com/Wilfred/deadgrep#beta-features (beta) which allows you to "edit files directly from results buffers" but I haven't tried it

👀 1
mpenet14:02:17

you can do that with vertico (interactive list) + consult-git-grep (project wide search, with live preview) + embark (to export the list in new buffer) + wgrep (edit results in buffer)

👀 1
mpenet14:02:28

sounds complicated but it's not

🌀 1
practicalli-johnny14:02:43

helm-ag works fine for me, usually coupled with iedit when editing the changes that are found. I havent needed anything more https://practical.li/spacemacs/spacemacs-basics/evil-tools/replacing-text-across-projects.html

practicalli-johnny14:02:17

I have ripgrep binary installed, so can use its filtering patterns in the initial search https://practical.li/spacemacs/spacemacs-basics/working-with-projects/searching-projects.html

mpenet14:02:39

consult can work with ag/rg/gitgrep/grep, you have the choice

mpenet14:02:16

in my experience git-grep gets the most relevant results and is often the quickest

vemv15:02:59

Thanks! from what I remember, with vanilla helm-ag too many steps were involved, hence my tweaking which IIRC halved the involved steps. I really appreciate a 'streamlined' workflow which I can eventually master by muscle memory, I guess I can use vanilla helm-ag again, and tweak again the bits that seemed redundant. Hacking from scratch sure is more effective than reverse-engineering whatever I did 5y ago :)

ericdallo16:02:55

doom-emacs uses vertico with ripgrep under the hood and it works amazingly well

👀 1
mpenet07:02:56

most of the modes from vertico author are really well done (consult, marginalia, corfu, etc), and they all compose nicely.

emacs 1
vemv07:02:45

Nice! Do you have a search-and-replace wrapped under a defun or such? I'd be less enthusiastic about understanding/debugging each step from scratch

mpenet08:02:00

I just trigger consult-git-grep via a binding, the results show via vertico in the minibuffer, then once I am happy with the selection I trigger embark-export to get all the matches in a separate buffer via another binding and just edit the buffer contents, save, done

mpenet08:02:11

it's very quick

mpenet08:02:56

consult-git-grep + vertico is useful for other things, you can use that to navigate around, vertico will do a buffer preview as you go up/down the matches in the minibuffer

anonimitoraf03:02:57

I use cousel-rg + ivy-occur (setting ivy-calling to t when I want to preview each search result's file and also allows me to do mass edit)