Bug 328900

Summary: Commenting out text does not apply static word wrap
Product: kate Reporter: Gerald Senarclens de Grancy <oss>
Component: partAssignee: KWrite Developers <kwrite-bugs-null>
Status: VERIFIED FIXED    
Severity: normal CC: kare.sars
Priority: NOR    
Version: 3.11.2   
Target Milestone: ---   
Platform: Ubuntu Packages   
OS: Linux   
Latest Commit: Version Fixed In: 4.11.5
Attachments: simple manual test case

Description Gerald Senarclens de Grancy 2013-12-17 10:10:35 UTC
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
Comment 1 Gerald Senarclens de Grancy 2013-12-17 10:11:27 UTC
Created attachment 84139 [details]
simple manual test case
Comment 2 Kåre Särs 2013-12-17 10:33:24 UTC
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.
Comment 3 Gerald Senarclens de Grancy 2013-12-17 10:57:51 UTC
(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.
Comment 4 Kåre Särs 2013-12-17 11:03:28 UTC
Yes you can be aware of it, but the bug here is that the wrapping is not applied when it is commented out.
Comment 5 Dominik Haumann 2013-12-17 12:34:30 UTC
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.
Comment 6 Gerald Senarclens de Grancy 2013-12-17 13:16:56 UTC
(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.
Comment 7 Dominik Haumann 2013-12-17 14:16:19 UTC
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?
Comment 8 Dominik Haumann 2013-12-17 14:22:43 UTC
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.
Comment 9 Gerald Senarclens de Grancy 2013-12-17 15:01:28 UTC
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.
Comment 10 Gerald Senarclens de Grancy 2013-12-17 15:02:55 UTC
Another good option would be to trigger the word wrap already when commenting out a region as Kåre suggested.
Comment 11 Dominik Haumann 2013-12-17 20:18:59 UTC
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
Comment 12 Dominik Haumann 2013-12-17 20:19:30 UTC
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
Comment 13 Dominik Haumann 2013-12-17 20:19:50 UTC
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
Comment 14 Dominik Haumann 2013-12-17 20:20:28 UTC
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
Comment 15 Dominik Haumann 2013-12-17 20:26:00 UTC
> 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).
Comment 16 Gerald Senarclens de Grancy 2013-12-17 21:38:56 UTC
@Dominik: thanks for the fix - works as expected