Bug 433455 - Unable to save trailing spaces
Summary: Unable to save trailing spaces
Status: RESOLVED NOT A BUG
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: 20.12.2
Platform: Slackware Linux
: NOR grave
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
: 418338 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-02-22 23:22 UTC by Dmitri Koulikoff
Modified: 2022-01-08 18:41 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
inteded was this (2.77 MB, image/jpeg)
2021-05-29 18:12 UTC, Dmitri Koulikoff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitri Koulikoff 2021-02-22 23:22:31 UTC
SUMMARY

It is the standard that trailing spaces in code should be removed. .
For that there is the setting "Remove trailing spaces: on modified lines". 
But sometimes it is required to keep the spaces at the end of a line.
In kde4 if you leave the cursor after the trailing spaces and save the file they are being kept. But in kde5 it is broken. And this is very annoying. The only way left is to change the setting, save the file, and then change the setting back. So the old behaviour must be restored.


STEPS TO REPRODUCE
1. Open Configure -> File opening & savig -> General
2. Change Remove trailing spaces: to "on modified lines" and save
3. Create a new line with some text and trailing spaces
4. Create the second line with some text and trailing spaces
5. Leave the cursor at the end of the second line
4. Save the text

OBSERVED RESULT

The trailing spaces on the both lines are removed 

EXPECTED RESULT

The trailing spaces on the fist line should be removed while on the second line the spaces to the left of the cursor must be kept. 

SOFTWARE/OS VERSIONS
Operating System: Slackware 14.5
KDE Plasma Version: 5.21.0
KDE Frameworks Version: 5.79.0
Qt Version: 5.15.2
Kernel Version: 5.10.17
OS Type: 64-bit
Graphics Platform: X11
Processors: 12 × Intel® Core™ i7-9750H CPU @ 2.60GHz
Memory: 31.1 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 630
Kate Version 20.12.2

ADDITIONAL INFORMATION
Probably it is worth to add an new option: "on modified lines except to the left of the cursor'
Comment 1 Kåre Särs 2021-02-23 07:34:44 UTC
Thanks for the report,

Your described behavior was seen to not be very intuitive. Why would you have to remember NOT to have your cursor on an indented empty line when you save? All other (edited) lines with trailing spaces have the trailing spaces removed...

If you want to "restore" spaces at the end of a line you edited by mistake,
I could imagine a solution to have a separate save command that does not clear the trailing spaces... Interested to provide a patch/pullrequest?
Comment 2 Dmitri Koulikoff 2021-02-23 08:29:40 UTC
Probably, this behaviour is intuitive, but it is how it works for decades. And for me it is very annoying to restore the spaces on the current line if I decide to save the code in the middle of the work.
To to make this behaviour to be more obvious I've suggested the explicit option.
Unfortunately, I have no time even to look at the code, not mentioning the patching. Sorry.
You can just use the old code for that that should be in the repo.
Comment 3 Dominik Haumann 2021-02-23 21:16:33 UTC
We got bug reports about trailing spaces being left in the document, although remove trailing spaces was active. It's not an option to go back to the old version.

If at all, it would be feasible to have an additional checkbox [ ] Keep spaces of left of the cursor position.

In any case, you're the first one who officially complains here after several years of this behavior. I don't see any immediate action item for now.
Comment 4 Dmitri Koulikoff 2021-02-23 21:28:10 UTC
Because I have started with kde5 only couple of months ago. Now I understand, why Patrick J. Volkerding did not include kde5 in Slackware-current so long. It is too raw. I have problems with many thins in kde5 that in kde4 work perfectly.
I am software developer and now I have to spend extra time adding vanishing spaces back or use extra typing to prevent it.
Comment 5 Dmitri Koulikoff 2021-02-23 21:40:01 UTC
I hope it will not take long to add the fourth option [ ] Keep spaces to left of the cursor position.
;-)
Comment 6 Bug Janitor Service 2021-03-03 15:38:44 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/112
Comment 7 Jan Paul Batrina 2021-03-09 20:44:32 UTC
Git commit 21c0431b7a04dceb4a7591b324e801a2f3aa6f95 by Jan Paul Batrina.
Committed on 09/03/2021 at 04:08.
Pushed by cullmann into branch 'master'.

Add option to keep spaces to the left of cursor when saving
GUI:

M  +5    -0    src/dialogs/opensaveconfigwidget.ui
M  +24   -5    src/document/katedocument.cpp
M  +6    -5    src/utils/kateconfig.h

https://invent.kde.org/frameworks/ktexteditor/commit/21c0431b7a04dceb4a7591b324e801a2f3aa6f95
Comment 8 Dmitri Koulikoff 2021-03-09 21:39:59 UTC
Thanks, only one question:

Is it exactly as removeMode = 1 with the exception of the current line?
Comment 9 Jan Paul Batrina 2021-04-15 08:00:33 UTC
*** Bug 418338 has been marked as a duplicate of this bug. ***
Comment 10 Jan Paul Batrina 2021-04-15 08:04:55 UTC
(In reply to Dmitri Koulikoff from comment #8)
> Thanks, only one question:
> 
> Is it exactly as removeMode = 1 with the exception of the current line?

The implemented behavior is exactly removeMode = 2 (remove all trailing lines in document) except spaces left of current cursor
Comment 11 Dmitri Koulikoff 2021-04-15 10:11:52 UTC
(In reply to Jan Paul Batrina from comment #10)
> (In reply to Dmitri Koulikoff from comment #8)
> > Thanks, only one question:
> > 
> > Is it exactly as removeMode = 1 with the exception of the current line?
> 
> The implemented behavior is exactly removeMode = 2 (remove all trailing
> lines in document) except spaces left of current cursor

It is important to keep all the trailing spaces on non-modified lines. Will removeMode = 2 keep them?
Comment 12 Jan Paul Batrina 2021-04-15 10:58:25 UTC
(In reply to Dmitri Koulikoff from comment #11)
> It is important to keep all the trailing spaces on non-modified lines. Will
> removeMode = 2 keep them?

No, removeMode = 2 removes all of the trailing space in the whole document regardless if the line is modified or not. When I find the time, I'll try to implement the "Keep spaces to left of cursor" a separate option so that the behavior can be more flexible (e.g. removeMode = 1 + keep trailing spaces to left of cursor would be possible), no promises though ;=)
Comment 13 Dmitri Koulikoff 2021-04-15 12:12:52 UTC
> No, removeMode = 2 removes all of the trailing space in the whole document
> regardless if the line is modified or not. 

  Then this option is useless as the purpose of it is to leave trailing spaces in document when needed. 
  You leave the cursor on the line, that need to have trailing spaces, and save the document. And if you need a second place with the trailing spaces, the first place must be untouched.
Comment 14 Christoph Cullmann 2021-05-24 15:44:00 UTC
I am sorry, but I don't see that we want to support this.

I actually would then even say we should remove that other extra option again.

On the other side this is now even already documented and I don't want to waste the time of our documentation writers/translators with this.

@dhaumann, @batrina, what do you think?
Comment 15 Dmitri Koulikoff 2021-05-24 16:38:33 UTC
(In reply to Christoph Cullmann from comment #14)
> I am sorry, but I don't see that we want to support this.
> 
> I actually would then even say we should remove that other extra option
> again.
> 
> On the other side this is now even already documented and I don't want to
> waste the time of our documentation writers/translators with this.
> 
> @dhaumann, @batrina, what do you think?

this is the functionality that worked in kde4, why should it be broken in kde5?
Comment 16 Christoph Cullmann 2021-05-24 18:00:38 UTC
(In reply to Dmitri Koulikoff from comment #15)
> (In reply to Christoph Cullmann from comment #14)
> > I am sorry, but I don't see that we want to support this.
> > 
> > I actually would then even say we should remove that other extra option
> > again.
> > 
> > On the other side this is now even already documented and I don't want to
> > waste the time of our documentation writers/translators with this.
> > 
> > @dhaumann, @batrina, what do you think?
> 
> this is the functionality that worked in kde4, why should it be broken in
> kde5?

In your opinion this is broken, but for others the new behaviors we support are an improvement.
This was intentionally changed.

As said, I don't want to support the variant you propose.
And I would rather remove the one we added again.

Therefore I close this bug.
KTextEditor behaves as intended.

If this is not the behavior you want, I am sorry.
No solution can fit all needs, but we can't add all features that are requested.
(and likely not interesting for a majority of the users, given this is the first wish in that way since >> 5 years of KDE Frameworks 5 existence)
Comment 17 Christoph Cullmann 2021-05-24 18:08:22 UTC
Git commit d0de9d9088b271bd239c52b5973c492e41194854 by Christoph Cullmann.
Committed on 24/05/2021 at 18:07.
Pushed by cullmann into branch 'master'.

Revert "Add option to keep spaces to the left of cursor when saving"

This reverts commit 21c0431b7a04dceb4a7591b324e801a2f3aa6f95.

remove the new option, the original reporter of this bug
isn't happy with it

M  +0    -5    src/dialogs/opensaveconfigwidget.ui
M  +5    -24   src/document/katedocument.cpp
M  +5    -6    src/utils/kateconfig.h

https://invent.kde.org/frameworks/ktexteditor/commit/d0de9d9088b271bd239c52b5973c492e41194854
Comment 18 veggero 2021-05-27 20:09:55 UTC
Hi
I humbly ask for the option to be added back. I understand that the behaviour of the bug reporter was not good; still, I ask you to consider that this could be an actually useful feature. My use case is: I'm writing code, I press enter to write a new line, I save the file just for sure and I have to re-indent.
The option was absolutely perfect for me and I really appreciate it.
I won't make a lot of rumor around this because I understand how you feel, and if you decide to not reintroduce the option it's fine, but I'd still like to say that I really liked it and was very sad to see it gone.
Niccolò
Comment 19 Dmitri Koulikoff 2021-05-29 18:05:25 UTC
(In reply to veggero from comment #18)
> Hi
> I humbly ask for the option to be added back. I understand that the
> behaviour of the bug reporter was not good; still, I ask you to consider
> that this could be an actually useful feature. My use case is: I'm writing
> code, I press enter to write a new line, I save the file just for sure and I
> have to re-indent.
> The option was absolutely perfect for me and I really appreciate it.
> I won't make a lot of rumor around this because I understand how you feel,
> and if you decide to not reintroduce the option it's fine, but I'd still
> like to say that I really liked it and was very sad to see it gone.
> Niccolò


Exactly, veggero, exactly the same problem with me. And I am sure for many others developers.
Comment 20 Dmitri Koulikoff 2021-05-29 18:12:49 UTC
Created attachment 138866 [details]
inteded was this
Comment 21 Christoph Cullmann 2021-05-29 18:16:17 UTC
(In reply to Dmitri Koulikoff from comment #19)
> (In reply to veggero from comment #18)
> > Hi
> > I humbly ask for the option to be added back. I understand that the
> > behaviour of the bug reporter was not good; still, I ask you to consider
> > that this could be an actually useful feature. My use case is: I'm writing
> > code, I press enter to write a new line, I save the file just for sure and I
> > have to re-indent.
> > The option was absolutely perfect for me and I really appreciate it.
> > I won't make a lot of rumor around this because I understand how you feel,
> > and if you decide to not reintroduce the option it's fine, but I'd still
> > like to say that I really liked it and was very sad to see it gone.
> > Niccolò
> 
> 
> Exactly, veggero, exactly the same problem with me. And I am sure for many
> others developers.

Perhaps I misunderstand this now: veggero wants the now reverted stuff back, or not?
Comment 22 Dmitri Koulikoff 2021-05-29 18:18:03 UTC
> KTextEditor behaves as intended.

  No, you are wrong. Intended was as I have shown. 

  I use Kate more than 20 years. (who uses longer, please, raise your hand)
And the only thing I'm asking for is to keep the original behaviour. It was very clever designed and worked well for the decades.
Comment 23 Dmitri Koulikoff 2021-05-29 18:19:49 UTC
> Perhaps I misunderstand this now: veggero wants the now reverted stuff back,
> or not?

yes, me too.
Comment 24 Christoph Cullmann 2021-05-29 18:21:06 UTC
(In reply to Dmitri Koulikoff from comment #23)
> > Perhaps I misunderstand this now: veggero wants the now reverted stuff back,
> > or not?
> 
> yes, me too.

You are aware, that the stuff I reverted you called useless a bit below here?

I am speaking about

Git commit d0de9d9088b271bd239c52b5973c492e41194854 by Christoph Cullmann.
Committed on 24/05/2021 at 18:07.
Pushed by cullmann into branch 'master'.

Revert "Add option to keep spaces to the left of cursor when saving"

This reverts commit 21c0431b7a04dceb4a7591b324e801a2f3aa6f95.

remove the new option, the original reporter of this bug
isn't happy with it

M  +0    -5    src/dialogs/opensaveconfigwidget.ui
M  +5    -24   src/document/katedocument.cpp
M  +5    -6    src/utils/kateconfig.h

https://invent.kde.org/frameworks/ktexteditor/commit/d0de9d9088b271bd239c52b5973c492e41194854

Perhaps we just don't talk about the same stuff ;=)
Comment 25 veggero 2021-05-29 19:10:30 UTC
> Perhaps I misunderstand this now: veggero wants the now reverted stuff back, or not?

Yes, I'd like the original fix to be re-introduced; the one that Dmitri called useless (it's not!)
Comment 26 Waqar Ahmed 2021-05-29 19:57:22 UTC
The option "Keep spaces to the left" is just noise and makes zero sense to me. For the case where you want to keep the spaces in an indentation this is a bad solution because if you accidentally had your cursor on 3rd column, you will have one trailing space in front of the cursor. This just results in weird behavior and possibly more bug reports asking for specialization of this behavior. 

One can think about not removing spaces from the *current* line **if** it is empty. However, I think our current way is fine and consistent with 99% of the rest of the world of editors.
Comment 27 Dmitri Koulikoff 2021-05-29 20:18:07 UTC
Yes, there is a misunderstanding. Of course, the spaces under the cursor must be preserved.

I meant something others. 

I need the option: Remove the trailing spaces: on modified lines not to remove the spaces under the cursor. 

Exactly as it was working before.
Comment 28 Dmitri Koulikoff 2021-05-29 20:21:05 UTC
Best if "keep the spaces under cursor" is a check-box.
Comment 29 Dmitri Koulikoff 2021-05-29 20:22:14 UTC
Or it can be the default behaviour as earlier without a special setting.
Comment 30 Kåre Särs 2021-05-29 20:44:50 UTC
What is the use-case for not removing trailing spaces on one line where you happen to have your cursor?

I can imagine a situation where you have random trailing spaces in a document and you do not want to destroy git history or if you want to edit a markdown file, that might need two empty spaces at the end of a line...

My experience of these situations is that you almost always have multiple lines that should not be stripped.


Wouldn't it be a better solution to have a separate save action that never strips trailing spaces? This could be used in the rare situations where you actually want trailing spaces.


If it is only about saving the document often and not wanting to loose the indentation, I do not really see the point... You should not have to save that often and why would you save something that is half done? Re-indenting is just a mater of executing the align action.

Why add an option-workaround for "bad habits" ;)

The previous behavior was a mistake that was introduced during a time when KDevelop crashed a bit too often and saving often in KDevelop was common...
Comment 31 Christoph Cullmann 2021-05-29 21:00:46 UTC
I am actually with Kåre here.

Ever since Kate got vi-like swap files to recover data, I had close to zero data loss in Kate in the last x years and stopped to save each second.
Comment 32 Dmitri Koulikoff 2021-05-30 06:30:18 UTC
(In reply to Kåre Särs from comment #30)
> What is the use-case for not removing trailing spaces on one line where you
> happen to have your cursor?

  veggero had explainded. For me the every-day's use-case is the following. I write the specs, and after one or more specs is written I have a new line with the only spaces to start a new spec with the required indent. Then I save the file in order to run the spec suit to check that the previous code is written correct. And at this time all spaces disappear and the cursor moves left to the start of the line. To continue I have to type the missing spaces again. This is really very annoying. Believe me.

> I can imagine a situation where you have random trailing spaces in a
> document and you do not want to destroy git history or if you want to edit a
> markdown file, that might need two empty spaces at the end of a line...

  Yes, and this is the second case not so often happened but also a typical, I have an old file from a git repo and need to add several lines and be sure I have not left any trailing spaces after adding a hundred of lines except the one. If the trailing spaces under cursor are preserved I can do that easy without checking every previously entered line.

> Wouldn't it be a better solution to have a separate save action that never
> strips trailing spaces?

  Yes this option is present. But I never used it as always, if I need to keep the trailing spaces, it is related only to the few lines.

> The previous behavior was a mistake that was introduced during a time when
> KDevelop crashed a bit too often and saving often in KDevelop was common...

  The previous behaviour was not a mistake. It was very clever done.

  To summarise, I suggest to leave the 3 select options in "Remove trailing spaces" item:
- never
- always
- only on modified lines

  AND for the latter option the spaces to the left of the cursor must be preserved. It is quite safe as when one saves the file again later with the cursor placed somewhere else, the previously kept spaces will be removed. But if I need them to be kept I will just reload the file after the save and these spaces will survive the next saves.

  As the alternative to the above you can add a checkbox with "keep the trailing lines to the left of the cursor" to make the behaviour to be more declared. And then it should affect the option "always".

  And the last solution to have 4 options with
- only on modified lines
- only on modified lines keeping them to the left of cursor

  I hope I was clear enough explaining why the preservation of the training spaces to the left of the cursor is urgent required and how to make it work correctly.
Comment 33 Alberto Salvia Novella 2021-06-18 15:16:23 UTC
Related: End line to have a predictable behavior:
https://bugs.kde.org/show_bug.cgi?id=438872
Comment 34 Christoph Cullmann 2022-01-08 16:30:06 UTC
As said, there is no consensus to add yet-another-variant again.
I will close this, please refrain from re-open it.
The last 6 months no Kate developer did want to work on this and this won't change.
Comment 35 Dmitri Koulikoff 2022-01-08 17:39:21 UTC
(In reply to Christoph Cullmann from comment #34)
> As said, there is no consensus to add yet-another-variant again.
> I will close this, please refrain from re-open it.
> The last 6 months no Kate developer did want to work on this and this won't
> change.

I am working with Kate for the decades. And it has the advantage for the other text editor that I can always keep the training spaces to the left of the cursor. Why did you break this behaviour making the product worse?
Comment 36 Waqar Ahmed 2022-01-08 18:41:05 UTC
> Why did you break this behaviour making the product worse?

This has been explained above, perhaps you can reread the thread.

Also, saying that you use it for decades and who uses longer as if you somehow own Kate or the developers owe you something is not good, and is definitely not the case. And you certainly haven't been using Kate for longer than at least 2 people in this thread, one of whom is the person who created Kate and has been maintaining it ever since. Moreover ordering around makes people turn against you. This is free software, we made it in our free time, you didn't hire us to make it for you or fix bugs for you.

However, if you really want to fix this for yourself here's what you can do to possibly get the behavior you want.
- Open Kate documentation and read about Kate scripting
- turn off strip trailing spaces in options
- write a script that strip spaces as you see fit.

Alternatively you can write a plugin too or define an "external tool" that will strip spaces from your document however you like.