GNU bug report logs - #18228
24.4.50; electrict-indent-mode bad indentation in python-mode

Previous Next

Package: emacs;

Reported by: Jorgen Schaefer <forcer <at> forcix.cx>

Date: Sat, 9 Aug 2014 10:02:02 UTC

Severity: minor

Found in version 24.3.93

Fixed in version 24.4.50

Done: fgallina <at> gnu.org (Fabián Ezequiel Gallina)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18228 in the body.
You can then email your comments to 18228 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Sat, 09 Aug 2014 10:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jorgen Schaefer <forcer <at> forcix.cx>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 09 Aug 2014 10:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jorgen Schaefer <forcer <at> forcix.cx>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4.50; electrict-indent-mode bad indentation in python-mode
Date: Sat, 09 Aug 2014 12:00:07 +0200
Hi!
With a freshly compiled Emacs (git ref 3fc84165), I get the following
behavior. In a Python buffer with electric-indent-mode enabled, enter
this:


def foo():
    print "Foo"

def bar()


Adding a colon (":"") at the end of bar() will then indent the line to
the same indentation level as the "print" statement.

While this is the default indentation level for RET after the print
statement, I would expect that the colon will not reindent my current
line. python-mode can not know which indentation level is correct, so it
should not insist on one.


In GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu)
 of 2014-08-09 on loki.jorgenschaefer.de
System Description:	Debian GNU/Linux 7.6 (wheezy)

Configured using:
 `configure --without-x'

Configured features:
SOUND NOTIFY LIBXML2 ZLIB

Important settings:
  value of $LC_ALL: 
  value of $LC_COLLATE: de_DE.UTF-8
  value of $LC_CTYPE: de_DE.UTF-8
  value of $LC_MESSAGES: POSIX
  value of $LC_MONETARY: POSIX
  value of $LC_NUMERIC: POSIX
  value of $LC_TIME: POSIX
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  gitty-mode: t
  flx-ido-mode: t
  yas-minor-mode: t
  flymake-mode: t
  eldoc-mode: t
  company-mode: t
  elpy-mode: t
  pyvenv-mode: t
  circe-lagmon-mode: t
  tracking-mode: t
  shell-dirtrack-mode: t
  winner-mode: t
  display-time-mode: t
  global-subword-mode: t
  subword-mode: t
  show-paren-mode: t
  ido-everywhere: t
  electric-pair-mode: t
  delete-selection-mode: t
  cua-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: do-auto-fill





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Mon, 11 Aug 2014 07:13:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#18228: 24.4.50; electrict-indent-mode bad indentation in
 python-mode
Date: Mon, 11 Aug 2014 09:11:03 +0200
On 09.08.2014 12:00, Jorgen Schaefer wrote:
> Hi!
> With a freshly compiled Emacs (git ref 3fc84165), I get the following
> behavior. In a Python buffer with electric-indent-mode enabled, enter
> this:
>
>
> def foo():
>      print "Foo"
>
> def bar()
>
>
> Adding a colon (":"") at the end of bar() will then indent the line to
> the same indentation level as the "print" statement.
>
> While this is the default indentation level for RET after the print
> statement, I would expect that the colon will not reindent my current
> line. python-mode can not know which indentation level is correct,

Right.

But what should electric-indent do than? IMO the only reasonable is indenting to outmost permitted.
Which seems the case.

Electric behaviour seems not that useful in Python than with other modes.
AFAICS not a bug.

Best,

Andreas






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Mon, 11 Aug 2014 14:46:01 GMT) Full text and rfc822 format available.

Message #11 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Mon, 11 Aug 2014 10:45:21 -0400
> But what should electric-indent do than?

No re-indent upon : when it's not 100% sure of the result.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Mon, 11 Aug 2014 17:20:01 GMT) Full text and rfc822 format available.

Message #14 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50; electrict-indent-mode bad indentation in
 python-mode
Date: Mon, 11 Aug 2014 19:18:50 +0200
On 11.08.2014 16:45, Stefan Monnier wrote:
>> But what should electric-indent do than?
>
> No re-indent upon : when it's not 100% sure of the result.
>

Which sums up to switch it off.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Tue, 12 Aug 2014 02:41:02 GMT) Full text and rfc822 format available.

Message #17 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: "Fabián E. Gallina" <fabian <at> anue.biz>,
 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Mon, 11 Aug 2014 22:40:52 -0400
>>> But what should electric-indent do than?
>> No re-indent upon : when it's not 100% sure of the result.
> Which sums up to switch it off.

Not to switch off electric-indent, no (it's enabled globally).

And presumably the : was made to re-indent because in some/many cases
there is only 1 correct indentation (and the code is able to find it).
I don't know if the code is also able to detect when it's correct and
when it's not, but if it is, then we don't need to disable the "reindent
on :" in all cases.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Tue, 12 Aug 2014 07:07:01 GMT) Full text and rfc822 format available.

Message #20 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: "Fabián E. Gallina" <fabian <at> anue.biz>,
 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50; electrict-indent-mode bad indentation in
 python-mode
Date: Tue, 12 Aug 2014 09:05:47 +0200
On 12.08.2014 04:40, Stefan Monnier wrote:
>>>> But what should electric-indent do than?
>>> No re-indent upon : when it's not 100% sure of the result.
>> Which sums up to switch it off.
>
> Not to switch off electric-indent, no (it's enabled globally).

Python modes should switch it off by default.

Using electric features with Python effectively requires a certain level of experience with Emacs and Python alike.
Nonetheless - nice play.

>
> And presumably the : was made to re-indent because in some/many cases
> there is only 1 correct indentation (and the code is able to find it).
> I don't know if the code is also able to detect when it's correct and
> when it's not,

In Python indent is meaning - at least sometimes.
A reliable electric-indent must know what the programmer wants to write, predict his decision.

There are some special cases, where its possible.
In a lot of other cases not.

Alltogether, when digging in here, you run in a complex matter where artificial intelligence might deliver some progress indeed - which seems fairly out of scope giving the 
resources when maintaining/developing Emacs' python-modes.

IMO it would be a waste of time investing here.

but if it is, then we don't need to disable the "reindent
> on :" in all cases.
>
>
>          Stefan
>





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Tue, 12 Aug 2014 14:05:02 GMT) Full text and rfc822 format available.

Message #23 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: Fabián E. Gallina <fabian <at> anue.biz>,
 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Tue, 12 Aug 2014 10:04:06 -0400
>> Not to switch off electric-indent, no (it's enabled globally).
> Python modes should switch it off by default.

No reason for that.

> Using electric features with Python effectively requires a certain level of
> experience with Emacs and Python alike.

Not at all.

> In Python indent is meaning - at least sometimes.

I know.

> There are some special cases, where its possible.
> In a lot of other cases not.

I know.

> IMO it would be a waste of time investing here.

Could be.  It's up to Fabián to decide whether it's best to disable
"reindent on :" or to make it smarter.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Wed, 27 Aug 2014 19:35:01 GMT) Full text and rfc822 format available.

Message #26 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Matthew Woodcraft <matthew <at> woodcraft.me.uk>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: "Fabián E. Gallina" <fabian <at> anue.biz>,
 Andreas Röhler <andreas.roehler <at> easy-emacs.de>,
 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Wed, 27 Aug 2014 20:34:18 +0100
In emacs 24.3, colon was electric by default (eg for 'else:'), but didn't
affect 'def' lines like Jorgen's example (which I am also finding very
annoying).

So I think this is a regression (I'm on the emacs-24 branch).

-M-




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Thu, 28 Aug 2014 06:07:01 GMT) Full text and rfc822 format available.

Message #29 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: Matthew Woodcraft <matthew <at> woodcraft.me.uk>, 
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: "Fabián E. Gallina" <fabian <at> anue.biz>,
 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50; electrict-indent-mode bad indentation in
 python-mode
Date: Thu, 28 Aug 2014 08:05:29 +0200
On 27.08.2014 21:34, Matthew Woodcraft wrote:
>
> In emacs 24.3, colon was electric by default (eg for 'else:'), but didn't
> affect 'def' lines like Jorgen's example (which I am also finding very
> annoying).
>
> So I think this is a regression (I'm on the emacs-24 branch).
>
> -M-
>

If inside a nested block, there is no way for Emacs to determine whereto such "else" should belong.
I.o.w, don't see a difference between these both cases.




bug Marked as found in versions 24.3.93. Request was from Matthew Woodcraft <matthew <at> woodcraft.me.uk> to control <at> debbugs.gnu.org. (Thu, 28 Aug 2014 19:01:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Thu, 28 Aug 2014 19:02:02 GMT) Full text and rfc822 format available.

Message #34 received at 18228 <at> debbugs.gnu.org (full text, mbox):

From: Matthew Woodcraft <matthew <at> woodcraft.me.uk>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: Fabián E. Gallina <fabian <at> anue.biz>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 18228 <at> debbugs.gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Thu, 28 Aug 2014 20:00:55 +0100
Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
> If inside a nested block, there is no way for Emacs to determine whereto such
> "else" should belong.
> I.o.w, don't see a difference between these both cases.

What emacs 24.3 does, in the common case, is dedent the 'else:' one step.

This is correct most of the time, and in the cases where it isn't
correct it moves the line one step closer to where it will end up.

In contrast, the behaviour in the current 24.4-pretest for 'def:' and
'class:' is wrong nearly all the time, and when it's wrong it moves the
line away from where it will end up rather than towards it.

-M-




Reply sent to fgallina <at> gnu.org (Fabián Ezequiel Gallina):
You have taken responsibility. (Mon, 01 Sep 2014 22:54:02 GMT) Full text and rfc822 format available.

Notification sent to Jorgen Schaefer <forcer <at> forcix.cx>:
bug acknowledged by developer. (Mon, 01 Sep 2014 22:54:03 GMT) Full text and rfc822 format available.

Message #39 received at 18228-done <at> debbugs.gnu.org (full text, mbox):

From: fgallina <at> gnu.org (Fabián Ezequiel Gallina)
To: 18228-done <at> debbugs.gnu.org
Subject: 24.4.50; electrict-indent-mode bad indentation in python-mode
Date: Mon, 01 Sep 2014 19:53:22 -0300
Fixed in revno 117470 in the Emacs 24 branch.


Cheers,
Fabián




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18228; Package emacs. (Mon, 01 Sep 2014 23:13:02 GMT) Full text and rfc822 format available.

Message #42 received at submit <at> debbugs.gnu.org (full text, mbox):

From: fgallina <at> gnu.org (Fabián Ezequiel Gallina)
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#18228: 24.4.50;
 electrict-indent-mode bad indentation in python-mode
Date: Mon, 01 Sep 2014 20:11:31 -0300
Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:

> On 12.08.2014 04:40, Stefan Monnier wrote:
>>>>> But what should electric-indent do than?
>>>> No re-indent upon : when it's not 100% sure of the result.
>>> Which sums up to switch it off.
>>
>> Not to switch off electric-indent, no (it's enabled globally).
>
> Python modes should switch it off by default.
>

No, it shouldn't.  The electric cases can be controlled in such way in
that the feature is still useful.

>>
>> And presumably the : was made to re-indent because in some/many cases
>> there is only 1 correct indentation (and the code is able to find it).
>> I don't know if the code is also able to detect when it's correct and
>> when it's not,
>
> In Python indent is meaning - at least sometimes.
> A reliable electric-indent must know what the programmer wants to write, predict his decision.
>

That's what I'm aiming to and the code is pretty much there, believe it
or not.

> There are some special cases, where its possible.
> In a lot of other cases not.
>

Name impossible ones and let's see.

> Alltogether, when digging in here, you run in a complex matter where
> artificial intelligence might deliver some progress indeed - which
> seems fairly out of scope giving the resources when
> maintaining/developing Emacs' python-modes.
>
> IMO it would be a waste of time investing here.
>

If because something it's "hard" we should drop any hopes of developing
further, let's go back to abacuses.  And no, electric indent is not that
hard, really.

Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
> If inside a nested block, there is no way for Emacs to determine whereto such
> "else" should belong.
> I.o.w, don't see a difference between these both cases.

Well, you'd be surprised at how smart the current implementation of
electric indent for python is.  Even if there's no sure shot, Emacs
would let you cycle between the possible indentations.  I invite you to
see `python-indent-dedenters-*' tests to understand what I'm talking
about.



Regards,
Fabián





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 30 Sep 2014 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 223 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.