From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#62031: 29.0.60; python-mode indentation after re.match Date: Fri, 10 Mar 2023 00:29:11 +0900 Message-ID: References: <5ea3a37a-4e43-4ede-9f96-7159f54272e8@yandex.ru> <87bkl4y5gw.fsf@metapensiero.it> <87wn3rk7bk.fsf@metapensiero.it> <69793abf-3d2f-2dbe-698b-877ededfc56b@yandex.ru> <875ybb9kry.fsf@metapensiero.it> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Fri_Mar_10_00:29:11_2023-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24438"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: Rob Moss , Lele Gaifax , 62031@debbugs.gnu.org, Dmitry Gutov To: Ruijie Yu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 09 16:30:29 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1paIDt-0006GB-QG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Mar 2023 16:30:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paIDa-0004ck-NP; Thu, 09 Mar 2023 10:30:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1paIDT-0004cL-Ji for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2023 10:30:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paIDT-0007qT-3w for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2023 10:30:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1paIDS-00056E-LW for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2023 10:30:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 Mar 2023 15:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62031 X-GNU-PR-Package: emacs Original-Received: via spool by 62031-submit@debbugs.gnu.org id=B62031.167837576319531 (code B ref 62031); Thu, 09 Mar 2023 15:30:02 +0000 Original-Received: (at 62031) by debbugs.gnu.org; 9 Mar 2023 15:29:23 +0000 Original-Received: from localhost ([127.0.0.1]:52888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paICp-00054x-B9 for submit@debbugs.gnu.org; Thu, 09 Mar 2023 10:29:23 -0500 Original-Received: from mail-pl1-f179.google.com ([209.85.214.179]:38414) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paICn-00054h-Me for 62031@debbugs.gnu.org; Thu, 09 Mar 2023 10:29:22 -0500 Original-Received: by mail-pl1-f179.google.com with SMTP id n6so2373117plf.5 for <62031@debbugs.gnu.org>; Thu, 09 Mar 2023 07:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678375755; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=6cDLBQBX7PH5xALRQrq/Nczn/Q0eAWf+Z2WkF895zDM=; b=eZ2OoVY4GOuy/HLNai4Gzi6CZMw0cQUd3jsqKPGfe4dsGhz1mMXYMGHkiPQyfYHDW+ QanHc3vM/+/EihGZ9vuBaMQ2MFrqo7XZUGD/NuKKqnI0jUYUxwW50jVm1Cd1NwR+NzDX pMVdU3FcDxXBcSahq4upiQlV3/gIETaDfhb6f2haUCQqwFv+7hu+N5vtGqegfsbYp59k 7EU8aaZLD7E+lY5az//4doDtvZ7J1YleMSc1Z/JoDFy/3tiA6CfcCUjLZxe9TgabzHbz pzs6HspAy89PCgIj3YJHZDwQwNtHzDbSn6O+NA9qQRdCMWP4IuuKQ2d1WbBIJPWIMje1 Bilg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678375755; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6cDLBQBX7PH5xALRQrq/Nczn/Q0eAWf+Z2WkF895zDM=; b=6Yhcpbdl2Rv4OGLcDj55rLXCCqHpi2ZQrlp+vKgi/6wZujQT38z0Cw/zBG939aSxV3 HUFMpaD/nawT8XjqkGbebp1NB0BJPi/ztpTIwt7sdG1YFniAGi/cM12VKVAARkhjF7Pn JtS5v4o4EtiszrEFvVrPJKngbhyghIUw7Kvx5BxZz6g5SF4zbb/FgR3BkgDfjWbtBvOT JHIGAVkEZOE0rL/S2ITFOQHaNQ05NQY8LQ2zHG5o8mfSdRcQ2H4paua8n3HNV40H7pLk TLX+y3LE/VUUBDX5PJ2Y08GtMzEpXEYyJorB9EZ+HO3RTjF0Wm5dXkgFAnATUZIgAA7f oqBA== X-Gm-Message-State: AO0yUKWwyjWot12x/w8YbVHKsDlXvYWguyuDk4vGyyCRbIN0AJrbOpWF uzZ9GE5Ng8smk8tJlCBT7eQ= X-Google-Smtp-Source: AK7set9b3uoI4XIXp3QWr+hwEw1WjETZ19fnAZbmhThx2P7zi3p0vSJ5Kdr9ZDwlEvENqaFvEM9+ug== X-Received: by 2002:a17:90b:1bc9:b0:237:9c41:e0a4 with SMTP id oa9-20020a17090b1bc900b002379c41e0a4mr25022207pjb.17.1678375755602; Thu, 09 Mar 2023 07:29:15 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id mg23-20020a17090b371700b00230cbb4b6e8sm78732pjb.24.2023.03.09.07.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 07:29:14 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:257622 Archived-At: --Multipart_Fri_Mar_10_00:29:11_2023-1 Content-Type: text/plain; charset=US-ASCII 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. --Multipart_Fri_Mar_10_00:29:11_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Don-t-misindent-else-after-if-match-in-Python.patch" Content-Disposition: attachment; filename="0001-Don-t-misindent-else-after-if-match-in-Python.patch" Content-Transfer-Encoding: 7bit >From 9d9f0d9af22f033a3471fd87f9e72d874bbb8b51 Mon Sep 17 00:00:00 2001 From: kobarity 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 --- 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)))) + ;;; Filling -- 2.34.1 --Multipart_Fri_Mar_10_00:29:11_2023-1--