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: Tue, 14 May 2019 08:38:55 +0000 Message-ID: <20190514083855.GA4231__16798.2748987683$1557823191$gmane$org@ACM> References: <87ftqms9db.fsf@secretsauce.net> <871s15k7ll.fsf@gmail.com> <20190513195323.GB5525@ACM> 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="2712"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Noam Postavsky , Stefan Monnier , 35254@debbugs.gnu.org, Dima Kogan 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 Tue May 14 10:39:47 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 1hQSyP-0000ar-DQ for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 May 2019 10:39:45 +0200 Original-Received: from localhost ([127.0.0.1]:42418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQSyO-00085Z-Cs for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 May 2019 04:39:44 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQSy6-00082f-KR for bug-gnu-emacs@gnu.org; Tue, 14 May 2019 04:39:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQSxy-00007u-Fs for bug-gnu-emacs@gnu.org; Tue, 14 May 2019 04:39:26 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33686) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQSxi-000878-7S; Tue, 14 May 2019 04:39:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQSxi-00031x-2m; Tue, 14 May 2019 04:39:02 -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: Tue, 14 May 2019 08:39: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.155782314111640 (code B ref 35254); Tue, 14 May 2019 08:39:01 +0000 Original-Received: (at 35254) by debbugs.gnu.org; 14 May 2019 08:39:01 +0000 Original-Received: from localhost ([127.0.0.1]:47230 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQSxg-00031g-HD for submit@debbugs.gnu.org; Tue, 14 May 2019 04:39:00 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:38807 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1hQSxe-00031X-La for 35254@debbugs.gnu.org; Tue, 14 May 2019 04:38:59 -0400 Original-Received: (qmail 50284 invoked by uid 3782); 14 May 2019 08:38:56 -0000 Original-Received: from acm.muc.de (p4FE15CA2.dip0.t-ipconnect.de [79.225.92.162]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 14 May 2019 10:38:55 +0200 Original-Received: (qmail 9215 invoked by uid 1000); 14 May 2019 08:38:55 -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: 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:159261 Archived-At: Hello, Joćo. On Mon, May 13, 2019 at 23:39:33 +0100, Joćo Tįvora wrote: > On Mon, May 13, 2019 at 8:53 PM Alan Mackenzie wrote: [ .... ] > > > 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? > > Good night Alan, > Unfortunately, I can't analyse this in depth right now or in the next > few days. As Stefan(?) said, there's no particular hurry (on a scale of days) to fix this. > I can only ask succintly: > 1. Does it fix the reported problem (assuming it is a problem, and not an > otherwise potentially desirable change in behaviour)? It does fix it, yes. It was a bug. > 2. Do any of you have suspicions that it might introduce problems > elsewhere? I don't, as such, but I haven't dug around the code looking for potential problems. That was the main reason I was asking you, as maintainer of the electric stuff. > 3. Does it pass the automated test suite? Noam has already tried this and said it fails on three tests. > I am only a bit wary of it because, without having understood the > problem in depth, it seems again caused by a c-electric quirk. The same bug occurs in Python Mode. Succinctly, the bug is that on pressing lots of times in a row, the indentation WS is being left on the blank lines rather than being removed. > My views on this are known: I always prefer that c-mode would, if > slowly, move in the direction of accepting electric.el abstractions as > closely as possible. I think we've already agreed that CC Mode should, in the long term, change to using the electric-* facilities, assuming no loss in functionality. :-) > Than said, the patch looks very simple, which is always good, and has > comments explaining what's going on. So I'll let Noam (and Stefan?) decide. > Joćo -- Alan Mackenzie (Nuremberg, Germany).