From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andreas =?UTF-8?Q?R=C3=B6hler?= Newsgroups: gmane.emacs.bugs Subject: bug#63959: python-mode does not keep indentation in square brackets [] Date: Wed, 28 Jun 2023 08:58:20 +0200 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 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18800"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cc: Eli Zaretskii , Konstantin Kharlamov , Stefan Monnier , 63959@debbugs.gnu.org To: kobarity Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 28 08:59:33 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 1qEP9I-0004mq-Qv for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Jun 2023 08:59:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEP8r-000687-NL; Wed, 28 Jun 2023 02:59:05 -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 1qEP8o-00067v-Kt for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 02:59: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 1qEP8o-0008AH-AA for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 02:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qEP8o-0002Ti-6x for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 02:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas =?UTF-8?Q?R=C3=B6hler?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Jun 2023 06:59: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.16879355169488 (code B ref 63959); Wed, 28 Jun 2023 06:59:02 +0000 Original-Received: (at 63959) by debbugs.gnu.org; 28 Jun 2023 06:58:36 +0000 Original-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 Original-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 Original-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 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:ksg4TNF0mBKkmgXWwUmIPp9MJAs+r9LAlNIIMtJObrDuqRojNx5 FSwM3ttNorD1DDdJXGyeIcabVnftTNUnciho4mSCyjICFK2Wd1xczGXCy02OOekL27RIQ7Y G5jq+NY87ggbRY5K78xUJhKxebEOJKjz4kN7M6+HQKxrepb1g7TpUIRTeYZBjj0CvwCqR9l cAR1hOhpnoYeW8vFYzLwA== 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-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:264195 Archived-At: 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.