GNU bug report logs -
#29305
26.0.90; Wrong electrified indentation with Python multiline string
Previous Next
Reported by: Lele Gaifax <lele <at> metapensiero.it>
Date: Wed, 15 Nov 2017 09:35:02 UTC
Severity: minor
Tags: fixed, patch
Found in version 26.0.90
Fixed in version 26.1
Done: Noam Postavsky <npostavs <at> users.sourceforge.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
severity 29305 minor
tags 29305 + patch
quit
Lele Gaifax <lele <at> metapensiero.it> writes:
> In python-mode, when I'm inside a triple-quoted string or immediately after
> it and insert (say) a comma, current line indentation should not change.
>
> I tried to play with python-indent-post-self-insert-function, but could not
> figure out how to recognize when I'm within or close to a multiline string.
How about this:
[0001-Disable-eletric-indent-for-python-strings-Bug-29305.patch (text/x-diff, inline)]
From d48c6f6d25911b2d128c72eec9ff5b3f457a3545 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sun, 19 Nov 2017 09:00:43 -0500
Subject: [PATCH] Disable eletric indent for python strings (Bug#29305)
* lisp/progmodes/python.el (python-indent-post-self-insert-function):
Do nothing when in string syntax or indent context.
---
lisp/progmodes/python.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d4226e5ce7..093dd0ae65 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1257,7 +1257,9 @@ python-indent-post-self-insert-function
If a line renders a paren alone, after adding a char before it,
the line will be re-indented automatically if needed."
(when (and electric-indent-mode
- (eq (char-before) last-command-event))
+ (eq (char-before) last-command-event)
+ (not (python-syntax-context 'string))
+ (not (eq (car (python-indent-context)) :inside-string)))
(cond
;; Electric indent inside parens
((and
--
2.11.0
This bug report was last modified 7 years and 268 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.