Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't type an empty string with single or double quotes #2097

Closed
benwbooth opened this issue Jun 23, 2015 · 8 comments
Closed

Can't type an empty string with single or double quotes #2097

benwbooth opened this issue Jun 23, 2015 · 8 comments

Comments

@benwbooth
Copy link
Contributor

I've tried this both in cperl mode and in sql mode:

If I try to type an empty string, e.g. "" or '', I can't do it. The first " or ' character creates a pair of quotes with the cursor inside it. But if I try to press the quote character again, it creates another pair. This only happens with empty strings. If I type, for example, "dog", the second quote is skipped when I press the " key. I would expect that, if I press the " key twice, I would get "", instead, I get """".

@TheBB
Copy link
Collaborator

TheBB commented Jun 24, 2015

I'm pretty sure this is intended behaviour from smartparens. Otherwise, you would have a hard time inserting e.g. Python multiline strings ("""blabla""").

@hijarian
Copy link
Contributor

The title "can't type an empty string with single or double quotes" is kinda misleading. Obviously, you can, and even easier than without smartparens-mode. Annoying part is in different place: that you have to ESC l i or C-f to put the cursor after the second quote and continue writing.

@TheBB
Copy link
Collaborator

TheBB commented Jun 24, 2015

You have to do ESC l a actually (ESC i moves point backwards). But I usually get around it with C-f.

@sooheon
Copy link

sooheon commented Jun 24, 2015

This is a bad default. I didn't notice it because I have lispy override some smartparens pair management, but the expected result of pressing " inside a quote pair should always be consistent. If it's intended, I think it should be changed. It shouldn't matter whether the string is empty or not, typing " just before the closing quote should take you out of the string.

One way to reason about it is that should a person choose to close all his pairs manually (i.e. type out every closing " and )), it should behave no differently than if he didn't have a pair management package installed. If this principle is held to, you would have no trouble typing Python multiline strings:

  1. 3 * " gives you """|"
  2. after typing contents, 3 more " gives you """blabla"""|

This is exactly the same as typing out multiline strings with no pair management, and functionally the same as:

  1. 3 * " giving you """|"""
  2. and then 3 more " to leave the string """blabla"""|

The only difference is that currently, there is additional overhead on the user to remember that only empty strings should be treated differently, having to press C-f, right arrow, or even escape to normal mode just to keep typing.

Another way of thinking about this is that smartparens should offer you pair completions, which you can always confirm by actually pressing " or ) or implicitly accept by navigating elsewhere. It shouldn't force you to change the way you type for no extra benefit.

@TheBB
Copy link
Collaborator

TheBB commented Jun 24, 2015

In any case, here's the upstream issue.

I should note that @sooheon's solution only works well for strings delimited by an odd number of quotation marks. If there's an even number, e.g. two times " gives you just ""|, with no closing quotes.

@sooheon
Copy link

sooheon commented Jun 24, 2015

@TheBB That isn't any real problem, because from ""foo|, you can just type " twice to get to ""foo""|. Which is exactly what you would do with no special minor mode, and therefore what the default should be.

@TheBB
Copy link
Collaborator

TheBB commented Jun 24, 2015

I agree it's not huge, but you don't get the auto-closing pairs.

One way to reason about it is that should a person choose to close all his pairs manually (i.e. type out every closing " and )), it should behave no differently than if he didn't have a pair management package installed.

And another way to reason is that with a pair management package installed, a person should be able to choose not to close all pairs manually.

I've yet to see a solution to this problem that checks all the checkboxes.

@Fuco1
Copy link

Fuco1 commented May 21, 2016

Hi. Today I've fixed a related issue so now the expected behaviour should be for the second quote to always move out of the pair. It was caused by a rather obscure bug I've configured around somehow and never realized it was actually a bug :/

The python issue is solved separately by adding a pair """...""" which you get after typing three quotes (first and second insert an empty string and the third triggers the tripple-pair). This is possible because we now allow pairs with shared prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants