From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode Date: Mon, 13 May 2019 19:53:23 +0000 Message-ID: <20190513195323.GB5525__8644.51904069341$1557777383$gmane$org@ACM> References: <87ftqms9db.fsf@secretsauce.net> <871s15k7ll.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="129101"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Dima Kogan , 35254@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 13 21:56:17 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQH3Y-000XR5-G4 for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 May 2019 21:56:16 +0200 Original-Received: from localhost ([127.0.0.1]:34231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQH3U-0002z0-Fz for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 May 2019 15:56:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQH3G-0002pf-MX for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:56:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQH1O-0001V0-13 for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:54:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32799) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQH1N-0001Uu-Tt; Mon, 13 May 2019 15:54:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQH1N-0007il-Ll; Mon, 13 May 2019 15:54:01 -0400 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: Mon, 13 May 2019 19:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35254 X-GNU-PR-Package: emacs,cc-mode Original-Received: via spool by 35254-submit@debbugs.gnu.org id=B35254.155777720929634 (code B ref 35254); Mon, 13 May 2019 19:54:01 +0000 Original-Received: (at 35254) by debbugs.gnu.org; 13 May 2019 19:53:29 +0000 Original-Received: from localhost ([127.0.0.1]:46343 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQH0q-0007ht-VA for submit@debbugs.gnu.org; Mon, 13 May 2019 15:53:29 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:36012 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1hQH0o-0007hk-FY for 35254@debbugs.gnu.org; Mon, 13 May 2019 15:53:27 -0400 Original-Received: (qmail 3160 invoked by uid 3782); 13 May 2019 19:53:24 -0000 Original-Received: from acm.muc.de (p4FE15EDF.dip0.t-ipconnect.de [79.225.94.223]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 13 May 2019 21:53:22 +0200 Original-Received: (qmail 7529 invoked by uid 1000); 13 May 2019 19:53:23 -0000 Content-Disposition: inline In-Reply-To: <871s15k7ll.fsf@gmail.com> 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: 209.51.188.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:159203 Archived-At: Hello, Joćo and Noam. On Fri, May 10, 2019 at 23:12:06 -0400, Noam Postavsky wrote: > Dima Kogan writes: > > Hi. > > I'm seeing a regression introduced in 2019/01 by an update meant to make > > electric-pair-mode and electric-layout-mode play nicely: > > http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=fd943124439b7644392919bca8bc2a77e6316d92 > > Recipe: > > 1. 'emacs -Q' with any emacs more recent than that patch > > 2. Open up tst.c that contains this: > > int main(int argc, char* argv[]) > > { > > return 0; > > } > > 3. Move the point to the beginning of the line containing "return 0" > > 4. RET RET RET RET RET > > Now there're a bunch of new lines between the { and the "return 0", as > > expected. But these lines aren't empty: they contain the initial > > indentation whitespace. This whitespace shouldn't be there; and it > > wasn't there prior to this patch. > Right, the problem is that electric-indent-inhibit only partially > disables electric indent, and the commit you reference changes which > parts. The patch below disables it more completely. Note however, that > this makes RET not do any electric indentation at all, just like in the > good old days of Emacs 24.3. Possibly c-mode should rebind RET to a > c-electric-return command or something. > >>From 1103fdfbf2be55d68d44151498c2598fd622ac08 Mon Sep 17 00:00:00 2001 > From: Noam Postavsky > Date: Fri, 10 May 2019 16:40:27 -0400 > Subject: [PATCH] Inhibit electric indent completely in cc mode buffers > (Bug#35254) > Electric indent mode's post-self-insert hook entry has 3 effects: > 1. Indent the previous line. > 2. Remove trailing whitespace from the previous line. > 3. Indent the current line (when at beginning of line). > The change from 2019-01-22 "electric-layout-mode kicks in before > electric-pair-mode", makes 'electric-indent-inhibit' inhibit 1 and 2, > whereas before then it inhibited only 1. While cc mode provides its > own electric commands and therefore sets 'electric-indent-inhibit', it > doesn't implement an electric newline command. So if only one of > effects 2 and 3 from Electric indent mode occur, then hitting RET will > leave trailing whitespace. I interpret the problem a little differently. electric-indent-post-self-insert-function, when electric-indent-inhibit is set, is inhibiting actions which are not really part of electric indentation, in particular action 2 (above). This is the heart of the bug. The following patch fixes the bug. It would need tidying up before being committed: diff --git a/lisp/electric.el b/lisp/electric.el index 07da2f1d9e..15a42930c1 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -282,9 +282,15 @@ electric-indent-post-self-insert-function (condition-case-unless-debug () (indent-according-to-mode) (error (throw 'indent-error nil))) - ;; The goal here will be to remove the trailing - ;; whitespace after reindentation of the previous line - ;; because that may have (re)introduced it. + ) + (unless (memq indent-line-function + electric-indent-functions-without-reindent) + ;; The goal here will be to remove the indentation + ;; whitespace from an otherwise blank line after + ;; typing twice in succession. Also to remove + ;; trailing whitespace after reindentation of the + ;; previous line because that may have + ;; (re)introduced it. (goto-char before) ;; We were at EOL in marker `before' before the call ;; to `indent-according-to-mode' but after we may Joćo and Noam, what're your views on this proposed patch? -- Alan Mackenzie (Nuremberg, Germany).