Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
Thats actually interesting request, from code I don't see it is configurable now, you may send a feature-request to emacs-devel. M-x report-emacs-bug. – kindahero May 31 '13 at 8:38
    
You should accept Andreas' solution and put the quotes on a separate line as well. Then emacs will indent them without aligning. – Zelphir Nov 22 '15 at 18:18

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,
]
share|improve this answer
    
Shows that PEP8 has its good sides. I've been doing that for years, it seemed natural to me to indent in this way. I wonder how anyone can think that the aligned version with parameters on the first line is better. Why treat some parameters different from the rest? – Zelphir Nov 22 '15 at 18:16

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'))
    )
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.