python-indentPEP8 indentation package for Atom editor

联合创作 · 2023-09-28 00:32

python-indent Build Status

Atom with easy PEP8 indentation...No more space bar mashing!

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.

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

Indent Types

Both indent types for continuing lines as described in PEP 0008 -- Style Guide for Python Code are auto-detected and applied by this package.

  • Aligned with Opening Delimiter

    def function_with_lots_of_params(param_1, param_2,
                                     param_3, param_4,
                                     very_long_parameter_name,
                                     param_6)
  • Hanging

    def function_with_lots_of_params(
        param_1, param_2,
        param_3, param_4,
        very_long_parameter_name,
        param_6)

Setting

  • Hanging Indent Tabs: Number of tabs used for hanging indents

Examples

def current_language_python_package(first_parameter, second_parameter,#<newline>
third_parameter):#<---default Atom language-python
    pass

def with_python_indent_package_added(first_parameter, second_parameter,
                                     third_parameter):
    #<--properly dedents to here
    pass

def with_hanging_indent(
    first_parameter, second_parameter, third_parameter):
    pass

also_works_with_lists = ["apples", "oranges", "pears", "peaches", "mangoes",
                         "clementines", "etc."]#<--PEP8 continued indentation
or_like_this = [
    "apples", "oranges", "pears",
    "peaches", "mangoes", "clementines",
    "etc."
]

There are plenty of other examples (ordinary and extraordinary) in the test_file.

This isn't working for me!

Sorry to hear that! Hopefully one of the following will help you fix the problem.

  • Check that Atom is using "soft tabs" (i.e. spaces). Hard tabs (i.e. '\t') are incompatible with PEP8 compliant continued indenting (newlines inside of a list, inside function definitions, etc.) so this package gives up if the editor is using hard tabs.
    • Atom has two different settings for this, the "TabType" setting (with choices "auto", "soft", and "hard"), and the "Soft Tabs" setting which is used when TabType is auto, but the auto detection fails.
  • Make sure the Python code is correctly written -- sometimes what looks like incorrect indentation is actually being caused by a bracket twenty lines ago that somehow lost its closing partner!
  • If the above didn't help, please read through the issues and submit a new one if you don't see an issue that covers your problem: https://github.com/DSpeckhals/python-indent/issues
浏览 6
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报