Sublime Forum

DetectSyntax

#21

Interestingly enough, everything seems to work fine on my Mac.

0 Likes

#22

Sadly, you don’t.

[quote=“sheamus”]I am on W7.

Path to rails project should be all ascii, it doesn’t even have spaces.
[/quote]

I just wanted to check. I was just dealing with a problem on Windows 7 where the username was in Russian and I was failing to get the unicode version of a directory. [There will be a fix for that later today]

The logic for determining if a file belongs to a Rails project is defined in Packages/DetectSyntax/is_rails_file.py, but the gist is it starts at the folder the file is in and looks for ./config/routes.rb. If it doesn’t find one, it steps up the directory structure, looking at each level along the way. It’s a bit of a hack, but I couldn’t think of a better way to do it at the time. If you happen to have C:\config\routes.rb for some reason, all of your .rb files could be mis-identified as Rails files. I took the chance that no one would reasonably have a config/routes.rb outside of a Rails project.

Are there any errors in the console when you switch to a Rails file?

0 Likes

#23

Hi, for some reason {“file_name”: “^wscript$”} or just “wscript” doesn’t work to enable python mode, but the following with first_line works and matches things like “#!/usr/bin/env python” which often is in there.
Bug or am I doing it wrong?

{“name”: “Python/Python”,
“rules”:
{“first_line”: “.python.”}]}

0 Likes

#24

[quote=“datgame”]Hi, for some reason {“file_name”: “^wscript$”} or just “wscript” doesn’t work to enable python mode, but the following with first_line works and matches things like “#!/usr/bin/env python” which often is in there.
Bug or am I doing it wrong?

{“name”: “Python/Python”,
“rules”:
{“first_line”: “.python.”}]}[/quote]

The regex ‘^wscript$’ anchors and the beginning and end, so the file_name would have to be ‘wscript’ to match. However, file_name in a view includes the full path to the file, so it would be /some/path/to/the/file/wscript. If you want to match a file named wscript in any location, the regex should be something like ‘*wscript$’. Try that and see if it works.

0 Likes

#25

Actually, I think the regex should be

.*/wscript$

I forgot the ‘.’ and not having the slash (or the appropriate characters for whatever platform you are on) would also match

/some/path/to/anotherwscript

when you really only want to match

/some/path/to/wscript

0 Likes

#26

Thanks, “.*wscript$” works fine.

I’m on all platforms, so using explicit slashes wouldn’t work, unless something handled that in sublime perhaps.
I didn’t know the regex checked the whole path string.
“wscript” are build rule files for the WAF buildsystem. All python.

0 Likes