[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#29305: 26.0.90; Wrong electrified indentation with Python multiline
From: |
Noam Postavsky |
Subject: |
bug#29305: 26.0.90; Wrong electrified indentation with Python multiline string |
Date: |
Sun, 19 Nov 2017 09:27:46 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) |
severity 29305 minor
tags 29305 + patch
quit
Lele Gaifax <lele@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:
>From d48c6f6d25911b2d128c72eec9ff5b3f457a3545 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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