Skip to content

Instantly share code, notes, and snippets.

@ozeias
Forked from JeanMertz/syntax_highlighting.py
Created November 21, 2011 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozeias/1384286 to your computer and use it in GitHub Desktop.
Save ozeias/1384286 to your computer and use it in GitHub Desktop.
Ruby on Rails syntax highlight switcher for Sublime Text 2 #Packages/User
{
// "color_scheme": "Packages/Color Scheme - Default/Monokai Bright.tmTheme",
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"detect_indentation": true,
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
//"font_face": "inconsolata",
//"font_face": "consolas",
//"font_face": "mensch",
"font_face": "monaco",
"font_size": 12.5,
"highlight_line": true,
"match_brackets": true,
"match_brackets_angle": false,
"match_brackets_braces": true,
"match_brackets_content": true,
"match_brackets_square": true,
"save_on_focus_lost": true,
"scroll_past_end": true,
"tab_size": 2,
"detect_indentation": true,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": false,
"draw_indent_guides": true,
"fold_buttons": false,
"vintage_start_in_command_mode": false
}
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
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[-8:] == "_spec.rb":
set_syntax(view, "Rspec", "RSpec.tmbundle/Syntaxes")
elif name == "factories.rb":
set_syntax(view, "Rspec", "RSpec.tmbundle/Syntaxes")
elif name == "gemfile":
set_syntax(view, "Ruby on Rails", "Rails")
elif name[-2:] == "rb":
set_syntax(view, "Ruby on Rails", "Rails")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment