3

I have emacs set up to indent Python code like so:

foo(
    bar, baz
)

That works fine. However, that style in a particular program I'm working on very often means I find myself with text like this:

some_very_long_python_function_call(an_extremely_long_name_here, and_another_one_right_here)

At which point I'd like to be able to ask emacs to reformat that line, or sexp if you like (the one at point, let's say), like this:

some_very_long_python_function_call(
    an_extremely_long_name_here, and_another_one_right_here
)

or possibly like this:

some_very_long_python_function_call(
    an_extremely_long_name_here,
    and_another_one_right_here
)

Is there a way to do that? Just using regular editing keys I find it a bit of a chore.

  • I'd also love to see a highly efficient method using vanilla Emacs keys. – PythonNut Aug 22 '15 at 18:22
  • AFAIK there is no command right out of the box. Seems worth a feature request. – Andreas Röhler Dec 19 '15 at 8:22
  • gist.github.com/wvxvw/964801b7300704cfdd207d57f48b32d0 something I wrote some time ago to do this. It can only switch between "all on one line" and "everything on separate line" formatting styles, by it's not hard to add more styles. – wvxvw Mar 28 '18 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.