3

Right now, in emacs' python-mode line continuations are aligned to the end of the previous line, as follows:

this_is_a_list_of_django_urls = ('',
                                 url(r'^admin/?', include(admin.site.urls)),
                                 url(r'^polls/?', include('polls.urls'))
                                )

But I find the above to be pretty ugly. Is there any way to configure emacs' python-mode to autoindent like this:

this_is_a_list_of_django_urls = ('',
    url(r'^admin/?', include(admin.site.urls)),
    url(r'^polls/?', include('polls.urls'))
)

I find the second version to be much easier to read, and so I'd like hitting TAB to only indent by one level, rather than however much it takes to align with the end of the previous line.

quanticle
  • 896

2 Answers2

2

PEP8 says:

No:

Arguments on first line forbidden when not using vertical alignment

foo = long_function_name(var_one, var_two,
    var_three, var_four)

WRT closing parenthesis python-mode.el meanwhile offers a choice, boolean `py-close-at-start-column-p', default is nil.

When non-nil, it will be lined up under the first character of the line that starts the multi-line construct, as in:

my_list = [
    1, 2, 3,
    4, 5, 6,
]
1

Not a solution, really, but if you put the first element of the tuple on a new line, you get almost the behavior you want out-of-the-box.

this_is_a_list_of_django_urls = (
    '',
    url(r'^admin/?', include(admin.site.urls)),
    url(r'^polls/?', include('polls.urls'))
    )
Inaimathi
  • 469