unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
@ 2014-08-09 10:00 Jorgen Schaefer
  2014-08-11  7:11 ` Andreas Röhler
  2014-09-01 22:53 ` Fabián Ezequiel Gallina
  0 siblings, 2 replies; 12+ messages in thread
From: Jorgen Schaefer @ 2014-08-09 10:00 UTC (permalink / raw)
  To: 18228

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






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-09 10:00 bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode Jorgen Schaefer
@ 2014-08-11  7:11 ` Andreas Röhler
  2014-08-11 14:45   ` Stefan Monnier
  2014-09-01 22:53 ` Fabián Ezequiel Gallina
  1 sibling, 1 reply; 12+ messages in thread
From: Andreas Röhler @ 2014-08-11  7:11 UTC (permalink / raw)
  To: 18228

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







^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-11  7:11 ` Andreas Röhler
@ 2014-08-11 14:45   ` Stefan Monnier
  2014-08-11 17:18     ` Andreas Röhler
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2014-08-11 14:45 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 18228

> But what should electric-indent do than?

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


        Stefan





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-11 14:45   ` Stefan Monnier
@ 2014-08-11 17:18     ` Andreas Röhler
  2014-08-12  2:40       ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Röhler @ 2014-08-11 17:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 18228

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.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-11 17:18     ` Andreas Röhler
@ 2014-08-12  2:40       ` Stefan Monnier
  2014-08-12  7:05         ` Andreas Röhler
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2014-08-12  2:40 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: Fabián E. Gallina, 18228

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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-12  2:40       ` Stefan Monnier
@ 2014-08-12  7:05         ` Andreas Röhler
  2014-08-12 14:04           ` Stefan Monnier
  2014-09-01 23:11           ` Fabián Ezequiel Gallina
  0 siblings, 2 replies; 12+ messages in thread
From: Andreas Röhler @ 2014-08-12  7:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Fabián E. Gallina, 18228

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
>






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-12  7:05         ` Andreas Röhler
@ 2014-08-12 14:04           ` Stefan Monnier
  2014-08-27 19:34             ` Matthew Woodcraft
  2014-09-01 23:11           ` Fabián Ezequiel Gallina
  1 sibling, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2014-08-12 14:04 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: Fabián E. Gallina, 18228

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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-12 14:04           ` Stefan Monnier
@ 2014-08-27 19:34             ` Matthew Woodcraft
  2014-08-28  6:05               ` Andreas Röhler
  0 siblings, 1 reply; 12+ messages in thread
From: Matthew Woodcraft @ 2014-08-27 19:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Fabián E. Gallina, 18228


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-





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-27 19:34             ` Matthew Woodcraft
@ 2014-08-28  6:05               ` Andreas Röhler
  2014-08-28 19:00                 ` Matthew Woodcraft
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Röhler @ 2014-08-28  6:05 UTC (permalink / raw)
  To: Matthew Woodcraft, Stefan Monnier; +Cc: Fabián E. Gallina, 18228

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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-28  6:05               ` Andreas Röhler
@ 2014-08-28 19:00                 ` Matthew Woodcraft
  0 siblings, 0 replies; 12+ messages in thread
From: Matthew Woodcraft @ 2014-08-28 19:00 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: Fabián E. Gallina, 18228

Andreas Röhler <andreas.roehler@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-





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-09 10:00 bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode Jorgen Schaefer
  2014-08-11  7:11 ` Andreas Röhler
@ 2014-09-01 22:53 ` Fabián Ezequiel Gallina
  1 sibling, 0 replies; 12+ messages in thread
From: Fabián Ezequiel Gallina @ 2014-09-01 22:53 UTC (permalink / raw)
  To: 18228-done


Fixed in revno 117470 in the Emacs 24 branch.


Cheers,
Fabián





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode
  2014-08-12  7:05         ` Andreas Röhler
  2014-08-12 14:04           ` Stefan Monnier
@ 2014-09-01 23:11           ` Fabián Ezequiel Gallina
  1 sibling, 0 replies; 12+ messages in thread
From: Fabián Ezequiel Gallina @ 2014-09-01 23:11 UTC (permalink / raw)
  To: 18228

Andreas Röhler <andreas.roehler@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@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






^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-09-01 23:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-09 10:00 bug#18228: 24.4.50; electrict-indent-mode bad indentation in python-mode Jorgen Schaefer
2014-08-11  7:11 ` Andreas Röhler
2014-08-11 14:45   ` Stefan Monnier
2014-08-11 17:18     ` Andreas Röhler
2014-08-12  2:40       ` Stefan Monnier
2014-08-12  7:05         ` Andreas Röhler
2014-08-12 14:04           ` Stefan Monnier
2014-08-27 19:34             ` Matthew Woodcraft
2014-08-28  6:05               ` Andreas Röhler
2014-08-28 19:00                 ` Matthew Woodcraft
2014-09-01 23:11           ` Fabián Ezequiel Gallina
2014-09-01 22:53 ` Fabián Ezequiel Gallina

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).