-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor doesn't support hanging indentation #3480
Comments
Spyder kind of does what you want. If you manually indent your first variables like this
then the coming lines will respect your initial indentation. If you want to improve this, you're welcome to send us a pull request to implement it because we don't have time to do it :-) |
it used to work like @yulkang wants. From pep8 (from what I recall, at least), vertical alignment should be used only if there is something right after the open parenthesis. # 1: OK
def long_function_name(
var_one, var_two, var_three)
# 2: OK
def long_function_name(var_one,
var_two,
var_three)
# 3: NOT OK
def long_function_name(var_one,
var_two,
var_three)
# 4: NOT OK
def long_function_name(
var_one,
var_two,
var_three) Spyder is currently doing 4 instead of 1. |
I made a preliminary version and made a pull request: It has an option for hanging indent at menu - python - Preferences - Editor - Advanced settings - Hanging indentation. It is unchecked by default, but when checked, allows hanging indentation, as follows:
The case I found not working is the following, where the subsequent line is indented one step too much:
But such cases are rarer for me, so it would be useful even as it stands now. I haven't found why this happens, and I would appreciate help. I checked the following and they work as expected, too:
Please let me know if there are other issues. |
@yulkang, thanks a lot for looking at it. I'd like to say two things:
|
Description of your problem
What steps will reproduce the problem?
long_function_name(
then press Enter.
What is the expected output? What do you see instead?
I wish there is an option for hanging indent (of a fixed number of spaces), rather than vertical alignment. That is, I want an option for:
rather than:
Currently the vertical alignment seems to be the only option. But it saves little space when there is a big indentation. PEP also recommends both styles.
If I could wish for more, I would suggest having the hanging indent of twice the amount for one level (e.g., 4 x 2 = 8 spaces), so as to disambiguate it with subsequent indents that are not continuations, as I copied above from the second example of the PEP: https://www.python.org/dev/peps/pep-0008/#indentation.
Interestingly, hanging indent (of twice the amount for one level) is also the style of the MATLAB editor, so users converting from MATLAB would find it more familiar. It could be important since Spyder is the IDE of choice for many previous MATLAB users.
Please provide any additional information below
Versions and main components
Dependencies
Please go to the menu entry
Help > Optional Dependencies
(orHelp > Dependencies
), press the buttonCopy to clipboard
and paste the contents below:
jedi >=0.8.1 : 0.9.0 (OK)
matplotlib >=1.0 : 1.5.3 (OK)
nbconvert >=4.0 : 4.2.0 (OK)
numpy >=1.7 : 1.11.1 (OK)
pandas >=0.13.1 : 0.18.1 (OK)
pep8 >=0.6 : 1.7.0 (OK)
psutil >=0.3 : 4.3.0 (OK)
pyflakes >=0.5.0 : 1.2.3 (OK)
pygments >=2.0 : 2.1.3 (OK)
pylint >=0.25 : 1.6.4 (OK)
qtconsole >=4.2.0: 4.2.1 (OK)
rope >=0.9.4 : 0.9.4 (OK)
sphinx >=0.6.6 : 1.4.1 (OK)
sympy >=0.7.3 : 1.0 (OK)
The text was updated successfully, but these errors were encountered: