11

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?

Community
  • 1
  • 1
Reed G. Law
  • 3,897
  • 1
  • 41
  • 78
  • 3
    Turning off `paredit-mode` sounds like a good idea, to me. ;-) (But why stop with doing it temporarily?) – Drew Oct 08 '14 at 02:33
  • 1
    @Drew I happen to like it most of the time ;) – Reed G. Law Oct 08 '14 at 03:08
  • Yeah, I know. Some do; some don't. – Drew Oct 08 '14 at 03:09
  • 1
    Using ``mark-sexp``, bound to ``C-M-SPC``, to mark the region you are yanking can help avoid the problem in the first place. – sw1nn Oct 08 '14 at 05:08
  • Sometimes I am copying text from a website such as a README on Github. – Reed G. Law Oct 08 '14 at 07:40
  • 1
    Consider using something like [`expand-region`](https://github.com/magnars/expand-region.el) to select text semantically. This will help you copy balanced parens, so yanking shouldn't complain so much. Not a solution, but it might help to reduce the problem. – ChrisGPT was on strike Oct 08 '14 at 12:12

4 Answers4

12

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.

noisesmith
  • 20,076
  • 2
  • 41
  • 49
  • 1
    One deletes an arbitrary region of text, the other inserts any character you like - I don't see what's missing there. – noisesmith Oct 08 '14 at 04:46
  • `quoted-insert` seems to be more of a way to type non-ASCII characters. I couldn't get it to paste text from the clipboard. – Reed G. Law Oct 08 '14 at 07:39
  • 8
    @ReedG.Law: Use `C-q`, then enter the closing bracket at the desired destination and paredit won't do the jump. – Leon Grapenthin Oct 08 '14 at 08:15
  • @LeonGrapenthin Ahh, I see now! Sorry for the confusion. – Reed G. Law Oct 08 '14 at 08:26
  • I do not see a `quoted-insert` action any where in the IntelliJ config. I used the search boxes and I also manually checked under "Editor" and "Keymap" – Jason Apr 15 '16 at 15:15
5

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

Thomas Wright
  • 86
  • 1
  • 1
3

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

You can do:

    ;  ]

and then copy it

mandy1339
  • 496
  • 3
  • 11
0

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

ctpenrose
  • 1,467
  • 2
  • 18
  • 28