Reputation: 3945
Occasionally I yank code into a paredit-mode
buffer that is missing a closing parenthesis or bracket. paredit-mode
then detects the unclosed expression and tries to add the missing paren in the wrong place. This is frustrating when I move the cursor to the point where I want the close paren but I can't put it there. I end up having to switch off paredit-mode
.
Here's an example:
I've just yanked
[["https://github.com/aconbere/yesql.git"
"aea69ebd4a7788a66fc8689fea7e806f1463c347"]
but paredit-mode
sees a missing )
at the very end (in red). I'm not even sure why it wants to use a close parens when the opening is a bracket. Typing ]
at the point makes the cursor jump to the end and try to fill in the red paren. Slurping or barfing don't have the intended effects and simply move the )
around.
Is there any way to fix this without temporarily disabling paredit-mode
?
Upvotes: 12
Views: 4461
Reputation: 516
Trust me. By far the easiest is to paste a bracket or parentheses.
You can do:
; ]
and then copy it
Upvotes: 3
Reputation: 106
Others have already mentioned C-q
for quoted-insert. You can also use C-u DEL
or C-u C-d
to override paredit's normal balanced behavior of DEL
and C-d
for a single deletion:
(foo)|)
C-u DEL
(foo|)
Upvotes: 7
Reputation: 1585
When you have unbalanced parenthesis, navigate to the character position you wish to place the balancing parenthesis, issue M-x quoted-insert
(bound by default to C-q
), and then enter the balancing parenthesis. quoted-insert
will not prevent parenthesis from being issued.
Same idea as noisesmith said differently. Turning paredit on and off is not an option :)
Upvotes: 0
Reputation: 20194
kill-region
(bound by default to C-w
) and quoted-insert
(bound by default to C-q
) are unaffected by paredit mode. You can delete regions or insert matching delimiters using these keybindings, bypassing paredit rules. Remember that you can also turn off paredit, clean something up, and then turn it back on again.
Upvotes: 13