Fork me on GitHub
#emacs
<
2021-03-12
>
bmaddy19:03:34

Here's a puzzler for someone. I need to change this

[datomic.api ...][wrapper.datomic.api ...]
to this
[datomic.api ...]
            [wrapper.datomic.api ...]
in 217 different files. I tried helm-ag-edit, but it didn't let me create newlines. Is there an easy way to do this in emacs?

dotemacs09:03:22

Don’t know about that package, but if you’re entering a newline try C-q C-j, it should enter a newline. But you can also do this, if you’re just replacing a ][ with ]\n[: M-x replace-regexp RET ][ RET ] C-q C-j[ RET

bmaddy19:03:10

Nice, that would have been great for adding the newline. I ended up using sed and then manually indenting each file. Thanks for the suggestion!

mpenet19:03:10

consult-git-grep + embark occur, then wgrep on the occur buffer

bmaddy19:03:46

I've never heard of these. I'll look into them. Thanks!

bmaddy19:03:32

Yeah, something like this is my fallback. I was just hoping I wouldn't have to write code for it. I have to learn sed over from scratch every time I use it. 🙂

andy.fingerhut19:03:16

At least some ways of doing string search and replace in Emacs let you type Ctrl-Q Ctrl-J in the middle of a replacement string to mean a newline

andy.fingerhut19:03:33

well, anywhere in the replacement string I mean, not just the middle.

andy.fingerhut19:03:20

Ctrl-Q being an Emacs 'escape' character prefix kind of thing, and Ctrl-J being the ASCII code for a newline

thanks3 3
lukasz19:03:43

I had to write a post-it note with the C-q C-j thing as I never remembered it. @U067Q76EP other (I'd say preferable) approach is to get the cljstyle binary and run it against the whole codebase.

bmaddy19:03:54

I just tried the c-q c-j thing in helm-ag-edit. Sadly, the newline it adds doesn't make it to the actual edit, so the line just gets truncated. Good idea though and I'm really happy to have found that key combo! I've been trying to figure that out for years. 😂