From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 08 05:39:38 2023 Received: (at submit) by debbugs.gnu.org; 8 Jun 2023 09:39:38 +0000 Received: from localhost ([127.0.0.1]:55694 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7C7G-0007ix-6C for submit@debbugs.gnu.org; Thu, 08 Jun 2023 05:39:38 -0400 Received: from lists.gnu.org ([209.51.188.17]:48648) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7C7A-0007im-U2 for submit@debbugs.gnu.org; Thu, 08 Jun 2023 05:39:36 -0400 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 1q7C7A-0001YO-Mo for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 05:39:32 -0400 Received: from forward101b.mail.yandex.net ([178.154.239.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7C77-0002Om-M6 for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 05:39:32 -0400 Received: from mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:2891:0:640:3c15:0]) by forward101b.mail.yandex.net (Yandex) with ESMTP id 6A9706012B for ; Thu, 8 Jun 2023 12:39:24 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id NdRqQb4WvSw0-nnoneWeC; Thu, 08 Jun 2023 12:39:24 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1686217164; bh=axbV7SDHXxpHGpntfCDDLwrnn/cyRVlV8UgH8ewJfsU=; h=Date:To:From:Subject:Message-ID; b=wna4IEg2TpNdhtLBk9DXxOcX4sqO1JD+8bi9MZKWCNp7SKucwxEIAGeI/K/oO7sdE ZMBR2TBPvkY/0/49O8MSA5a1NONyso6q2OKH7IG1Dr6iFlND8MQRX8W+THFPzLuwTd xoEz24nYLwMxfLMLtsWuod7WDiJLVqymno4CFX4s= Authentication-Results: mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> Subject: python-mode does not keep indentation in square brackets [] From: Konstantin Kharlamov To: bug-gnu-emacs@gnu.org Date: Thu, 08 Jun 2023 12:39:23 +0300 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.2 MIME-Version: 1.0 Received-SPF: pass client-ip=178.154.239.148; envelope-from=hi-angel@yandex.ru; helo=forward101b.mail.yandex.net 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, FREEMAIL_FROM=0.001, 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.3 (-) 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.3 (--) Usually in programming modes, when previous indentation is kind of "special= ", the new lines should keep the indentation from the previous line. However, = it doesn't work in this case. # Steps to reproduce 1. Create file `test.py` with following content: for infix in [ # some description "_cdata", "_cmeta", "_corig", "_cpool", "_cvol", "_wcorig= ", "indentation is broken here", "bar"]: print(infix) 2. Open it as `emacs -Q test.py` 3. Put a caret on the 3rd line (which says "indentation is broken" 4. Press TAB ## Expected Indentation won't change ## Actual The line goes back by 4 spaces or so # Additional information emacs version: compiled from latest git a week ago, commit 5cace109d2b From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 09 07:21:24 2023 Received: (at 63959) by debbugs.gnu.org; 9 Jun 2023 11:21:24 +0000 Received: from localhost ([127.0.0.1]:58484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7aBI-0004OY-1y for submit@debbugs.gnu.org; Fri, 09 Jun 2023 07:21:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7aBG-0004OM-BX for 63959@debbugs.gnu.org; Fri, 09 Jun 2023 07:21:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7aBA-0000iB-TS; Fri, 09 Jun 2023 07:21:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=sSc6kD56w69HKqrxxxDk+SvdbvL8peW52bDivQunwo0=; b=DFcNC9Pjh6LO eh3gunn/98NntsAvQXsnBaXm9yudUO4cijwPZd+ELlbw4zGKE0XFRjzzrnPeJZW8KYXnZxRJDtUrc E3xm1SWyyXHdNFSBQqBzUhboAi898AGLlcYFqD9S9SlgN5Ga7bLtr75T7Vena82+r2sG3+eYEuLu7 0jjpdgdTYpXMtmRMfkD6DvdzguqohVyCGkrMcVtCp1yzmnnwdgDbfwO8G3jTTL8aYqs1rTLZxhP32 8CZmc7KHwQrWH2IhxFESQypdeJrZnOdQPYaWUSH+5I5GHBoxamdtb20cHYSHK5NlI2eo9aW/Zojpz ImlcPxHIcRRS8JVodwG0KQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7aBA-0005KV-A3; Fri, 09 Jun 2023 07:21:16 -0400 Date: Fri, 09 Jun 2023 14:21:24 +0300 Message-Id: <83mt18285n.fsf@gnu.org> From: Eli Zaretskii To: Konstantin Kharlamov , kobarity In-Reply-To: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> (message from Konstantin Kharlamov on Thu, 08 Jun 2023 12:39:23 +0300) Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 63959 Cc: Stefan Monnier , 63959@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 (---) > From: Konstantin Kharlamov > Date: Thu, 08 Jun 2023 12:39:23 +0300 > > Usually in programming modes, when previous indentation is kind of "special", > the new lines should keep the indentation from the previous line. However, it > doesn't work in this case. > > > # Steps to reproduce > > 1. Create file `test.py` with following content: > > for infix in [ # some description > "_cdata", "_cmeta", "_corig", "_cpool", "_cvol", "_wcorig", > "indentation is broken here", "bar"]: > print(infix) > > 2. Open it as `emacs -Q test.py` > 3. Put a caret on the 3rd line (which says "indentation is broken" > 4. Press TAB > > > ## Expected > > Indentation won't change > > ## Actual > > The line goes back by 4 spaces or so > > # Additional information > > emacs version: compiled from latest git a week ago, commit 5cace109d2b kobarity, any comments? From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 09 10:36:01 2023 Received: (at 63959) by debbugs.gnu.org; 9 Jun 2023 14:36:01 +0000 Received: from localhost ([127.0.0.1]:59991 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7dDd-0003vg-1O for submit@debbugs.gnu.org; Fri, 09 Jun 2023 10:36:01 -0400 Received: from mail-pf1-f171.google.com ([209.85.210.171]:54548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7dDa-0003vT-RN for 63959@debbugs.gnu.org; Fri, 09 Jun 2023 10:35:59 -0400 Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-65131e85be4so1916077b3a.1 for <63959@debbugs.gnu.org>; Fri, 09 Jun 2023 07:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686321351; x=1688913351; 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=lSIn5X+nrO2Oo+JKTcu8zqYg9ldVIJ5K1ZEj/4IKH34=; b=eoG1Z6bLuiap9KfLkZEK5/UV7LPKbQ2ZvoZ8lyfl+OoVddgVAaqJuwM2xBagP9Fvzr XtCfZIkjIG0jejHLk4XUcJ2tfTsOE6gx+TaE3ZzYFo/ViRAV62E/pulmymkfDnR9lLvo JqfYb2wRjvHHVgtgASgnc4XuGncMy6dTtAZgwXQvjNFmBaDLU19ruSO0i2VGKZx6BoGz NdHqClvPNjFsZv+hZTTFouGjY1BahEznAMWnXWx5Imhjhl9rOUL62t3NT6WlpiMcrBfS HnlmFVqdBDxei0fDOsTzyuyjzgdfRlwxI5uuiVrSFj66d/5/pDsy09V+dxFJ+noyj1am +vWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686321351; x=1688913351; 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=lSIn5X+nrO2Oo+JKTcu8zqYg9ldVIJ5K1ZEj/4IKH34=; b=axoCRVfhC7Wr8Hgo0OqxPX5CFyz4Agw0SCWUE+NOv5P0Vos17k8a2JhkdisGkZCYI/ 9DrtH1D95DXzscIDcCKs80DqqjnUQ/p2l0apI7fkpv95C4lbi8QFXusi/JXWry6UxW1s ENlXpKp5Y1WjdMySB5ftfoXrU4qIP6sr3j6kWZMpLG1ejYbP9jXMFQpL9VzUMhm0aeFU CsF0AVrCOJEAWsHUuY+DBUcZPeL+mHEq5hCE6TBbMhCTHeHM94SUITtChV1OKeGSwtDB 9RavpbK2FrADlFeE/9a6UT5+ezpNNiHPddTfYfBTG6RNW+9AvmoS6ecshYLrDPz0EoiK U6Gw== X-Gm-Message-State: AC+VfDzcqiIELIwg+5F831atDqCC/PLiulO6rZg75JwXu6goDxJeeg0w DCYzU7Co/WM3rmaiVgI9p/Q= X-Google-Smtp-Source: ACHHUZ60IPgVGqPkoi4f5sfcqv8b2JK0jfnGjLqP+uuwMT7wlVG4ULrL5Z3sEeUH+bR8btyp1PG9SA== X-Received: by 2002:a05:6a20:8f11:b0:10b:40a9:ec48 with SMTP id b17-20020a056a208f1100b0010b40a9ec48mr1785462pzk.29.1686321350568; Fri, 09 Jun 2023 07:35:50 -0700 (PDT) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id d16-20020aa78690000000b006505bae11bcsm2791480pfo.23.2023.06.09.07.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 07:35:50 -0700 (PDT) Date: Fri, 09 Jun 2023 23:35:30 +0900 Message-ID: From: kobarity To: Eli Zaretskii Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] In-Reply-To: <83mt18285n.fsf@gnu.org> References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 63959 Cc: 63959@debbugs.gnu.org, Stefan Monnier , Konstantin Kharlamov 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: -1.0 (-) Eli Zaretskii wrote: > > From: Konstantin Kharlamov > > Date: Thu, 08 Jun 2023 12:39:23 +0300 > > > > Usually in programming modes, when previous indentation is kind of "special", > > the new lines should keep the indentation from the previous line. However, it > > doesn't work in this case. > > > > > > # Steps to reproduce > > > > 1. Create file `test.py` with following content: > > > > for infix in [ # some description > > "_cdata", "_cmeta", "_corig", "_cpool", "_cvol", "_wcorig", > > "indentation is broken here", "bar"]: > > print(infix) > > > > 2. Open it as `emacs -Q test.py` > > 3. Put a caret on the 3rd line (which says "indentation is broken" > > 4. Press TAB > > > > > > ## Expected > > > > Indentation won't change > > > > ## Actual > > > > The line goes back by 4 spaces or so > > > > # Additional information > > > > emacs version: compiled from latest git a week ago, commit 5cace109d2b > > kobarity, any comments? I think the current Python mode tries to indent based on parens, regardless of the indentation of the previous line. However, it would also be reasonable to maintain the indentation of the previous line. I will see if I can implement it. From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 18 10:57:20 2023 Received: (at 63959) by debbugs.gnu.org; 18 Jun 2023 14:57:20 +0000 Received: from localhost ([127.0.0.1]:54819 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAtqC-0003eq-43 for submit@debbugs.gnu.org; Sun, 18 Jun 2023 10:57:20 -0400 Received: from mail-pf1-f169.google.com ([209.85.210.169]:42131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAtqA-0003eX-16 for 63959@debbugs.gnu.org; Sun, 18 Jun 2023 10:57:18 -0400 Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-666edfc50deso891612b3a.0 for <63959@debbugs.gnu.org>; Sun, 18 Jun 2023 07:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687100232; x=1689692232; 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=CJyP7ZEzRUArAK1dU54KnxAVnoBHjdnT5sBvqzGX5po=; b=O+cchf0mApuJwCl5mlZol5C2jsSmPX411X+ri+Bttkemvl2X05q0fD3U3qyVy9uTSS AbBUDDaq3GJxNxsSQdAUD3rkqPWn8oTWRDm9F6mI23d99wOUK1xGa5IfFSPLDKhq/YjH PPrBA3Favt3+s3diDxKJJwVinbXqJMMoYasGqAzoLYIwmz/0YWCUyKU4YFKXElS3Vlrq GPi67gxkG9Qw4rv0giSaMPzk0JZVzIYhNimsPUOxKdbDyYZrlRu3cWUx69lybh4WcigT lvaz8gcgnjNgPdP0wirE1KHiOEJ5DLzNGEWFNZiJqUkzaIjSD3iaQ0Lx6wT01+E3vYq+ BWEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687100232; x=1689692232; 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=CJyP7ZEzRUArAK1dU54KnxAVnoBHjdnT5sBvqzGX5po=; b=EuIHbkdpTZ3vqlKxslhWiAmuSlhGA0Jz1DCjFHueBnR15bm9G8NYVgeuOfxSY99P6H ZLAKyCT6WWgJ9MpsXmjVMw3Tflbpvf8B4uj1kT9J+Tcj9iyMV0edYJYF4SG5pubsMj0+ qhE0FhoJNhs4dzFnvNvXfGW0Ma+toTviXYFluXQ0+gWZf7ov4FiWkuv52YSBjj5auNfA CSGKVcw0Y0fBy0zUHxzM5zK+WAjSfCiMvIWF39fVB3RR6Ln3x2yCbptrUYXskEic5npj P/7gSiZOWvHFrRwQcJNOrO67gAFh65zlxHw6qg0p8SNw000epPDmGrb0+QILJ7eIehGh rCvQ== X-Gm-Message-State: AC+VfDyUPTRa/QkYmxaYKmtTjxM25joqRAJjzKsSqpIKJFZnvguQVeMJ NZvMAOD3UZ0yxanvIwsitBk= X-Google-Smtp-Source: ACHHUZ4exj9O9rwC3AQQVGDckOCvIqK0VUKntngflvW9VeT6y8MD7BqGpxRLoI+JjQeOnwmQo+eDBA== X-Received: by 2002:a05:6a00:17a3:b0:668:7fb2:d9a5 with SMTP id s35-20020a056a0017a300b006687fb2d9a5mr198880pfg.17.1687100231739; Sun, 18 Jun 2023 07:57:11 -0700 (PDT) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id m26-20020a056a00165a00b0064f71d8adf8sm16155120pfc.208.2023.06.18.07.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 07:57:11 -0700 (PDT) Date: Sun, 18 Jun 2023 23:56:50 +0900 Message-ID: From: kobarity To: Eli Zaretskii Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] In-Reply-To: References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sun_Jun_18_23:56:49_2023-1" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 63959 Cc: 63959@debbugs.gnu.org, Stefan Monnier , Konstantin Kharlamov 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: -1.0 (-) --Multipart_Sun_Jun_18_23:56:49_2023-1 Content-Type: text/plain; charset=US-ASCII I wrote: > Eli Zaretskii wrote: > > > From: Konstantin Kharlamov > > > Date: Thu, 08 Jun 2023 12:39:23 +0300 > > > > > > Usually in programming modes, when previous indentation is kind of "special", > > > the new lines should keep the indentation from the previous line. However, it > > > doesn't work in this case. > > > > > > > > > # Steps to reproduce > > > > > > 1. Create file `test.py` with following content: > > > > > > for infix in [ # some description > > > "_cdata", "_cmeta", "_corig", "_cpool", "_cvol", "_wcorig", > > > "indentation is broken here", "bar"]: > > > print(infix) > > > > > > 2. Open it as `emacs -Q test.py` > > > 3. Put a caret on the 3rd line (which says "indentation is broken" > > > 4. Press TAB > > > > > > > > > ## Expected > > > > > > Indentation won't change > > > > > > ## Actual > > > > > > The line goes back by 4 spaces or so > > > > > > # Additional information > > > > > > emacs version: compiled from latest git a week ago, commit 5cace109d2b > > > > kobarity, any comments? > > I think the current Python mode tries to indent based on parens, > regardless of the indentation of the previous line. However, it would > also be reasonable to maintain the indentation of the previous line. > I will see if I can implement it. Attached is a patch to implement it. I introduced a new indent context `:inside-paren-continuation-line' for the continuation lines within paren. The indent context respects the indentation of the previous line. However, it may happen that the previous line is indented for the inner paren as in the ERT `python-indent-inside-paren-2': data = {'key': { 'objlist': [ {'pk': 1, 'name': 'first'}, {'pk': 2, 'name': 'second'} ] }} The line "{'pk': 2," is considered as the continuation line, but it should not respect the indentation of the PREVIOUS line "'name': 'first'},". So skipping such lines with inner parens were needed. It searches backward for the line which starts with the item of the same opening paren as the target line. In the case of the above example, if the target line is "{'pk': 2,", its opening paren is "[" in the line "'objlist': [". It first checks the previous line "'name': 'first'},", but its opening paren is "{" in "{'pk': 1,". So this line is skipped. Next, it checks the line "{'pk': 1," and its opening paren is "[" in the line "'objlist': [", which is same as the target line. So the target line's indentation will be as same as the line "{'pk': 1,". It would be helpful if you could try this patch. Does anyone think we should have a customize variable that switches between the traditional behavior of ignoring the indentation of the previous line and this new behavior? --Multipart_Sun_Jun_18_23:56:49_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-Python-indentation-of-continuation-lines-within-.patch" Content-Disposition: attachment; filename="0001-Fix-Python-indentation-of-continuation-lines-within-.patch" Content-Transfer-Encoding: 7bit >From c3aac2626eb346b19f5128208dc6ca4b7ca7b6c3 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sun, 18 Jun 2023 23:47:25 +0900 Subject: [PATCH] Fix Python indentation of continuation lines within parens * lisp/progmodes/python.el (python-indent-context): Add a new indent context `:inside-paren-continuation-line'. (python-indent--calculate-indentation): Use the new indent context. * test/lisp/progmodes/python-tests.el (python-indent-pep8-2) (python-indent-pep8-3) (python-indent-inside-paren-1) (python-indent-inside-paren-2) (python-indent-inside-paren-3) (python-indent-inside-paren-6) (python-indent-after-backslash-2): Change to use the new indent context. (python-indent-inside-paren-8) (python-indent-inside-paren-9): New tests. (Bug#63959) --- lisp/progmodes/python.el | 26 ++++++++- test/lisp/progmodes/python-tests.el | 89 +++++++++++++++++++++++++---- 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 26dafde7591..50d712ebb0c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1406,6 +1406,10 @@ python-indent-context - Point is inside a paren from a block start followed by some items on the same line. - START is the first non space char position *after* the open paren. +:inside-paren-continuation-line + - Point is on a continuation line inside a paren. + - START is the position where the previous line (excluding lines + for inner parens) starts. :after-backslash - Fallback case when point is after backslash. @@ -1460,7 +1464,21 @@ python-indent-context (= (line-number-at-pos) (progn (python-util-forward-comment) - (line-number-at-pos)))))))) + (line-number-at-pos))))))) + (continuation-start + (when start + (save-excursion + (forward-line -1) + (back-to-indentation) + ;; Skip inner parens. + (cl-loop with prev-start = (python-syntax-context 'paren) + while (and prev-start (>= prev-start start)) + if (= prev-start start) + return (point) + else do (goto-char prev-start) + (back-to-indentation) + (setq prev-start + (python-syntax-context 'paren))))))) (when start (cond ;; Current line only holds the closing paren. @@ -1476,6 +1494,9 @@ python-indent-context (back-to-indentation) (python-syntax-closing-paren-p)) (cons :inside-paren-at-closing-nested-paren start)) + ;; This line is a continuation of the previous line. + (continuation-start + (cons :inside-paren-continuation-line continuation-start)) ;; This line starts from an opening block in its own line. ((save-excursion (goto-char start) @@ -1591,7 +1612,8 @@ python-indent--calculate-indentation (`(,(or :after-line :after-comment :inside-string - :after-backslash) . ,start) + :after-backslash + :inside-paren-continuation-line) . ,start) ;; Copy previous indentation. (goto-char start) (current-indentation)) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 9323f72f384..54e32cbf07b 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -683,7 +683,7 @@ python-indent-pep8-2 (should (= (python-indent-calculate-indentation) 8)) (python-tests-look-at "var_four):") (should (eq (car (python-indent-context)) - :inside-paren-newline-start-from-block)) + :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 8)) (python-tests-look-at "print (var_one)") (should (eq (car (python-indent-context)) @@ -707,8 +707,8 @@ python-indent-pep8-3 (should (eq (car (python-indent-context)) :inside-paren-newline-start)) (should (= (python-indent-calculate-indentation) 4)) (python-tests-look-at "var_three, var_four)") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) - (should (= (python-indent-calculate-indentation) 4)))) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) + (should (= (python-indent-calculate-indentation) 2)))) (ert-deftest python-indent-hanging-close-paren () "Like first pep8 case, but with hanging close paren." ;; See Bug#20742. @@ -864,7 +864,7 @@ python-indent-inside-paren-1 (should (eq (car (python-indent-context)) :inside-paren-newline-start)) (should (= (python-indent-calculate-indentation) 4)) (python-tests-look-at "{") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 4)) (python-tests-look-at "'objlist': [") (should (eq (car (python-indent-context)) :inside-paren-newline-start)) @@ -876,20 +876,20 @@ python-indent-inside-paren-1 (should (eq (car (python-indent-context)) :inside-paren-newline-start)) (should (= (python-indent-calculate-indentation) 16)) (python-tests-look-at "'name': 'first',") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 16)) (python-tests-look-at "},") (should (eq (car (python-indent-context)) :inside-paren-at-closing-nested-paren)) (should (= (python-indent-calculate-indentation) 12)) (python-tests-look-at "{") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 12)) (python-tests-look-at "'pk': 2,") (should (eq (car (python-indent-context)) :inside-paren-newline-start)) (should (= (python-indent-calculate-indentation) 16)) (python-tests-look-at "'name': 'second',") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 16)) (python-tests-look-at "}") (should (eq (car (python-indent-context)) @@ -933,7 +933,7 @@ python-indent-inside-paren-2 (should (eq (car (python-indent-context)) :inside-paren)) (should (= (python-indent-calculate-indentation) 9)) (python-tests-look-at "{'pk': 2,") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 8)) (python-tests-look-at "'name': 'second'}") (should (eq (car (python-indent-context)) :inside-paren)) @@ -966,10 +966,10 @@ python-indent-inside-paren-3 (should (eq (car (python-indent-context)) :inside-paren)) (should (= (python-indent-calculate-indentation) 8)) (forward-line 1) - (should (eq (car (python-indent-context)) :inside-paren)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 8)) (forward-line 1) - (should (eq (car (python-indent-context)) :inside-paren)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 8)))) (ert-deftest python-indent-inside-paren-4 () @@ -1023,7 +1023,7 @@ python-indent-inside-paren-6 (should (eq (car (python-indent-context)) :inside-paren)) (should (= (python-indent-calculate-indentation) 11)) (forward-line 1) - (should (eq (car (python-indent-context)) :inside-paren)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 11)))) (ert-deftest python-indent-inside-paren-7 () @@ -1034,6 +1034,71 @@ python-indent-inside-paren-7 ;; This signals an error if the test fails (should (eq (car (python-indent-context)) :inside-paren-newline-start)))) +(ert-deftest python-indent-inside-paren-8 () + "Test for Bug#63959." + (python-tests-with-temp-buffer + " +for a in [ # comment + 'some', # Manually indented. + 'thing']: # Respect indentation of the previous line. +" + (python-tests-look-at "for a in [ # comment") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) + :inside-paren-newline-start-from-block)) + (should (= (python-indent-calculate-indentation) 8)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) + (should (= (python-indent-calculate-indentation) 10)))) + +(ert-deftest python-indent-inside-paren-9 () + "Test `:inside-paren-continuation-line'." + (python-tests-with-temp-buffer + " +a = ((( + 1, 2), + 3), # Do not respect the indentation of the previous line + 4) # Do not respect the indentation of the previous line +b = (( + 1, 2), # Manually indented + 3, # Do not respect the indentation of the previous line + 4, # Respect the indentation of the previous line + 5, # Manually indented + 6) # Respect the indentation of the previous line +" + (python-tests-look-at "a = (((") + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren)) + (should (= (python-indent-calculate-indentation) 6)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren)) + (should (= (python-indent-calculate-indentation) 5)) + (forward-line 1) + (should (eq (car (python-indent-context)) :after-line)) + (should (= (python-indent-calculate-indentation) 0)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (= (python-indent-calculate-indentation) 4)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren)) + (should (= (python-indent-calculate-indentation) 5)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) + (should (= (python-indent-calculate-indentation) 5)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) + (should (= (python-indent-calculate-indentation) 5)) + (forward-line 1) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) + (should (= (python-indent-calculate-indentation) 8)))) + (ert-deftest python-indent-inside-paren-block-1 () "`python-indent-block-paren-deeper' set to nil (default). See Bug#62696." @@ -1271,7 +1336,7 @@ python-indent-after-backslash-2 (should (eq (car (python-indent-context)) :inside-paren-newline-start)) (should (= (python-indent-calculate-indentation) 27)) (python-tests-look-at "status='bought'") - (should (eq (car (python-indent-context)) :inside-paren-newline-start)) + (should (eq (car (python-indent-context)) :inside-paren-continuation-line)) (should (= (python-indent-calculate-indentation) 27)) (python-tests-look-at ") \\") (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren)) -- 2.34.1 --Multipart_Sun_Jun_18_23:56:49_2023-1-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 18 11:20:33 2023 Received: (at 63959) by debbugs.gnu.org; 18 Jun 2023 15:20:33 +0000 Received: from localhost ([127.0.0.1]:54839 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAuCf-0004OU-E6 for submit@debbugs.gnu.org; Sun, 18 Jun 2023 11:20:33 -0400 Received: from forward500b.mail.yandex.net ([178.154.239.144]:36660) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAuCb-0004OC-UA for 63959@debbugs.gnu.org; Sun, 18 Jun 2023 11:20:31 -0400 Received: from mail-nwsmtp-smtp-production-main-37.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-37.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:601e:0:640:1bb:0]) by forward500b.mail.yandex.net (Yandex) with ESMTP id 2B9E95E8F2; Sun, 18 Jun 2023 18:20:27 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-37.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id PKhj6kXDTuQ0-6nz9QvGs; Sun, 18 Jun 2023 18:20:26 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1687101626; bh=yGSCYVD61g6nbvDV63c78H03AGTzL2/eeGhqgumLys4=; h=References:Date:In-Reply-To:Cc:To:From:Subject:Message-ID; b=rDx+3ugihJkD5Mge/D9MiD/lrD9afqhkSbOPEnz7vb2Gs0iz0kzfK8rkTYNzxX5XA Mt2n53gpQInGYRxWToHQuoyF7jQtUetMmRtioii+Z9j3+kfxFcM+byXHsr4WR6HKlI CiZzlE/8pN3B1eE9irQrI5OysfQc7U2DTThoqPFk= Authentication-Results: mail-nwsmtp-smtp-production-main-37.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] From: Konstantin Kharlamov To: kobarity , Eli Zaretskii Date: Sun, 18 Jun 2023 18:20:25 +0300 In-Reply-To: References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 MIME-Version: 1.0 X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 63959 Cc: Stefan Monnier , 63959@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: -1.0 (-) On Sun, 2023-06-18 at 23:56 +0900, kobarity wrote: >=20 > I wrote: > > Eli Zaretskii wrote: > > > > From: Konstantin Kharlamov > > > > Date: Thu, 08 Jun 2023 12:39:23 +0300 > > > >=20 > > > > Usually in programming modes, when previous indentation is kind of > > > > "special", > > > > the new lines should keep the indentation from the previous line. > > > > However, it > > > > doesn't work in this case. > > > >=20 > > > >=20 > > > > # Steps to reproduce > > > >=20 > > > > 1. Create file `test.py` with following content: > > > >=20 > > > > =C2=A0=C2=A0=C2=A0 for infix in [ # some description > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "_cdata", "_cmeta", "_corig", "_cpool"= , "_cvol", > > > > "_wcorig", > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "indentation is broken here", "bar"]: > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print(infix) > > > >=20 > > > > 2. Open it as `emacs -Q test.py` > > > > 3. Put a caret on the 3rd line (which says "indentation is broken" > > > > 4. Press TAB > > > >=20 > > > >=20 > > > > ## Expected > > > >=20 > > > > Indentation won't change > > > >=20 > > > > ## Actual > > > >=20 > > > > The line goes back by 4 spaces or so > > > >=20 > > > > # Additional information > > > >=20 > > > > emacs version: compiled from latest git a week ago, commit 5cace109= d2b > > >=20 > > > kobarity, any comments? > >=20 > > I think the current Python mode tries to indent based on parens, > > regardless of the indentation of the previous line.=C2=A0 However, it w= ould > > also be reasonable to maintain the indentation of the previous line. > > I will see if I can implement it. >=20 > Attached is a patch to implement it.=C2=A0 I introduced a new indent > context `:inside-paren-continuation-line' for the continuation lines > within paren.=C2=A0 The indent context respects the indentation of the > previous line. >=20 > However, it may happen that the previous line is indented for the > inner paren as in the ERT `python-indent-inside-paren-2': >=20 > data =3D {'key': { > =C2=A0=C2=A0=C2=A0 'objlist': [ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {'pk': 1, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'name': 'first'}, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {'pk': 2, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'name': 'second'} > =C2=A0=C2=A0=C2=A0 ] > }} >=20 > The line "{'pk': 2," is considered as the continuation line, but it > should not respect the indentation of the PREVIOUS line "'name': > 'first'},".=C2=A0 So skipping such lines with inner parens were needed. > It searches backward for the line which starts with the item of the > same opening paren as the target line. >=20 > In the case of the above example, if the target line is "{'pk': 2,", > its opening paren is "[" in the line "'objlist': [".=C2=A0 It first check= s > the previous line "'name': 'first'},", but its opening paren is "{" in > "{'pk': 1,".=C2=A0 So this line is skipped.=C2=A0 Next, it checks the lin= e > "{'pk': 1," and its opening paren is "[" in the line "'objlist': [", > which is same as the target line.=C2=A0 So the target line's indentation > will be as same as the line "{'pk': 1,". >=20 > It would be helpful if you could try this patch. Thank you, tested, works for me! > Does anyone think we should have a customize variable that switches > between the traditional behavior of ignoring the indentation of the > previous line and this new behavior? I doubt it's useful. It is in general how indentation works in many modes, = and I don't think there ever been a variable to disable that. Stefan Monnier in particular has a paper called "SMIE: weakness is power", where such indenta= tion is shortly discussed. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 19 04:46:57 2023 Received: (at submit) by debbugs.gnu.org; 19 Jun 2023 08:46:57 +0000 Received: from localhost ([127.0.0.1]:55494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBAXI-0002SW-KS for submit@debbugs.gnu.org; Mon, 19 Jun 2023 04:46:57 -0400 Received: from lists.gnu.org ([209.51.188.17]:56844) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qBAXF-0002SL-QL for submit@debbugs.gnu.org; Mon, 19 Jun 2023 04:46:55 -0400 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 1qBAXF-0000NL-AH for bug-gnu-emacs@gnu.org; Mon, 19 Jun 2023 04:46:53 -0400 Received: from mout.kundenserver.de ([212.227.126.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBAXD-0001ng-Bq for bug-gnu-emacs@gnu.org; Mon, 19 Jun 2023 04:46:53 -0400 Received: from [192.168.178.61] ([89.247.171.240]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MlwBf-1pllfP3qrL-00j1JE for ; Mon, 19 Jun 2023 10:46:48 +0200 Message-ID: <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> Date: Mon, 19 Jun 2023 10:46:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] To: bug-gnu-emacs@gnu.org References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> Content-Language: en-US From: =?UTF-8?Q?Andreas_R=c3=b6hler?= In-Reply-To: <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:gCKrQ+YEgQ2B4gjf8vZivYrp0hzDhdDLKKzDYCJhfCYCC6R97Wl EA+GfDgfG70G0rz5uJDiM3GmB1wIE1x+sFFty2x1RZAJ+dmUa7t4ZFThfmxccKPJ4q7u+eQ rOncdmT9XDTBBEiQJGLAOgshyC3nK5WwTGVxslbwxufAb70GQZ6KiWgAURcAc60G0+VcoeC qZqETn8rxyKANAdDEVMdw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:wSpZjJAZMvw=;wXhQcAxtKZRDCgIR4QwiVyIqS5J vxktj9vVcDcfKuIpv+x/T0e4ETU4kkV41RboHBJS3kq9q9/BrOEkANXK8YtHFLJNWF6Xw9OSB I2vNIUolXcLk8CuPtl0ECH7CmwJCPO0PZ1kROkpW6/rTmaKljW9xjQRm15JOJaDK9ybqz4if9 jMmvKCEiI806mbpBZWmxSM6xxiuGzIkh58qbsh8cj6oIneRCK1BikUyE7gMcyZT+D2bSu32IV L0Hy7Ml36FkZQWntbehOAB2rLXrdsJNXfhXa7ZFpil9rlfupFH/YhLzSc9gjlf5yofUd8G/SJ FdYVtC85XyBQi8fUA0pwinaFIhTDjxGPv4NlCxPxRV5kOff9YLx4KvQ6wjXlUi6XUWNYGkO9q jM6PCgv5LtvzhkoZKlO4ZTNIA8L1Qcw8h8Qknlc8Eer0qbgd5IWPLBUQVtPRabW+AAfnOIvRS BTDIUArnIGlOjjyZT8/2dr/Jqt6UVy/2/C5GqfnDNy3DY0e0XS2nYqiWB7Sfxit7mxU0snaal LtCyt9TtglplUG+z1f/2RdjR/3sL1Gn7vPDIBGQKKpvQs2zJuxFZ5yp/QB3JspV6gC3yFTbG5 rVgQelAodha5cX5l2OZiMt0xyPihAAu3tYQE8kdz+UhjJT+BCbm8GRzlo7saR3o0dFOe1ROwR nkkl4D0ajMeVc0t91LsKqOFZs85oDfnBvBda08iQ7g== Received-SPF: pass client-ip=212.227.126.187; envelope-from=andreas.roehler@easy-emacs.de; helo=mout.kundenserver.de X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.09, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: -2.5 (--) 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: -3.5 (---) Am 18.06.23 um 17:20 schrieb Konstantin Kharlamov: > On Sun, 2023-06-18 at 23:56 +0900, kobarity wrote: >> I wrote: >>> Eli Zaretskii wrote: >>>>> From: Konstantin Kharlamov >>>>> Date: Thu, 08 Jun 2023 12:39:23 +0300 >>>>> >>>>> Usually in programming modes, when previous indentation is kind of >>>>> "special", >>>>> the new lines should keep the indentation from the previous line. >>>>> However, it >>>>> doesn't work in this case. >>>>> >>>>> >>>>> # Steps to reproduce >>>>> >>>>> 1. Create file `test.py` with following content: >>>>> >>>>>     for infix in [ # some description >>>>>                   "_cdata", "_cmeta", "_corig", "_cpool", "_cvol", >>>>> "_wcorig", >>>>>                   "indentation is broken here", "bar"]: >>>>>         print(infix) >>>>> >>>>> 2. Open it as `emacs -Q test.py` >>>>> 3. Put a caret on the 3rd line (which says "indentation is broken" >>>>> 4. Press TAB >>>>> >>>>> >>>>> ## Expected >>>>> >>>>> Indentation won't change >>>>> >>>>> ## Actual >>>>> >>>>> The line goes back by 4 spaces or so >>>>> >>>>> # Additional information >>>>> >>>>> emacs version: compiled from latest git a week ago, commit 5cace109d2b >>>> kobarity, any comments? >>> I think the current Python mode tries to indent based on parens, >>> regardless of the indentation of the previous line.  However, it would >>> also be reasonable to maintain the indentation of the previous line. >>> I will see if I can implement it. >> Attached is a patch to implement it.  I introduced a new indent >> context `:inside-paren-continuation-line' for the continuation lines >> within paren.  The indent context respects the indentation of the >> previous line. >> >> However, it may happen that the previous line is indented for the >> inner paren as in the ERT `python-indent-inside-paren-2': >> >> data = {'key': { >>     'objlist': [ >>         {'pk': 1, >>          'name': 'first'}, >>         {'pk': 2, >>          'name': 'second'} >>     ] >> }} >> >> The line "{'pk': 2," is considered as the continuation line, but it >> should not respect the indentation of the PREVIOUS line "'name': >> 'first'},".  So skipping such lines with inner parens were needed. >> It searches backward for the line which starts with the item of the >> same opening paren as the target line. >> >> In the case of the above example, if the target line is "{'pk': 2,", >> its opening paren is "[" in the line "'objlist': [".  It first checks >> the previous line "'name': 'first'},", but its opening paren is "{" in >> "{'pk': 1,".  So this line is skipped.  Next, it checks the line >> "{'pk': 1," and its opening paren is "[" in the line "'objlist': [", >> which is same as the target line.  So the target line's indentation >> will be as same as the line "{'pk': 1,". >> >> It would be helpful if you could try this patch. > Thank you, tested, works for me! > >> Does anyone think we should have a customize variable that switches >> between the traditional behavior of ignoring the indentation of the >> previous line and this new behavior? > I doubt it's useful. It is in general how indentation works in many modes, and I > don't think there ever been a variable to disable that. Stefan Monnier in > particular has a paper called "SMIE: weakness is power", where such indentation > is shortly discussed. > > > IMO the question of previous lines indentation isn't raised here, as a more specific rule applies: inside a non-empty list > indent with its first element. Whereas if list starts empty, as with "[" here, next indents as that line plus offset. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 24 08:14:02 2023 Received: (at 63959-done) by debbugs.gnu.org; 24 Jun 2023 12:14:02 +0000 Received: from localhost ([127.0.0.1]:40028 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD29R-0006DB-RT for submit@debbugs.gnu.org; Sat, 24 Jun 2023 08:14:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD29O-0006Cl-CB for 63959-done@debbugs.gnu.org; Sat, 24 Jun 2023 08:14:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qD29I-0002K0-Eq; Sat, 24 Jun 2023 08:13:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=F9oM9EBuHq9gDaSQKKn8bzS4iyKDhdk0fOmezUSuYTo=; b=SwsotdjIeokJ iNzwUq4z8JOLy3bo9kRu0NbbNgN4iSyxUOB23diMK6Da0pUw7jJvUJIky1eTKocTjxiyDSSMoBcfq Pd4TccZm4qqCrNYAmqpFG8xve4AqpKuJAcfRhDcaXZIBCvreQ8QFSs9OZ+0bB6IvVjpKOHRj7dfuK p/QKdZy2jvhDO0Cmg9YdxmbGkBbDuGZnhPLzaPOoblaDRTzhT1ktk3NlDTfaR1Nd8Obd5sIuKqznE /1wzOJ6sHpoX+ghqBqraff2ZSNPnyfxc/buPzx09ZYgaF6h1RU5kD/orFFZkDU1KZVFxDea4XfQ+9 Hmv6esWGfKOAQbaJUulBtg==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qD29H-000247-Uj; Sat, 24 Jun 2023 08:13:52 -0400 Date: Sat, 24 Jun 2023 15:14:07 +0300 Message-Id: <83jzvtys4w.fsf@gnu.org> From: Eli Zaretskii To: Konstantin Kharlamov In-Reply-To: <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> (message from Konstantin Kharlamov on Sun, 18 Jun 2023 18:20:25 +0300) Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 63959-done Cc: 63959-done@debbugs.gnu.org, kobarity@gmail.com, monnier@iro.umontreal.ca 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 (---) > From: Konstantin Kharlamov > Cc: 63959@debbugs.gnu.org, Stefan Monnier > Date: Sun, 18 Jun 2023 18:20:25 +0300 > > > It would be helpful if you could try this patch. > > Thank you, tested, works for me! Thanks for testing. I've now installed this on the master branch, and I'm marking the bug done. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 24 08:37:31 2023 Received: (at 63959) by debbugs.gnu.org; 24 Jun 2023 12:37:31 +0000 Received: from localhost ([127.0.0.1]:40082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD2WA-0006pQ-UW for submit@debbugs.gnu.org; Sat, 24 Jun 2023 08:37:31 -0400 Received: from mail-pl1-f182.google.com ([209.85.214.182]:49335) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qD2W5-0006p7-6i for 63959@debbugs.gnu.org; Sat, 24 Jun 2023 08:37:29 -0400 Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1b52bf6e669so12741015ad.2 for <63959@debbugs.gnu.org>; Sat, 24 Jun 2023 05:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687610239; x=1690202239; h=content-transfer-encoding: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=TNzNKMQuCLlGDUHWP1jWsTv4pWE8lB9OZyUsVk9bTcc=; b=Aalj8ztV2phU7hOYNdmKY8J26FPWkBO93V5r+zVfFAgeyi4FPCqCYlugRMbTYBuUv9 45bHNAEmqMioP/Hu25Cf7sfQkfkgEAzqlh/n0o8EYNfI9EdEEcifKDqn2q36R3LavPeX XD4PJxcVy1ZMTV5H/7qrv7qa8UROU3rJuwv81NOOG2Yj3Ah0Lg+YTBQF5wmkz1TPwK4U Z1XcqpVTdgL7Yb9zTHk+lCxm/3WtMjfcbRDjx1D4YpUrivBrJFEr8mfqvQ04wSf8sMJG SmVgw1FvRrx6x/KlJhCl36qom1E6HPMWvailHpt5g9W3UkZGHHwT78e8GdRKRUZ1T8Ns E50A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687610239; x=1690202239; h=content-transfer-encoding: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=TNzNKMQuCLlGDUHWP1jWsTv4pWE8lB9OZyUsVk9bTcc=; b=kPXOOpmDT6IICbcXypNgNuJc619VJWLZqOTjz0GJH549scPTuop1msIrUgdFPWb2HD e/wXj3hOXuJMpf4F5APZfsq/bh/F03uLYweFHf1+FQwLwFBtnEpTfI6DXKhWerA5HUL3 1Pw5ipRCVMXdgZ0u2E51MJT1xCXnvGCsOog9WgXAVFkSCvDFj2H0zDbqRnriMk/BWnGD y4K7bD1OJUlRXwZ5hrclrbuBvUdx84O5uPADmCfbaibN1tQrwCyihUWiPVnTn+q8PRWV 6uj+fDHi0v3edr8V3E2Z3G1p0vNo0drOs6i79FFVoYFe4t51iBE+M7Yvq+j3RuIkCKwA tLpA== X-Gm-Message-State: AC+VfDw/23SfDAXE6EtM+iY7wsG9KiTpHJ0NDSGxDr6RZ42AtoWY0zYV K5PVT8lgX2+jAf63n9M/tKc= X-Google-Smtp-Source: ACHHUZ5EPzoZKhBSVgqo1lwj7jDlfUpVkf6kV8Ubfv60woMSMzr1e32KKyk9ZcKOK+flK93tByyrGg== X-Received: by 2002:a17:902:ce8d:b0:19c:dbce:dce8 with SMTP id f13-20020a170902ce8d00b0019cdbcedce8mr2135661plg.15.1687610239036; Sat, 24 Jun 2023 05:37:19 -0700 (PDT) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id d22-20020a170902b71600b001b39ffff838sm1179383pls.25.2023.06.24.05.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jun 2023 05:37:18 -0700 (PDT) Date: Sat, 24 Jun 2023 21:37:12 +0900 Message-ID: From: kobarity To: Andreas =?ISO-8859-1?Q?R=F6hler?= Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] In-Reply-To: <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 63959 Cc: Eli Zaretskii , Konstantin Kharlamov , Stefan Monnier , 63959@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: -1.0 (-) Andreas R=F6hler wrote: > >> However, it may happen that the previous line is indented for the > >> inner paren as in the ERT `python-indent-inside-paren-2': > >>=20 > >> data =3D {'key': { > >> =A0=A0=A0 'objlist': [ > >> =A0=A0=A0=A0=A0=A0=A0 {'pk': 1, > >> =A0=A0=A0=A0=A0=A0=A0=A0 'name': 'first'}, > >> =A0=A0=A0=A0=A0=A0=A0 {'pk': 2, > >> =A0=A0=A0=A0=A0=A0=A0=A0 'name': 'second'} > >> =A0=A0=A0 ] > >> }} > >>=20 > >> The line "{'pk': 2," is considered as the continuation line, but it > >> should not respect the indentation of the PREVIOUS line "'name': > >> 'first'},".=A0 So skipping such lines with inner parens were needed. > >> It searches backward for the line which starts with the item of the > >> same opening paren as the target line. > >>=20 > >> In the case of the above example, if the target line is "{'pk': 2,", > >> its opening paren is "[" in the line "'objlist': [".=A0 It first checks > >> the previous line "'name': 'first'},", but its opening paren is "{" in > >> "{'pk': 1,".=A0 So this line is skipped.=A0 Next, it checks the line > >> "{'pk': 1," and its opening paren is "[" in the line "'objlist': [", > >> which is same as the target line.=A0 So the target line's indentation > >> will be as same as the line "{'pk': 1,". > >>=20 > >> It would be helpful if you could try this patch. > > Thank you, tested, works for me! > >=20 > >> Does anyone think we should have a customize variable that switches > >> between the traditional behavior of ignoring the indentation of the > >> previous line and this new behavior? > > I doubt it's useful. It is in general how indentation works in many mod= es, and I > > don't think there ever been a variable to disable that. Stefan Monnier = in > > particular has a paper called "SMIE: weakness is power", where such ind= entation > > is shortly discussed. > >=20 > >=20 > > IMO the question of previous lines indentation isn't raised here, as a = more specific rule applies: inside a non-empty list > > indent with its first element. Whereas if list starts empty, as with "[= " here, next indents as that line plus offset. Let me explain it again. I added the line numbers. 1: data =3D {'key': { 2: 'objlist': [ 3: {'pk': 1, 4: 'name': 'first'}, 5: {'pk': 2, 6: 'name': 'second'} 7: ] 8: }} I think you are saying that the third line will be indented with an additional offset to the second line, am I correct? If so, I totally agree with you. This behavior has not changed with my patch. What I wanted to say in the previous mail is that the fifth line should align with the third line, not the fourth line. As for such standard indentation, my patch does not change the behavior. However, if the user intentionally changed the indentation of the third line, the current Python mode would indent the fourth and subsequent lines as follows: 1: data =3D {'key': { 2: 'objlist': [ 3: {'pk': 1, # Intentionally changed 4: 'name': 'first'}, 5: {'pk': 2, 6: 'name': 'second'} 7: ] 8: }} After applying my patch, it is indented as follows: 1: data =3D {'key': { 2: 'objlist': [ 3: {'pk': 1, # Intentionally changed 4: 'name': 'first'}, 5: {'pk': 2, 6: 'name': 'second'} 7: ] 8: }} From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 28 02:58:36 2023 Received: (at 63959) by debbugs.gnu.org; 28 Jun 2023 06:58:36 +0000 Received: from localhost ([127.0.0.1]:49940 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qEP8O-0002Sy-1P for submit@debbugs.gnu.org; Wed, 28 Jun 2023 02:58:36 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:36101) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qEP8K-0002Sg-Pi for 63959@debbugs.gnu.org; Wed, 28 Jun 2023 02:58:34 -0400 Received: from [192.168.179.153] ([37.228.147.242]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MJV5K-1qTj5a3feC-00JuLe; Wed, 28 Jun 2023 08:58:22 +0200 Message-ID: Date: Wed, 28 Jun 2023 08:58:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] To: kobarity References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> Content-Language: en-US From: =?UTF-8?Q?Andreas_R=c3=b6hler?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:ksg4TNF0mBKkmgXWwUmIPp9MJAs+r9LAlNIIMtJObrDuqRojNx5 FSwM3ttNorD1DDdJXGyeIcabVnftTNUnciho4mSCyjICFK2Wd1xczGXCy02OOekL27RIQ7Y G5jq+NY87ggbRY5K78xUJhKxebEOJKjz4kN7M6+HQKxrepb1g7TpUIRTeYZBjj0CvwCqR9l cAR1hOhpnoYeW8vFYzLwA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:1VIEnGzOYa8=;rOw58YiXVd+M7415lbyUpbsH/68 Wojcjgy0hpDQMQfE+alcogk9a8fFzMcZXJdlwuZkJtBD+C1oB2OUjqaXwlReC4NQ3qHFNPLky uoZeNB13c0JhrOnebL7zE85FK4jj4TGy/kOLBwmNohnrx5n0PgDGsez9R0oFBhvnZsbArZPI4 EU4/u21NPkiOUZdIVmfLQVT60HLnXXeHr/XCqjXvd1/XZ4roQJhd7Q+fziDgthGdgh5afig0K aWuR8oxSF8+o+ut6FVaX+xRCx661xKRVaj7rs9a+O+fRVJHrg8hNnblZyJ/Av+seenBV1HScP 22YAQTE0gKq9/EEePwFDzRzETNosOi+OZnJ/P3d6wfXt97lshEI5fpq76WJ7naBAqK2Co7OFX 2XOBq8r66hvqIscQ49LSRKO3H0e46KhPXWXGuNgqdNChp0WYCExsZeUcBbPW33cbAVs+/vTbt lbphMcUPhd9M0QncwnEdTzis4tGeawo2efX+XNZzdq5fDGVw7timO3prEJyLG+B6pRSyfcWOA 2Cokv9skOjkgrV8UkE+61rmFOILfL9CoShk74D4dCSsT5kb9so6QR7KZu82bQdFcbtHX6aScn Br4HuaupKZlFoalfRYQdSaGRCun7tzwI299/J9LelHvJVZ0tfTmaMV6OmuWtVNe+fKlUH+0pb lJdVyjKiypOMRYLP7nUIlZUOQtCpTOWNjOKlhieQ7g== X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 63959 Cc: Eli Zaretskii , Konstantin Kharlamov , Stefan Monnier , 63959@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: -2.1 (--) Il 24.06.23 14:37, kobarity ha scritto: > Andreas Röhler wrote: >>>> However, it may happen that the previous line is indented for the >>>> inner paren as in the ERT `python-indent-inside-paren-2': >>>> >>>> data = {'key': { >>>>     'objlist': [ >>>>         {'pk': 1, >>>>          'name': 'first'}, >>>>         {'pk': 2, >>>>          'name': 'second'} >>>>     ] >>>> }} >>>> >>>> The line "{'pk': 2," is considered as the continuation line, but it >>>> should not respect the indentation of the PREVIOUS line "'name': >>>> 'first'},".  So skipping such lines with inner parens were needed. >>>> It searches backward for the line which starts with the item of the >>>> same opening paren as the target line. >>>> >>>> In the case of the above example, if the target line is "{'pk': 2,", >>>> its opening paren is "[" in the line "'objlist': [".  It first checks >>>> the previous line "'name': 'first'},", but its opening paren is "{" in >>>> "{'pk': 1,".  So this line is skipped.  Next, it checks the line >>>> "{'pk': 1," and its opening paren is "[" in the line "'objlist': [", >>>> which is same as the target line.  So the target line's indentation >>>> will be as same as the line "{'pk': 1,". >>>> >>>> It would be helpful if you could try this patch. >>> Thank you, tested, works for me! >>> >>>> Does anyone think we should have a customize variable that switches >>>> between the traditional behavior of ignoring the indentation of the >>>> previous line and this new behavior? >>> I doubt it's useful. It is in general how indentation works in many modes, and I >>> don't think there ever been a variable to disable that. Stefan Monnier in >>> particular has a paper called "SMIE: weakness is power", where such indentation >>> is shortly discussed. >>> >>> >>> IMO the question of previous lines indentation isn't raised here, as a more specific rule applies: inside a non-empty list >>> indent with its first element. Whereas if list starts empty, as with "[" here, next indents as that line plus offset. > Let me explain it again. I added the line numbers. > > 1: data = {'key': { > 2: 'objlist': [ > 3: {'pk': 1, > 4: 'name': 'first'}, > 5: {'pk': 2, > 6: 'name': 'second'} > 7: ] > 8: }} > > I think you are saying that the third line will be indented with an > additional offset to the second line, am I correct? If so, I totally > agree with you. This behavior has not changed with my patch. > > What I wanted to say in the previous mail is that the fifth line > should align with the third line, not the fourth line. > > As for such standard indentation, my patch does not change the > behavior. > > However, if the user intentionally changed the indentation of the > third line, the current Python mode would indent the fourth and > subsequent lines as follows: > > 1: data = {'key': { > 2: 'objlist': [ > 3: {'pk': 1, # Intentionally changed > 4: 'name': 'first'}, > 5: {'pk': 2, > 6: 'name': 'second'} > 7: ] > 8: }} > > After applying my patch, it is indented as follows: > > 1: data = {'key': { > 2: 'objlist': [ > 3: {'pk': 1, # Intentionally changed > 4: 'name': 'first'}, > 5: {'pk': 2, > 6: 'name': 'second'} > 7: ] > 8: }} Thanks for your explanation, which makes me better understand your endeavour. A question remains: is this new feature worth that possibly raise of complexity? Your patch provides a higher degree of freedom while keeping regularity  - which is a pro. From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 01 09:43:10 2023 Received: (at 63959) by debbugs.gnu.org; 1 Jul 2023 13:43:10 +0000 Received: from localhost ([127.0.0.1]:56984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFasY-0002Hf-81 for submit@debbugs.gnu.org; Sat, 01 Jul 2023 09:43:10 -0400 Received: from mail-pj1-f49.google.com ([209.85.216.49]:45315) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFasV-0002HR-Ti for 63959@debbugs.gnu.org; Sat, 01 Jul 2023 09:43:09 -0400 Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2637ab3d8efso749539a91.3 for <63959@debbugs.gnu.org>; Sat, 01 Jul 2023 06:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688218982; x=1690810982; h=content-transfer-encoding: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=TJOTAcwxLrCjPBVkNQXhxpnAtqz5Fqv5fRDQKgZQGOk=; b=Lh9DVkclRyCJCxHgR5l1TjTrLwi18ScasM8r1XJhJUsVC2yW5C5Vv/jhTXLCSYsY3t /g05QUk9+Cx7JI2PISf6/T9FWyH3pQ8cuePU1+vVAgFUWhq7J6LExhfS6b+nAf7+xb/E pcFpjcbr8Nk6v1GgWtPeQj6y2chZlNW7638uYCR0QuGyhwC5pM0wbx/7leW+JOwRFvG2 HwqwfAt3JNZpIV9DC3MrzdHcvEnqxdFN37pqW3IojsszfKFWXY5LOvpA7/hL6oxoQvLX 2ZdZyTrEvfOVdbPVIZlDHVW077UBtPDKWPldLRZvftXYMSEkVcdpJoOuZBOFrQ+PcuQC /0BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688218982; x=1690810982; h=content-transfer-encoding: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=TJOTAcwxLrCjPBVkNQXhxpnAtqz5Fqv5fRDQKgZQGOk=; b=AZBMjrKDLME3xxVx6NAa9d75WXRPG7350ThM6tv53SSYG7F7VzBzFhtCjqmjtBAgx+ PNvaXm9ZB+tOPFRI/Pa8USuK04OKeNC0+xOZFzbD0myRPqVW+hYcd3rUb7VQ97Bihdpk TPv1zPX6NhAGV5efDcavP6lk9trLUBb7IuCGZBSw2rdjTORbAiKbsl5LjPB6mwbO8PeW IumwGuUkBk/fmzoyuHBMfNOWvGLPzlG24XEItHN05GsjLoL9nm1XjeT571ZKJLoxdnEv JErEyNfscySkr0NwGAqOmJ7a7kejxqmZDANV4V6c50qtRKxAo4HWfumO/apmnUeqZ9cF cvgw== X-Gm-Message-State: AC+VfDwI8JuA1eefWV5rSG9nLLlUSeyy3nrv5euEzEXn7zdFoesmVjIK vxe+CtfY+TYzzJAnvLMfBKA= X-Google-Smtp-Source: APBJJlGMjDzpEwvZW9vGOQUQyHVgS+mC1CWBRtF7QQ5OoN8g4S550+M62TqFxDnZUCITMAam4jailQ== X-Received: by 2002:a17:90a:6b4f:b0:262:e629:f545 with SMTP id x15-20020a17090a6b4f00b00262e629f545mr3663833pjl.1.1688218981905; Sat, 01 Jul 2023 06:43:01 -0700 (PDT) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id k7-20020a17090a658700b00262eccfa29fsm10110933pjj.33.2023.07.01.06.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 06:43:01 -0700 (PDT) Date: Sat, 01 Jul 2023 22:42:55 +0900 Message-ID: From: kobarity To: Andreas =?ISO-8859-1?Q?R=F6hler?= Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] In-Reply-To: References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 63959 Cc: Eli Zaretskii , Konstantin Kharlamov , Stefan Monnier , 63959@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: -1.0 (-) Andreas R=F6hler wrote: > Thanks for your explanation, which makes me better understand your > endeavour. A question remains: is this new feature worth that possibly > raise of complexity? Your patch provides a higher degree of freedom > while keeping regularity=A0 - which is a pro. I think it is natural for many people to indent the same as the previous line. In fact, it is standard behavior outside the parens. For example, if you intentionally change the indentation of the first line of a block, the following lines will have the same indentation: def func(): a =3D 1 # Intentionally changed. b =3D 2 # Same indent as previous line You can even do the following, although it will result in an IndentationError when executed: def func(): a =3D 1 b =3D 2 # Intentionally changed. c =3D 3 # Same indent as previous line If inside the parens, the following will not result in an IndentationError: a =3D ( 1, 2, # Intentionally changed. 3) # Same indent as previous line So I rather think the rule of indenting the same as the previous line is more useful inside parens. I would consider making the indentation the same as the previous line inside the parens a fix rather than a new feature. This is why I named the commit "Fix Python indentation of continuation lines within parens." From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 01 09:58:05 2023 Received: (at 63959) by debbugs.gnu.org; 1 Jul 2023 13:58:05 +0000 Received: from localhost ([127.0.0.1]:58395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFb6y-00033M-W1 for submit@debbugs.gnu.org; Sat, 01 Jul 2023 09:58:05 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:58661) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qFb6w-00032e-K6 for 63959@debbugs.gnu.org; Sat, 01 Jul 2023 09:58:03 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 321E0100115; Sat, 1 Jul 2023 09:57:56 -0400 (EDT) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 4C1431000C4; Sat, 1 Jul 2023 09:57:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1688219875; bh=+oHQeAT4gc0CU6Z7FJgzgyTW5QCNyI87d+fveJ/7Zyk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=MVwAknMYiheoHl+OpMo6MhH0lAP8jDvI8Fwn+GlyvJGVl+ONXSl2HAWGjtklB4UYC x+TurjPrOGQn15ocNeOOLXpjIs6WqmxXH3xmmtM/Enhdaz0xfGwAYj5GxJQfFGBxeh zTvoe0CFfDw/Pf9h604TOK2soBVaTbElNTAByMP9grxmAWktJiHW5o5g/IpsZmmhkt d8Mn+S+QWQbVcL8bN2nX1iUrhVhakpd/dt3mGdJsIIIcTHM/DPaAIsjPjoXobj5TrT WukMeS4vvTSRzUW4/rkCO0/gnLJFRa/ppPwcTfzozg4Uz74TQpWGhgzTPZkS6yJYxC 4X/TLixnPQaDQ== Received: from pastel (69-165-155-162.dsl.teksavvy.com [69.165.155.162]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1B8EF1204E5; Sat, 1 Jul 2023 09:57:55 -0400 (EDT) From: Stefan Monnier To: kobarity Subject: Re: bug#63959: python-mode does not keep indentation in square brackets [] In-Reply-To: (kobarity@gmail.com's message of "Sat, 01 Jul 2023 22:42:55 +0900") Message-ID: References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> Date: Sat, 01 Jul 2023 09:57:48 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.237 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 63959 Cc: Eli Zaretskii , Andreas =?windows-1252?Q?R=F6hler?= , Konstantin Kharlamov , 63959@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 (---) > I would consider making the indentation the same as the previous line > inside the parens a fix rather than a new feature. Definitely. It might also fix a performance bug (when re-indenting line by line a long parenthesized list of things, always going back to the beginning can make the overall indentation O(N=B2) rather than O(N), where N is the number of lines). Stefan From unknown Sat Aug 09 13:17:59 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 30 Jul 2023 11:24:10 +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