unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
@ 2019-08-01  7:06 Jarosław Rzeszótko
  2019-08-01  7:56 ` Andreas Röhler
  0 siblings, 1 reply; 7+ messages in thread
From: Jarosław Rzeszótko @ 2019-08-01  7:06 UTC (permalink / raw)
  To: 36884

[-- Attachment #1: Type: text/plain, Size: 658 bytes --]

When pressing enter with the cursor like this:

def test():
    print("test")
[cursor]

Emacs (26.1) correctly just inserts a blank line. However, with this:

def test():
    if True:
          print("test")
[cursor]

Emacs inserts a blank line and indents it one level. With this:

def test():
    if True:
        if False:
              print("test")
[cursor]

it inserts a blank line and indents it two levels, etc. Moreover, with two
methods like this:

def test1():
    if True:
          print("test")

[cursor]def test2():
    if True:
          print("test")

pressing enter will also indent the def block, instead of just inserting
the empty line.

[-- Attachment #2: Type: text/html, Size: 1152 bytes --]

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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-01  7:06 bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines Jarosław Rzeszótko
@ 2019-08-01  7:56 ` Andreas Röhler
  2019-08-01  8:51   ` Jarosław Rzeszótko
  2019-08-02  1:25   ` Noam Postavsky
  0 siblings, 2 replies; 7+ messages in thread
From: Andreas Röhler @ 2019-08-01  7:56 UTC (permalink / raw)
  To: 36884


On 01.08.19 09:06, Jarosław Rzeszótko wrote:
> When pressing enter with the cursor like this:
>
> def test():
>     print("test")
> [cursor]
>
> Emacs (26.1) correctly just inserts a blank line. However, with this:
>
> def test():
>     if True:
>           print("test")
> [cursor]
>
> Emacs inserts a blank line and indents it one level. With this:
>
> def test():
>     if True:
>         if False:
>               print("test")
> [cursor]
>
> it inserts a blank line and indents it two levels, etc. Moreover, with 
> two methods like this:
>
> def test1():
>     if True:
>           print("test")
>
> [cursor]def test2():
>     if True:
>           print("test")
>
> pressing enter will also indent the def block, instead of just 
> inserting the empty line.


Hi Jarosław,

python-mode.el developer here, just being interested.

AFAIU electric-indent-mode doesn't run a timer, cursor position alone 
would not trigger it.

Assume there is a command used from pos. Which? BTW the key alone 
doesn't tell enough, as RET and C-j changed binding recently. Reporting 
Emacs version will be useful.

Thanks,

Andreas






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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-01  7:56 ` Andreas Röhler
@ 2019-08-01  8:51   ` Jarosław Rzeszótko
  2019-08-02  1:25   ` Noam Postavsky
  1 sibling, 0 replies; 7+ messages in thread
From: Jarosław Rzeszótko @ 2019-08-01  8:51 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 36884

[-- Attachment #1: Type: text/plain, Size: 1622 bytes --]

M-x about-emacs shows:
GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.4) of
2019-02-03, modified by Debian

C-h k [RET] shows that it is bound to the "newline" function. I get the
same behavior with --no-init.

Cheers,
Jarek

On Thu, Aug 1, 2019 at 9:55 AM Andreas Röhler <andreas.roehler@easy-emacs.de>
wrote:

>
> On 01.08.19 09:06, Jarosław Rzeszótko wrote:
> > When pressing enter with the cursor like this:
> >
> > def test():
> >     print("test")
> > [cursor]
> >
> > Emacs (26.1) correctly just inserts a blank line. However, with this:
> >
> > def test():
> >     if True:
> >           print("test")
> > [cursor]
> >
> > Emacs inserts a blank line and indents it one level. With this:
> >
> > def test():
> >     if True:
> >         if False:
> >               print("test")
> > [cursor]
> >
> > it inserts a blank line and indents it two levels, etc. Moreover, with
> > two methods like this:
> >
> > def test1():
> >     if True:
> >           print("test")
> >
> > [cursor]def test2():
> >     if True:
> >           print("test")
> >
> > pressing enter will also indent the def block, instead of just
> > inserting the empty line.
>
>
> Hi Jarosław,
>
> python-mode.el developer here, just being interested.
>
> AFAIU electric-indent-mode doesn't run a timer, cursor position alone
> would not trigger it.
>
> Assume there is a command used from pos. Which? BTW the key alone
> doesn't tell enough, as RET and C-j changed binding recently. Reporting
> Emacs version will be useful.
>
> Thanks,
>
> Andreas
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2304 bytes --]

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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-01  7:56 ` Andreas Röhler
  2019-08-01  8:51   ` Jarosław Rzeszótko
@ 2019-08-02  1:25   ` Noam Postavsky
  2019-08-02  5:08     ` Jarosław Rzeszótko
  1 sibling, 1 reply; 7+ messages in thread
From: Noam Postavsky @ 2019-08-02  1:25 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 36884

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> AFAIU electric-indent-mode doesn't run a timer, cursor position alone
> would not trigger it.

electric-indent-mode works from post-self-insert-hook.  Not sure how
cursor position and timers are related.





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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-02  1:25   ` Noam Postavsky
@ 2019-08-02  5:08     ` Jarosław Rzeszótko
  2019-08-02 10:39       ` Andreas Röhler
  0 siblings, 1 reply; 7+ messages in thread
From: Jarosław Rzeszótko @ 2019-08-02  5:08 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 36884

[-- Attachment #1: Type: text/plain, Size: 1258 bytes --]

Perhaps this behavior exists because there can also be a situation like
this:

def test():
    print("test")
[cursor, on empty line in middle of indented block]
    print("test")

where what electric indent does after pressing RET (creates new line
aligned to the print statements) makes sense. I think it is mostly
irritating though, and editors I tested, Vim and Sublime Text, do not
automatically indent in any of the situations I mentioned.

FWIW this works as a workaround for me:

(setq electric-indent-functions
      '((lambda (inserted-char)
          (when (eq major-mode 'python-mode)
            ;; Do not auto-indent after inserting any empty line
            (when (save-excursion
                    (previous-line)
                    (beginning-of-line)
                    (looking-at "^\s*$"))
              'no-indent)))))

Cheers,
Jarek

On Fri, Aug 2, 2019 at 3:26 AM Noam Postavsky <npostavs@gmail.com> wrote:

> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>
> > AFAIU electric-indent-mode doesn't run a timer, cursor position alone
> > would not trigger it.
>
> electric-indent-mode works from post-self-insert-hook.  Not sure how
> cursor position and timers are related.
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 1979 bytes --]

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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-02  5:08     ` Jarosław Rzeszótko
@ 2019-08-02 10:39       ` Andreas Röhler
  2019-08-02 14:55         ` Jarosław Rzeszótko
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Röhler @ 2019-08-02 10:39 UTC (permalink / raw)
  To: 36884

[-- Attachment #1: Type: text/plain, Size: 1681 bytes --]

All you need probably is calling C-j, not RET

There is certain confusion IMO in recent design, as

C-j is bound to electric-newline-and-maybe-indent

which works as I would expect from newline.


On 02.08.19 07:08, Jarosław Rzeszótko wrote:
> Perhaps this behavior exists because there can also be a situation 
> like this:
>
> def test():
>     print("test")
> [cursor, on empty line in middle of indented block]
>     print("test")
>
> where what electric indent does after pressing RET (creates new line 
> aligned to the print statements) makes sense. I think it is mostly 
> irritating though, and editors I tested, Vim and Sublime Text, do not 
> automatically indent in any of the situations I mentioned.
>
> FWIW this works as a workaround for me:
>
> (setq electric-indent-functions
>       '((lambda (inserted-char)
>           (when (eq major-mode 'python-mode)
>             ;; Do not auto-indent after inserting any empty line
>             (when (save-excursion
>                     (previous-line)
>                     (beginning-of-line)
>                     (looking-at "^\s*$"))
>               'no-indent)))))
>
> Cheers,
> Jarek
>
> On Fri, Aug 2, 2019 at 3:26 AM Noam Postavsky <npostavs@gmail.com 
> <mailto:npostavs@gmail.com>> wrote:
>
>     Andreas Röhler <andreas.roehler@easy-emacs.de
>     <mailto:andreas.roehler@easy-emacs.de>> writes:
>
>     > AFAIU electric-indent-mode doesn't run a timer, cursor position
>     alone
>     > would not trigger it.
>
>     electric-indent-mode works from post-self-insert-hook.  Not sure how
>     cursor position and timers are related.
>
>
>

[-- Attachment #2: Type: text/html, Size: 3522 bytes --]

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

* bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines
  2019-08-02 10:39       ` Andreas Röhler
@ 2019-08-02 14:55         ` Jarosław Rzeszótko
  0 siblings, 0 replies; 7+ messages in thread
From: Jarosław Rzeszótko @ 2019-08-02 14:55 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: 36884

[-- Attachment #1: Type: text/plain, Size: 2064 bytes --]

So this is by design? Of course I can insert a newline in some other way,
circumventing the electric stuff, but having to decide between
RET-version-1 and RET-version-2 seems really inconvenient, personally I
would much rather have RET insert a newline without indent if the cursor is
not after text. This is also how it seems to work in other editors.

Cheers,
Jarek

On Fri, Aug 2, 2019 at 12:38 PM Andreas Röhler <
andreas.roehler@easy-emacs.de> wrote:

> All you need probably is calling C-j, not RET
>
> There is certain confusion IMO in recent design, as
>
> C-j is bound to electric-newline-and-maybe-indent
>
> which works as I would expect from newline.
>
>
> On 02.08.19 07:08, Jarosław Rzeszótko wrote:
>
> Perhaps this behavior exists because there can also be a situation like
> this:
>
> def test():
>     print("test")
> [cursor, on empty line in middle of indented block]
>     print("test")
>
> where what electric indent does after pressing RET (creates new line
> aligned to the print statements) makes sense. I think it is mostly
> irritating though, and editors I tested, Vim and Sublime Text, do not
> automatically indent in any of the situations I mentioned.
>
> FWIW this works as a workaround for me:
>
> (setq electric-indent-functions
>       '((lambda (inserted-char)
>           (when (eq major-mode 'python-mode)
>             ;; Do not auto-indent after inserting any empty line
>             (when (save-excursion
>                     (previous-line)
>                     (beginning-of-line)
>                     (looking-at "^\s*$"))
>               'no-indent)))))
>
> Cheers,
> Jarek
>
> On Fri, Aug 2, 2019 at 3:26 AM Noam Postavsky <npostavs@gmail.com> wrote:
>
>> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>>
>> > AFAIU electric-indent-mode doesn't run a timer, cursor position alone
>> > would not trigger it.
>>
>> electric-indent-mode works from post-self-insert-hook.  Not sure how
>> cursor position and timers are related.
>>
>>
>>
>>

[-- Attachment #2: Type: text/html, Size: 4122 bytes --]

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

end of thread, other threads:[~2019-08-02 14:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-01  7:06 bug#36884: Default python mode with electric-indent-mode sometimes indents empty lines Jarosław Rzeszótko
2019-08-01  7:56 ` Andreas Röhler
2019-08-01  8:51   ` Jarosław Rzeszótko
2019-08-02  1:25   ` Noam Postavsky
2019-08-02  5:08     ` Jarosław Rzeszótko
2019-08-02 10:39       ` Andreas Röhler
2019-08-02 14:55         ` Jarosław Rzeszótko

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