unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: Eli Zaretskii <eliz@gnu.org>,
	Konstantin Kharlamov <hi-angel@yandex.ru>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	63959@debbugs.gnu.org
Subject: bug#63959: python-mode does not keep indentation in square brackets []
Date: Sat, 24 Jun 2023 21:37:12 +0900	[thread overview]
Message-ID: <eke7mt0p5953.wl-kobarity@gmail.com> (raw)
In-Reply-To: <93804360-aafe-fe2f-46fa-f2fca67d9add@easy-emacs.de>


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: }}





  reply	other threads:[~2023-06-24 12:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  9:39 bug#63959: python-mode does not keep indentation in square brackets [] Konstantin Kharlamov
2023-06-09 11:21 ` Eli Zaretskii
2023-06-09 14:35   ` kobarity
2023-06-18 14:56     ` kobarity
2023-06-18 15:20       ` Konstantin Kharlamov
2023-06-19  8:46         ` Andreas Röhler
2023-06-24 12:37           ` kobarity [this message]
2023-06-28  6:58             ` Andreas Röhler
2023-07-01 13:42               ` kobarity
2023-07-01 13:57                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-24 12:14         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eke7mt0p5953.wl-kobarity@gmail.com \
    --to=kobarity@gmail.com \
    --cc=63959@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    --cc=eliz@gnu.org \
    --cc=hi-angel@yandex.ru \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).