Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure python hanging indent after an open parenthesis

Emacs indents my code like this:

def my_function(
    a, b, c):
    pass

if my_function(
    1, 2, 3):
    pass

However, PEP8 states that it should be indented like this, to avoid confusing the hanging indent with the next line:

def my_function(
        a, b, c):
    pass

if my_function(
        1, 2, 3):
    pass

How can I configure emacs' old python.el to use the existing python-continuation-offset variable in this case (after an opening parenthesis and newline), so as to indent the second way?

like image 233
Lily Chung Avatar asked Apr 03 '14 02:04

Lily Chung


People also ask

What is hanging indent in Python?

What is a Hanging Indent? A hanging indent is a type of indentation where the first line of a paragraph is not indented, but subsequent lines in the same paragraph are indented. In Google Docs, you can create a hanging indent by following these simple steps: Step 1: Select the text you want to format.

How to close brackets in Python?

According to the PEP 8 standard, there are two ways to line up the closing braces, brackets, or parentheses. First, line it up with the first non-whitespace character of the previous line. Second, line it up with the first character that starts the multi-line construct. What is this?


1 Answers

Just for information, Python mode in GNU Emacs 25 formats this correctly.

like image 81
parkydr Avatar answered Oct 29 '22 19:10

parkydr