all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 59009@debbugs.gnu.org, Randomneo <rostislav9999@gmail.com>
Subject: bug#59009: python mode indentation behavior fix
Date: Mon, 07 Nov 2022 22:57:48 +0900	[thread overview]
Message-ID: <eke7leomhnoj.wl-kobarity@gmail.com> (raw)
In-Reply-To: <83wn881oo4.fsf@gnu.org>

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

Eli Zaretskii wrote:
> > From: Randomneo <rostislav9999@gmail.com>
> > 
> > This patch will fix this bug #42513.
> 
> kobarity, any comments on this patch?

Hello,

Unfortunately, the presented patch breaks the ERT
python-indent-electric-colon-4.

I think the problem lies in the forward-line after block-start
detection.  The while loop is used to detect indentation inside the
block, so if block-start spans multiple lines, it should start at the
next line.  To address this issue, I propose to add
python-nav-end-of-statement before forward-line.  Attached is the
patch with an ERT.

Regards,

[-- Attachment #2: 0001-Fix-indentation-for-multi-line-block-start-in-Python.patch --]
[-- Type: application/octet-stream, Size: 2157 bytes --]

From 20c81eb76f8e9251610f40e7cb6c110ddabbb8c6 Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Mon, 7 Nov 2022 22:24:44 +0900
Subject: [PATCH] Fix indentation for multi-line block start in Python mode

* lisp/progmodes/python.el
(python-info-dedenter-opening-block-positions): Fix for multi-line
block start.
* test/lisp/progmodes/python-tests.el
(python-info-dedenter-opening-block-positions-6): New test. (Bug#59009)
---
 lisp/progmodes/python.el            |  1 +
 test/lisp/progmodes/python-tests.el | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index cec0d54a44..a734e06149 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5377,6 +5377,7 @@ python-info-dedenter-opening-block-positions
                            ;; block and the current line, otherwise it
                            ;; is not an opening block.
                            (save-excursion
+                             (python-nav-end-of-statement)
                              (forward-line)
                              (let ((no-back-indent t))
                                (save-match-data
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 8330525394..f871b7bc7d 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -5592,6 +5592,23 @@ python-info-dedenter-opening-block-positions-5
      (equal (list (python-tests-look-at "else:" -1 t))
             (python-info-dedenter-opening-block-positions)))))
 
+(ert-deftest python-info-dedenter-opening-block-positions-6 ()
+  "Test multiline block start."
+  (python-tests-with-temp-buffer
+   "
+def func():
+    if (
+        cond1 or
+        cond2
+    ):
+        something()
+        else
+"
+   (python-tests-look-at "else\n")
+    (should
+     (equal (list (python-tests-look-at "if (" -1 t))
+            (python-info-dedenter-opening-block-positions)))))
+
 (ert-deftest python-info-dedenter-opening-block-message-1 ()
   "Test dedenters inside strings are ignored."
   (python-tests-with-temp-buffer
-- 
2.34.1


  reply	other threads:[~2022-11-07 13:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03 15:41 bug#59009: python mode indentation behavior fix Randomneo
2022-11-06  8:18 ` Eli Zaretskii
2022-11-07 13:57   ` kobarity [this message]
2022-11-10 10:26     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eke7leomhnoj.wl-kobarity@gmail.com \
    --to=kobarity@gmail.com \
    --cc=59009@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rostislav9999@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.