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#62092: 30.0.50; "case" does not work as dedenter in Python Date: Sat, 25 Mar 2023 23:13:06 +0900 Message-ID: References: <48fd0271-45d4-4f8e-0e13-f344f2fe1a31@yandex.ru> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sat_Mar_25_23:13:03_2023-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37360"; 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: Lele Gaifax , 62092@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 25 15:14:26 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 1pg4f3-0009Q6-OY for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Mar 2023 15:14:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pg4eh-0008IS-VJ; Sat, 25 Mar 2023 10:14:03 -0400 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 1pg4eg-0008G6-Nr for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 10:14:02 -0400 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 1pg4eg-00015K-Cb for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 10:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pg4eg-000870-5s for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 10:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Mar 2023 14:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62092 X-GNU-PR-Package: emacs Original-Received: via spool by 62092-submit@debbugs.gnu.org id=B62092.167975361931135 (code B ref 62092); Sat, 25 Mar 2023 14:14:02 +0000 Original-Received: (at 62092) by debbugs.gnu.org; 25 Mar 2023 14:13:39 +0000 Original-Received: from localhost ([127.0.0.1]:43147 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg4eJ-000867-Hh for submit@debbugs.gnu.org; Sat, 25 Mar 2023 10:13:39 -0400 Original-Received: from mail-pj1-f46.google.com ([209.85.216.46]:45583) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg4eI-00085u-0E for 62092@debbugs.gnu.org; Sat, 25 Mar 2023 10:13:38 -0400 Original-Received: by mail-pj1-f46.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so4185213pjl.4 for <62092@debbugs.gnu.org>; Sat, 25 Mar 2023 07:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679753604; 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=BngzbsZ6TtD8iO6kPBA4QnOkNNn+qHV+23b1ehonN/s=; b=W3kA9iAT1eWvYrYnt+89BuR/VG7ZreI1/eCL76nnUnt1tG3psSiuW2Eq7fCEWspVgk GWOHynnsmygd7VHq14Qb+Aza5ifl+Zi1Y49BGIDylyflG49EGniIkpgiW1fw3CYlWcmi eWXQbH3qNoPg33OU2s+T0JFWWujFEJo0fsB+nKmS6rJQcnKh8642DiV4mN9tmRTonSmj aA7rN/8TVJGGYP5+dbHcM15WFWibh6lgxsBE+Og8aJwdastTLxCJ8rzonqPU0sClmvex pRxJlqPXL4MT7/m+kAP7Wa03nWUkmqps4jK+Fbin+fe2azgRli3dNsaafOApW6WMEtcM Cmjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679753604; 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=BngzbsZ6TtD8iO6kPBA4QnOkNNn+qHV+23b1ehonN/s=; b=XoCK9fGqsyEG7hLKWEKSJ0uzUYrVgVFyc+gFzMuooothbYRmJdImR0TQV8Wr/Wwv6j xD8n6tyOTx64hAqmxuQK7kXTxxBJNxyPB3KL9RCw17hxByspT4Kt+TsKGrj+bdai8DVh ShHrwzyzDpsLaA9gDiwQpthyTMCNKE1XKHtgFHKBRt8+jRWp5j2uYNM4du5zYvrcLfJw C47IKA/cK+QnPYMpfqj8cS1wT/3PQCcGjduvAtt0gP7d965ZVc3ESBK3OVxT6JDHlXt2 +ZRTV6xZbraINey/pwhuVt+R/ibiOXTl5wbJgRc87jc67cOLOBSViSqedzIhSU6mG8My 9hxA== X-Gm-Message-State: AAQBX9ee98cJmO4b4ZJlRa8+OGbNBTyw5WSKfwjxjApDKweOABRF4fqO scno5xJdyF0zpOdNnZgX+2s= X-Google-Smtp-Source: AKy350atPa/PFiAt5fLcaCVVR4WjusCS2/QTKT0Kr4on8wpUKZ4OYZ4s76/A9I/FW1n8TfmhyPUhvA== X-Received: by 2002:a17:903:32d2:b0:19e:68b1:65b9 with SMTP id i18-20020a17090332d200b0019e68b165b9mr8021515plr.12.1679753603838; Sat, 25 Mar 2023 07:13:23 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id p6-20020a1709028a8600b00194c2f78581sm16002855plo.199.2023.03.25.07.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 07:13:23 -0700 (PDT) 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:258576 Archived-At: --Multipart_Sat_Mar_25_23:13:03_2023-1 Content-Type: text/plain; charset=US-ASCII Dmitry Gutov wrote: > Pushed your change to emacs-29, and closing. Thanks! Thank you for applying the patch. However, I overlooked one problem. #+begin_src python match a: case 1: match b: case 2 #+end_src When I type ":" at the last line after "case 2", the message "Closes case 1:" is shown. This is wrong because it cannot be the "case" block of the outer "match" block (match a:). I'm sorry if you were mentioning this case. Similar message can be shown with "elif": #+begin_src python for c in (1, 2): if a == 1: for d in (3, 4): elif b == 1: #+end_src However, this is not a correct Python code because "elif" cannot be the first sentence in a block. Dedenters other than "case" can never be the first sentence of a block, whereas "case" can be the first sentence of a block. So I think it is appropriate that the first "case" in the block should not be considered a dedenter. Attached is a patch to add a condition in `python-info-dedenter-statement-p'. --Multipart_Sat_Mar_25_23:13:03_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Improve-indenting-case-in-Python.patch" Content-Disposition: attachment; filename="0001-Improve-indenting-case-in-Python.patch" Content-Transfer-Encoding: 7bit >From f0dafe85cb78b0510e70fe7b1d093d013aea9008 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 25 Mar 2023 22:59:05 +0900 Subject: [PATCH] Improve indenting "case" in Python * lisp/progmodes/python.el (python-info-dedenter-statement-p): Do not consider the first "case" in the block as dedenter. * test/lisp/progmodes/python-tests.el (python-info-dedenter-opening-block-positions-7) (python-info-dedenter-statement-p-6): New tests. (Bug#62092) --- lisp/progmodes/python.el | 9 ++++++- test/lisp/progmodes/python-tests.el | 38 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 2fe88323c35..bbabce80b4d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5854,7 +5854,14 @@ python-info-dedenter-statement-p (save-excursion (python-nav-beginning-of-statement) (when (and (not (python-syntax-context-type)) - (looking-at (python-rx dedenter))) + (looking-at (python-rx dedenter)) + ;; Exclude the first "case" in the block. + (not (and (string= (match-string-no-properties 0) + "case") + (save-excursion + (back-to-indentation) + (python-util-forward-comment -1) + (equal (char-before) ?:))))) (point)))) (defun python-info-line-ends-backslash-p (&optional line-number) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index ed4a08da6ab..50153e66da5 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -5940,6 +5940,26 @@ python-info-dedenter-opening-block-positions-6 (equal (list (python-tests-look-at "if (" -1 t)) (python-info-dedenter-opening-block-positions))))) +(ert-deftest python-info-dedenter-opening-block-positions-7 () + "Test case blocks." + (python-tests-with-temp-buffer + " +match a: + case 1: + match b: + case 2: + something() + case 3: +" + (python-tests-look-at "case 1:") + (should-not (python-info-dedenter-opening-block-positions)) + (python-tests-look-at "case 2:") + (should-not (python-info-dedenter-opening-block-positions)) + (python-tests-look-at "case 3:") + (equal (list (python-tests-look-at "case 2:" -1) + (python-tests-look-at "case 1:" -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 @@ -6125,6 +6145,24 @@ python-info-dedenter-statement-p-5 (point)) (python-info-dedenter-statement-p))))) +(ert-deftest python-info-dedenter-statement-p-6 () + "Test case keyword." + (python-tests-with-temp-buffer + " +match a: # Comment + case 1: + match b: + case 2: + something() + case 3: +" + (python-tests-look-at "case 1:") + (should-not (python-info-dedenter-statement-p)) + (python-tests-look-at "case 2:") + (should-not (python-info-dedenter-statement-p)) + (python-tests-look-at "case 3:") + (should (= (point) (python-info-dedenter-statement-p))))) + (ert-deftest python-info-line-ends-backslash-p-1 () (python-tests-with-temp-buffer " -- 2.34.1 --Multipart_Sat_Mar_25_23:13:03_2023-1--