07975 997026 enquiries@ harpanet.com
First, create a new package in: SublimeText3/Data/Packages with a relevant name, eg. myLang
Second, create a new language file(this is simply a text file containing XML) in your new package, eg. myLang.tmLanguage
The .tmLanguage extension comes from the TextMate text editor, which SublimeText adheres to as far as possible. The .tmLanguage files themselves are 'plist' (property list) formatted XML files which were popularised by Apple.
Most discussions and web resources regarding tmLanguage files use the JSON format, then use a converter to create the PLIST formatted XML file. Here, we're going to write the XML directly and save installing/running any converter.
Let's first create the basic XML skeleton that all PLIST files require.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>name</key> <string>##LANGUAGE NAME##</string> <key>fileTypes</key> <array> <string>##FILE EXTENSION##</string> </array> ##LANGUAGE PATTERNS## <key>scopeName</key> <string>text.html.##LANGUAGE IDENTIFIER##</string> <key>uuid</key> <string>##UNIQUE UUID##</string> </dict> </plist>
I have included some ##PLACEHOLDERS## in the above skeleton which are not part of the PLIST language, but I will use them in the text below to indicate what goes where.
The structure of the PLIST file is basically an outer
<dict>...</dict> containing multiple
<string>...</string> tags, where the
key contains names that SublimeText needs to recognise to identify what is contained in the next
string (or other) tag.
This is fine for some instances, but in a number of cases the
key requires multiple values. In the skeleton, we can see that this is achieved for the
<key>fileTypes</key> by adding the strings inside
name key and associated
string entity appears once within a
<dict> entity, and is used to give a unique name to the
<dict> in which it exists. In our skeleton, the outermost
<dict> will be identified by the name that we give for ##LANGUAGE NAME##.
To fill out the ##PLACEHOLDER## tags, we need to agree some parameters for our new language syntax.
Now we can complete the ##PLACEHOLDERS## in the skeleton.
The name key specifies the string for our syntax language that will be shown in the Syntax list within SublimeText.
We have already decided on a file extension, so just replace the placeholder with the correct value.
Notice that you do not include the dot
. in the file extension.