-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathsyntax_highlighting.py
34 lines (29 loc) · 1.25 KB
/
syntax_highlighting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 code 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", "User")
elif name == "factories.rb":
set_syntax(view, "RSpec", "User")
elif name == "gemfile":
set_syntax(view, "Ruby on Rails", "Rails")
elif name == "guardfile":
set_syntax(view, "Ruby on Rails", "Rails")
elif name[-3:] == ".rb":
set_syntax(view, "Ruby on Rails", "Rails")
elif name[-5:] == ".scss":
set_syntax(view, "SASS", "SASS/Syntaxes")
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)