emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newline-and-indent vs. electric-indent-mode


From: Stefan Monnier
Subject: Re: newline-and-indent vs. electric-indent-mode
Date: Fri, 22 Jan 2021 09:49:14 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Many (almost all?) modes bind RET to newline-and-indent,

Any mode which does that should be fixed.  Whether RET indents or not is
a user preference, not something that should depend on the kind of
language you're editing.

> So, whenever a newline is entered,

By that I assume you simply mean whenever `newline-and-indent` is executed?

> there are three calls to the mode-specific indenting function:
>
>  - one call for the current line, caused by electric-indent-mode.  This
>    makes some sense because the line's content might suggest a different
>    indentation than what could be guessed when the line started out as a
>    new empty line.  It is annoying, however, when the mode gets the
>    indentation wrong (which occasionally happens).  It is also
>    superfluous if the character which causes a change in indentation
>    (for example "}") is either itself in electric-indent-chars (as in
>    perl-mode) or handled by the mode's keymap (as in cperl-mode), both
>    resulting in a call to the indenting function.
>
>  - two calls for the following, empty line.  One is caused by '(?\n)
>    being in electric-indent-chars, the other by the current command
>    being newline-AND-INDENT.  This doesn't make any sense.

It sounds like a bug indeed.  I think both having two calls (one for
each line) or having one call (for the new line) could arguably be
correct, but three calls is indeed an error.

> Or should the modes refrain from mapping RET?

Very much so, yes (unless there's a good language-related reason why RET
should behave differently for that specific language).  But that doesn't
change the fact that `newline-and-indent` should work right, including
not calling the indent function redundantly.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]