Have fill-region break Python code into multiple lines to stay under 80 columns in Emacs

1

How can I get Emacs' indent-region command to re-indent

def foo():
    my_favorite_object_ever = ObjectConstructor(cool_parameter=4, not_cool_parameter=5)

as

def foo():
    my_favorite_object_ever = ObjectConstructor(cool_parameter=4,
                                                not_cool_parameter=5)

when I'm working in Python mode?

Is there a way I can perhaps combine fill-region and indent-region?

EDIT:

So far I've got this Elisp code in my .emacs:

(defun fill-indent-region (begin end)
  "Fill and then indent the code from BEGIN to END."
  (interactive "r")
  (save-restriction
    (narrow-to-region begin end)
    (fill-region (point-min) (point-max))
    (indent-region (point-min) (point-max))))

It is a little buggy though.

leo-the-manic

Posted 2014-02-28T21:13:57.037

Reputation: 111

No answers