A new feature for ST3 only has been added to allow Apply Syntax to add extensions to sublime in a more native way.
Adding extensions to the Language sublime-settings file is how Sublime usually handles simple extension association. In the past, ApplySyntax didn’t care about this because there was no real advantage to complying. But with recent versions of ST3, file icons have been added. Post processing the syntax of a file will not show the appropriate icon in the sidebar, but utilizing the built in extension handling for a language can.
…so, ApplySyntax now as an experimental feature to utilize this native extension handling. Ideally, it will replace all the current regex rules that just define extensions:
[pre=#232628] “syntaxes”:
{
“name”: “Makefile/Makefile”,
“rules”:
Now ApplySyntax will track all of the extensions it specifically adds, so that it can clean them up when the rule is removed or the feature is disabled (this is done automatically and you don’t really need to care):
[pre=#232628]{
“apply_syntax_extensions”:
"xml.dist"
],
"extensions":
"svg",
"xslt",
"xsd",
"xml.dist",
"xml"
]
}[/pre]
The rules can actually coexist for backwards compatibility (though in the future, if all goes according to plan, I will force the extension method by default and remove the old method):
[pre=#232628] “default_syntaxes”:
{
// I put XML first because of files like .tmLanguage. It is unlikely
// that this rule will result in a false positive, meaning if it
// matches, you probably want the XML syntax
“name”: “XML/XML”,
“rules”:
{“file_name”: ".\.xml(\.dist)?$"},
{“first_line”: “^<\?xml”},
// See “add_exts_to_lang_settings” setting above for more info
// if using extensions, you don’t need to set “file_name”.
// Rule could be simplified to this:
//
// “name”: “XML/XML”,
// “rules”:
// {“first_line”: “^<\?xml”},
// {“extensions”: “xml.dist”]}
// ]
//
{“extensions”: “xml.dist”]}
]
},[/pre]
When defining them the legacy way and the new way, the file, by default is opened correctly by sublime, and then apply syntax checks it again with the regex rule (which is completely unnecessary, but safe).
Now this is only for simple extensions and not for complex file patterns, so there are language cases where you will rightly have regex rules and extensions rules.
Also, it is important to note that when define rule sets with the “match” option set to “all”, “extensions” rules will be ignored in the evaluation. Really extensions is ignored at all times except when ApplySyntax is updating the language settings extensions.
This new feature can be turned on with the following switch:
[pre=#232628] // Auto add extensions to language settings file in User folder. This changes the
// default syntax for a file extension. Keep in mind though that other rules can
// override this. By adding the extension to the language settings file, sidebar
// icons in ST3 will display proper icon for the syntax it will load with
// (assuming another rule doesn’t override the syntax it loads with).
// ApplySyntax will log the extensions it adds under “apply_syntax_extensions”
// to try and track when obsolete ApplySyntax extensions should be removed.
// Do not manually remove “apply_syntax_extensions” from the settings file.
// “extenstions” rules are ignored by “match”: “all” setting.
“add_exts_to_lang_settings”: false,[/pre]