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#59009: python mode indentation behavior fix Date: Mon, 07 Nov 2022 22:57:48 +0900 Message-ID: References: <83wn881oo4.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Mon_Nov__7_22:57:47_2022-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37665"; 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/29.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 59009@debbugs.gnu.org, Randomneo To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 07 14:59:15 2022 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 1os2eg-0009en-Gt for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Nov 2022 14:59:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os2eY-0001Wk-6G; Mon, 07 Nov 2022 08:59:06 -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 1os2eW-0001VI-EV for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2022 08:59:04 -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 1os2eU-0007ty-Fb for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2022 08:59:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1os2eU-00030b-1y for bug-gnu-emacs@gnu.org; Mon, 07 Nov 2022 08:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Nov 2022 13:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59009 X-GNU-PR-Package: emacs Original-Received: via spool by 59009-submit@debbugs.gnu.org id=B59009.166782950411517 (code B ref 59009); Mon, 07 Nov 2022 13:59:02 +0000 Original-Received: (at 59009) by debbugs.gnu.org; 7 Nov 2022 13:58:24 +0000 Original-Received: from localhost ([127.0.0.1]:33641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1os2ds-0002zh-It for submit@debbugs.gnu.org; Mon, 07 Nov 2022 08:58:24 -0500 Original-Received: from mail-pl1-f170.google.com ([209.85.214.170]:41582) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1os2dq-0002zU-Vb for 59009@debbugs.gnu.org; Mon, 07 Nov 2022 08:58:23 -0500 Original-Received: by mail-pl1-f170.google.com with SMTP id io19so11120666plb.8 for <59009@debbugs.gnu.org>; Mon, 07 Nov 2022 05:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=H2m4FWJygRhS9Tfdt3Omujp4YskzqQE5iuDamcDS7rE=; b=ZXHlxqYYS0Yq20H1534QJZB5wkbxf+WqXW82x6unN232gfjQTYbWx6ASI0G5VpZUD1 qf/Qtwfpfp8aJd00zfoyyd2Sjj/MTuYXoYp/iLyZjeQeHYSJJmv/r9rR804ZTTSdTDwc hNRQqTyo8u3woV1zPNTuolazcARxkfi0J08JXUD73fv+ojARI5UVYOuqgcTINQtewfsR KRzHuuuE1pgKKHEfJ89gMMilWjkVdEZbL1pBEom/Zs4do2RjGsPRAdiNl+Y+Uq39dQBc JOtvfj1fcgz0AM5nuC6RmYoy8AlFvQbGlCBE5Z1LRKhBB9n0KGUYYRJzMIwgyMlX19S4 9r3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=H2m4FWJygRhS9Tfdt3Omujp4YskzqQE5iuDamcDS7rE=; b=gS3RcmpXFSz+9ouZpC9cYNS9oTHdwwAzBwBP0CMa2nqdZ1asGL4yyvSEz7HSM6oSSh Vai/JD/MCc+H8rtpqWlxU7O2lys0z2Wpm24vPh9f6n8j5yzBD+TvqXouPaCMy+D0FAco MbobYC2CWx7WDRjwAVJ/Qsmve5mIAds3pOVTaf5nKomyf9Rd4ZztKdln7mcfEgtloIYI Vs7eQCoPLoqC5TSde1O00VCwF0TpyDx0ZZ1KwzhA2Lq7SXvGcb8sPAZ3YqEP9pFpsetS +eKMQhrNiwsW8IrvfrvLcf0KUELzuyFOfkpTb6/a8j3Cj46CoWFzdXCSZxz6CUzguHAz pfCA== X-Gm-Message-State: ACrzQf20nONsimdSm97rRkRNnQ2yqPBn0r166hLz64K++LivRFQF02yG Or1SwNDWIfIJsNMUJ3dTIUk= X-Google-Smtp-Source: AMsMyM4j5zZ1ezDN0O8vej5oYWNm7npk5dvY7rWZI2VQsHEFxkv2HDMPgt/vzJp+JTlXPsAkzp6F1w== X-Received: by 2002:a17:902:b70c:b0:179:eb79:cf9a with SMTP id d12-20020a170902b70c00b00179eb79cf9amr50398052pls.130.1667829497054; Mon, 07 Nov 2022 05:58:17 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id k3-20020a170902c40300b00176a6ba5969sm5023340plk.98.2022.11.07.05.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 05:58:16 -0800 (PST) In-Reply-To: <83wn881oo4.fsf@gnu.org> 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:247282 Archived-At: --Multipart_Mon_Nov__7_22:57:47_2022-1 Content-Type: text/plain; charset=US-ASCII Eli Zaretskii wrote: > > From: Randomneo > > > > 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, --Multipart_Mon_Nov__7_22:57:47_2022-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-indentation-for-multi-line-block-start-in-Python.patch" Content-Disposition: attachment; filename="0001-Fix-indentation-for-multi-line-block-start-in-Python.patch" Content-Transfer-Encoding: 7bit >From 20c81eb76f8e9251610f40e7cb6c110ddabbb8c6 Mon Sep 17 00:00:00 2001 From: kobarity 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 --Multipart_Mon_Nov__7_22:57:47_2022-1--