Home Download Buy Blog Forum Support

ST3: ApplySyntax (was DetectSyntax) new maintainer

ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Mon Mar 11, 2013 3:36 pm

I was waiting forever for someone to step up and take ownership of phillipkoebbe's great plugin DetectSyntax. I wasn't looking for another plugin to maintain because I have so many as is, but sadly, none of the many users wanted to actually take ownership. So seeing that it may fade away into oblivion (and I actually use this plugin), I decided to take it up. Per phillipkoebbe's request, I have renamed it to ApplySyntax which makes a bit more sense.

New Repo here:
https://github.com/facelessuser/ApplySyntax

ST3 Repo:
https://github.com/facelessuser/ApplySyntax/tree/ST3

I am adding the ST2 repo to PackageControl, and like most of my plugins right now, there is a separate repo for ST3.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Wed Mar 13, 2013 6:09 pm

I pushed a couple of fixes for ST3 version. Should be working better now if you were having issues.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Thu Mar 14, 2013 12:04 am

More windows fixes for ST3...now I need to look and see if some of these issues exist on the ST2 version...sigh.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Thu Mar 14, 2013 9:09 pm

A more sane approach to loading external plugins to determine a syntax has been added to the ST3 branch. This allows for cleaner plugins to ApplySyntax (though I am not really sure if people have written any besides the default is_rails_file.py).

Anyways, paths in the settings file must be Package relative. Example: "Packages/User/my_file" optionally if the plugin is within ApplySyntax you can just use the file name "my_file". All the other rules still apply with regards to function name vs file name etc. Again, I don't think many people are using this option, but I decided to clean it up on the ST3 branch.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Fri May 30, 2014 5:31 pm

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:

     "syntaxes": [
{
"name": "Makefile/Makefile",
"rules": [
- {"file_name": ".*\\.mak"}
+ {"extensions": ["mak"]}
]
},


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):

{
"apply_syntax_extensions":
[
"xml.dist"
],
"extensions":
[
"svg",
"xslt",
"xsd",
"xml.dist",
"xml"
]
}


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):
    "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"]}
]
},


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:
    // 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,
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Sat May 31, 2014 3:44 am

Better logic for experimental extension logic. ApplySyntax now won't add the same extension to multiple languages, but the last one in the list is the final one. It should also override existing extension settings properly.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ApplySyntax (was DetectSyntax) new maintainer

Postby facelessuser on Sat Jun 21, 2014 4:47 am

After more consideration, extensions has been moved out of rules a level up. So now to define extensions, put them as shown below:

        {
// 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",
"extensions": ["xml.dist"],
"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"]
//
]
},
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 9 guests