From: kobarity <kobarity@gmail.com>
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: Rob Moss <robm.dev@gmail.com>, Lele Gaifax <lele@metapensiero.it>,
62031@debbugs.gnu.org, Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#62031: 29.0.60; python-mode indentation after re.match
Date: Fri, 10 Mar 2023 00:29:11 +0900 [thread overview]
Message-ID: <eke7mt4mvt88.wl-kobarity@gmail.com> (raw)
In-Reply-To: <sdv8rg6hb6s.fsf@fw.net.yu>
[-- Attachment #1: Type: text/plain, Size: 384 bytes --]
Ruijie Yu wrote:
> As I mentioned in the other subthread, there is a variation to this
> issue that remains unfixed. The following test case, a slightly
> modified version of the test case in your commit, has failed (tested on
> 7e1012765c40):
I think it's better to check the block-start is located at the
beginning of the line. Attached is a patch which can pass the test
case.
[-- Attachment #2: 0001-Don-t-misindent-else-after-if-match-in-Python.patch --]
[-- Type: application/octet-stream, Size: 2460 bytes --]
From 9d9f0d9af22f033a3471fd87f9e72d874bbb8b51 Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Fri, 10 Mar 2023 00:08:41 +0900
Subject: [PATCH] Don't misindent 'else:' after 'if match:' in Python
* lisp/progmodes/python.el
(python-info-dedenter-opening-block-positions): Check that the block
start is at the beginning of the line (Bug#62031).
* test/lisp/progmodes/python-tests.el (python-indent-after-bare-match):
New test.
Co-authored-by: Ruijie Yu <ruijie@netyu.xyz>
---
lisp/progmodes/python.el | 7 +++----
test/lisp/progmodes/python-tests.el | 12 ++++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 630250c15c3..136bf6a81db 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5792,12 +5792,11 @@ python-info-dedenter-opening-block-positions
(catch 'exit
(while (python-nav--syntactically
(lambda ()
- (cl-loop while (re-search-backward (python-rx block-start) nil t)
- if (memq (char-before) '(nil ?\s ?\t ?\n))
- return t))
+ (re-search-backward (python-rx block-start) nil t))
#'<)
(let ((indentation (current-indentation)))
- (when (and (not (memq indentation collected-indentations))
+ (when (and (= indentation (- (point) (line-beginning-position)))
+ (not (memq indentation collected-indentations))
(or (not collected-indentations)
(< indentation
(apply #'min collected-indentations)))
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 6928e313dc4..4461921f142 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1994,6 +1994,18 @@ python-indent-after-re-match
(python-tests-look-at "else:")
(should (= (python-indent-calculate-indentation) 4))))
+(ert-deftest python-indent-after-bare-match ()
+ (python-tests-with-temp-buffer
+ "
+from re import match
+def test_re(string):
+ if match('^[a-c]+$', string):
+ print('yes')
+ else:
+ "
+ (python-tests-look-at "else:")
+ (should (= (python-indent-calculate-indentation) 4))))
+
\f
;;; Filling
--
2.34.1
next prev parent reply other threads:[~2023-03-09 15:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 4:44 bug#62031: 29.0.60; python-mode indentation after re.match Rob Moss
2023-03-07 14:35 ` Dmitry Gutov
2023-03-07 14:57 ` Lele Gaifax
2023-03-07 23:31 ` Rob Moss
2023-03-08 7:53 ` Lele Gaifax
2023-03-08 13:23 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-08 22:46 ` Dmitry Gutov
2023-03-09 2:31 ` Rob Moss
2023-03-08 13:54 ` Eli Zaretskii
2023-03-08 17:57 ` Dmitry Gutov
2023-03-08 18:10 ` Lele Gaifax
2023-03-08 20:52 ` Dmitry Gutov
2023-03-09 3:04 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-09 15:29 ` kobarity [this message]
2023-03-09 15:42 ` Dmitry Gutov
2023-03-09 15:44 ` Lele Gaifax
2023-03-09 15:40 ` Dmitry Gutov
2023-03-08 18:15 ` Dmitry Gutov
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=eke7mt4mvt88.wl-kobarity@gmail.com \
--to=kobarity@gmail.com \
--cc=62031@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=lele@metapensiero.it \
--cc=robm.dev@gmail.com \
--cc=ruijie@netyu.xyz \
/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.