bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29305: 26.0.90; Wrong electrified indentation with Python multiline


From: Lele Gaifax
Subject: bug#29305: 26.0.90; Wrong electrified indentation with Python multiline string
Date: Wed, 15 Nov 2017 10:33:39 +0100

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.

The attached patch adds two (currently) failing tests.

>From 21cd61ab71a16490a5c0c569a2715b7e5f2d7b98 Mon Sep 17 00:00:00 2001
From: Lele Gaifax <lele@metapensiero.it>
Date: Wed, 15 Nov 2017 10:10:19 +0100
Subject: [PATCH 2/2] Add failing tests on electric-indentation and Python
 multiline strings

* test/lisp/progmodes/python-tests.el
  (python-indent-electric-comma-inside-multiline-string,
  python-indent-electric-comma-after-multiline-string): New tests.
---
 test/lisp/progmodes/python-tests.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index a59885637e..010eb67160 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1109,6 +1109,37 @@ python-tests-visible-string
    (should (eq (car (python-indent-context)) :inside-string))
    (should (= (python-indent-calculate-indentation) 4))))
 
+(ert-deftest python-indent-electric-comma-inside-multiline-string ()
+  "Test indentation ...."
+  (python-tests-with-temp-buffer
+   "
+a = (
+    '''\
+- foo,
+- bar
+'''
+"
+   (python-tests-look-at "- bar")
+   (should (eq (car (python-indent-context)) :inside-string))
+   (goto-char (line-end-position))
+   (python-tests-self-insert ",")
+   (should (= (current-indentation) 0))))
+
+(ert-deftest python-indent-electric-comma-after-multiline-string ()
+  "Test indentation ...."
+  (python-tests-with-temp-buffer
+   "
+a = (
+    '''\
+- foo,
+- bar'''
+"
+   (python-tests-look-at "- bar'''")
+   (should (eq (car (python-indent-context)) :inside-string))
+   (goto-char (line-end-position))
+   (python-tests-self-insert ",")
+   (should (= (current-indentation) 0))))
+
 (ert-deftest python-indent-electric-colon-1 ()
   "Test indentation case from Bug#18228."
   (python-tests-with-temp-buffer
-- 
2.15.0

-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]