Subject: Re: bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode

From: Alan Mackenzie <[email-masked]>
Date: 21 Dec 2018 13:48:29 -0000

Hello, Beatrix.

In article <[email-masked]> 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.

> In GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS
> appkit-1348.17 Version 10.10.5 (Build 14F2511))
>  of 2018-05-30 built on builder10-10.porkrind.org
> Windowing system distributor 'Apple', version 10.3.1671
> Recent messages:
> Saving file /Users/bea/.emacs.d/lisp/dotnet.el...
> Wrote /Users/bea/.emacs.d/lisp/dotnet.el
> ; expected
> Undo!
> ; expected
> Undo! [2 times]
> ; expected
> Auto-saving...
> ; expected [2 times]
> Making completion list...

-- 
Alan Mackenzie (Nuremberg, Germany).