From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#63959: python-mode does not keep indentation in square brackets [] Date: Sun, 18 Jun 2023 18:20:25 +0300 Message-ID: <45d2d886ba9bd52f33c588c457cfc0338f504eca.camel@yandex.ru> References: <0a9099c91a3cd323c78e08fb6263d11fe66429bb.camel@yandex.ru> <83mt18285n.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17070"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.48.3 Cc: Stefan Monnier , 63959@debbugs.gnu.org To: kobarity , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 18 17:21: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 1qAuDa-0004D6-3g for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Jun 2023 17:21:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAuDA-0007jw-4G; Sun, 18 Jun 2023 11:21:04 -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 1qAuD8-0007ja-Ac for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2023 11:21:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAuD8-0006xH-2J for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2023 11:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qAuD7-0004Pp-TT for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2023 11:21:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Jun 2023 15:21:01 +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.168710163316898 (code B ref 63959); Sun, 18 Jun 2023 15:21:01 +0000 Original-Received: (at 63959) by debbugs.gnu.org; 18 Jun 2023 15:20:33 +0000 Original-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 Original-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 Original-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) Original-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 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263641 Archived-At: 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.