all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alan Mackenzie <acm@muc.de>
Cc: gnu-emacs-bug@moderators.isc.org
Subject: bug#15478: cc-mode does not obey electric-indent-mode
Date: Mon, 07 Oct 2013 12:14:19 -0400	[thread overview]
Message-ID: <jwv7gdp84so.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <20131007103041.GB3859@acm.acm> (Alan Mackenzie's message of "Mon, 7 Oct 2013 10:30:42 +0000")

>> Emacs has never provided this feature in any mode that I know, cc-mode
>> included.  Some major modes (such as CC-mode) try to provide some vague
>> approximation of it, using "electric keys" that trigger indentation
>> "often enough" that it works more or less OK in some common cases.
> :-).  I think CC Mode DTRT practically 100% of the time.  There haven't
> been bug reports asking for the details of the electric indentation to be
> improved.

I can assure you it doesn't work 100%: in many circumstances you have to
hit TAB (or M-C-\ or M-C-q) manually before the text's indentation
reflects the modifications that took place.

I don't think it's a failure of your code, tho (and
electric-indent-mode fails in the exact same way).

> from 1992.  Somebody (RMS?  Barry Warsaw?) clearly thought it very
> important.

I thought it's important enough to embark on electric-indent-mode
(which is reasonably easy to implement, except it's hellish to get all
the various authors to get back in line and start using the generic
infrastructure, for the long term benefit of end users, at the cost
of short term disruption and extra work).

>> No they're not.  And I think it's blatantly obvious, even to you.
>> I understand that simply to mean that you do not want CC-mode's default
>> behavior to change.
> You're not wrong there.

Thank you.

>> The core is then: how should we make cc-mode integrate better with Emacs
>> and use the generic electric-*-mode functionality instead of
>> rolling its own?
> How about aliasing `c-electric-mode' and `electric-indent-mode' and
> making them buffer-local in CC Mode buffers?  Then setting CC Mode's
> value of `electric-indent-chars' to nil, for now, and in the medium
> future (once e-i-m has percolated through to old versions and XEmacs)
> integrating CC Mode into electric-indent-mode properly?

Poor, but does satisfy the requirements.

> How about introducing `global-electric-indent-mode' and redefining e-i-m
> to be buffer-local?  Or, alternatively, leaving e-i-m as it is and
> defining `local-electric-indent-mode'?

`electric-indent-local-mode' sounds good.

> What about defining a property `no-electric-indentation' which could
> be set on python-mode and others?

I wouldn't use a property.  Just a buffer-local variable
`electric-indent-inhibit' which those modes can set.
For Python and Haskell, this should only inhibit *re*indentation, while
still calling indent-according-to-mode after inserting a newline.

>> For the record: CC-mode is not the only major mode in this boat.
>> I've already converted several major modes to use electric-indent-mode,
>> and for some of them this also involved changing the default behavior.
> Would you identify (some of) these modes, please, so I can go and have a
> look.

If you "grep electric-indent- **/*.el" you'll find some of them (I also
changed a few external ones like sml-mode).

Note that in most cases I made the change by completely side-stepping
the old code (i.e. the define-key that rebinds the keys to electric
versions was either removed or made conditional on something like
(fboundp 'electric-indent-mode)).

And those were usually simpler than what cc-mode does, with the
exception maybe of octave.el where the old behavior was a bit more
complex, and replaced by a mix of electric-indent-mode,
electric-layout-mode.

But in most of those cases, I only made a minimal effort at trying to
preserve old behavior and user's customization.  I've seen a few
questions about "why foo-mode doesn't indent as before", and the answer
"it's now controlled by electric-indent-mode" always seemed to satisfy
the user.


        Stefan





  parent reply	other threads:[~2013-10-07 16:14 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-28 18:10 bug#15478: cc-mode does not obey electric-indent-mode Stefan Monnier
2013-09-28 20:11 ` Alan Mackenzie
2013-09-29  3:02   ` Stefan Monnier
2013-09-29  9:10     ` Alan Mackenzie
2013-09-30 18:23       ` Stefan Monnier
2013-10-02 20:07         ` Alan Mackenzie
2013-10-03  1:50           ` Stefan Monnier
2013-10-03  2:46             ` Daniel Colascione
2013-10-03  4:10               ` Stefan Monnier
2013-10-03  4:13                 ` Daniel Colascione
2013-10-03  4:50                   ` Stefan Monnier
2013-10-03  5:56                 ` Andreas Röhler
2013-10-03  6:31                   ` Daniel Colascione
2013-10-03 15:52                     ` Eli Zaretskii
2013-10-03 13:15                   ` Dmitry Gutov
2013-10-03 15:04                     ` Stefan Monnier
2013-10-03 17:40                     ` Andreas Röhler
2013-10-03  9:45                 ` Alan Mackenzie
2013-10-03 14:02                   ` Stefan Monnier
2013-10-03 17:45                   ` Andreas Röhler
2013-10-03 10:56             ` Alan Mackenzie
2013-10-03 14:32               ` Stefan Monnier
2013-10-04 21:21                 ` Josh
2013-10-05 16:50                   ` Alan Mackenzie
2013-10-06 17:45                     ` Josh
2013-10-07 13:11                       ` Alan Mackenzie
2013-10-07 21:23                         ` Josh
2013-10-09 17:55                           ` Alan Mackenzie
2013-10-03 11:54 ` Alan Mackenzie
2013-10-03 17:43   ` Andreas Röhler
2013-10-05 17:06 ` Alan Mackenzie
2013-10-06  1:10   ` Stefan Monnier
2013-10-06  2:55     ` Eli Zaretskii
2013-10-06  5:04       ` Josh
2013-10-07  9:39         ` Alan Mackenzie
     [not found]         ` <20131007093859.GA3859@acm.acm>
2013-10-07 16:05           ` Eli Zaretskii
2013-10-07 21:17             ` Josh
2013-10-08  6:49               ` Eli Zaretskii
2013-10-08 15:59                 ` Josh
2013-10-09 17:32               ` Alan Mackenzie
     [not found]               ` <20131009173206.GA2610@acm.acm>
2013-10-10 19:11                 ` Josh
2013-10-06 17:01       ` Stefan Monnier
2013-10-12 14:54         ` bug#15596: Let's improve the default workings of electric-indent-mode Alan Mackenzie
2013-10-12 16:35           ` Stefan Monnier
2013-10-13 12:36             ` Alan Mackenzie
2013-10-14  2:16               ` Stefan Monnier
2013-10-07 10:30     ` bug#15478: cc-mode does not obey electric-indent-mode Alan Mackenzie
     [not found]     ` <20131007103041.GB3859@acm.acm>
2013-10-07 16:14       ` Stefan Monnier [this message]
2013-10-07 20:37         ` Alan Mackenzie
     [not found]         ` <20131007203738.GA3099@acm.acm>
2013-10-07 23:08           ` Stefan Monnier
2013-10-05 17:08 ` Alan Mackenzie
2014-02-17 19:02 ` Alan Mackenzie
     [not found] ` <20140217190249.GB4173@acm.acm>
2014-02-18  0:04   ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=jwv7gdp84so.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acm@muc.de \
    --cc=gnu-emacs-bug@moderators.isc.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.