all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Josh <josh@foxtail.org>
To: Alan Mackenzie <acm@muc.de>
Cc: 15478@debbugs.gnu.org
Subject: bug#15478: cc-mode does not obey electric-indent-mode
Date: Mon, 7 Oct 2013 14:23:20 -0700	[thread overview]
Message-ID: <CANdFEAEp0s3ZJVDZgOBE-pQL5=Z3OgU6m3X+SoPRpePULjUHWg@mail.gmail.com> (raw)
In-Reply-To: <20131007131122.GC3859@acm.acm>

On Mon, Oct 7, 2013 at 6:11 AM, Alan Mackenzie <acm@muc.de> wrote:
> On Sun, Oct 06, 2013 at 10:45:59AM -0700, Josh wrote:
> > My previous question was based on a supposition (perhaps naive, as I'm
> > not at all familiar with the CC Mode code) that its indentation
> > functionality was either already centralized into a some "indent this
> > line properly" function or that it would be desirable and feasible to
> > make it so.  If that were so, it seemed to me that such a function
> > could be pressed into service as an electric-indent-function without
> > too much trouble.
> That could indeed be done, but the "too much trouble" would arise from
> having to maintain separate versions of this code for the current Emacs,
> and for Xemacs and historical Emacsen.
>
> Have a look at the code for `c-electric-brace' in cc-cmds.el.

OK, I did.  I saw what I take to be the embodiment of years of hard-won
experience about how to implement this functionality correctly, and I
fully agree that we could ill-afford to lose it.  In hindsight I don't
think I described the "centralized" `c-indent-this-line-properly'
function I have in mind very well so let me try again, continuing with
your example of braces.

Start by factoring the indentation logic out of the current
`c-electric-brace' implementation and call the extracted function
`c-electric-brace-indent'.  Call what's left `c-electric-brace*' and
change its behavior to merely insert the brace and then call
`c-indent-this-line-properly' with the inserted character as an
argument.  The latter function would then dispatch to the appropriate
CC Mode indentation function, in this case the extracted
`c-electric-brace-indent'.  Here are the key bindings and call trees I
had in mind:

|--------+---------------------------------+--------------------------------|
|        | Current Emacs                   | XEmacs, older GNU Emacs        |
|--------+---------------------------------+--------------------------------|
| {,} -> | self-insert-command             | c-electric-brace*              |
|--------+---------------------------------+--------------------------------|
| Call   | electric-indent-post-self-[...] | c-electric-brace*              |
| Tree   | `- c-indent-this-line-properly  | `- c-indent-this-line-properly |
|        |    `- c-electric-brace-indent   |    `- c-electric-brace-indent  |
|--------+---------------------------------+--------------------------------|

In both cases, the same events (character insertion) trigger the same
CC Mode indentation code extracted from the current implementation.
I'm aware that such a scheme may be impractical for reasons unknown to
me, but otherwise then at least for indentation triggered by character
insertion the only maintenance burden I can see is that of the thin
c-electric-brace* wrapper.

> >   (or c-force-electric-flag electric-layout-mode electric-indent-mode)
> That's not going to gain anything, since `c-force-electric-flag' would
> need to default to t to preserve existing behaviour.

The need to preserve existing behavior is not a given.  The above
change would cause the (initial) enablement of electric behavior in CC
Mode to be predicated on global electricity enablement, which is the
subject of this bug.

> > .... Even so, it would be a vast improvement for newbies who do not
> > want this behavior.
>
> Yes, but it would be undesirable for those other newbies who do want
> automatic indentation.  "Newby" here means those unfamiliar with
> `c-toggle-electric-state' and `electric-indent-mode'.

Identifying the right set of defaults is important and likely to be an
extensive discussion in itself, but one that should take place as part of
some other bug.  This bug is about the fact that CC Mode disregards
configuration that is documented to be global.





  reply	other threads:[~2013-10-07 21:23 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 [this message]
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='CANdFEAEp0s3ZJVDZgOBE-pQL5=Z3OgU6m3X+SoPRpePULjUHWg@mail.gmail.com' \
    --to=josh@foxtail.org \
    --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.