Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping a long line which is partly commented #46

Open
jccha opened this issue Aug 22, 2017 · 5 comments
Open

Wrapping a long line which is partly commented #46

jccha opened this issue Aug 22, 2017 · 5 comments
Labels
backlog On the backlog of things to do

Comments

@jccha
Copy link

jccha commented Aug 22, 2017

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.

@jccha jccha changed the title Wrapping a long line with a comment beginning from the middle of the line Wrapping a long line which is partly commented Aug 22, 2017
@stkb
Copy link
Owner

stkb commented Aug 26, 2017

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.

@jccha
Copy link
Author

jccha commented Aug 28, 2017

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.

@stkb
Copy link
Owner

stkb commented Aug 28, 2017

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.

@john-cj
Copy link

john-cj commented Dec 17, 2017

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.

@tfiers
Copy link
Contributor

tfiers commented Jan 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog On the backlog of things to do
Projects
None yet
Development

No branches or pull requests

4 participants