Created attachment 147168 [details] test file STEPS TO REPRODUCE 1. Open the attached txt file in Kate. This file has 4608 rows and 4607 newlines (not sure of which kind). It has NO newline at the end of the file 2. Without editing the file AT ALL, save it 3. close it and open it again OBSERVED RESULT When you save the file, a newline character is added for no reason at the end of the file, without warning. Worse than that, you can't even see it. If you move the cursor at the end of the file, there is no empty line at the end (just like there wasn't before saving). Kate has modified the file but you can't see it. But when you reopen it, you will see the empty line at the end in Kate. So not only Kate is modifying a file upon saving despite the fact that I have not touched it; and not only is it doing so silently. It is also inconsistent in how it shows the contents of the same file. After step 2 the newline at the end has already been added but can't be seen. After step 3 nothing has changed wrt after step 2, but now the empty line can be seen. EXPECTED RESULT 1. No change should be made to a file when saving it if I have done absolutely nothing in the editor. If I open a file and save it, it shouldn't be changed the slightest bit 2. If you have a good reason for changing a file that I haven't touched when I save it, you should warn me one way or another. You don't do that silently 3. If I close a file that I already saved and reopen it (meaning I am opening a file that is identical to how it was when I closed it), it should look the same, in every aspect, no matter what. If I don't see an empty line at the end before closing (and I repeat: after saving), than I shouldn't see an empty line at the end after reopening, given that the file hasn't been modified in the meantime. No matter how you choose to visually represent the presence or absence of a newline at the end of file (I don't think there's much ambiguity there actually, if there is a newline at the end I should see an empty line, I think that's all, but even if I'm missing something here), you must be consistent, and never ever should a file that hasn't changed look different. SOFTWARE/OS VERSIONS Operating System: openSUSE Tumbleweed 20220207 KDE Plasma Version: 5.24.0 KDE Frameworks Version: 5.90.0 Qt Version: 5.15.2 Kernel Version: 5.16.5-1-default (64-bit) Graphics Platform: X11 Processors: 8 × Intel® Core™ i7-1065G7 CPU @ 1.30GHz Memory: 7.3 GiB of RAM Graphics Processor: Mesa Intel® Iris® Plus Graphics
> When you save the file, a newline character is added for no reason at the end of the file There is a reason. You can disable this setting here: Configure Kate -> Open/Save -> Auto append new line on save
Ok, everything else remains valid. Especially the part where the appended new line is not even shown.
Yeah, but nothing critcial.
I strongly disagree with classifying this as "wishlist". There are two things here: 1. The fact that when you save and the contents are changed (whatever the changes are and even if it is as per the settings), the first time that happens a warning should be shown with a "don't show again" option. That I can understand classifying as wishlist. It is standard behavior that one expects from any decent software, but it can be considered a feature request. 2. The fact that when you save the file and add a newline at the end, that newline is not shown. It is not shown in the same way it is when you close and reopen the file. This is a bug, and I don't know whether you call it "critical" or not, but it's pretty bad: you are not showing the current content of the file as-is. That's definitely way above wishlist. What will happen if I go to the end of the file and add something at the very end? Will that be added after or before the now-already-existing newline? What if I manually add a newline (which will look like it's the only newline at the end of the last line, while in fact Kate had already added another one)? Will there be one or two newline when saving? How can I trust an editor that does not show me the contents of the thing I'm editing reliably? One thing is that it doesn't warn me when modifying upon saving because that obeys a setting, but not showing the current contents reliably is a huge bug. It is not just a feature that is missing.
> What will happen if I go to the end of the file and add something at the very end? Will that be added after or before the now-already-existing newline? It will be added where you add it. > What if I manually add a newline (which will look like it's the only newline at the end of the last line, while in fact Kate had already added another one)? Will there be one or two newline when saving? one. You see, this is something that the author of the file doesn't need to worry about. If the setting is enabled, the new line will be added at the end if it doesn't exist. Probably working as designed. If you don't like the feature, disable it and add newlines whenever you want. > How can I trust an editor that does not show me the contents of the thing I'm editing reliably? I don't know. Maybe use another editor to see if it's 1:1, it works reliably for me during the 8+ hours I spend using it everyday.
e.g. vim doesn't show trailing or no-trailing newline at the end of a file at all. Even if it adds one. But yes, it would be nicer to show it. But no, in my eyes this is nothing urgent either. You can disable that behavior. It is normal to add the newline for most editors (beside mcedit), therefore the default seems OK, too.
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/310
Git commit 501f0b04178962e35248675882206449d7a1f8ea by Christoph Cullmann. Committed on 05/03/2022 at 18:17. Pushed by cullmann into branch 'master'. add new line on save inside the buffer this works like for stripping trailing spaces one now has the correct content in the buffer after save M +0 -11 src/buffer/katetextbuffer.cpp M +0 -14 src/buffer/katetextbuffer.h M +0 -3 src/document/katebuffer.cpp M +31 -15 src/document/katedocument.cpp M +3 -2 src/document/katedocument.h https://invent.kde.org/frameworks/ktexteditor/commit/501f0b04178962e35248675882206449d7a1f8ea