Is there a way to automatically insert parenthesis (or other s-expressions) around a highlighted region by only typing (, {, ",
etc.? I don't want to have to use a key bind (M-(
) for that. It's a common feature in modern text editors like VSCode, so I'm wondering if there is a way to do it in emacs.
Edit: I have delete-selection-mode
on, but in general I want this behavior to trump all others. So if a region is selected, no matter if delete-selection-mode
is on or off, typing the start symbol of an s-expression would wrap the region in the s-expression. I also just realized that electric-pair-mode
includes this feature. But I don't want the other features of electric-pair-mode
, namely that it inserts a pair whenever you type the starting pair, no matter if a region is selected.
(
etc. whenever the region is selected, that seems very limiting. Withdelete-selection-mode
ON it prevents replacing the selected text with that char. With it off, it prevents inserting the char at point. Please give a recipe, saying what you do at each step, what you see now when doing that, and what you want to see instead.