I have searched the googlewebs, but I have been unable to find an emacs package that will automatically break long lines in a (Python) language conforming way. For example:

    def _formatDependencyList(usedList):
        if len(usedList) == 0:
            return '(This thing does not use modules)'
        return ', '.join([_escapeUnderscores(_getBaseNameHead(s)) for s in usedList])

The s in the rightmost occurrence of usedList is in column 80 in my file, and having gotten to the end of the line, I would like to issue a command, much like the M-q/fill-paragraph command, to 'fix' this one line and make it look like this:

        return ', '.join([
                _escapeUnderscores(_getBaseNameHead(s)) for s in usedList])

In this special case the ( and the [ that follow join are adjacent, so I would break the line after [. (In the more typical case, I would break the line at the first ( or [ character.)

This seems to me like something that emacs could do, and probably does (somewhere), and it would save me a whole lotta keystrokes. Honestly, I do not know how people use editors that cannot fill paragraphs, and if I had this too I would likewise be unable to continue living without it.

  • This is not about filling paragraphs, but automated code formatting, a surprisingly hard problem. You'll have more success finding an external program doing this, then running it over your code. – wasamasa Mar 3 '16 at 17:25
  • 2
    Pep8ify is a great program to do this for python. By default though it does not do long lines, you need to toggle the long line flag when you run it. – Jules Mar 3 '16 at 21:10

You should give multi-line a try. Without configuration, it allows you to cycle through different white space policies with a single key press.

All I do is:

(use-package multi-line :bind ("C-;" . multi-line))
|improve this answer|||||

Your Answer

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

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