Sublime Forum

// vs /// comments syntax hilighting

#1

Hello,

When I was using the “Kate” programming editor on Linux, there was a useful distinction with syntax hi-lighting on comments (with C/C++ syntax hilighting):

// got a certain color
/// was a different color

This is really useful for having a visual difference between code I want to disable and not stand out, and actual comments within the code that I want to stand out and have a different color.

Is there a way to do this in Sublime Text 2?

Thank you,
Christos

0 Likes

#2

You’ll have to edit your .tmLanguage file, but it should be fairly straightforward (copy and paste, add a slash?).

0 Likes

#3

Was any particular solution agreed upon to address this issue? If so, can you please it share it?

I am new to sublime and it seems non trivial for me to figure out how to edit the .tmLanguage file for C++ to change the highlighting on blocks of code that I would like to disable vs lines that carry information that I want to stand out.

0 Likes

#4

to the .tmLanguagefile add this before the comment.line.double-slash.php portion

	<dict>
		<key>captures</key>
			<dict>
				<key>2</key>
				<dict>
					<key>name</key>
					<string>punctuation.definition.comment.php</string>
				</dict>
			</dict>
		<key>match</key>
		      <string>(///).*?($\n?|(?=\?&gt;))</string>
		<key>name</key>
		     <string>comment.line.triple-slash.php</string>
	</dict>

then in your .tmTheme file add this before the line. Change the hex colour to what ever you want

<dict>
  <key>name</key>
  <string>Slash Comment</string>
  <key>scope</key>
  <string>comment.line.triple-slash.php</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#666600</string>
  </dict>
</dict>

So far the only problem I’ve seen with this is that when you hit return it creates only a // double slash on the next line.

0 Likes

#6

Thanks rob,

finally getting back to this!

OK I’ve located my C++.tmLanguage file but already have a key 2 in there so adding a key 3. There is already a “match” and “name” key, do I just append those or duplicate them with this new one for triple slash:

	<key>block</key>
	<dict>
		<key>begin</key>
		<string>\{</string>
		<key>end</key>
		<string>\}</string>
		<key>name</key>
		<string>meta.block.c++</string>
		<key>patterns</key>
		<array>
			<dict>
				<key>captures</key>
				<dict>
					<key>1</key>
					<dict>
						<key>name</key>
						<string>support.function.any-method.c</string>
					</dict>
					<key>2</key>
					<dict>
						<key>name</key>
						<string>punctuation.definition.parameters.c</string>
					</dict>
					<key>3</key>
					<dict>
						<key>name</key>
						<string>punctuation.definition.comment.c++</string>
					</dict>
				</dict>
				<key>match</key>
				<string>(?x)
				(
					(?!while|for|do|if|else|switch|catch|enumerate|return|r?iterate)(?: \b[A-Za-z_][A-Za-z0-9_]*+\b | :: )*+                  # actual name
				)
				 \s*(\()</string>
				<key>name</key>
				<string>meta.function-call.c</string>
			</dict>

Thanks!

0 Likes