[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad
From: |
Noam Postavsky |
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:38:48 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) |
João Távora <joaotavora@gmail.com> writes:
>> > 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 <CR> 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?
> 1. Does it fix the reported problem (assuming it is a problem, and not
> an otherwise potentially desirable change in behaviour)?
It does fix the problem.
> 2. Do any of you have suspicions that it might introduce problems
> elsewhere?
I'm unsure. It seems to be undoing a small part of [fd94312443]
2019-01-22 "electric-layout-mode kicks in before electric-pair-mode", so
I guess it might rebreak whatever that commit is fixing. But I don't
quite understand what that commit is fixing (in particular, where the
commit message says "which can be a problem in some modes", which modes
are those? What is "a problem"?).
> 3. Does it pass the automated test suite?
No, it breaks 3 tests in tests/lisp/electric.el:
3 unexpected results:
FAILED electric-layout-int-main-kernel-style
FAILED electric-layout-plainer-c-mode-use-c-style
FAILED electric-modes-int-main-allman-style
In each case, the reason for failure is that the expected result has
trailing whitespace that the actual result misses. I guess
electric-layout does want to put trailing whitespace in certain cases?
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, (continued)
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/11
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Basil L. Contovounesios, 2019/05/11
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/12
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Basil L. Contovounesios, 2019/05/12
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/13
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Basil L. Contovounesios, 2019/05/13
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/12
- bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Noam Postavsky, 2019/05/12
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/13
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Stefan Monnier, 2019/05/14
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/14
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, João Távora, 2019/05/14
bug#35254: 27.0.50; cc-mode/electric-pair-mode/electric-layout-mode: bad trailing whitespace behavior in cc-mode, Alan Mackenzie, 2019/05/15