Skip to content

Set 'comments' and 'commentstring' options in ftplugin#5

Open
ribru17 wants to merge 1 commit intolee-lindley:mainfrom
ribru17:comments
Open

Set 'comments' and 'commentstring' options in ftplugin#5
ribru17 wants to merge 1 commit intolee-lindley:mainfrom
ribru17:comments

Conversation

@ribru17
Copy link

@ribru17 ribru17 commented Jun 9, 2025

Useful for interacting with 'formatoptions', adding fold markers, and toggling comments.

Useful for interacting with 'formatoptions', adding fold markers, and
toggling comments.
@lee-lindley
Copy link
Owner

lee-lindley commented Jun 11, 2025

@ribru17 , @chrisbra ,

My internal code already does folds on multiline comments with "/* */", though not with multiple lines all starting with "--". There is a lot going on with other syntax as to how Oracle and sqlplus parse these files. It is not as simple as finding the start and end markers for comments. For example comment markers inside quoted strings are not comments and with the q' syntax for quoting, it gets especially tricky.

I do not see a reason to add this. If you can explain a reason for it, I'll reconsider, but I put a lot of testing into folds and comments, and am loathe to change it. I need a good reason. My fold code isn't perfect, but I have doubts this would be better.

See below for the main block of code that handles comments with awarness of ofther syntax that can impact it.

" Various types of comments.
syntax region plsqlCommentL start="--" skip="\\$" end="$" keepend extend contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
if get(g:,"plsql_fold",0) == 1
    syntax region plsqlComment
        \ start="/\*" end="\*/"
        \ extend
        \ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
        \ fold
else
    syntax region plsqlComment
        \ start="/\*" end="\*/"
        \ extend
        \ contains=@plsqlCommentGroup,plsqlSpaceError,plsqlIllegalSpace,plsqlSqlplusDefine
endif
syn cluster plsqlCommentAll contains=plsqlCommentL,plsqlComment

syn sync ccomment plsqlComment
syn sync ccomment plsqlCommentL

@chrisbra
Copy link

The 'commentstring' option is not so much for syntax highlighting, but rather enables users to quickly comment out parts of your syntax, so shouldn't not affect your syntax script using .e.g the vim-commentary plugin (or the now included vim comments plugin). It is also used for setting foldmarkers, e.g. when using :set foldmethod=marker and then folding blocks using zf.

For the 'comments' options, I think this is mainly used when formatting code using e.g. gq and allows vim to add detected comments at the start of a line when the line was broken into a new line.

Neither of those two options are must-have ones and if you don't want to support it, that is fine. People will then need to make use of the after directory to set those if they really need it.

@lee-lindley
Copy link
Owner

I'm not sure what "enables users to quickly comment out parts of your syntax" means.

I was looking at the help section on these in the last version of vim I installed (9.0 2022 Jun 28), and interpreted both as being involved in folding. Seems like a good time to upgrade.

For 'commentstring' if I understand you correctly this would only impact someone who was trying to use :set foldmethod=marker. If that is the case, I can add it as there should be no impact.

I'm still leary of 'comments' option. Does one have to set something to enable the behavior described about automatically adding the comment start for you when you split a line? I wouldn't like it doing that to me, but others might. I can certainly add it to my doucmentation and add it as a commented section in .ftplugin with a brief explanation or pointer to the documentation.

Thanks for explaining.

@chrisbra
Copy link

I'm not sure what "enables users to quickly comment out parts of your syntax" means.

I am sorry, I meant, it enables users to quickly comment or un-comment part your file. In combination with Vim word movements and text objects this is quite simple. However in order to do this, the comment plugin needs to know what is a valid comment marker for each specific language, which it usually does by (ab-)using the 'commentstring' option (which was originally meant to be used for adding fold-markers) and works quite well.

I'd recommend to try out one of those plugins to see how it works (or not works for plsql 😬 )

@ribru17
Copy link
Author

ribru17 commented Jul 17, 2025

Friendly ping @lee-lindley

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

Successfully merging this pull request may close these issues.

3 participants