From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Alan Mackenzie <acm@muc.de>
Cc: 15478@debbugs.gnu.org
Subject: bug#15478: cc-mode does not obey electric-indent-mode
Date: Thu, 03 Oct 2013 10:32:32 -0400 [thread overview]
Message-ID: <jwva9iqv4dn.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <20131003105600.GB3211@acm.acm> (Alan Mackenzie's message of "Thu, 3 Oct 2013 10:56:00 +0000")
>> > Without electricity, correct indentation would require continual pressing
>> > of the <tab> key.
>> Yes. Just as is the case in all major modes.
> No. Electric indentation is completely unneeded in Emacs Lisp Mode,
Nitpicking.
>> That's because *you* like electric-indent-mode. Not because C is special.
> No, it's not just my preference.
That's what you say, but I don't see the evidence. So far you've only
pointed to Elisp mode and Python mode as counter examples, but from
where I stand it's more like Elisp and Python are the exceptions (and
as soon as someone improves Elisp indentation for cl-lib constructs
or :keyword arguments, Elisp won't be an exception any more).
> All modes should indent correctly automatically, by default.
Again, you're arguing for enabling electric-indent-mode by default.
I'm not necessarily opposed to it, but it's a different issue than the
one I'm concerned with in this bug-report.
> But you need to hit <tab> _after_ typing the brace, but _before_ typing
> C-j. This doesn't seem like an effective way of working. Do you really
> run C Mode without electric indentation?
Of course. And cc-mode is one of the very few modes where
electric-indent is so "in your face" all the time.
>> >> For me, I'd like cc-mode to do as little as possible besides adding
>> >> ?\;, ?\{, and ?\} to electric-indent-chars.
>> > These characters should not trigger electric indentation when typed
>> > inside a string or a comment. electric-indent-mode isn't best placed to
>> > make such distinctions.
>> Why not?
> Because each such distinction is going to be major mode specific.
That's not a good reason, since there's no technical difficulty in
making it possible for a major mode to tell electric-indent-mode which
behavior is desired.
>> > It doesn't seem to be the Right Thing to split the electric activity
>> > between electric-indent-mode (for indentation) and c-electric-brace
>> > and friends (for auto-newlining and clean-ups).
>> As explained, there's electric-layout-mode for auto-newlining. Not sure
>> what "clean-ups" is about, but we can probably work something out.
> Clean-ups, for example, remove auto-newlines when it later transpires
> they're unwanted. For example, one clean-up converts
> }
> else
> {
> to
> } else {
> on typing the "{".
Ah, right. I don't see any particular problem here, cc-mode can provide
a c-electric-cleanup-mode (or maybe we can even make it generic, so
other major modes can provide their own cleanup rules).
>> I'm all for improving electric-indent-mode. And indeed, it needs
>> improvement for indentation-sensitive modes like Python and Haskell.
> Does it even make sense for these modes?
No, it doesn't, which is the needed improvement: make it default to Off
there even if it is enabled globally.
>> > Each major mode needs its own default for e-i-m:
>> I disagree with it: some major modes need their own default because
>> their syntax has something very special, e.g. incompatible with
>> electric-indent-mode (Python/Coffescript/Haskell), ...
> Does that even make sense? How can Python have its own default, yet C
> not?
Technically, C could have its own default as well, of course.
I just don't see any reason for it.
> The default setting doesn't reflect a user's preference, if that
> preference is ON for C, OFF for Python, and the major mode specific
> optimum for everything else.
Indeed, which is why only very few major modes should override the
global default. Python has a good reason to override it. C doesn't.
>> > something like `electric-indent-mode-alist', analogous with
>> > `auto-mode-alist'. This default would be consulted at mode
>> > initialisation time.
>> I don't see why the major mode can't just set a var in its major-mode
>> function for the rare cases where it can be needed, and why the user
>> can't make his own choice via the major-mode's hook, if needed.
> Because, as so often in this list, we're talking about defaults, not the
> extent to which an experienced user can customise his Emacs. Defaults
> are important.
My point above was arguing against using an electric-indent-mode-alist
mechanism rather than one of the standard mechanisms (setq-local for the
major-mode or add-hook for the user). It was not about what the default
should be.
>> > A buffer's setting of e-i-m should also be more than just nil or t. That
>> > is inflexible to an un-Emacs like degree. At the very least, there
>> > should be some sort of setting that means "electric indentation is
>> > performed entirely by the major mode".
>> I don't understand what you're suggesting.
> You seem to be suggesting dismantling not only CC Mode's electric
> indentation, but its auto-newlining too. The generic replacements for
> them are going to be less good.
I don't want them to be less good. They may be marginally less good, or
slightly different in some corner cases, of course. But "significantly
less good" would be a bug to fix by improving the generic code.
As already mentioned, fixing this bug report may require fixes not just
in cc-mode but also in electric.el.
> What I'm suggesting is some sort of hook so that electric-indent-mode
> (and electric-layout-mode, too, I suppose) invokes the "electric
> engine" in CC Mode rather than trying to do the electric
> indentation itself.
Sounds OK.
Stefan
next prev parent reply other threads:[~2013-10-03 14:32 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 [this message]
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
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=jwva9iqv4dn.fsf-monnier+emacsbugs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=15478@debbugs.gnu.org \
--cc=acm@muc.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 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.