Sublime Forum

Issue creating syntax highlight file

#1

Hello, I’m trying to create a syntax highlight file for nushell. I edited a file meant for matlab syntax highlight, and it looks good on a nushell script, but the shortcut for commenting a line doesn’t work. What could I be doing wrong?

You can find the file here.

Regards,

0 Likes

#2

For commenting you need a tmPreferences file that adds the metadata rules necessary for the command that does the commenting to know what characters to use for comments. If you use View Package File from the command palette, you can open Matlab/Comments.tmPreferences to get a sense for what is required.

You would need a similar file (name does not matter, just the extension) with the same scope as your syntax, and for which TM_COMMENT_START specifies the correct comment character for a line comment. If the language supports it, TM_COMMENT_START_2 and TM_COMMENT_END_2 specify the characters used to start and end a block comment.

1 Like

#3

Thank you so much, I’ll try it out.

0 Likes

#4

OK, I copy-pasted Matlab tmPreferences file and edited it, the result is this:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>scope</key>
	<string>source.nu</string>
	<key>settings</key>
	<dict>
		<key>shellVariables</key>
		<array>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_START</string>
				<key>value</key>
				<string># </string>
			</dict>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_START_2</string>
				<key>value</key>
				<string>
</string>
			</dict>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_END_2</string>
				<key>value</key>
				<string>
</string>
			</dict>
		</array>
	</dict>
</dict>
</plist>

I saved it as nuComments.tmPreferences in sublime config dir: Packages/User, but shortcut to comment line still doesn’t work. What did I did wrong?

0 Likes

#5

In the syntax file you linked above, the scope is source.m (presumably because it’s derived from matlab):

%YAML 1.2
---
# https://www.sublimetext.com/docs/syntax.html
# https://www.https://www.nushell.sh/book/
name: nushell
scope: source.m
version: 1

file_extensions:
  - nu

The scope in the syntax needs to match the scope in the tmPreferences file; so as currently displayed one of them needs to be modified.

1 Like

#6

Thanks!! That was it! Regards.

1 Like

#7

Yo, mind sharing the finished syntax highlighting file?
Or is it already hosted somewhere on a repo?

0 Likes

#8

No problem. It is probably improbable but it works so far.

1 Like