unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: bea@klebe.blog, "João Távora" <joaotavora@gmail.com>,
	33794@debbugs.gnu.org
Subject: bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode
Date: Fri, 21 Dec 2018 20:11:06 +0000	[thread overview]
Message-ID: <20181221201106.GB16032@ACM> (raw)
In-Reply-To: <jwvk1k3j7th.fsf-monnier+emacsbugs@gnu.org>

Hello, Stefan.

On Fri, Dec 21, 2018 at 09:12:49 -0500, Stefan Monnier wrote:
> >> Yes.  What is happening, from the viewpoint of CC Mode, is that on
> >> inserting a {, electric-pair-mode is prematurely inserting its }, before
> >> the processing for the { is complete.

> Since it's done from post-self-insert-hook, it's done at the very end of
> inserting { so I'm not sure what you mean by "before the processing for
> the { is complete".

c-electric-brace calls self-insert-function then performs the rest of
its processing.

> >> Also, due to the way } gets inserted, the CC Mode processing for
> >> the } isn't done at all.

> I think you meant "due to the way CC-Mode hooks itself into the }
> processing, ..." ;-)

No, not at all.  CC Mode has been working for several decades, and works
well.  electric-pair-mode is the new kid on the block, just a few years
old, and was apparently hacked together without regard to some well
established conventions.  It should have provided interfaces to allow
existing software to connect to it - for example a variable to contain a
function to insert the electric character, or something like that.
Maybe.  It should have been considered, but apparently wasn't.

> >> Would it therefore be possible, rather than having a crude insertion on
> >> post-self-insert-hook, to use something like post-command-hook to allow
> >> the insertion of the { first to complete?  Then, rather than using the
> >> brutal self-insert-command for } in electric-pair--insert, use the
> >> command to which the key } is bound?

> Talking about brutal: how could electric-pair-mode run whichever command
> is bound to } without taking the risk of running a much more brutal
> command than one that inserts a character?

That isn't a risk.  It's a user decision.

> > FWIW, I think cc-mode should rather use post-self-insert-hook instead
> > of redefining ....

There's no "redefining".  There's definition of functions bound to keys,
and these definitions are several decades old and work well.  Such
software construction is recommended by the Emacs manual (page "Major
Modes").

> > .... commands for keys whose expected behaviour is (with minor
> > variations presumably covered by abundant hookage) self-insertion.

post-self-insert-hook smells bad.  I can't quite put my finger on what's
wrong with it, but it definitely doesn't feel good.  Anyhow, it's too
new for CC Mode.  And it would involve a lot of work for no increase in
functionality.

The fault lies in electric-pair-mode's failure to provide appropriate
interfaces for existing code to use it.

> IIRC it should be able to just use electric-layout-mode for that (tho
> maybe electric-layout's featureset doesn't currently cover 100% that of
> CC-mode's auto-newline, in which case it would be nice to extend
> electric-layout accordingly).

electric-layout-mode seems to be a reinvention of the wheel,
incomptible, sadly, with the original in CC Mode.  That original works
well.  The copy likely works less well, though I admit not having
examined it in any great detail.

> For things like electric-pair, electric-indent, and electric-layout to
> work correctly together, they need to agree on some convention.

Yes.  I've searched the emacs-devel archives briefly, and found no
attempt there to sketch out and discuss such a convention, and
definitely no attempt to reach any agreement.  Maybe I've missed
something, but given how recent these electric-.. things are (2010),
it's likely I would have been involved in such discussion had it taken
place, and it's likely electric-pair-mode wouldn't now be clashing with
CC Mode.

> Note that CC-mode can also side-step that convention and use `insert`
> instead of self-insert-command.

That wouldn't help electric-pair-mode work in CC Mode, I think.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2018-12-21 20:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-18 17:38 bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode Beatrix Klebe
     [not found] ` <mailman.5894.1545155289.1284.bug-gnu-emacs@gnu.org>
2018-12-21 13:48   ` Alan Mackenzie
2018-12-21 13:57     ` João Távora
2018-12-21 14:12       ` Stefan Monnier
2018-12-21 16:00         ` Beatrix Klebe
2018-12-21 18:49           ` João Távora
2018-12-21 19:06             ` Beatrix Klebe
2018-12-21 19:20               ` João Távora
2018-12-21 19:24                 ` João Távora
2018-12-21 19:43                 ` Beatrix Klebe
2018-12-22  1:08                   ` João Távora
2018-12-22  2:16                     ` João Távora
2018-12-22  2:41                       ` Alan Mackenzie
2018-12-22  3:22                         ` João Távora
2018-12-22  4:41                           ` Beatrix Klebe
2018-12-22 10:02                             ` João Távora
2018-12-22 12:33                           ` Alan Mackenzie
2019-01-01 19:27           ` Alan Mackenzie
2019-01-15 16:10             ` Alan Mackenzie
2018-12-21 20:11         ` Alan Mackenzie [this message]
2018-12-22  0:45           ` João Távora
2018-12-22 10:20             ` Alan Mackenzie
2018-12-22 13:47               ` João Távora
2018-12-21 21:50       ` Alan Mackenzie
2018-12-22 16:22         ` Stefan Monnier
2018-12-22 16:34           ` Beatrix Klebe
2018-12-22 17:12             ` Stefan Monnier
2018-12-22 17:34               ` Beatrix Klebe
2018-12-22 21:19                 ` João Távora
2018-12-22 22:15                   ` Alan Mackenzie
2018-12-22 22:55                     ` João Távora
2018-12-23 20:21                       ` Alan Mackenzie
     [not found]                       ` <20181223202143.GA6658@ACM>
2018-12-23 21:38                         ` João Távora
2018-12-23 21:46                           ` Alan Mackenzie
2018-12-28 12:44                           ` Alan Mackenzie
2018-12-23 14:43                     ` Stefan Monnier
2018-12-23 14:48   ` Alan Mackenzie

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20181221201106.GB16032@ACM \
    --to=acm@muc.de \
    --cc=33794@debbugs.gnu.org \
    --cc=bea@klebe.blog \
    --cc=joaotavora@gmail.com \
    --cc=monnier@IRO.UMontreal.CA \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).