From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier 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:32:49 -0400 Message-ID: References: <87ftqms9db.fsf@secretsauce.net> <871s15k7ll.fsf@gmail.com> <20190513195323.GB5525@ACM> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="151623"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Noam Postavsky , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , 35254@debbugs.gnu.org, Dima Kogan To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 14 09:07:45 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 1hQRXM-000dJn-HU for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 May 2019 09:07:44 +0200 Original-Received: from localhost ([127.0.0.1]:40838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQRXL-0000ee-IB for geb-bug-gnu-emacs@m.gmane.org; Tue, 14 May 2019 03:07:43 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQRXE-0000eO-Tp for bug-gnu-emacs@gnu.org; Tue, 14 May 2019 03:07:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQKRK-00029M-Ep for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 19:34:45 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33070) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQKRK-00027O-3U; Mon, 13 May 2019 19:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQKRJ-0004Tq-Na; Mon, 13 May 2019 19:33:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Mon, 13 May 2019 23:33: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.155779037717212 (code B ref 35254); Mon, 13 May 2019 23:33:01 +0000 Original-Received: (at 35254) by debbugs.gnu.org; 13 May 2019 23:32:57 +0000 Original-Received: from localhost ([127.0.0.1]:46614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQKRD-0004TW-Pb for submit@debbugs.gnu.org; Mon, 13 May 2019 19:32:56 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:60820) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQKRB-0004TN-6p for 35254@debbugs.gnu.org; Mon, 13 May 2019 19:32:54 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x4DNWnKg021100; Mon, 13 May 2019 19:32:50 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 3E55566227; Mon, 13 May 2019 19:32:49 -0400 (EDT) In-Reply-To: <20190513195323.GB5525@ACM> (Alan Mackenzie's message of "Mon, 13 May 2019 19:53:23 +0000") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6545=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6545> : inlines <7076> : streams <1821448> : uri <2844179> 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:159253 Archived-At: >> 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). Note that `newline` itself already does some subset of 2 (before running electric-indent's post-self-insert hook). > 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: I haven't followed enough of the discussion to understand why that might cause a bug. > 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 I don't understand why you distinguish electric-indent-inhibit from (memq indent-line-function electric-indent-functions-without-reindent) When I introduced these, electric-indent-functions-without-reindent was only meant to paper over those pre-existing cases that don't set electric-indent-inhibit. So, I'd suggest an even simpler patch which just closes the `unless` earlier. Would that work? Stefan diff --git a/lisp/electric.el b/lisp/electric.el index 07da2f1d9e..beb3348755 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -281,7 +281,7 @@ electric-indent-post-self-insert-function (goto-char before) (condition-case-unless-debug () (indent-according-to-mode) - (error (throw 'indent-error nil))) + (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. @@ -290,7 +290,7 @@ electric-indent-post-self-insert-function ;; to `indent-according-to-mode' but after we may ;; not be (Bug#15767). (when (and (eolp)) - (delete-horizontal-space t)))))) + (delete-horizontal-space t))))) (unless (and electric-indent-inhibit (not at-newline)) (condition-case-unless-debug ()