💾 Archived View for idiomdrottning.org › ready-made-regexp captured on 2024-03-21 at 15:29:29. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-11-14)
-=-=-=-=-=-=-
Here are five Emacs functions that let you do stuff to words, vars, lines, sentences, or paragraphs.
They’re called replace-word, replace-line, replace-paragraph, replace-var and replace-sentence. They have the same semantics as replace-regexp does, i.e. if the region is active it only affects stuff in there, otherwise it’ll affect from point to end-of-buffer.
The difference from replace-regexp is that here the regex is ready-made for you. It only prompts for a replacement. So if you wanna replace all words with “foo”, you just run replace-word and type foo and you’re done. Not very useful? But \& contains the match! So if you want to quote all words individually, you replace-word with "\&", or of you want to wrap all paragraphs in square brackets you replace-paragraph with [\&] or if you wanna reverse each line you replace-line with \,(reverse \&) and so on. Fun fun fun.♥
(A var is a word that can contain _ or - and end with ? or !)
Typing “M-x replace-word” is more annoying than typing the actual regex, I get that, but you can bind these.
Here’s how to install it with straight.el.
(push '(idi "idiomdrottning.org" "") straight-hosts) (straight-use-package '(ready-made-regexp :host idi :repo "ready-made-regexp"))
With other package systems, I don’t know, but you can get a repo with:
git clone https://idiomdrottning.org/ready-made-regexp