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

Previous Next

Packages: cc-mode, emacs;

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: Beatrix Klebe <beeuhtricks <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Alan Mackenzie <acm <at> muc.de>, "Mx. Beatrix Klebe" <bea <at> klebe.blog>, João Távora <joaotavora <at> gmail.com>, 33794 <at> debbugs.gnu.org
Subject: bug#33794: 26.1; electric-pair-mode breaks auto-newline minor mode of cc-mode
Date: Fri, 21 Dec 2018 11:00:10 -0500
I believe I saw your Stack Overflow answer about this while searching
for the solution. electric-layout-mode works with some quirks, such as
that if you put a space after parens in a function definition, the
space gets carried on to the newline with that method, which is a bit
annoying. What would be ideal, and what I'm looking for, is to get
auto-pairing of brackets with braces being placed where they should be
automatically and the insertion point getting put in between them at
the correct indent level, such as what happens with Visual Studio, or
Visual Studio Code, or several other editors with this functionality.
Perhaps it is not emacslike to have such behavior be totally
automated, but I am used to it and finds it decreases my ordinary
levels of frustration when working with verbose and imperative
languages. I am currently trying to write some insert specifiers for
smartparens to do this, but it is proving more difficult to find an
elegant solution than I had expected.

On Fri, Dec 21, 2018 at 10:54 AM Stefan Monnier
<monnier <at> iro.umontreal.ca> 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".
>
> >> 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, ..." ;-)
>
> >> 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?
>
> > 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.
>
> 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).
>
> For things like electric-pair, electric-indent, and electric-layout to
> work correctly together, they need to agree on some convention.
>
> Note that CC-mode can also side-step that convention and use `insert`
> instead of self-insert-command.
>
>
>         Stefan




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.