Bug 397956 - Kate unconditionally removes trailing spaces if .kateconfig file doesn't exist
Summary: Kate unconditionally removes trailing spaces if .kateconfig file doesn't exist
Status: RESOLVED NOT A BUG
Alias: None
Product: kate
Classification: Applications
Component: application (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-27 22:23 UTC by Ardith Metz
Modified: 2019-01-05 16:20 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ardith Metz 2018-08-27 22:23:35 UTC
I've found that if .kateconfig file doesn't exist in user $HOME, Kate always removes trailing whitespaces on document saving.

[Document]
...
Keep Extra Spaces=true
Remove Spaces=0
...

In "Open/Save" -> "Remove trailing spaces" is set to "never"

Clicking on "Save" in Kate toolbar clear all trailing spaces in document making it irreversibly damaged as there is no chance to undo changes without saving document.

After merely touching an empty ".kateconfig" file in top $HOME dir or the dir where files are edited, everything is working normal, i.e. Kate keeps whitespaces if config is set to "never" and clears them if config is set to "In entire Document". I tested this with fresh kate config.

Steps to reproduce:

1. touch abc
2. echo " " >abc
3. kate abc
4. Chose "Open/Save" -> "Remove trailing spaces" -> "never" -> "Apply" -> "Ok"
5. Click "Save" button (notice "Undo button is activated which means changes are done in document)
6. Exit kate
7. touch .kateconfig
8. rm abc && touch abc && echo " " >abc
9. Click "Save" button (notice "Undo button isn't activated which means there aren't changes done in document)

Kde plasma:5.13
Kde frameworks: 5.49
Qt: 5.11.1
Distro: Archlinux
Comment 1 Lothar 2018-12-31 14:04:35 UTC
I guess ~/.config/katerc is responsible how to act in case of a not existing .kateconfig
Comment 2 Ardith Metz 2019-01-01 12:34:18 UTC
@Lothar

did you read my description above? I tested this with "Remove Spaces=0" in ~/.config/katerc . Also with fresh config.
Comment 3 Lothar 2019-01-01 14:29:13 UTC
I have, and spent a couple of time to investigate that, but can't reproduce it. 
Your explanations are not clear enough for me, sorry.
Happy New Year!
Comment 4 Ardith Metz 2019-01-02 12:48:29 UTC
Which part isn't clear?
Comment 5 Lothar 2019-01-02 14:26:18 UTC
In you initial post...
https://bugs.kde.org/show_bug.cgi?id=397956#c0
...did you not explicit mention ~/.config/katerc but often .kateconfig.

- Step 1. looks to me obsolete
- In 7. you create an empty file but you did not note before to ensure that 
  there is no such file
- Between 8. + 9. seems to be missed to start Kate again

Lastly I have only played around with my "Remove trailing spaces" setting, with 
and without to start Kate again, but couldn't observe the described damage.
Have also set "Keep extra spaces" from indention page as shown in your post.
Comment 6 Ardith Metz 2019-01-02 21:11:18 UTC
I showed excerpt from ~/.config/katerc (without saying that it's from ~/.config/katerc because I assumed it's obvious at least for kate developers).

I also pointed to relevant gui option which will modify ~/.config/katerc.

If you want me to go for full nit, then here I am:

1. rm ~/.kateconfig
2. rm ~/.config/katerc
3. rm ~/kate_test
4. echo " " >kate_test
5. kate kate_test
6. Chose from toolbar: "Settings" -> "Open/Save" -> "General" -> "Remove trailing spaces" -> "Never" -> "Apply" -> "Ok"
7. Click "Save" button (notice "Undo button is activated which means changes are done in document)
8. Close kate
9. touch .kateconfig
10. rm ~/.config/katerc
11. rm kate_test
12. echo " " >kate_test
13. kate kate_test
14. Chose from toolbar: "Settings" -> "Open/Save" -> "General" -> "Remove trailing spaces" -> "Never" -> "Apply" -> "Ok"
15. Click "Save" button from toolbar (notice "Undo button isn't activated which means there aren't changes done in document)

I hope everything is clear now. Tested on:

Kde plasma:5.14.4
Kde frameworks: 5.53.0
Qt: 5.12.0
Kate: 18.12.0
Distro: Arch Linux
Comment 7 Lothar 2019-01-03 13:45:14 UTC
> I assumed it's obvious at least for kate developers

Well, I have submitted some patches in the recent past but to call me as such,
would be a little presumptuous. Besides I'm as while a little "slow", but I'm
here. The smart guys are usually busy.

That's much better but I still can't reproduce it. At 6./14. did you change it
to "Never" or is it also before on "Never"? Without any config file around it
should be on "Never".

I notice there is also a ~/.config/katepartrc as fall back and Kate support
https://editorconfig.org/

From docs
  KatePart has support for reading configurations from .editorconfig files,
  when the editorconfig library is installed. KatePart automatically searches
  for a editorconfig whenever you open a file. It gives priority to kateconfig
  files, though.
https://docs.kde.org/stable5/en/applications/katepart/config-variables.html

That sounds to me promising, when you add an empty .kateconfig, Kate stops using
.editorconfig. So I hope you have such around.

I couldn't got .editorconfig to work but with an .kateconfig the display in the
config dialog is not changed, it still says "Never" but the space will removed.

Kate 19.03.70
Frameworks 5.53.0
Comment 8 Ardith Metz 2019-01-04 13:46:30 UTC
Wow, that's a nice finding!

The excerpt that I showed in first post:

[Document]
...
Keep Extra Spaces=true
Remove Spaces=0
...

was from ~/.config/katepartrc, not ~/.config/katerc. I misremembered it but I originally posted this couple of months ago :)

Anyway my ~/.config/katepartrc matches ~/.config/katerc so that wasn't much relevant.

I indeed have .editorconfig (not sure where it comes from) which has a below line:

trim_trailing_whitespace = true

after changing it to:

trim_trailing_whitespace = false

the issue reported here goes away. Thank you very much for helping to find this!

There are still couple of things which aren't clear for me:

1. What is the difference between ~/.config/katepartrc and ~/.config/katerc, when they're used and why they both exist.
2. Why .editorconfig takes precedence over ~/.config/katepartrc and ~/.config/katerc? It may create confusion as:
a) it makes kate gui config inapplicable
b) it may be created by some different app than kate thus users like me may be unaware why the kate behavior suddenly changed
Comment 9 Lothar 2019-01-04 14:17:54 UTC
> Thank you very much for helping to find this!

Puh! You're welcome, but Thanks for the "Thanks" :-)

> when they're used and why they both exist.

Well, as said I'm no guru, but so far I know, katerc is Kate only, katepartrc is also used e.g by Kile, Kwrite and any stuff which based on KTexteditor
What, when, where is something saved/used I can't say ATM. Kate has some more "config" files, like for session management

> Why .editorconfig takes precedence over ~/.config/katepartrc and ~/.config/katerc? 

I think only when editorconfig is nearby the file you currently edit. So when some (Code) project have such in their tree it will used. So I understood the docs.

> it makes kate gui config inapplicable

Yes, I think so too

> it may be created by some different app than kate thus users like me may be unaware why the kate behavior suddenly changed

Yeah, it should somehow clear be shown which config (file) is in use to avoid these kind of trouble.

Feel free to file a new bug report, and close this one :-)
Comment 10 Dominik Haumann 2019-01-05 11:38:14 UTC
Thanks to all for you detailed investigation.
PS: Not, most things are not even obvious for "Kate developers", whatever that means :-) A Kate developer is someone who contributes to Kate, that includes you, Lothar :-)
Comment 11 Ardith Metz 2019-01-05 16:20:32 UTC
I opened new bug about editorconfig/kate interaction:

https://bugs.kde.org/show_bug.cgi?id=402896