Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

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.