GNU bug report logs - #33794
26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode

Previous Next

Packages: emacs, cc-mode;

Reported by: bea <at> klebe.blog

Date: Tue, 18 Dec 2018 17:48:02 UTC

Severity: normal

Found in version 26.1

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Alan Mackenzie <acm <at> muc.de>
To: João Távora <joaotavora <at> gmail.com>
Cc: bea <at> klebe.blog, 33794 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode
Date: Fri, 21 Dec 2018 21:50:42 +0000
Hello, João.

On Fri, Dec 21, 2018 at 13:57:21 +0000, João Távora wrote:
> On Fri, Dec 21, 2018 at 1:48 PM Alan Mackenzie <acm <at> muc.de> wrote:

> > Hello, Beatrix.

> > In article <mailman.5894.1545155289.1284.bug-gnu-emacs <at> gnu.org> you wrote:
> > > When using cc-mode, turning on electric-pair-mode causes the
> > > auto-newline minor mode to stop inserting newlines where expected. This
> > > is relevant to the formatting of C# code with the Allman/BSD brace style
> > > in particular, though it would be nice if these modes specifically did
> > > work together.

> > 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.  Also, due to the way } gets
> > inserted, the CC Mode processing for the } isn't done at all.

> > @João: I think electric pair mode is intended to simulate the manual
> > insertion of a matching paren, etc., when a paren, etc., is typed.

> > 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?  This should allow CC Mode's
> > auto-newline facility to work, and also more closely simulate the manual
> > insertion of the closing delimiter.


> I don't know.  We better ask Stefan (CC'ed) who I believe designed the
> original strategy of inserting closing delimiters in the previous
> electric-pair-mode. That didn't change in my redesign.

> FWIW, I think cc-mode should rather use post-self-insert-hook instead
> of redefining commands for keys whose expected behaviour is
> (with minor variations presumably covered by abundant hookage)
> self-insertion.  If you place your specific cc-mode processing late
> enough in the hook then its insertion will be "complete" for all
> practical purposes.

I think I've worked out what I don't like about such (ab)use of
post-self-insert-hook.  There are 113 uses of self-insert-command in our
sources, and it seems most of them expect self-insert-command to do just
that, with possible things like refilling.  If one makes additional
buffer changes, one will foul up many of these 113 uses of s-i-c.

It is a bit like before/after-change-functions.  Although it is not
written in tablets of stone anywhere (as fas as I'm aware), there's an
understanding that you don't make buffer changes inside b/a-c-f.  The
same should apply to post-self-insert-hook, which is a sort of change
hook, for the same reasons.

> João

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 6 years and 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.