unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: Stefan Kangas <stefankangas@gmail.com>, Michael Arndt <michael@rndt.dev>
Cc: 72750@debbugs.gnu.org
Subject: bug#72750: 29.3; indent-region changes semantics of python code
Date: Sat, 21 Sep 2024 23:51:00 +0900	[thread overview]
Message-ID: <eke7tte9oyaz.wl-kobarity@gmail.com> (raw)
In-Reply-To: <CADwFkmmPsEC=u-B0QiC8Qgo6ME8Te36+VhbQctyi-UwW_GAF=g@mail.gmail.com>

Stefan Kangas wrote:
> Michael Arndt via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs@gnu.org> writes:
> 
> > I have a problem when indenting python files. There seems to be a case
> > when using indent-region changes the semantics of the python code. When
> > there is no blank line after an if-statement, the next line becomes part
> > of the if statement.
> >
> > The problem can be reproduced by the following steps:
> >
> > 1. Start emacs -Q
> > 2. Create a python file with the following contents:
> >
> > if False:
> >       print("output1")
> > print("output2")
> >
> > 3. Use M-x mark-whole-buffer
> > 4. Use M-x indent-region
> > 5. The file contents change into:
> >
> > if False:
> >       print("output1")
> >       print("output2")
> >
> > The problem can be avoided by adding a blank line after the if statement.
> > Because I use a custom indentation function that calls (indent-region
> > (point-min) (point-max)) this can happen pretty quickly. Is this a
> > limitation of python-indent-region?
> 
> I'm not sure that I see a bug here.  I don't think one can generally
> expect `indent-region` to be able to avoid changing semantics in a
> language where indentation matters.

I agree.  Even though `python-indent-region' can be improved to some
extent, it seems to me that it is better to use an external tool like
"black" to preserve the semantics and format the entire buffer.





  reply	other threads:[~2024-09-21 14:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 18:06 bug#72750: 29.3; indent-region changes semantics of python code Michael Arndt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-23 18:52 ` Andreas Röhler
2024-09-21 11:56 ` Stefan Kangas
2024-09-21 14:51   ` kobarity [this message]
2024-09-21 16:03     ` Michael Arndt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-22  1:05       ` Stefan Kangas

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=eke7tte9oyaz.wl-kobarity@gmail.com \
    --to=kobarity@gmail.com \
    --cc=72750@debbugs.gnu.org \
    --cc=michael@rndt.dev \
    --cc=stefankangas@gmail.com \
    /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).