Subject: Let's improve the default workings of electric-indent-mode.

From: Alan Mackenzie <[email-masked]>
Date: Sat, 12 Oct 2013 14:54:15 +0000

Hi, Stefan.

On Sun, Oct 06, 2013 at 01:01:31PM -0400, Stefan Monnier wrote:
> Hey, guys.  What are you waiting for on the bug-report requesting to
> change the default of electric-indent-mode?
> Really!

I think the default behaviour of electric-indent-mode can and should be
improved.

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).

We need a method of {en,dis}abling e-i-m for both modes and for indiviual
buffers.  We probably don't want to change the definition of the variable
`electric-indent-mode'.

So, make `electric-indent-mode' t by default, yet have it tempered by the
new buffer local variables `electric-indent-enabled-function' and
`electric-indent-enabled-flag', both defaulting to nil, which work in the
canonical Emacs fashion.  These variables will be intended mainly for
mode maintainers, yet will be available to knowledgeable users for
configuration/toggling.  When `e-i-m' is t and one of these new variables
returns/is t, then electric indentation will take place.

With this scheme, users can globally disable e-i-m by toggling
electric-indent-mode, as at present.  They can enable it in all buffers
in which it makes sense by toggling it again.  They can enable it in
other buffers by setting `electric-indent-enabled-flag' in those buffers.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).