From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs 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 Message-ID: <20181221201106.GB16032@ACM> References: <20181221134829.29135.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1545423369 31645 195.159.176.226 (21 Dec 2018 20:16:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Dec 2018 20:16:09 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) Cc: bea@klebe.blog, =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , 33794@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 21 21:16:05 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gaRDH-00088P-Ni for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Dec 2018 21:16:03 +0100 Original-Received: from localhost ([::1]:47700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaRFO-00019O-CN for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Dec 2018 15:18:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaRFG-000196-LL for bug-gnu-emacs@gnu.org; Fri, 21 Dec 2018 15:18:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gaRFF-00052N-QA for bug-gnu-emacs@gnu.org; Fri, 21 Dec 2018 15:18:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gaRFC-00051J-DV; Fri, 21 Dec 2018 15:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gaRFC-0007bW-5W; Fri, 21 Dec 2018 15:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 21 Dec 2018 20:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33794 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 33794-submit@debbugs.gnu.org id=B33794.154542346629207 (code B ref 33794); Fri, 21 Dec 2018 20:18:02 +0000 Original-Received: (at 33794) by debbugs.gnu.org; 21 Dec 2018 20:17:46 +0000 Original-Received: from localhost ([127.0.0.1]:58830 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gaREv-0007b1-Td for submit@debbugs.gnu.org; Fri, 21 Dec 2018 15:17:46 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:48148 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1gaREt-0007as-9A for 33794@debbugs.gnu.org; Fri, 21 Dec 2018 15:17:44 -0500 Original-Received: (qmail 7514 invoked by uid 3782); 21 Dec 2018 20:17:41 -0000 Original-Received: from acm.muc.de (p2E5D5AAE.dip0.t-ipconnect.de [46.93.90.174]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 21 Dec 2018 21:17:40 +0100 Original-Received: (qmail 18666 invoked by uid 1000); 21 Dec 2018 20:11:06 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:153698 Archived-At: 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).