Sublime Forum

Create additional comment type to same language

#1

From my understanding, there are only two types of comments:

  • Single line (macOS: cmd + /)
  • Block (macOS: cmd + Option/Alt + /)

Currently you can only tigger comments either as Single line, or Block.

If I want to add additional single line comment type, so that now I have:
Single_Line_Type1 (i.e. uses // to comment out)(triggered by cmd + /)
Single_Line_Type2 (i.e. uses ## to comment out)(triggered by cmd + .)
Single_Line_Type3 (i.e. uses * to comment out)(triggered by cmd + ,)

How may I achieve that? I wish to apply this new comment settings to markdown filetype .md, if possible.

Thank you so much!

0 Likes

#2

Has anyone has any idea how we can achieve this? Thank you!

0 Likes

#3

The default toggle_comment only support two styles of comments. You could write your own plugin to do the comment toggling you desire. You can take a look at the built-in one as an example using the command palette View Package File > Default/comment.py

0 Likes

#4

Thank you so much bschaaf! The comment.py seems so complex I honestly don’t know how to edit it, compared to the way more easier .tmPreferences files.

Is there any other easier way to accomplish such goal?

0 Likes

#5

No; the tmPreferences files just provide the metadata about (in this case) what comment markers there are and how they pair together. It’s the plugin that uses that to actually insert the comments.

0 Likes