0

Emacs's Python mode has an annoying "feature" that automatically indents line continuations from parentheses and brackets against the opening bracket in the previous line. So we get stuff like

myfunc(a, b, c,
       d, e, f)

This is annoying because it makes the indentation throughout the file look inconsistent, but also because you get stuff like

myfunc(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, (x,
                                                                             y, z))

(I've made it so long to illustrate that this usually happens automatically based on the column size)

If I were to add more arguments to myfunc, everything would be stuck over there with the x.

I want it to always indent additional lines four spaces more than the first line. Continuations against \ seem to do the right thing (I'm not positive that it's right 100% of the time, though, as I rarely use \). For example, what I want for the above would be

myfunc(a, b, c,
    d, e, f)

and

myfunc(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, (x,
    y, z))

So I guess I want the reverse of Proper indendation with backslash line continuations in python-mode.el.

Community
  • 1
  • 1
asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • 2
    Are you sure you're okay violating PEP 8? http://www.python.org/dev/peps/pep-0008/#indentation – Wilduck Sep 15 '12 at 06:22
  • In this case, I disagree with PEP 8, for the reasons I noted above. – asmeurer Sep 15 '12 at 07:52
  • Actually, read what it says under "optional" in that section. I don't think this is a violation at all. – asmeurer Sep 15 '12 at 07:54
  • I have, and that's the preferred way to do very long function definitions (it's different than what you've posted: i.e. the arguments _start_ on a new line) which is handled by python-mode.el just fine. – Wilduck Sep 15 '12 at 07:56
  • 1
    If some piece of code is indented too far, usually the best solution is not to go and redesign the indentation rules, but to simply break your lines at other places. E.g. if you break the line before `(x,` instead of after it, the indentation won't depend on the number of arguments that precede it. – Stefan Sep 15 '12 at 22:26

2 Answers2

0

the value is fetched from py-compute-indentation, just now at line 5091 of current trunks python-mode.el

bzr branch lp:python-mode

introcuce a boolean there: (if my-boolean py-indent-offset (INSTEAD OF COUMPUTED VALUE RETURNED...

OTOH that value seems reasonable as is, not mixing up with block design

Andreas Röhler
  • 4,804
  • 14
  • 18
0

I'm still new to lisp, so this probably could have been done without editing the source code, but for me, this is the easiest way. I have modified python.el at https://github.com/asmeurer/python.el/tree/indentation to remove this. I also removed the automatic alignment of dots (like multi lines python indentation on emacs), but it's a separate commit.

Community
  • 1
  • 1
asmeurer
  • 86,894
  • 26
  • 169
  • 240