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

C block comments handled incorrectly if delimiters not followed/preceded by space #29

Open
wilywampa opened this issue Apr 15, 2014 · 3 comments

Comments

@wilywampa
Copy link

Hi,

I noticed that the plugin doesn't play well with a style of comments I have to work with. This C code:

/*-----------
|  comment
|-----------*/
foo();

is commented as:

/* /*----------- */
/* |  comment */
/* |-----------*/ */
/* foo(); */

which, as you can see, causes a syntax error at the end of the comment block. The problem occurs if there is any character other than a space after the left delimiter or before the right delimiter.

I was able to make it work without a syntax error (Vim highlights it as a syntax error but it compiles) by removing the spaces from the delimiters that are added in in s:surroundings() and changing the strlen check from 2 to 1. The result is functional but ugly due to lack of whitespace and Vim's syntax error:

/*/1*-----------*/
/*|  comment*/
/*|-----------*1/*/
/*foo();*/

My suggestion is that the pre-existing '/*' and '*/' should be replaced with ' /1* ' and ' *1/ ' i.e. add spaces around the modified delimiter, but I haven't figured out a way to implement it yet.

@tpope
Copy link
Owner

tpope commented Apr 15, 2014

See 8647be4 for the initial /1* implementation, which might give some clues how to proceed.

@wilywampa
Copy link
Author

I got it working, but I won't do a pull request for now because I added too many lines (20). First, I had to do multiple substitutes because I don't think I can use submatches other than submatch(0) for searches with multiple branches. Second, I could probably do something clever with the uncomment flag to handle including spaces in the substitutes or not instead of adding another if statement.

8d30a7a

EDIT: I realized my version adds a trailing space to the line originally containing the right-hand comment delimiter. Will fix tonight.

@wilywampa
Copy link
Author

I corrected a lot of little problems that showed up in my testing and only added two more lines. It's still pretty inelegant compared to what I started with, but it handles everything I throw at it, like commenting a paragraph three levels in by including it in gggcG or gc3} and other motions, then being able to uncomment correctly back to the original including leaving trailing whitespace that was in the original text. I also regression tested it against other non-C comment styles and didn't find any problems.

b6bd945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants