Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs paredit-mode -- how to correct unbalanced parenthesis in yanked code?

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: enter image description here

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?

like image 250
Reed G. Law Avatar asked Oct 08 '14 02:10

Reed G. Law


3 Answers

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.

like image 128
noisesmith Avatar answered Nov 18 '22 05:11

noisesmith


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|)

like image 38
Thomas Wright Avatar answered Nov 18 '22 04:11

Thomas Wright


Trust me. By far the easiest is to paste a bracket or parentheses.

You can do:

    ;  ]

and then copy it

like image 35
mandy1339 Avatar answered Nov 18 '22 05:11

mandy1339