Packages
Packages copied to clipboard
[C family] Alt + Q hard-line-wrap feature doesn't work for comments which begin with 3 slashes `///` (Doxygen comments)
Description of the bug
Any comments in C or C++ which begin with 3 slashes (///
) make the Alt + Q hard-line-wrap feature not work right.
Steps to reproduce
Put this into a C or C++ file:
/// This is a really long doxygen comment This is a really long doxygen comment This is a really long doxygen comment This is a really long doxygen comment
Place your cursor on that line, then press Alt + Q to hard-line-wrap. It does this:
/// This is a really long doxygen comment This is a really long doxygen comment This is a really
// long doxygen comment This is a really long doxygen comment
That's not right. The 2nd line has only 2 slashes, not 3, and it has an extra space in it. It should have done this instead:
/// This is a really long doxygen comment This is a really long doxygen comment This is a really
/// long doxygen comment This is a really long doxygen comment
Expected behavior
see above
Actual behavior
see above
Sublime Text build number
4126
Operating system & version
Ubuntu 18.04
(Linux) Desktop environment and/or window manager
Gnome
Additional information
My clunky work-around, which is time-consuming, is to use the multi-line cursor mode to remove 1 slash per line, making each line begin with //
. I then hit Alt + Q to hard-line-wrap, then I use the multi-line cursor mode to add 1 slash per line back to the beginning of each line, making them all begin with ///
again.
OpenGL context information
No response
Possible minimal fix:
--- Shipped Packages/C++/C.sublime-syntax
+++ Packages/C++/C.sublime-syntax
@@ -85,7 +85,7 @@
scope: comment.line.banner.c
captures:
1: meta.toc-list.banner.line.c
- - match: //
+ - match: //[/!]?
scope: punctuation.definition.comment.c
push:
- meta_scope: comment.line.double-slash.c
This would require a pull request in https://github.com/sublimehq/Packages.
Not sure if the comment scope should be adjusted for ///
and //!
style Doxygen comments, because comment.line.double-slash
wouldn't be really accurate anymore.
Any fix for this? I've been fighting with it for years.
In case it helps expedite it: I am a paying user. I have a Single User Licence registered to Gabriel Staples, and Sublime Text is my primary editor.
See the linked PR #3217. Unfortunatelly C/C++ reviewers are rare.
@jwortmann , what does [/!]?
mean?
@ElectricRCAircraftGuy it matches "a /
or a ?
appears 0 or 1 time". It's called regular expression if you are interested.
@jfcherng , it doesn't appear to be a proper regular expression. Regex101.com doesn't like the forward slashes unescaped: https://regex101.com/r/sATC3R/1
And what about the !
? What's it do there? The /!
part seems to want to match a /
literal char or a !
literal char.
it doesn't appear to be a proper regular expression. Regex101.com doesn't like the forward slashes unescaped: https://regex101.com/r/sATC3R/1
@ElectricRCAircraftGuy we are not talking about javascript or php. choose a language that doesnt require using //
for wrapping, which will need to escape /
.
And what about the ! ? What's it do there? The /! part seems to want to match a / literal char or a ! literal char.
I believe there is a typo so that I dont know what you are asking. But it has been answered in https://github.com/sublimehq/Packages/issues/3215#issuecomment-1403106745 anyway.
What are we talking about then?
And what about the !
? What's it do there? The /!
part seems to want to match a /
literal char or a !
literal char, right? Why match the !
char too?
It seems to be valid Python:
lgtm.
Why match the ! char too?
https://github.com/sublimehq/Packages/issues/3215#issuecomment-1022729703 has answered.
Yes, I put the exclamation mark there because it's one of the possible ways to write Doxygen comments in C-like languages, according to https://www.doxygen.nl/manual/docblocks.html#cppblock
@jwortmann , understood. Thanks for explaining and posting the link! Now it's clear.
I'm still hoping to see this feature added to the Alt + Q hardwrap in sublime text. Meanwhile, I'm moving to VSCode and the Rewrap extension to do this for me:
More info: https://stkb.github.io/Rewrap/
Note: I still use Sublime Text a ton--more than VSCode, so I still need Alt + Q text wrapping in Sublime Text all the time, including these features. And Rewrap isn't perfect, either (see my bug reports and feature requests for it).
Maybe https://packagecontrol.io/packages/Wrap%20Plus can help you out.