Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[C family] Alt + Q hard-line-wrap feature doesn't work for comments which begin with 3 slashes `///` (Doxygen comments)

Open ElectricRCAircraftGuy opened this issue 3 years ago • 3 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

ElectricRCAircraftGuy avatar Jan 26 '22 22:01 ElectricRCAircraftGuy

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.

jwortmann avatar Jan 27 '22 00:01 jwortmann

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.

ElectricRCAircraftGuy avatar Nov 11 '22 01:11 ElectricRCAircraftGuy

See the linked PR #3217. Unfortunatelly C/C++ reviewers are rare.

deathaxe avatar Nov 11 '22 17:11 deathaxe

@jwortmann , what does [/!]? mean?

ElectricRCAircraftGuy avatar Jan 25 '23 05:01 ElectricRCAircraftGuy

@ElectricRCAircraftGuy it matches "a / or a ? appears 0 or 1 time". It's called regular expression if you are interested.

jfcherng avatar Jan 25 '23 05:01 jfcherng

@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.

ElectricRCAircraftGuy avatar Jan 25 '23 07:01 ElectricRCAircraftGuy

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.

jfcherng avatar Jan 25 '23 07:01 jfcherng

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: image

ElectricRCAircraftGuy avatar Jan 25 '23 07:01 ElectricRCAircraftGuy

lgtm.

Why match the ! char too?

https://github.com/sublimehq/Packages/issues/3215#issuecomment-1022729703 has answered.

jfcherng avatar Jan 25 '23 07:01 jfcherng

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 avatar Jan 25 '23 08:01 jwortmann

@jwortmann , understood. Thanks for explaining and posting the link! Now it's clear.

ElectricRCAircraftGuy avatar Jan 25 '23 15:01 ElectricRCAircraftGuy

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:

image

More info: https://stkb.github.io/Rewrap/

ElectricRCAircraftGuy avatar May 11 '23 22:05 ElectricRCAircraftGuy

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).

ElectricRCAircraftGuy avatar Sep 23 '23 18:09 ElectricRCAircraftGuy

Maybe https://packagecontrol.io/packages/Wrap%20Plus can help you out.

deathaxe avatar Sep 23 '23 18:09 deathaxe