all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#29305: 26.0.90; Wrong electrified indentation with Python multiline string
@ 2017-11-15  9:33 Lele Gaifax
  2017-11-19 14:27 ` Noam Postavsky
  0 siblings, 1 reply; 6+ messages in thread
From: Lele Gaifax @ 2017-11-15  9:33 UTC (permalink / raw)
  To: 29305

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Add-failing-tests-on-electric-indentation-and-Python.patch --]
[-- Type: text/x-diff, Size: 1820 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 211 bytes --]


-- 
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.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-02 14:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-15  9:33 bug#29305: 26.0.90; Wrong electrified indentation with Python multiline string Lele Gaifax
2017-11-19 14:27 ` Noam Postavsky
2017-11-21  9:15   ` Lele Gaifax
2017-11-21 13:52     ` Noam Postavsky
2017-11-21 14:22       ` Lele Gaifax
2017-12-02 14:54         ` Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.