From unknown Fri Jun 20 07:16:26 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#55572 <55572@debbugs.gnu.org> To: bug#55572 <55572@debbugs.gnu.org> Subject: Status: Properly indent Python PEP634 match/case blocks Reply-To: bug#55572 <55572@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:16:26 +0000 retitle 55572 Properly indent Python PEP634 match/case blocks reassign 55572 emacs submitter 55572 Lele Gaifax severity 55572 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sun May 22 05:03:33 2022 Received: (at submit) by debbugs.gnu.org; 22 May 2022 09:03:33 +0000 Received: from localhost ([127.0.0.1]:43636 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nshUr-0003Ua-Ia for submit@debbugs.gnu.org; Sun, 22 May 2022 05:03:33 -0400 Received: from lists.gnu.org ([209.51.188.17]:56556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nshUp-0003US-NS for submit@debbugs.gnu.org; Sun, 22 May 2022 05:03:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nshUp-0006Pf-Bz for bug-gnu-emacs@gnu.org; Sun, 22 May 2022 05:03:31 -0400 Received: from orphu.arstecnica.it ([178.63.97.204]:59502) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nshUn-0006ri-0M for bug-gnu-emacs@gnu.org; Sun, 22 May 2022 05:03:30 -0400 From: Lele Gaifax DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metapensiero.it; s=mail; t=1653210204; bh=led0vUbmfReyAmhe0Vru2RWLCNKL0whGE0DU7gNhlxo=; h=From:To:Subject:Date; b=iWgPAZfHkvbYRXKBwuJQEuwkTKlAxz7bNJMufIcDJh1IA5oW3BgpRXgorr73zPZFU FwY5TdUCDtZwRJWnqPPBBvk8VnBKa5BWry5VQfbGIBO16xqFOxkuSob0uDDhJ8lgIT S9kFGTKCL9lk/yjQBS2K5fWzJJ6UCO18g4467lBI= To: bug-gnu-emacs@gnu.org Subject: Properly indent Python PEP634 match/case blocks Date: Sun, 22 May 2022 11:03:22 +0200 Message-ID: <87k0aeueg5.fsf@metapensiero.it> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=178.63.97.204; envelope-from=lele@metapensiero.it; helo=orphu.arstecnica.it X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Hi, PEP634, introduced in Python 3.10, added two new keywords, "match" and "case". Commit 139042eb8629e6fd49b2c3002a8fc4d1aabd174d added them to the font-lock machinery, but missed the opportunity to configure them as block-starter as well. The attached patch does that, adding also two simple indentation tests. All the best, ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Properly-indent-Python-PEP634-match-case-blocks.patch >From 49730d01dbf3a72c29d5c881e5b5ae1fc55c71ec Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Sun, 22 May 2022 10:44:31 +0200 Subject: [PATCH] Properly indent Python PEP634 match/case blocks Python 3.10 introduced the "structural pattern matching" syntax, and commit 139042eb8629e6fd49b2c3002a8fc4d1aabd174d told font-lock about the new keywords. This adds them also as block-start statements, to enable proper indentation of such blocks. * lisp/progmodes/python.el (python-rx): Add "match" and "case" as block-start keywords. * test/lisp/progmodes/python-tests.el (python-indent-after-match-block, python-indent-after-case-block): New tests to verify indentation of "match" and "case" blocks. --- lisp/progmodes/python.el | 2 ++ test/lisp/progmodes/python-tests.el | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 0761aaebdc..94297d4ea5 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -362,6 +362,8 @@ python-rx `(rx-let ((block-start (seq symbol-start (or "def" "class" "if" "elif" "else" "try" "except" "finally" "for" "while" "with" + ;; Python 3.10+ PEP634 + "match" "case" ;; Python 3.5+ PEP492 (and "async" (+ space) (or "def" "for" "with"))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index ee7b66610a..a3f778bbbe 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -1516,6 +1516,31 @@ python-virt-bin (should (string= (buffer-substring-no-properties (point-min) (point-max)) expected))))) +(ert-deftest python-indent-after-match-block () + "Test PEP634 match." + (python-tests-with-temp-buffer + " +match foo: +" + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (goto-char (point-max)) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + +(ert-deftest python-indent-after-case-block () + "Test PEP634 case." + (python-tests-with-temp-buffer + " +match foo: + case 1: +" + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (goto-char (point-max)) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 8)))) + ;;; Filling -- 2.36.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun May 22 07:23:53 2022 Received: (at 55572) by debbugs.gnu.org; 22 May 2022 11:23:53 +0000 Received: from localhost ([127.0.0.1]:43767 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nsjgf-0007Aq-9i for submit@debbugs.gnu.org; Sun, 22 May 2022 07:23:53 -0400 Received: from quimby.gnus.org ([95.216.78.240]:39264) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nsjgb-0007AT-6J for 55572@debbugs.gnu.org; Sun, 22 May 2022 07:23:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=I026Ji0ZF7Yuh07ugbTEIiKKT843LwjE4fL/AiAFq90=; b=Q9sHTX2yrr57JDRuQbKYLiNYY4 KpcAmPGFLVfhobsVXtxmYZnFoky9wq89/JaLQ0Vj9LrqzxdD2aatj/ieuMNJwX5Jt4JwEn4x77bCo CaScystz44crTgbNC0wbk11l9HMgKUq2nImUfkoZDEt0FtFYmJs6subrmpy8zy+dqqok=; Received: from [84.212.220.105] (helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsjgS-0005Yh-NL; Sun, 22 May 2022 13:23:43 +0200 From: Lars Ingebrigtsen To: Lele Gaifax Subject: Re: bug#55572: Properly indent Python PEP634 match/case blocks References: <87k0aeueg5.fsf@metapensiero.it> X-Now-Playing: The Names's _Swimming_: "Life By The Sea" Date: Sun, 22 May 2022 13:23:40 +0200 In-Reply-To: <87k0aeueg5.fsf@metapensiero.it> (Lele Gaifax's message of "Sun, 22 May 2022 11:03:22 +0200") Message-ID: <878rqtx137.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Lele Gaifax writes: > PEP634, introduced in Python 3.10, added two new keywords, "match" > and "case". Commit 139042eb8629e6fd49b2c3002a8fc4d1aabd174d added them to the > font-lock machinery, but missed the opportunity t [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55572 Cc: 55572@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Lele Gaifax writes: > PEP634, introduced in Python 3.10, added two new keywords, "match" > and "case". Commit 139042eb8629e6fd49b2c3002a8fc4d1aabd174d added them to the > font-lock machinery, but missed the opportunity to configure them as > block-starter as well. > > The attached patch does that, adding also two simple indentation tests. Thanks; pushed to Emacs 29. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Sun May 22 07:23:57 2022 Received: (at control) by debbugs.gnu.org; 22 May 2022 11:23:57 +0000 Received: from localhost ([127.0.0.1]:43769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nsjgi-0007B2-Gj for submit@debbugs.gnu.org; Sun, 22 May 2022 07:23:57 -0400 Received: from quimby.gnus.org ([95.216.78.240]:39278) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nsjge-0007Aa-UA for control@debbugs.gnu.org; Sun, 22 May 2022 07:23:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qtmAxo/WcIQpeVoiFOF/dJcXDH9fW2AdmpsBjVx7GL8=; b=lzo4+6hinMsaus8922agy2VJan AdF5L0KLSnaHPqUMMJHhhr4R9L52pjltRg28Pd50/rjgb3S9bgv18U04fAZUAFzN40pYBbt2bIUri UT48ZdmeNIuA9Z3knxXff/5NkT1ap+Ji4j6GmNQ8JfsDI4u826rfB5pnGPhs62uce/6U=; Received: from [84.212.220.105] (helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsjgX-0005Yq-AI for control@debbugs.gnu.org; Sun, 22 May 2022 13:23:47 +0200 Date: Sun, 22 May 2022 13:23:44 +0200 Message-Id: <877d6dx133.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #55572 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 55572 29.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 55572 29.1 quit From unknown Fri Jun 20 07:16:26 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 20 Jun 2022 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator