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 21:50:42 +0000 Message-ID: <20181221215042.GC16032@ACM> References: <20181221134829.29135.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1545429368 12078 195.159.176.226 (21 Dec 2018 21:56:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Dec 2018 21:56:08 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) Cc: bea@klebe.blog, 33794@debbugs.gnu.org, Stefan Monnier To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 21 22:56:03 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 1gaSm2-0002zQ-Oc for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Dec 2018 22:56:02 +0100 Original-Received: from localhost ([::1]:48034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaSo9-0006Ft-7T for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Dec 2018 16:58:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaSo3-0006E7-28 for bug-gnu-emacs@gnu.org; Fri, 21 Dec 2018 16:58:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gaSo1-0002La-Qj for bug-gnu-emacs@gnu.org; Fri, 21 Dec 2018 16:58:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54611) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gaSny-0002IQ-6P; Fri, 21 Dec 2018 16:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gaSnx-0001VF-VK; Fri, 21 Dec 2018 16:58: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 21:58:01 +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.15454294435728 (code B ref 33794); Fri, 21 Dec 2018 21:58:01 +0000 Original-Received: (at 33794) by debbugs.gnu.org; 21 Dec 2018 21:57:23 +0000 Original-Received: from localhost ([127.0.0.1]:58869 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gaSnL-0001UK-7h for submit@debbugs.gnu.org; Fri, 21 Dec 2018 16:57:23 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:53943 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1gaSnI-0001UB-Od for 33794@debbugs.gnu.org; Fri, 21 Dec 2018 16:57:21 -0500 Original-Received: (qmail 44342 invoked by uid 3782); 21 Dec 2018 21:57:19 -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 22:57:17 +0100 Original-Received: (qmail 19158 invoked by uid 1000); 21 Dec 2018 21:50:42 -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:153702 Archived-At: 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 wrote: > > Hello, Beatrix. > > In article 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).