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#63959: python-mode does not keep indentation in square brackets [] Date: Sat, 24 Jun 2023 21:37:12 +0900 Message-ID: References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> 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 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3219"; 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: Eli Zaretskii , Konstantin Kharlamov , Stefan Monnier , 63959@debbugs.gnu.org To: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 24 14:38:31 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 1qD2X8-0000hF-QR for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 24 Jun 2023 14:38:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qD2Wk-0007py-A1; Sat, 24 Jun 2023 08:38:06 -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 1qD2Wh-0007pC-92 for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 08:38:03 -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 1qD2Wg-0002OE-Vk for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 08:38:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qD2Wg-0006qZ-Bi for bug-gnu-emacs@gnu.org; Sat, 24 Jun 2023 08:38: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, 24 Jun 2023 12:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63959 X-GNU-PR-Package: emacs Original-Received: via spool by 63959-submit@debbugs.gnu.org id=B63959.168761025126257 (code B ref 63959); Sat, 24 Jun 2023 12:38:02 +0000 Original-Received: (at 63959) by debbugs.gnu.org; 24 Jun 2023 12:37:31 +0000 Original-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 Original-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 Original-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) Original-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) In-Reply-To: <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de> 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:263990 Archived-At: 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: }}