[Top][All Lists]

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

bug#15596: Let's improve the default workings of electric-indent-mode.

From: Alan Mackenzie
Subject: bug#15596: Let's improve the default workings of electric-indent-mode.
Date: Sun, 13 Oct 2013 12:36:59 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

Hello, Stefan.

On Sat, Oct 12, 2013 at 12:35:46PM -0400, Stefan Monnier wrote:
> > At the moment, it is (rather crudely) just nil or t, globally for all
> > modes and all buffers.  This is unsatisfactory, as it makes it difficult
> > to {en,dis}able e-i-m for a single mode, and for a single buffer.  An
> > example of when you might want to do the latter is thus: one has an
> > isolated file.c (or section therewithin) whose indentation style does not
> > conform to project norms, and one does not wish to reindent the file
> > wholesale.  Electric indentation makes editing such a file inconvenient,
> > hence the need for the ability readily to switch it off (currently
> > available in CC Mode with C-c C-l).

> Currently it's easyish for the user to do

>    (add-hook 'blabla-hook
>              (lambda () (setq-local electric-indent-mode nil)))

> Or to set electric-indent-mode to nil in the file variables.

These are surely bad ideas.  `electric-indent-mode' is a global mode, so
creating buffer local copies of it will lead to confusion.  What does M-x
electric-indent-mode do when there's a buffer local value of e-i-m?  If
it toggles the global binding, it will appear not to have worked in the
current buffer.  If it toggles the local binding, it is no longer a
global mode.  This is why I suggested extra variables to handle locality
(see below).

> But we could provide an electric-indent-local-mode, yes.  Patch welcome.

> > So, make `electric-indent-mode' t by default, yet have it tempered by the

> Have any one of you tried to use Emacs with this setting?  I'm not
> fundamentally opposed to changing the default setting, but just as was
> the case for font-lock-mode, transient-mark-mode, etc... we need to be
> sure it actually works well enough in "all" cases (except those cases
> where the user just doesn't like the feature and will disable it
> globally).

I think I was a bit unclear.  I meant have the _variable_ e-i-m set to t
by default, but have the electricity disabled by default by the new
buffer local variable `electric-indent-enabled-flag'.  But the new
variable `electric-indent-inhibit' can do this anyhow.

> But contrary to font-lock-mode, transient-mark-mode, AFAIK not many
> people have enabled this mode yet, so I'd urge you all to try it out for
> a few weeks first, to see if you like it not only in modes like c-mode
> but also everywhere else, and if there are cases where you find it
> inconvenient, report it here, so we can see what we should do about it.

As I reported in emacs-devel, I had trouble in Text Mode with e-i-m.

> > new buffer local variables `electric-indent-enabled-function' and

> The buffer-local value of electric-indent-mode is already used for
> that purpose .....

I think this is a bad thing (see above), and such uses should be
superseded by using ...

> ... (and there's also the new electric-indent-inhibit which I recently
> added, which prevents reindentation, while still doing automatic
> indentation for new lines.

Surely e-i-inhibit should be t by default.  Electric indentation is
useful in (?most) programming modes, but probably not very much in text
modes, or things like Outline Mode.  It is useful precisely where the
indentation of a line is determined by that same line's contents.
(That's not counting the `newline-and-indent' behaviour.) That surely
happens only in programming modes, or the like.  How about having
e-i-inhibit t by default, but setting it to nil in `prog-mode'?

>         Stefan

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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