Among others, in Latex documents it can be useful to enable a static word wrap. If this setting is active and trailing spaces are removed when saving. this can badly mess up comments. For example: % Constraints (2.11) to (2.13) ensure that the time window of each customer is not % violated. Constraints (2.11) ensure that the actual starting time is larger then % the earliest start time towards a customer from the parking site. If the % customer is not assigned to the cluster, this time is irrelevant and can be turned into % Constraints (2.11) to (2.13) ensure that the time window of each customer is not % violated. Constraints (2.11) ensure that the actual starting time is larger then % the earliest start time towards a customer from the parking site. If the % customer is not assigned to the cluster, this time is irrelevant and Reproducible: Always Steps to Reproduce: 1. open the attached tc.tex file w/ Kate or Kwrite or Kile or any other editor using kate part 2. go to settings->editing->general and enable static word wrap 3. go to settings->open/save->general and set remove trailing spaces to 'on modified lines' 4. put the cursor at the end of the document and hit enter 5. mark the entire document (ctrl + a), comment out the text (ctrl + d) and save it (ctrl + s) Actual Results: comments are messed up w/ comment signs in the middle of the text. Expected Results: lines are wrapped with either a) wrapped text on separate lines starting with comments or b) wrapped text part of next line's comment but no comment signs in the middle of the text
Created attachment 84139 [details] simple manual test case
The problem is that when the statically wrapped text is commented out the wrapping is not applied. The wrapping is then applied when the document is saved with the remove trailing spaces option enabled. You get the same problem if you go and edit the first commented out line.
(In reply to comment #2) > You get the same problem if you go and edit the first commented out line. I know ;) - but at least you are aware of what happens then. In the comment block case you might hit save later at a different position of the document and then wonder what happend why you try compiling.
Yes you can be aware of it, but the bug here is that the wrapping is not applied when it is commented out.
It's pretty much unfixable. We get bug reports about it again and again. There is no good way to fix that. A workaround would be to not wrap lines that start with a single-line comment. But then, if the comment starts in the middle of the line, it's again broken... Essentially it comes down to: Static word wrap is a feature that is broken by design. Just don't use it in any text editor ;) We can talk about it in Barcelona, if you want.
(In reply to comment #5) > It's pretty much unfixable. We get bug reports about it again and again. > There is no good way to fix that. A workaround would be to not wrap lines > that start with a single-line comment. But then, if the comment starts in > the middle of the line, it's again broken... > > Essentially it comes down to: Static word wrap is a feature that is broken > by design. Just don't use it in any text editor ;) We can talk about it in > Barcelona, if you want. Bummer I can't make it to Barcelona :( - so I fear we have to talk about it here or on the mailing list. Or we could close the bug as won't fix.
Ok. The thing is, what do you expect? We could change it to: % Constraints (2.11) to (2.13) ensure that the time window of each customer is % not % violated. Constraints (2.11) ensure that the actual starting time is % larger then % the earliest start time towards a customer from the parking site. % If the % customer is not assigned to the cluster, this time is irrelevant and But then, inserting the additional "% " might again wrap the text. Or we could change it to: % Constraints (2.11) to (2.13) ensure that the time window of each customer is % not % violated. Constraints (2.11) ensure that the actual starting time is % larger then % the earliest start time towards a customer from the parking site. % If the % customer is not assigned to the cluster, this time is irrelevant and While this at least does not introduce a syntax error, imho this behavior sucks just as much. Noone really wants code like this one. So we could just NOT wrap it when saving. That's probably the best workaround. But then, as soon as you type a character, it again will wrap with broken behavior. Would you consider this bug as fixed if we disable static word wrap when removing trailing spaces on save?
See also bug #113047 or bug #298496 In the latter one, Christoph writes: "Actually sometime this whole static word wrap should be deleted and moved to a script which allows you to fast wrap the last paragraph or so." I personally tend to agree :p Btw, you can try to use F7 (command line) "rewrap". This command either rewraps the selection, or the current paragraph. I've once written this, but I'm pretty sure noone uses it. Now you could disable static word wrap and wrap with a script manually by binding it to some convenient shortcut. Apart from that, it would probably be good to disable static word wrap while saving though, to avoid this bug.
Disabling static word wrap when removing trailing spaces on save sounds like a sane solution. After all, this is a corner case. Otherwise the 2nd option of Comment 7 would still be better than sneaking syntax errors in a file.
Another good option would be to trigger the word wrap already when commenting out a region as Kåre suggested.
Git commit ddf061a4b46357e7adfbf58522f11e0270005d79 by Dominik Haumann. Committed on 17/12/2013 at 20:18. Pushed by dhaumann into branch 'master'. do not word wrap when removing trailing spaces Thanks to Gerald for the detailed report! FIXED-IN: 4.11.5 M +7 -0 part/document/katedocument.cpp http://commits.kde.org/kate/ddf061a4b46357e7adfbf58522f11e0270005d79
Git commit 7acc7a1de4d5276836740fd705e64607df388b46 by Dominik Haumann. Committed on 17/12/2013 at 20:18. Pushed by dhaumann into branch 'KDE/4.12'. do not word wrap when removing trailing spaces Thanks to Gerald for the detailed report! FIXED-IN: 4.11.5 M +7 -0 part/document/katedocument.cpp http://commits.kde.org/kate/7acc7a1de4d5276836740fd705e64607df388b46
Git commit 0b0ceed0cf488e0f6d908664f0a4c9715a31b551 by Dominik Haumann. Committed on 17/12/2013 at 20:18. Pushed by dhaumann into branch 'KDE/4.11'. do not word wrap when removing trailing spaces Thanks to Gerald for the detailed report! FIXED-IN: 4.11.5 M +7 -0 part/document/katedocument.cpp http://commits.kde.org/kate/0b0ceed0cf488e0f6d908664f0a4c9715a31b551
Git commit 04b0fdeaf1313d1d354401609969d2e61540ed1d by Dominik Haumann. Committed on 17/12/2013 at 20:18. Pushed by dhaumann into branch 'KDE/4.10'. do not word wrap when removing trailing spaces Thanks to Gerald for the detailed report! FIXED-IN: 4.11.5 M +7 -0 part/document/katedocument.cpp http://commits.kde.org/kate/04b0fdeaf1313d1d354401609969d2e61540ed1d
> Another good option would be to trigger the word wrap already when commenting out a region as Kåre suggested. Looking into the code, not triggering word wrap was added (just like I added this for remove trailing spaces now) to fix bug #105373 (see comment #26-end for details).
@Dominik: thanks for the fix - works as expected