language-python icon indicating copy to clipboard operation
language-python copied to clipboard

Auto indent on line continuation with list/tuple

Open alvinchow86 opened this issue 10 years ago • 49 comments

Pressing enter after continuing a list or tuple on a second line. It should either auto indent one tab, or to the first char of the previous item, but it just goes to the beginning of the line. Manually pressing auto indent (Lines->Auto Indent, or cmd+i), doesn't do anything.

image

should be either

somefunc(bar,
    m)

or

somefunc(bar,
         m)

alvinchow86 avatar Apr 29 '14 02:04 alvinchow86

I vote for:

f = function(foo,
   bar)

rougeth avatar Apr 29 '14 03:04 rougeth

Actually, that is not a good example since it's not recommended in PEP8:

# Shouldn't be used:

# Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
    var_three, var_four)

# Further indentation required as indentation is not distinguishable.
def long_function_name(
    var_one, var_two, var_three,
    var_four):
    print(var_one)

But, for the recommended ones, this change would help:

# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

# More indentation included to distinguish this from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

# Hanging indents should add a level.
foo = long_function_name(
    var_one, var_two,
    var_three, var_four)

rougeth avatar May 02 '14 02:05 rougeth

+1 for this and I also vote for following the PEP8 guidelines. The following indentation is usually what other editors use:

# More indentation included to distinguish this from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

sebdah avatar Aug 04 '14 13:08 sebdah

+1

My vote is for these two:

# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
                         var_three, var_four)

# More indentation included to distinguish this from the rest.
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)

thelastnode avatar Nov 07 '14 10:11 thelastnode

+1

TakenPilot avatar Feb 17 '15 12:02 TakenPilot

+1

denisgarci avatar Apr 24 '15 12:04 denisgarci

I was this close to replacing Emacs with Atom but I cannot use an editor that doesn't get autoindent right.

PEP8 compliance is obviously the only right choice, anything else would be unacceptable. Where PEP8 allows leeway, just do the base case:

[1, 2, 3
 4, 5, 6]

[
  1, 2, 3
  4, 5, 6
]

mattdeboard avatar Apr 24 '15 21:04 mattdeboard

:+1:

fariza avatar May 21 '15 13:05 fariza

+1

pikeas avatar May 22 '15 22:05 pikeas

+1, was trying out Atom today, wouldn't use it unless this was supported. Too used to Vim/PyCharm doing this for me.

EntilZha avatar May 28 '15 21:05 EntilZha

Is there any work that would need to be done in order to make it happen? If its something someone unfamiliar with the project can do, I might be interested.

EntilZha avatar May 28 '15 22:05 EntilZha

+1

tscholak avatar May 30 '15 18:05 tscholak

Is there a third-party package that implements this behavior since it's not in core yet?

radix avatar Jun 03 '15 22:06 radix

So with Atom 1.0, this issue is still definitely legitimate. However, it looks like hitting tab at least allows you to manually indent the line, which is a passable bridge until it works properly. Auto-indent will completely remove any manual indentation, however, which seems like something that should be fixed.

mattdeboard avatar Jun 25 '15 19:06 mattdeboard

+1 for following pep8 guidelines by default. jupyter notebook does it by default and it feels like an instant reward whenever I use it. I would love atom behaving the same.

ogrisel avatar Jun 25 '15 19:06 ogrisel

@mattdeboard I'm not sure what you mean -- I've upgraded to 1.0 but I haven't noticed any difference with what my tab key does. It still just always either indents 4 spaces, or indents to the previous line's level.

It's really painful to match up indentation to PEP8 style, especially since atom makes it very difficult to indent to levels indivisible by the tabstop. I often find myself deleting an "indent" (4 spaces) and then spamming my spacebar to get my code to line up properly. :sob:

radix avatar Jun 25 '15 23:06 radix

@radix Pre-1.0, when you hit enter after an open-paren (or any sequence literal), the cursor would start at the beginning of the next line, instead of indented by one level. Hitting <Tab> would not move the cursor.

Now, the cursor still starts at the beginning of the next line, but tab moves the cursor. This is good-enough behavior, I think. Especially since it appears this is the same behavior as in SublimeText (and presumably TextMate, but I didn't check).

mattdeboard avatar Jun 27 '15 23:06 mattdeboard

FWIW that pain you have adhering to PEP 8 is because, IMO, only regex is being used to define indentation behavior.

mattdeboard avatar Jun 27 '15 23:06 mattdeboard

+1 voting for this, this is the reason I prefer pycharm over atom for python file editing.

huang475 avatar Aug 04 '15 04:08 huang475

This is NOT the same behavior as in SublimeText, there I get PEP8 correct indenting of function parameter lists that become too long to fit on one line. Without this, I cannot use Atom, alas. :(

michaelaye avatar Aug 07 '15 18:08 michaelaye

+1

fdegrave avatar Sep 09 '15 07:09 fdegrave

yep this is very annoying. Atom has so much potential..alas if basic code indentation doesn't work then I would be able to continue using atom.

neotrinity avatar Sep 29 '15 08:09 neotrinity

For one that is new to atom and its packages, is this a python package specific problem or an atom problem?

Twizzledrizzle avatar Oct 08 '15 18:10 Twizzledrizzle

Part of it is this package (missing a lot of regex rules) and part is atom (no way to define dynamic indentation rules required by PEP8).

patrys avatar Oct 08 '15 18:10 patrys

+1 ... come on ...

lzkelley avatar Oct 18 '15 22:10 lzkelley

+1 dear god this is ****ing ridiculous. How is this not a thing. Why even have support for pep8 linters if you can't ACTUALLY support pep8?

xguse avatar Oct 30 '15 17:10 xguse

Can we get an update from a maintainer? This bug/defect has been around for a very long time, and clearly there are many people who are interested in having this fixed. What would it take to fix this? I haven't contributed to Atom before, but am willing give it a try if thats what it takes for this to move to in progress.

EntilZha avatar Oct 30 '15 20:10 EntilZha

What would it take to fix this?

The current auto-indentation rules are regex based, which makes matching these types of scenarios very hard.

winstliu avatar Oct 30 '15 21:10 winstliu

It's also worth mentioning that TextMate, upon which Atom's language mode is based, doesn't get this right either (last I checked anyway).

python-mode for emacs does.

mattdeboard avatar Oct 30 '15 21:10 mattdeboard

How do editors that do this correctly accomplish it? Some method that is not regex based?

EntilZha avatar Oct 30 '15 21:10 EntilZha