GNU bug report logs - #36884
Default python mode with electric-indent-mode sometimes indents empty lines

Previous Next

Package: emacs;

Reported by: Jarosław Rzeszótko <jrzeszotko <at> gmail.com>

Date: Thu, 1 Aug 2019 07:07:01 UTC

Severity: normal

Full log


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

From: Jarosław Rzeszótko <jrzeszotko <at> gmail.com>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: 36884 <at> debbugs.gnu.org
Subject: Re: bug#36884: Default python mode with electric-indent-mode
 sometimes indents empty lines
Date: Fri, 2 Aug 2019 16:55:03 +0200
[Message part 1 (text/plain, inline)]
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 <at> 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 <at> gmail.com> wrote:
>
>> Andreas Röhler <andreas.roehler <at> 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.
>>
>>
>>
>>
[Message part 2 (text/html, inline)]

This bug report was last modified 5 years and 324 days ago.

Previous Next


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