unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: haj@posteo.de (Harald Jörg)
Cc: Emacs Developer List <emacs-devel@gnu.org>
Subject: Re: newline-and-indent vs. electric-indent-mode
Date: Fri, 22 Jan 2021 17:05:41 -0500	[thread overview]
Message-ID: <jwv4kj8u0if.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87o8hgzrzi.fsf@hajtower> ("Harald Jörg"'s message of "Fri, 22 Jan 2021 20:33:37 +0100")

>>> Many (almost all?) modes bind RET to newline-and-indent,
>> Any mode which does that should be fixed.
> Ouch... I see now that my "observation" was plain wrong.

Yes and now: historically, it's been quite common for major modes to do
that kind of thing.  I've been fighting it for many years now (even
long before `electric-indent-mode`) since it's usually the reflection of
the major mode's author's preference, rather than something directly
linked to the major mode (there are several other examples of this
behavior: setting `comment-column` in the major mode is another similar
example).

>> Whether RET indents or not is a user preference, not something that
>> should depend on the kind of language you're editing.
> For most programming and markup languages indenting makes sense, but
> less so for other modes.

Concrete examples would be helpful and could be reported as bugs (I have
made efforts to setup `electric-indent-mode` such that it tries not to
get in the way in "plain text" modes, but of course that's no guarantee
that it catches all relevant cases).

> I guess it wouldn't hurt to add a sentence to the docstring of
> electric-indent-mode how it should be managed for a single buffer.  The
> method with an extra variable (electric-indent-inhibit, works only to
> disable a globally enabled mode) or an extra mode
> (electric-indent-local-mode, works both ways) is somewhat nonstandard
> and the question seems to pop up occasionally on various platforms.

`electric-indent-inhibit` doesn't inhibit auto-indentation.  It inhibits
auto-*re*indentation.

I know it takes many people by surprise (because the choices are more
refined than just "on or off" and they don't expect that), but I find it
hard to improve the docs to guide the users/programmers.

>> 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.
> So... I guess newline-and-indent could suppress the call to
> indent-line-function for the new line if electric-indent-mode is t and
> electric-indent-inhibit is nil and ?\n is in electric-indent-chars?

That would be one way, tho I find it fairly ugly.  Another might be to
temporarily disable `electric-indent-mode`.  The more I think about it,
the more I think this is the better choice.

> Just for the record: The results are correct, and the delay isn't
> noticeable even with the convoluted indenting routines of CPerl mode.

Usually indentation of a single line is very quick so doing twice is
indeed lost in the noise.  Of course, there are corner cases where
indentation can take a non-negligible amount of time, in which case
doubling it can be noticed (but still isn't a main worry: even if it
increases the runtime from 30s to 1min it's not that significant since
30s is really not all that much better than 1min).

Still counts as a performance bug to me.

> It is just a bit annoying when you are tracing through the routines
> trying to figure out where to fix a bug.

I suspect that there are cases where it really does introduce bugs
beyond a (minor) performance impact, e.g. in some of the major modes
where repeated TABs cycle between different indentation points.

In any case, I pushed a change to `master` to disable
`electric-indent-mode` in `newline-and-indent`, so this should hopefully
be fixed now.

> In CPerl mode, the remaining issue is actually the other way around.
> You can activate cperl-electric-linefeed via customize to do
> newline-and-indent.

More or less.  `cperl-mode` intends to offer basically 3 different
options: plain newline, newline+indent, and newline+indent+fancystuff.
And these are bound be default resp. to RET, LFD, and C-c LFD.
Then `cperl-electric-linefeed` lets you swap the last two.  Of course,
with `electric-indent-mode` RET ends up doing (more or less) what
LFD does.

IMO keybindings is more harmful than anything here, so a better choice
would be to offer only plain newline and newline+indent+fancystuff, bind
them to RET and LFD, let `electric-indent-mode` control which of RET and
LFD does which, and let `cperl-electric-linefeed` control whether
fancystuff is done at all.


        Stefan




  reply	other threads:[~2021-01-22 22:05 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 13:53 newline-and-indent vs. electric-indent-mode Harald Jörg
2021-01-22 14:49 ` Stefan Monnier
2021-01-22 15:02   ` Dmitry Gutov
2021-01-22 15:09     ` Stefan Monnier
2021-01-22 22:43       ` Dmitry Gutov
2021-01-22 22:56         ` Stefan Monnier
2021-01-22 23:00           ` Dmitry Gutov
2021-01-22 23:16             ` Stefan Monnier
2021-01-23  0:45               ` Dmitry Gutov
2021-01-23  3:16                 ` Stefan Monnier
2021-01-24  2:54                   ` Dmitry Gutov
2021-01-24  5:29                     ` Stefan Monnier
2021-01-24 21:45                       ` Dmitry Gutov
2021-01-25  1:56                   ` Madhu
2021-01-25  2:29                     ` Dmitry Gutov
2021-01-25 10:45                       ` Madhu
2021-01-25 11:59                         ` Dmitry Gutov
2021-01-25 14:36                         ` Stefan Monnier
2021-01-25 14:42                           ` Dmitry Gutov
2021-01-25 15:15                             ` Stefan Monnier
2021-01-25 20:10                               ` Rudolf Schlatte
2021-01-26  2:04                               ` Dmitry Gutov
2021-01-26  2:43                                 ` Stefan Monnier
2021-01-26 15:58                               ` martin rudalics
2021-01-25  3:33                     ` Eli Zaretskii
2021-01-22 19:33   ` Harald Jörg
2021-01-22 22:05     ` Stefan Monnier [this message]
2021-01-23  2:19       ` Harald Jörg
2021-01-23  3:29         ` Stefan Monnier
2021-01-23 16:27           ` Harald Jörg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv4kj8u0if.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=haj@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).