Sathish
Sathish

Reputation: 21080

How to delete extra parens in Paredit mode?

I'm using Paredit in Emacs to edit Lisp code. How do I delete an extra pair of parens that I accidentally inserted? Paredit does not allow this without extra commands.

((square 5)) into (square 5)

Upvotes: 40

Views: 12482

Answers (4)

bensisva
bensisva

Reputation: 3

The paredit wont let us deleting parens while there is any elements inside. My trick is to cut the the right code and paste it to other place adjacent. It will leave the extra parens empty, then now I can delete it. Actually the right way is using M-s to reindent it. Conversely we can insert single paren using C-q ( or C-q }.

Upvotes: 0

Michiel Borkent
Michiel Borkent

Reputation: 34820

This is called paredit-splice-sexp, keybinding is M-s. Take a look at the paredit cheat sheet here.

Upvotes: 65

Jisang Yoo
Jisang Yoo

Reputation: 3745

If I realized accidental extra parens right after inserting those extra parens, I would invoke the undo command. If I saw the extra parens much later, then there are paredit commands for fixing it as other answers specified, but if I did not know those commands, then I would have put point somewhere within the inner form, and then typed the following, provided that CUA mode is on.

C-M-u C-M-SPC C-x <timeout> <left> C-M-SPC C-v

Upvotes: 1

Phil Lord
Phil Lord

Reputation: 3057

Read up on barfage and slurpage.

You can also installed "paredit-menu.el" which provides a menu of actions, with tooltips that show you their effects.

Paredit occasionally gets you into a situation when the easiest thing to do is to turn it off, fix everything and turn it on again. However, it is worth the effort.

Upvotes: 4

Related Questions