spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Auto-indent in multi-line strings #14908

Open sphh opened 3 years ago

sphh commented 3 years ago

Issue Report Checklist

Problem Description

Whenever I am pressing Enter when I am between parentheses () in any multi-line string (""" """), spyder autoindents the next line and I have to press backspace repeatedly to get to the beginning of the line.

What steps reproduce the problem?

There are different cases, depending where the cursor is, when you press Enter (I marked the cursor position with ¦):

  1. In the first line:
    """Spyder is great (¦
    """

    becomes after pressing Enter

    """Spyder is great (
    ¦
    """
  2. In any other line:
    """Spyder is great
    Spyder is great (¦
    """

    becomes after pressing Enter

    """Spyder is great.
    Spyder is great (
        ¦
    """
  3. If you already have some text after the opening parenthesis - first line:
    """Spyder is great (really|
    """

    becomes after pressing Enter

    """Spyder is great (really
    ¦
    """
  4. … but in every other line:

    """Spyder is great.
    
    Spyder is great (really¦
    """

    becomes after pressing Enter

    """Spyder is great.
    
    Spyder is great (really
                     ¦
    """
  5. With an open quotation mark (it does not matter, if it is a " or ') before the opening parenthesis, everything works like expected:

    """Spyder is great.
    
    Spyder is "great (really¦
    """

    becomes after pressing Enter

    """Spyder is great.
    
    Spyder is "great (really
    ¦
    """
  6. The same behaviour can be observed with square and curly brackets [] and {}.

What is the expected output? What do you see instead?

It would be great, if the cursor gets positioned always at same column as the beginning of the previous line.

Exceptions are, when the line starts with >>> or ....

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=7.6.0                 :  7.21.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  23.0.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.6.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.5.1 (OK)
pygments >=2.0                  :  2.8.1 (OK)
pylint >=1.0                    :  2.7.2 (OK)
pyls >=0.36.2;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.3.2             :  0.3.2 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.2 (OK)
qtconsole >=5.0.1               :  5.0.2 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
setuptools >=39.0.0             :  54.1.1 (OK)
sphinx >=0.6.6                  :  3.5.2 (OK)
spyder_kernels >=1.10.2;<1.11.0 :  1.10.2 (OK)
textdistance >=4.2.0            :  4.2.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0        :  1.0.2 (OK)
xdg >=0.26                      :  0.26 (OK)
zmq >=17                        :  22.0.3 (OK)

# Optional:
cython >=0.21                   :  None (NOK)
matplotlib >=2.0.0              :  3.3.4 (OK)
numpy >=1.7                     :  1.20.1 (OK)
pandas >=1.1.1                  :  1.2.3 (OK)
scipy >=0.17.0                  :  1.6.1 (OK)
sympy >=0.7.3                   :  1.7.1 (OK)
dalthviz commented 3 years ago

Hi @sphh thanks for the feedback! I was able to reproduce this, I'm not totally sure but seems like the auto-indentation is just taking into account if the line has " to apply or not the indent (so my guess is that we are not properly supporting multi-line strings yet)