Rewrap
Rewrap copied to clipboard
Wrapping a long line which is partly commented
When a line begins with a non-comment part which is followed by a (long) comment, it is wrapped incorrectly. For instance,
|
int main() // this is a long comment which starts from the middle of a line.
|
becomes
|
int main() // this is a long comment which |
starts from the middle of a line. |
|
This happens, for instance, C and LaTeX. Perhaps for other formats as well.
I guess the expected result is
|
int main() // this is a long comment which |
// starts from the middle of a line. |
|
Indeed emacs does filling in this way.
Hi, have been away this week.
Yeah I decided early on not to support these type of end-of-line comments, partly because it wasn't clear to me how to wrap them:
SomeType varOne; // Given a long comment at the end of this line
SomeType varTwo;
SomeType varOne; // Wrap the comment and put
SomeType varTwo; // the rest here
SomeType varOne; // Wrap the comment to the
// same column on a new line
SomeType varTwo;
SomeType varOne; // Wrap the comment onto a
// new line with no indent
SomeType varTwo;
SomeType varOne; // Wrap the comment onto a
// new line with some indent
SomeType varTwo;
It will take some work but I never say never. I guess we can go with the 3rd one as you suggest. I'll need to figure out if there'll be any problems.
Thanks for the response. I guess I understand why you didn't support this.
I've just tested a few more cases in emacs, and found that the result depends on the language.
In C/C++: it behaves like the second case above, if ALT-Q is used inside the comment. (So I was wrong.) If ALT-Q is used outside the comment (e.g. on the variable name varOne), then nothing is rewrapped.
In LaTeX (AucTeX mode): it behaves like the second case above, if ALT-Q is used inside the comment. If ALT-Q is used outside the comment, then the whole paragraph containing the cursor is rewrapped, but a long comment in the paragraph is left unwrapped.
So, in any case, a part of a comment is never uncommented by rewrap. I think this behavior is good, since the rewrapped result is equivalent to the original to the eyes of a compiler.
Thanks for the further explanations. Yes end of line comments are currently invisible to Rewrap, so it treats them just like normal text in a paragraph, which means they could get broken up.
In source code files that's not too much of a problem since it only happens if you explicitly try to wrap those lines. However I now see how it's a problem in LaTeX, so I'd like to fix that. I will look into wrapping of end-of-line comments too.
I've now got emacs and auctex installed so will do some experimenting and come back with my thoughts.
Just came here to see this issue is already opened.
I don't work with C or LaTeX, but use JS and AutoHotkey a lot. Yes, something like
Before
------
var a = "x" // some very very long comment
var b = "y"
After
-----
var a = "x" // some very
// very long comment
var b = "y"
would be awesome.
Just wanna add my support for this feature, after 4 years. I use style 2 (from above) just like @john-cj, and currently do it manually.