Sublime Forum

DetectSyntax

#5

Hi Alex,

Rename ~/Application Support/Sublime Text 2/phillipkoebbe-DetectSyntax to ~/Application Support/Sublime Text 2/DetectSyntax and it should work. The function rule looks for the file in User/ and then DetectSyntax/ and because it didn’t find it, it raised an error. If you try it again with the twig rule after the function rule, and view your console, you should see it. When I wrote the function processing part, I originally had exception handling in there to catch stuff like that and just return false, but then I decided to remove that in favor of letting the exceptions bubble up so those writing functions would get feedback when things didn’t work right. I think I’ll add an option in the settings that controls whether exceptions are handled gracefully or bubble up. I’ll default to handling errors properly so the average user won’t experience this problem.

I will also look for a way to determine the plugin’s directory at runtime. That would have also avoided your pain.

Thanks for helping work out the bugs!

0 Likes

#6

The Package Control Channel has an option to name your package, that way everyone has the same folder name for your package and eliminating these problems.

0 Likes

#7

I saw that when I was adding the package to the repository but I thought it was primarily for when your repository has one thing but you want the package to show up as something else. The GitHub repository name is the same as what I’d like the package to be. Either way, it isn’t available in Package Control yet. I’ve submitted a pull request, but have not received a response.

I think, in this case, the package was downloaded from GitHub. When I download it by clicking the ZIP icon, it comes down as phillipkoebbe-DetectSyntax.zip. Unzipping in the Packages directory would place it in the wrong directory. It would just add a nice bit of user-friendliness if I could determine the directory at runtime.

0 Likes

#8

I added an option (reraise_exceptions) to the settings file which controls whether the function rule will fail silently and just return False or reraise any exception encountered. Default is false, don’t reraise exceptions. If you work on a function rule, though, you should turn reraise_exceptions on while developing so you’ll know why it fails (if it does). Once satisfied that your function works correctly, you can then turn reraise_exceptions off again.

0 Likes

#9

Totally awesome! I am going to retire SetSyntax, this is much better.

0 Likes

#10

Considering I got the idea of using a settings file from SetSyntax, that is really saying something!

Thank you for the kind words. I’m humbled.

0 Likes

#11

I have an issue with this plugin. Not working for me on (I am on Windows 7 x64)
When I run Sublime I receive this error:

Error loading syntac file “Packages\PHP\PHP.tmLanguage”:
Error parsing plist xml: Failed to open file in file “Packages\PHP\PHP.tmLanguage”

Any ideas what wrong?

0 Likes

#12

[quote=“sbloom”]I have an issue with this plugin. Not working for me on (I am on Windows 7 x64)
When I run Sublime I receive this error:

Error loading syntac file “Packages\PHP\PHP.tmLanguage”:
Error parsing plist xml: Failed to open file in file “Packages\PHP\PHP.tmLanguage”

Any ideas what wrong?[/quote]

Hi sbloom,

Sorry it’s not working correctly for you. I don’t have access to windows 7, but I think I know what’s going on. In the default settings file where the syntax rules are defined, I use a forward slash to separate path from name, and I’m thinking that Windows doesn’t like that. So I made a small change to normalize the string before doing some more work on it, and I’m hopeful it will work for you. I pushed the change to GitHub, so the next time Package Control updates, you should get the fix. If it still doesn’t work, please let me know. If nothing else, I’ll install ST2 on XP and see what happens.

0 Likes

#13

[quote=“phillip.koebbe”]
Hi sbloom,

Sorry it’s not working correctly for you. I don’t have access to windows 7, but I think I know what’s going on. In the default settings file where the syntax rules are defined, I use a forward slash to separate path from name, and I’m thinking that Windows doesn’t like that. So I made a small change to normalize the string before doing some more work on it, and I’m hopeful it will work for you. I pushed the change to GitHub, so the next time Package Control updates, you should get the fix. If it still doesn’t work, please let me know. If nothing else, I’ll install ST2 on XP and see what happens.[/quote]

Hi,
Thanks for trying to fix this. I think your plugin is awesome. Only if I had a chance to try it heh :smile:
Unfortunately latest update still not working to me, I get same error.

Update: the odd thing about it, that I can’t get rid of that error now, even after disabling/deleting DetectSyntax. Really weird.

0 Likes

#14

[quote=“sbloom”]
Hi,
Thanks for trying to fix this. I think you plugin is awesome. Only if I had a chance to try it heh :smile:
Unfortunately latest update still not working to me, I get same error.[/quote]

Well, that’s certainly disheartening :frowning:

It will be tonight before I’ll have a chance to take another look at it, but I’ll get it fixed as soon as I can. Thanks for the encouragement!

0 Likes

#15

I was able to test on Windows XP in a virtual machine. I changed the use of os.path.sep to a forward slash when building the name of the syntax file that is given to ST2. It worked as expected. I pushed the changes out so if you update the plugin (or when Package Control updates it), it should work now.

As always, please let me know if it doesn’t. I’m sorry for the inconvenience.

0 Likes

#16

Great plugin! Thanks Phillip!

I was having the same problems as sbloom (I’m also on Win7), but your latest update fixed all of the problems and I’m now able to automatically load extensionless Apache config files with the correct syntax. Thanks again!

0 Likes

#17

Thanks for a fix!

0 Likes

#18

I have installed the plugin, and copied over the DetectSyntax.sublime-settings into my User folder. I changed default_syntaxes to syntaxes.

But all my rails files are still being ?detected? as plain Ruby files.

Did I miss a step? Do the default rules not detect rails? Do I have to add a rule?

0 Likes

#19

Installing the plugin should have been all you needed to do. Well, maybe restarting ST2. You only need to have a copy of DetectSyntax.sublime-settings in your User folder if you want to add your own rules. By default, DetectSyntax should identify *.rb files in a Rails directory structure and set the syntax to Ruby on Rails.

What platform are you on? What is the path to the Rails project? Is there a Rails.root/config/routes.rb (that’s what DetectSyntax looks for to determine if it’s a Rails project). Do you have any non-ascii characters in your path?

0 Likes

#20

I am on W7.

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

I do have a config/routes.rb folder. What does it look relative to? I started ST2 from start menu, then choose open recent projects. My project file lives in the root of the rails project directory.

C:\Users\myname\Code\SyncCode\MyProj

I removed the settings file from my User directory, and restarted ST2. But opening a model_obj.rb file still shows Ruby syntax, as opposed to Ruby on Rails.

ps - how the heck do you get notified of replies in this forum?

0 Likes

#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