You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Repository navigation
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
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.
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.deflong_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.deflong_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)
Reacted by David Pärsson, Pan Teparak, Iván Martín, Gal Fisher, naoliden and Arno Veletanlic
# 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)
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.
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.
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.
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, PEP8allows 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?
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.
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:
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.
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.
Reacted by Chris Coutinho, Sergey Maranchuk, Bohdan Lisnenko and Koshlan Mayer-Blackwell
Reacted by Luke Zoltan Kelley, Maxim Rybalov, Vinjai Vale, Jazz Weisman and matg19
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.
+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.
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)."
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. 😸
Activity
rougeth commentedon Apr 29, 2014
I vote for:
rougeth commentedon May 2, 2014
Actually, that is not a good example since it's not recommended in PEP8:
But, for the recommended ones, this change would help:
sebdah commentedon Aug 4, 2014
+1 for this and I also vote for following the PEP8 guidelines. The following indentation is usually what other editors use:
thelastnode commentedon Nov 7, 2014
+1
My vote is for these two:
ironspecs commentedon Feb 17, 2015
+1
denisgarci commentedon Apr 24, 2015
+1
mattdeboard commentedon Apr 24, 2015
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:
fariza commentedon May 21, 2015
👍
pikeas commentedon May 22, 2015
+1
EntilZha commentedon May 28, 2015
+1, was trying out Atom today, wouldn't use it unless this was supported. Too used to Vim/PyCharm doing this for me.
EntilZha commentedon May 28, 2015
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.
tscholak commentedon May 30, 2015
+1
radix commentedon Jun 3, 2015
Is there a third-party package that implements this behavior since it's not in core yet?
mattdeboard commentedon Jun 25, 2015
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.
24 remaining items
patrys commentedon Oct 31, 2015
Python uses dynamic indenting, it's not a matter of increasing indent after an open parenthesis.
lzkelley commentedon Oct 31, 2015
What do you mean by 'dynamic indenting'? Do you mean that indents are used as delimiters?
patrys commentedon Oct 31, 2015
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.
lzkelley commentedon Oct 31, 2015
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?
EntilZha commentedon Oct 31, 2015
Given the above, is there low hanging fruit that can be accomplished via regex even if it isn't fully PEP8 compliant?
patrys commentedon Oct 31, 2015
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.
DSpeckhals commentedon Jan 18, 2016
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:
columnparam in the code that would give an offset back from the tab setting, but I don't see it utilized anywhere yet.language-mode.coffeeand 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.
EntilZha commentedon Jan 18, 2016
Very nice work @DSpeckhals! I tried the package out and it worked great and definitely bridges a much needed gap.
nzufelt commentedon Feb 12, 2016
Beautiful, @DSpeckhals, works like a charm!
cbcoutinho commentedon Sep 24, 2016
Exactly what solves (sidesteps?) the indentation issue in atom w.r.t python. Thanks again @DSpeckhals.
kepbod commentedon Apr 26, 2017
Seem like python-indent has solved this problem.
sah commentedon Mar 2, 2018
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.apometta commentedon Oct 23, 2018
+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.
kmayerb commentedon Jun 21, 2019
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)."
jazzlw commentedon Oct 12, 2019
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. 😸