facelessuser / ApplySyntax

Syntax detector for Sublime Text
https://facelessuser.github.io/ApplySyntax/
343 stars 48 forks source link

Path file : Exclude files in subdirectories #111

Closed zimxavier closed 7 years ago

zimxavier commented 7 years ago

Hi,

I would like to associate files at the root of the folder countries with a syntax file, and files in the subdirectory flags with another one. Unfortunately, I don't master the required syntax and ST load files in flags with the syntax highlighting for countries.

Game\common\countries\

        {
            "syntax": [
                "User/Game_Syntaxes/Game_txt_countries",
            ],
            "rules": [
                {"file_path": ".*\\\\Game\\\\common\\\\countries\\\\.*\\.txt$"}
            ]
        },

        {
            "syntax": [
                "User/Game_Syntaxes/Game_txt_flags",
            ],
            "rules": [
                {"file_path": ".*\\\\Game\\\\common\\\\countries\\\\flags\\\\.*\\.txt$"}
            ]
        },

How can I exclude files in subdirectories?

Thank you for your plugin :) And for any help.

zimxavier commented 7 years ago

Hm. I just found the solution, I guess. Sorry. "file_path": ".*\\\\Game\\\\common\\\\countries\\.txt$"

zimxavier commented 7 years ago

It appears I spoke too soon. The syntax highlighting for the files at the root of countries is not loaded. Any help?

facelessuser commented 7 years ago

The reason why flags get rendered with countries syntax is because of your regex. This is not a problem with ApplySyntax. You have a regex that grabs any file under countries (even files under flags). And since that rule comes before the flags rule, it will always consume files under flags.

{"file_path": ".*\\\\Game\\\\common\\\\countries\\\\.*\\.txt$"}

Notice you path uses things like countries\\\\.*\\.txt which says you'll take any file under countries. Even countries\flags\somefile.txt because you used .* which grabs any character. If you used something like [^\\]* you would avoid anything under countries with \ (like folders).

zimxavier commented 7 years ago

Apparently, [^\\]* doesn't work. [^\\\\]* works though: {"file_path": ".*\\\\Game\\\\common\\\\countries\\\\[^\\\\]*\\.txt$"}

Thank you.

facelessuser commented 7 years ago

Yeah, sorry. That's what I meant.