Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Auto indent on line continuation with list/tuple #22

Open

Description

@alvinchow86

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)

Activity

  1. rougeth commented on Apr 29, 2014

    @rougeth

    I vote for:

    f = function(foo,
       bar)
  2. rougeth commented on May 2, 2014

    @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)
  3. sebdah commented on Aug 4, 2014

    @sebdah

    +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)
    
  4. thelastnode commented on Nov 7, 2014

    @thelastnode

    +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)
    
  5. ironspecs commented on Feb 17, 2015

    @ironspecs

    +1

  6. denisgarci commented on Apr 24, 2015

    @denisgarci

    +1

  7. mattdeboard commented on Apr 24, 2015

    @mattdeboard

    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
    ]
  8. fariza commented on May 21, 2015

    @fariza

    👍

  9. pikeas commented on May 22, 2015

    @pikeas

    +1

  10. EntilZha commented on May 28, 2015

    @EntilZha

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

  11. EntilZha commented on May 28, 2015

    @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.

  12. tscholak commented on May 30, 2015

    @tscholak

    +1

  13. radix commented on Jun 3, 2015

    @radix

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

  14. mattdeboard commented on Jun 25, 2015

    @mattdeboard

    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.

  15. 24 remaining items

  16. patrys commented on Oct 31, 2015

    @patrys

    Python uses dynamic indenting, it's not a matter of increasing indent after an open parenthesis.

  17. lzkelley commented on Oct 31, 2015

    @lzkelley

    What do you mean by 'dynamic indenting'? Do you mean that indents are used as delimiters?

  18. patrys commented on Oct 31, 2015

    @patrys

    No I mean that PEP8 demands at least three different kinds of indents. One is eight spaces and one depends on the position of the last open parenthesis in the line before. See the Atom issue linked above.

  19. lzkelley commented on Oct 31, 2015

    @lzkelley

    Okay, I see what you mean. You're right that it definitely wouldn't allow for all of the acceptable indentation patterns. At the same time, PEP8 allows for many different types of indents. My suggestion won't work for the 'Aligned with opening delimiter' case --- but I think it will work for the 'Hanging indents should add a level' case. Wouldn't one working case be better than none?

  20. EntilZha commented on Oct 31, 2015

    @EntilZha

    Given the above, is there low hanging fruit that can be accomplished via regex even if it isn't fully PEP8 compliant?

  21. patrys commented on Oct 31, 2015

    @patrys

    Yes, the regex is far from perfect. I think Sublime Text's grammar files may carry a better version for Python even though Sublime no longer depends on the regex itself.

  22. DSpeckhals commented on Jan 18, 2016

    @DSpeckhals

    I scanned through the core editor code, and definitely see the complication with adding some forms of Python indentation to language-python. I think a long term solution would require changes to both atom/atom and atom/language-python. The missing pieces I see are:

    1. Necessity to indent at a level not divisible by the current tab-width. It looks like there's an optional column param in the code that would give an offset back from the tab setting, but I don't see it utilized anywhere yet.
    2. Necessity to look back multiple lines to the corresponding opening delimiter after the "fluid/dynamic" indentation is complete. atom/atom language-mode.coffee and atom/language-python do not currently leave room for this from what I can see.

    In the meantime, I wrote a relatively simple package that hooks into Python new line events, and indents/unindents based on PEP8 style: python-indent. I hope this helps to fill the gap for those hesitant to write Python in Atom. Feel free to offer suggestions too; this is my first Atom package! 😄

    EDIT: I just added a couple of features to the python-indent package to cover the "hanging" indent suggested by some. Now, it has the option to line up succeeding lines with the opening delimiter OR hang the indent 1 or 2 tabs from the current block.

  23. EntilZha commented on Jan 18, 2016

    @EntilZha

    Very nice work @DSpeckhals! I tried the package out and it worked great and definitely bridges a much needed gap.

  24. nzufelt commented on Feb 12, 2016

    @nzufelt

    Beautiful, @DSpeckhals, works like a charm!

  25. cbcoutinho commented on Sep 24, 2016

    @cbcoutinho

    Exactly what solves (sidesteps?) the indentation issue in atom w.r.t python. Thanks again @DSpeckhals.

  26. kepbod commented on Apr 26, 2017

    @kepbod

    Seem like python-indent has solved this problem.

  27. sah commented on Mar 2, 2018

    @sah

    Would still be nicer if this were implemented as part of this package, so that e.g. autoIndentBufferRow (and therefore things like emacs-tab) would work correctly.

  28. apometta commented on Oct 23, 2018

    @apometta

    +1 this is also a problem in C++. Anyone know of a package that solves it for this language? It also happens when formatting long multi-line string literals.

  29. kmayerb commented on Jun 21, 2019

    @kmayerb

    FOR PYTHON:
    https://atom.io/packages/python-indent
    "Python Indent is the indentation behavior you've been waiting for in Atom! You should no longer have to worry about mashing your tab/space/backspace key every time you press enter in the middle of coding. Also, compared to other editors, there is no need to change an app configuration if you want to have a mixture of different types of indents (namely hanging and opening-delimiter-aligned).

    The main obstacle with Atom's native indentation behavior is that it doesn't yet have the necessary API's to do what Python's PEP8 style guide suggests. Enhancement requests and issues have been opened in Atom Core on a few occasions, but none have been resolved yet.

    language-python - Auto indent on line continuation with list/tuple
    atom - Autoindent not working properly
    This package was made to give you expected indentation behavior; python-indent listens for editor:newline events in Python source files, and when triggered, adjusts the indentation to be lined up relative to the opening delimiter of the statement or "hanging" (for parameters, tuples, or lists)."

  30. jazzlw commented on Oct 12, 2019

    @jazzlw

    Thanks a bunch @DSpeckhals, this was driving me crazy and I'm so happy to have just found this. Don't know why this isn't integrated into Atom, but I'm just happy that the pain is over. 😸

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions