-
-
Save olivierlacan/1183724 to your computer and use it in GitHub Desktop.
# ======================================================================================= # | |
# NOTE: This is relatively outdated, you should use the DetectSyntax package | |
# from Package Control instead: http://wbond.net/sublime_packages/community#sort-installs | |
# ======================================================================================= # | |
# Instructions: put this inside of the following folder on a Mac: | |
# /Users/<yourusername>/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/ | |
# ======================================================================================= # | |
import sublime, sublime_plugin | |
import os | |
class DetectFileTypeCommand(sublime_plugin.EventListener): | |
def on_load(self, view): | |
filename = view.file_name() | |
if not filename: # buffer has never been saved | |
return | |
name = os.path.basename(filename.lower()) | |
if name[-2:] == "rb": | |
set_syntax(view, "Ruby on Rails", "Rails") | |
elif name[-7:] == "gemfile": | |
set_syntax(view, "Ruby", "Ruby") | |
elif name[-4:] == "haml": | |
set_syntax(view, "Ruby Haml", "Ruby Haml") | |
elif name[-4:] == "sass": | |
set_syntax(view, "SASS", "SASS/Syntaxes") | |
elif name[-9:] == "guardfile": | |
set_syntax(view, "Ruby", "Ruby") | |
elif name[-2:] == "ru": | |
set_syntax(view, "Ruby", "Ruby") | |
elif name[-9:] == "coffeekup": | |
set_syntax(view, "CoffeeKup", "CoffeeKup") | |
def set_syntax(view, syntax, path=None): | |
if path is None: | |
path = syntax | |
view.settings().set('syntax', 'Packages/'+ path + '/' + syntax + '.tmLanguage') | |
print "Switched syntax to: " + syntax |
I've found that if you aren't specifically working on a ruby file this script likes to set the syntax of say a python file to Ruby i modified the script a lil bit to prevent this thanks for the script!!!!
Btw it seems it specifically has to do with the Gemfile line heres the modified script.
https://gist.github.com/1212295
Good fix, the RSpec stuff was breaking anyway, took it out. Added your line for gemfile
with an additional one for guardfile
I've updated this script to work with https://github.com/n00ge/sublime-text-haml-sass
For some reason Sass files were incorrectly detected as Ruby Haml.
where does this go?
Please note that you should probably be using the DetectSyntax package from Package Control instead of this outdated hack.
Hi,
My .sass
files were being detected as Ruby Haml
syntax. I found your script and tried by using DetectSyntax on ST2.
Unfortunately its still failing on detection. I tried to add a Sass
rule in the user configurations for the plugin but it doesn't seem to work also.
(...)
{
"name": "Sass",
"rules": [
{"file_name": ".*\\.sass$"}
]
}
(...)
Do you have anything to share?
Added Guardfile support for the wonderful Guard by @thibaudgg