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

Commenting Paragraph #826

Open
chaand625 opened this issue Apr 7, 2019 · 3 comments
Open

Commenting Paragraph #826

chaand625 opened this issue Apr 7, 2019 · 3 comments

Comments

@chaand625
Copy link

chaand625 commented Apr 7, 2019

Commenting a pargraph

When commenting a paragraph using "gcap" , extra blank line getting commented every time.
Then when pressing " . " to toggle commenting it is doing something else like commenting another paragraph instead of uncommenting the present paragraph.

Screenshot 2019-04-07 at 8 03 39 PM

Screenshot 2019-04-07 at 8 03 53 PM

@keforbes
Copy link
Contributor

keforbes commented Apr 8, 2019

Whether or not to include the trailing line(s) in a paragraph is the difference between a and i for those text objects. Try using gcip rather than gcap. This is consistent with Vim behavior as well.

As for hitting . to repeat... it looks like this depends on where your cursor is when you hit .. If I do gcip, it comments the paragraph but leaves the cursor on the line below the paragraph. If I hit . from that location, it repeats the gcip operation in the context of the current position, which is a different paragraph. Instead, if I move the cursor up a couple lines (so it's inside the paragraph again) and hit . then it correctly toggles the commented lines.

@chaand625
Copy link
Author

It is commenting blank lines. Blank lines don't get commented in the 'tpope/vim-commentary'. If I comment 4 paragraphs using 4gcap and I want to uncomment only two of them. It comments two paragraphs which is a 4 + 2 = 6 paragraphs instead of

Screenshot 2019-04-09 at 12 08 14 PM

Screenshot 2019-04-09 at 12 08 27 PM

Screenshot 2019-04-09 at 12 05 53 PM

Screenshot 2019-04-09 at 12 07 03 PM

uncommenting 2 paragraphs.
Normally gcip doesn't work with more than 1 paragraph I mean a count. I don't understand why it's working for you. I want to comment and uncomment paragraphs easily cause it's easy to type ngcap .

@keforbes
Copy link
Contributor

keforbes commented Apr 9, 2019

It is commenting blank lines. Blank lines don't get commented in the 'tpope/vim-commentary'.

Ok, that's a different question entirely and is a valid enhancement request.

The issue you're hitting is that by adding comments to blank lines, Vrapper is taking what was 4 paragraphs (as defined by blank lines) and turning them into one big paragraph (since the lines are no longer blank). Then when you run 2gcap we have one big paragraph already commented and one paragraph which is not commented, so it comments the entire block.

Unfortunately, this is not easy to fix. Whenever I can, I call the underlying Eclipse API to perform operations for me. Those APIs are typically more robust since they are more aware of the entire Eclipse ecosystem and can handle more corner cases. For the gc<text object> command, I'm simply calling: org.eclipse.jdt.ui.edit.text.java.toggle.comment with the text object selection. That Eclipse command determines whether the selection needs to be commented or uncommented. So Vrapper is sending a text selection (4 paragraphs) to that command and it adds or removes the comment characters as needed. And apparently this JDT toggle.comment command doesn't exclude blank lines.

Since I can't change the way this toggle.comment command behaves, this is basically an enhancement request for the JDT.

Now, maybe we could do some post-processing ourselves where we run this Eclipse command as normal and then run through all the affected lines and remove any comment characters from what would otherwise be empty lines. That introduces its own complexity (how do we know if comments were added or removed when the command ran? How do we know if a commented line was added by the user or by the Eclipse command?) and it's a bit of a hack to modify some lines and then run a process to un-modify them.

Or, rather than using this Eclipse command, we could implement the feature ourselves. Since this command is provided by the JDT, it only affects java code and therefore only adds/removes the // characters. So that's a pretty narrow set of requirements. If preventing comments on blank lines when using the gc<text object> feature bothers you that much, go ahead and create a pull request with your own implementation. It would be in the plugins/languages/net.sourceforge.vrapper.eclipse.jdt project of the code. You would need to create a new Operation in that project. Operations accept TextRanges which would be the lines that need to be commented/uncommented. Then you could probably wrap it in a TextOperationTextObjectCommand in JdtSpecificStateProvider since that class requires a Command to set to gc<text object>.

EDIT: Actually, I don't think you'd use the TextOperationTextObjectCommand. I think you could just use the operatorCmds method as a static import since it has an overloaded version that accepts an Operation.

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