Courtesy of a post from the_cecep over at the Emacs subreddit, I just discovered a builtin gem I didn’t know about. The post is about the delete-pair function. The idea is that you have some text surrounded by a pair of delimiters and you’d like to delete the surrounding delimiters.
That’s something that I sometimes want to do but it gets better. The_cecep shows how to quickly change (foo) to [foo] with delete-pair. That’s something that I want to do less frequently than simply deleting the delimiters but it’s still useful.
Take a look at the_cecep’s post for some more examples and a few details. He also recommends that because delete-pair is unbound you should bind it to Ctrl+Meta+z, which he thinks of as “zap pair”. That seems like a good suggestion to me.
There’s a couple of things worth noting:
- Although the post doesn’t make it clear, you don’t need to select the expression if you just want to delete the delimiters.
- You can set
delete-pair-blink-delayto 0 to disable the delay if you don’t want it. The default is 1 second so you should at least set it to a smaller value as the_cecep suggests.
I’m really happy to learn about delete-pair. It’s not something I’m going to use every day but I will use it often enough to internalize it.