unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* python-mode's broken indentation behavior
@ 2015-06-28 19:47 Florian Weimer
  2015-06-29  1:23 ` Ian Zimmerman
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Florian Weimer @ 2015-06-28 19:47 UTC (permalink / raw)
  To: help-gnu-emacs

Indentation in python-mode has been fairly broken for me, I believe
since Emacs 24.  The electric colon makes this especially annoying.

In the following, _ marks the position of point.

If I press RET here:

def foo(x):
    if x:
        return 2
    else:
        raise Foo_

I get this, which is correct.

def foo(x):
    if x:
        return 2
    else:
        raise Foo
    _

Continuing typing:

def foo(x):
    if x:
        return 2
    else:
        raise Foo
    for i in range(0, 10)_

So far, so good.  Now press ‘:’:

def foo(x):
    if x:
        return 2
    else:
        raise Foo
        for i in range(0, 10):_

Going from:

def foo(x):
    if x:
        x()
    else:
        y()
    for i in range(0, 10)_

to:

def foo(x):
    if x:
        x()
    else:
        y()
        for i in range(0, 10):_

is equally unhelpful.

For me, this makes editing Python scripts with Emacs a fairly painful
experience.

Surely this is a known issue because it has been around for so long.
Is this the behavior the python-mode maintainers prefer?  I find this
hard to believe.


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

* Re: python-mode's broken indentation behavior
  2015-06-28 19:47 python-mode's broken indentation behavior Florian Weimer
@ 2015-06-29  1:23 ` Ian Zimmerman
  2015-06-29  1:31 ` Stefan Monnier
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Ian Zimmerman @ 2015-06-29  1:23 UTC (permalink / raw)
  To: help-gnu-emacs

On 2015-06-28 21:47 +0200, Florian Weimer wrote:

> def foo(x):
>     if x:
>         return 2
>     else:
>         raise Foo
>     for i in range(0, 10)_
> 
> So far, so good.  Now press ‘:’:
> 
> def foo(x):
>     if x:
>         return 2
>     else:
>         raise Foo
>         for i in range(0, 10):_
> 
> Going from:
> 
> def foo(x):
>     if x:
>         x()
>     else:
>         y()
>     for i in range(0, 10)_
> 
> to:
> 
> def foo(x):
>     if x:
>         x()
>     else:
>         y()
>         for i in range(0, 10):_
> 
> is equally unhelpful.

While I completely agree that this behavior is broken in both cases (and
I feel smug using emacs23, which doesn't do this), I thought it's worth
pointing out that these cases are quite different.  In the second case,
it is correct for the code to not unindent automatically, but it should
not restore the indent after you manually fix it.

Maybe you can just turn off the electric colon somehow?  If nothing
else, you should be able to do

(add-hook 'python-mode-hook
  (lambda ()
    (local-unset-key ":")))

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




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

* Re: python-mode's broken indentation behavior
  2015-06-28 19:47 python-mode's broken indentation behavior Florian Weimer
  2015-06-29  1:23 ` Ian Zimmerman
@ 2015-06-29  1:31 ` Stefan Monnier
  2015-06-29  2:55 ` Jude DaShiell
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2015-06-29  1:31 UTC (permalink / raw)
  To: help-gnu-emacs

> Indentation in python-mode has been fairly broken for me, I believe
> since Emacs 24.

These are usually bugs, so the better way to deal with them is to
report them.  Which version of Emacs are you using?
I don't see the behavior you describe (at least in Emacs-25),

        Stefan




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

* Re: python-mode's broken indentation behavior
  2015-06-28 19:47 python-mode's broken indentation behavior Florian Weimer
  2015-06-29  1:23 ` Ian Zimmerman
  2015-06-29  1:31 ` Stefan Monnier
@ 2015-06-29  2:55 ` Jude DaShiell
  2015-06-29 19:29 ` John Mastro
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jude DaShiell @ 2015-06-29  2:55 UTC (permalink / raw)
  To: Florian Weimer, help-gnu-emacs

I've used python-mode and what I had to learn and I don't know if this 
is nailing you was once an indent was arranged, when a new line is typed 
only hit tab once.  The python-mode for me then indented all code 
correctly.  If I examined the spacing of the indent and tried hitting 
tab more than once (second guessing python_mode) that's when I got 
myself into trouble.  If this is nailing you, I hope this helps.

On Sun, 28 Jun 2015, Florian Weimer wrote:

> Date: Sun, 28 Jun 2015 15:47:03
> From: Florian Weimer <fw@deneb.enyo.de>
> To: help-gnu-emacs@gnu.org
> Newsgroups: gnu.emacs.help
> Subject: python-mode's broken indentation behavior
> 
> Indentation in python-mode has been fairly broken for me, I believe
> since Emacs 24.  The electric colon makes this especially annoying.
>
> In the following, _ marks the position of point.
>
> If I press RET here:
>
> def foo(x):
>    if x:
>        return 2
>    else:
>        raise Foo_
>
> I get this, which is correct.
>
> def foo(x):
>    if x:
>        return 2
>    else:
>        raise Foo
>    _
>
> Continuing typing:
>
> def foo(x):
>    if x:
>        return 2
>    else:
>        raise Foo
>    for i in range(0, 10)_
>
> So far, so good.  Now press ?:?:
>
> def foo(x):
>    if x:
>        return 2
>    else:
>        raise Foo
>        for i in range(0, 10):_
>
> Going from:
>
> def foo(x):
>    if x:
>        x()
>    else:
>        y()
>    for i in range(0, 10)_
>
> to:
>
> def foo(x):
>    if x:
>        x()
>    else:
>        y()
>        for i in range(0, 10):_
>
> is equally unhelpful.
>
> For me, this makes editing Python scripts with Emacs a fairly painful
> experience.
>
> Surely this is a known issue because it has been around for so long.
> Is this the behavior the python-mode maintainers prefer?  I find this
> hard to believe.
>

-- 




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

* Re: python-mode's broken indentation behavior
  2015-06-28 19:47 python-mode's broken indentation behavior Florian Weimer
                   ` (2 preceding siblings ...)
  2015-06-29  2:55 ` Jude DaShiell
@ 2015-06-29 19:29 ` John Mastro
       [not found] ` <mailman.5883.1435541016.904.help-gnu-emacs@gnu.org>
       [not found] ` <mailman.5885.1435541477.904.help-gnu-emacs@gnu.org>
  5 siblings, 0 replies; 8+ messages in thread
From: John Mastro @ 2015-06-29 19:29 UTC (permalink / raw)
  To: Florian Weimer, help-gnu-emacs@gnu.org

Florian Weimer <fw@deneb.enyo.de> wrote:
> Indentation in python-mode has been fairly broken for me, I believe
> since Emacs 24.  The electric colon makes this especially annoying.

I find the indentation engine to be quite good overall, but use
something like the following to prevent the colon issue:

(defun no-electric-colon ()
  (setq-local electric-indent-chars (remq ?: electric-indent-chars)))

(with-eval-after-load 'python
  (add-hook 'python-mode-hook #'no-electric-colon))

Hope that helps

-- 
john



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

* Re: python-mode's broken indentation behavior
       [not found] ` <mailman.5883.1435541016.904.help-gnu-emacs@gnu.org>
@ 2015-06-29 19:33   ` Florian Weimer
  0 siblings, 0 replies; 8+ messages in thread
From: Florian Weimer @ 2015-06-29 19:33 UTC (permalink / raw)
  To: help-gnu-emacs

* Ian Zimmerman:

> On 2015-06-28 21:47 +0200, Florian Weimer wrote:
>
>> def foo(x):
>>     if x:
>>         return 2
>>     else:
>>         raise Foo
>>     for i in range(0, 10)_
>> 
>> So far, so good.  Now press ‘:’:
>> 
>> def foo(x):
>>     if x:
>>         return 2
>>     else:
>>         raise Foo
>>         for i in range(0, 10):_
>> 
>> Going from:
>> 
>> def foo(x):
>>     if x:
>>         x()
>>     else:
>>         y()
>>     for i in range(0, 10)_
>> 
>> to:
>> 
>> def foo(x):
>>     if x:
>>         x()
>>     else:
>>         y()
>>         for i in range(0, 10):_
>> 
>> is equally unhelpful.
>
> While I completely agree that this behavior is broken in both cases (and
> I feel smug using emacs23, which doesn't do this), I thought it's worth
> pointing out that these cases are quite different.  In the second case,
> it is correct for the code to not unindent automatically, but it should
> not restore the indent after you manually fix it.

I wanted to show that incorrect re-indent happens in both cases, both
for the unreachable case and the reachable case.  I have no problem
with automatic deindenting after a statement which causes an abnormal
exit of the block.


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

* Re: python-mode's broken indentation behavior
       [not found] ` <mailman.5885.1435541477.904.help-gnu-emacs@gnu.org>
@ 2015-06-29 19:42   ` Florian Weimer
  2015-06-30 13:40     ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2015-06-29 19:42 UTC (permalink / raw)
  To: help-gnu-emacs

* Stefan Monnier:

>> Indentation in python-mode has been fairly broken for me, I believe
>> since Emacs 24.
>
> These are usually bugs, so the better way to deal with them is to
> report them.

The hideous indentation provided by sml-mode wasn't considered a bug.
:-)

> Which version of Emacs are you using?

Debian's Emacs 24.4.1.  I've also seen it on Fedora with 24.5.1.

> I don't see the behavior you describe (at least in Emacs-25),

Hmm.  If it's already fixed, then maybe it was commit
749813e9d4a844384e0450f6f7f88484b15e348a.  Initial testing confirms
this.


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

* Re: python-mode's broken indentation behavior
  2015-06-29 19:42   ` Florian Weimer
@ 2015-06-30 13:40     ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2015-06-30 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

>> These are usually bugs, so the better way to deal with them is to
>> report them.
> The hideous indentation provided by sml-mode wasn't considered a bug.
> :-)

Sometimes it's indeed a feature, but features can be configured ;-)


        Stefan


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

end of thread, other threads:[~2015-06-30 13:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-28 19:47 python-mode's broken indentation behavior Florian Weimer
2015-06-29  1:23 ` Ian Zimmerman
2015-06-29  1:31 ` Stefan Monnier
2015-06-29  2:55 ` Jude DaShiell
2015-06-29 19:29 ` John Mastro
     [not found] ` <mailman.5883.1435541016.904.help-gnu-emacs@gnu.org>
2015-06-29 19:33   ` Florian Weimer
     [not found] ` <mailman.5885.1435541477.904.help-gnu-emacs@gnu.org>
2015-06-29 19:42   ` Florian Weimer
2015-06-30 13:40     ` Stefan Monnier

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