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 22:29:06 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> Concrete examples would be helpful and could be reported as bugs ...
> I don't think these are bugs, but my personal user preference is to have
> RET indent in programming modes but not in text modes.

You might like to try removing that customization and then complain
about the cases that don't behave like you want.  I don't guarantee I'll
agree, but since `electric-indent-mode` is globally enabled by default,
I think it's important to try and make sure it's not too annoying in
those modes where it's not helpful.

>> 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.
> I admit that the whole electric-indent stuff is new to me.  I saw it
> happening but never checked *why* it is happening.  First time I noticed
> it explicitly was in the backtrace leading to my original post.

Yes, it happened because I think it's important to consolidate the
needs shared by all major modes.  It's surprisingly hard work, because
every major mode tends to do it slightly differently, so the
consolidated version is never "quite the same", thus encountering a lot
of resistance to change.

> Wouldn't that result in `newline` re-indenting both the new and the
> previous line (as per electric-indent-mode), but `newline-and-indent`
> *not* re-indenting the previous line?

Yes.

> That would seem a bit surprising.

Then again, the users have the choice of either calling
`newline-and-indent` or `reindent-then-newline-and-indent`, so
presumably when they choose `newline-and-indent` it's because they don't
want the first line to be reindented.

It also brings back the behavior they had before `electric-indent-mode`.

> First experiments suggest that the patch does indeed change the behavior
> when a line contains just a closing "]" or ")" - neither
> (newline-and-indent) nor (cperl-linefeed) now re-indent that line (which
> they should)

This behavior is the behavior that `cperl-linefeed` had when it was
written, so I disagree with "they should".

>> 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.
>
> That sounds good... it would need some unraveling to prevent deep
> recursion.  `electric-indent-mode` calls the mode-specific indentation
> function, which would optionally call fancystuff, which in turn calls
> both newline-and-indent _and_ the mode-specific indentation function.

I haven't even looked at what it would take in terms of coding.
Hell!  I don't even know half of what the "fancystuff" does, so maybe
I'm just plain wrong about what should be done.
In other words: I won't be touching this code any time soon (I'd much
rather add some of the "fancystuff" features to `perl-mode`, where
I wouldn't need to worry about breaking old cperl-mode users's habits).


        Stefan




reply via email to

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