From: "João Távora" <joaotavora@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: Noam Postavsky <npostavs@gmail.com>,
Dima Kogan <dima@secretsauce.net>,
35254@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode
Date: Wed, 15 May 2019 12:27:52 +0100 [thread overview]
Message-ID: <CALDnm53CG7Nsir__h5nDum12e4PgCt0hcWSJ0ny-SpyhCn3K4w@mail.gmail.com> (raw)
In-Reply-To: <20190515100339.GB15042@ACM>
[-- Attachment #1: Type: text/plain, Size: 5817 bytes --]
Well,
I've just come across the bug myself, and it is indeed annoying.
Can you check if this patch, which seems the simplest, serves
all purposes? It also adds a test to prevent future regressions
Thanks,
João
diff --git a/lisp/electric.el b/lisp/electric.el
index 657913a396..f15a95bf91 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -281,10 +281,13 @@ electric-indent-post-self-insert-function
(goto-char before)
(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.
+ (error (throw 'indent-error nil))))
+ (unless (eq electric-indent-inhibit 'electric-layout-mode)
+ ;; Unless we're operating under
+ ;; `electric-layout-mode' (Bug#35254), the goal here
+ ;; will be to remove the 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
@@ -464,7 +467,7 @@ electric-layout-post-self-insert-function-1
;; really wants to reindent, then
;; `last-command-event' should be in
;; `electric-indent-chars'.
- (let ((electric-indent-inhibit t))
+ (let ((electric-indent-inhibit
'electric-layout-mode))
(funcall nl-after)))))))
(pcase sym
('before (funcall nl-before))
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 4f1e5729be..22b7a18ba5 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -876,6 +876,24 @@ electric-layout-for-c-style-du-jour
(call-interactively (key-binding `[,last-command-event])))
(should (equal (buffer-string) "int main () {\n \n}"))))
+(ert-deftest electric-layout-control-reindentation ()
+ "Same as `e-l-int-main-kernel-style', but checking Bug#35254."
+ (ert-with-test-buffer ()
+ (plainer-c-mode)
+ (electric-layout-local-mode 1)
+ (electric-pair-local-mode 1)
+ (electric-indent-local-mode 1)
+ (setq-local electric-layout-rules
+ '((?\{ . (after))
+ (?\} . (before))))
+ (insert "int main () ")
+ (let ((last-command-event ?\{))
+ (call-interactively (key-binding `[,last-command-event])))
+ (should (equal (buffer-string) "int main () {\n \n}"))
+ ;; insert an additional newline and check indentation
+ (call-interactively 'newline)
+ (should (equal (buffer-string) "int main () {\n\n \n}"))))
+
(define-derived-mode plainer-c-mode c-mode "pC"
"A plainer/saner C-mode with no internal electric machinery."
(c-toggle-electric-state -1)
On Wed, May 15, 2019 at 11:03 AM Alan Mackenzie <acm@muc.de> wrote:
> Hello, João.
>
> On Tue, May 14, 2019 at 11:34:24 +0100, João Távora wrote:
> > On Tue, May 14, 2019 at 10:27 AM Alan Mackenzie <acm@muc.de> wrote:
>
> > > The bug is, type lots of <CR>s in a row; the indentation WS isn't
> > > getting removed from the blank lines. Currently
> electric-indent-inhibit
> > > is inhibiting this removal.
>
>
> > Do you mean the "removal of the WS in the lines preceding the current".
> > In other words, do you mean "removal of the trailing WS that was once
> > proper indentation"?
>
> Yes. To be absolutely clear, supposing we have point at the end of a
> line containing nothing but indentation space (e.g., we've just typed
> <CR>):
>
> <spaces>!
> ^
> point
>
> Type <CR> again. What we are currently seeing is:
>
> <spaces>
> <spaces>!
>
> . What we want to see is
>
> <nothing>
> <spaces>!
>
> .
>
> > Or do you think that the current line, the one where point stands, should
> > not be indented at all in certain electric-* variable combinations and or
> > c-electric-* variable? Which of those combinations?
>
> When electric-indent-inhibit is set, the (electric) indentation of the
> current line should not be done by electric-indent-mode. For the
> moment, in CC Mode it should be done by c-electric-brace, and friends,
> if so configured in CC Mode (the default being enabled).
>
> > > Probably. Maybe João should check this, once he's fully back with us.
>
>
> > I'm afraid I can't put a date on that. There's a bun in the oven...
>
> Well, congratulations! I hope everything goes well.
>
> > An important development towards figuring out this issue is that a
> > significant fraction of us agrees on what the behavior should be
> > in what cases. Then we should code tests that assert that behavior
> > possibly reusing the fixtures in electric-tests.el.
>
> Yes.
>
> > > The same bug occurs in Python Mode.
> > > Succinctly, the bug is that on pressing <CR> lots of times in a row,
> the
> > > indentation WS is being left on the blank lines rather than being
> > > removed.
>
> > I see. That does make sense. But, to be sure, we _dont_ what to
> > remove the indentation WS on the "current" line, right?
>
> Right. Unless, and until, the current line becomes the "previous" line,
> still otherwise being blank.
>
> I think we're agreed on everything. :-)
>
> > João
>
> --
> Alan Mackenzie (Nuremberg, Germany).
>
--
João Távora
[-- Attachment #2: Type: text/html, Size: 7565 bytes --]
next prev parent reply other threads:[~2019-05-15 11:27 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-13 6:32 bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode Dima Kogan
2019-05-11 3:12 ` Noam Postavsky
2019-05-11 12:05 ` Alan Mackenzie
[not found] ` <20190511120524.GA15991@ACM>
2019-05-11 14:06 ` Noam Postavsky
2019-05-11 16:19 ` Alan Mackenzie
2019-05-11 19:34 ` Basil L. Contovounesios
2019-05-12 16:14 ` Alan Mackenzie
2019-05-12 21:45 ` Basil L. Contovounesios
2019-05-13 10:14 ` Alan Mackenzie
[not found] ` <20190513101448.GA5525@ACM>
2019-05-13 12:49 ` Basil L. Contovounesios
2019-05-12 15:12 ` Alan Mackenzie
2019-05-12 18:42 ` Noam Postavsky
2019-05-13 19:53 ` Alan Mackenzie
[not found] ` <20190513195323.GB5525@ACM>
2019-05-13 22:39 ` João Távora
2019-05-13 23:38 ` Noam Postavsky
2019-05-14 1:20 ` João Távora
2019-05-14 1:28 ` Stefan Monnier
2019-05-14 1:56 ` Noam Postavsky
2019-05-14 8:38 ` Alan Mackenzie
2019-05-13 23:32 ` Stefan Monnier
[not found] ` <jwvimue9bzj.fsf-monnier+emacs@gnu.org>
2019-05-13 23:45 ` Noam Postavsky
2019-05-14 1:26 ` Stefan Monnier
2019-05-14 9:27 ` Alan Mackenzie
2019-05-14 9:34 ` Alan Mackenzie
[not found] ` <20190514092735.GB4231@ACM>
2019-05-14 10:34 ` João Távora
2019-05-15 10:03 ` Alan Mackenzie
2019-05-15 11:27 ` João Távora [this message]
2019-05-15 13:19 ` Stefan Monnier
2019-05-15 13:55 ` João Távora
2019-05-15 14:03 ` João Távora
2019-07-01 12:24 ` João Távora
2019-07-01 13:34 ` Alan Mackenzie
[not found] ` <20190701133427.GA23312@ACM>
2019-07-06 16:24 ` Noam Postavsky
2019-07-06 22:24 ` João Távora
2019-07-06 22:50 ` Noam Postavsky
2019-07-06 22:33 ` João Távora
[not found] ` <20190514093415.GC4231@ACM>
2019-05-14 15:38 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALDnm53CG7Nsir__h5nDum12e4PgCt0hcWSJ0ny-SpyhCn3K4w@mail.gmail.com \
--to=joaotavora@gmail.com \
--cc=35254@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=dima@secretsauce.net \
--cc=monnier@iro.umontreal.ca \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).