GNU bug report logs -
#17658
Python mode has odd indentation behavior
Previous Next
Reported by: Adam Connor <adamc55 <at> gmail.com>
Date: Sun, 1 Jun 2014 02:25:02 UTC
Severity: normal
Done: fgallina <at> gnu.org (Fabián Ezequiel Gallina)
Bug is archived. No further changes may be made.
Full log
Message #20 received at 17658 <at> debbugs.gnu.org (full text, mbox):
>> Makes no difference,
> Did you try it?
I tried it in Emacs-24.3 which doesn't enable electric-indent-mode by
default, but suffers from the same problem. Admittedly, In 24.4,
I half-fixed the problem by linking this python-mode feature to
electric-indent-mode, so that it can be turned off.
> The chars, which trigger an indent, may differ. In this case a comma
> triggers it.
Any char triggers it. As I said:
The important detail is not to hit "," but to insert a char right
before the inner close paren.
The comma is not in electric-indent-chars.
Here's the offending code in python-indent-post-self-insert-function:
((and (not (bolp))
(memq (char-after) '(?\) ?\] ?\})))
(save-excursion
(goto-char (line-beginning-position))
;; If after going to the beginning of line the point
;; is still inside a paren it's ok to do the trick
(when (python-syntax-context 'paren)
(let ((indentation (python-indent-calculate-indentation)))
(when (< (current-indentation) indentation)
(indent-line-to indentation))))))
This means that current line is reindented whenever you insert a char
right before a close-paren and line-beginning-position is inside some
parentheses. Since reindenting a line is problematic in Python, it
should only be done when we really know for sure that the current indent
is wrong. So clearly the above condition triggers too often.
But I don't understand the intention of the code, i.e. I don't
understand when the above is meant to trigger reindentation, so I don't
know how to fix it. Presumably Fabián should be able to shed some
light here.
Stefan
This bug report was last modified 11 years and 49 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.