-
Notifications
You must be signed in to change notification settings - Fork 147
Auto indent on line continuation with list/tuple #22
Comments
I vote for: f = function(foo,
bar) |
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) |
+1 for this and I also vote for following the PEP8 guidelines. The following indentation is usually what other editors use:
|
+1 My vote is for these two:
|
+1 |
1 similar comment
+1 |
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
] |
👍 |
1 similar comment
+1 |
+1, was trying out Atom today, wouldn't use it unless this was supported. Too used to Vim/PyCharm doing this for me. |
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. |
+1 |
Is there a third-party package that implements this behavior since it's not in core yet? |
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. |
+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. |
@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. 😭 |
@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 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). |
FWIW that pain you have adhering to PEP 8 is because, IMO, only regex is being used to define indentation behavior. |
+1 voting for this, this is the reason I prefer pycharm over atom for python file editing. |
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. :( |
+1 |
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. |
For one that is new to atom and its packages, is this a python package specific problem or an atom problem? |
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). |
+1 ... come on ... |
+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? |
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. |
The current auto-indentation rules are regex based, which makes matching these types of scenarios very hard. |
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. |
How do editors that do this correctly accomplish it? Some method that is not regex based? |
emacs uses regex, but I can confirm that it does get very complicated with look-ahead/-behind rules and so forth. Emacs has SMIE, a generic framework for indentation in language modes. |
As mentioned above, there are linters that look for correct indentation (e.g. linter-flake8, linter-pep8, linter-python-pep8). Could the same method be used somehow? |
Not until atom/atom#9059 is fixed. |
I'm unclear* on why this is a difficult fix --- it looks like the suggested indentation is based on first finding the indentation of the previous row, and then seeing if this should be incremented or decremented based on matches to the Wouldn't adding regex for lines ending with open brackets/parenthesis to the *I have no idea how Atom works, nor have I ever even looked at coffeescript before... so this shouldn't be surprising. Sorry if my comments are insultingly stupid, I'm trying to help instead of just complaining. |
Python uses dynamic indenting, it's not a matter of increasing indent after an open parenthesis. |
What do you mean by 'dynamic indenting'? Do you mean that indents are used as delimiters? |
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, 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? |
Given the above, is there low hanging fruit that can be accomplished via regex even if it isn't fully PEP8 compliant? |
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:
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. |
Very nice work @DSpeckhals! I tried the package out and it worked great and definitely bridges a much needed gap. |
Beautiful, @DSpeckhals, works like a charm! |
Exactly what solves (sidesteps?) the indentation issue in atom w.r.t python. Thanks again @DSpeckhals. |
Seem like python-indent has solved this problem. |
Would still be nicer if this were implemented as part of this package, so that e.g. |
+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: 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 |
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. 😸 |
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.
should be either
or
The text was updated successfully, but these errors were encountered: