Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying to set a completions for Grails Domain classes
- Loading branch information
1 parent
7445b4a
commit 2c5a5eb
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"scope": "source.groovy.grails.domain", | ||
"completions": [ | ||
{ | ||
"trigger": "ArrayBuffer();" | ||
}, | ||
{ | ||
"trigger": "zlib.inflateRaw(buffer, callback);", | ||
"contents": "zlib.inflateRaw(${1:buffer}, ${2:callback});$0" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>fileTypes</key> | ||
<array> | ||
<string>groovy</string> | ||
</array> | ||
<key>keyEquivalent</key> | ||
<string>^~G</string> | ||
<key>name</key> | ||
<string>Grails Domain (Groovy)</string> | ||
<key>patterns</key> | ||
<array> | ||
<dict> | ||
<key>include</key> | ||
<string>source.groovy</string> | ||
</dict> | ||
</array> | ||
<key>scopeName</key> | ||
<string>source.groovy.grails.domain</string> | ||
<key>uuid</key> | ||
<string>5EE8A923-863E-499D-A136-9B0DF5FDC8AD</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import sublime, sublime_plugin | ||
import os, string, re | ||
|
||
ST2_dir = os.path.dirname(os.path.dirname(os.getcwdu())) | ||
|
||
class GrailsSyntaxCommand(sublime_plugin.EventListener): | ||
""" Attempts to set Grails Syntax when appropriate. """ | ||
|
||
|
||
def __init__(self): | ||
super(GrailsSyntaxCommand, self).__init__() | ||
self.path = None | ||
self.name = None | ||
self.ext = None | ||
self.view = None | ||
|
||
|
||
def on_load(self, view): | ||
self.check_syntax(view) | ||
|
||
|
||
def on_post_save(self, view): | ||
self.check_syntax(view) | ||
|
||
|
||
def check_syntax(self, view): | ||
self.view = view | ||
self.file_name = view.file_name() | ||
|
||
if not self.file_name: # buffer has never been saved | ||
return | ||
|
||
self.reset_cache_variables() | ||
|
||
if not self.ext == '.groovy': | ||
print "Not Groovy file - GrailsSyntax exiting" | ||
return | ||
|
||
if self.is_domain(): | ||
self.set_syntax('Python Django', 'Djaneiro') | ||
return | ||
else: | ||
self.set_syntax('Python', 'Python') | ||
return | ||
|
||
|
||
def is_django(self): | ||
if self.view.find('from django',0,sublime.IGNORECASE) > -1: | ||
return True | ||
return False | ||
|
||
|
||
def reset_cache_variables(self): | ||
self.path = os.path.dirname(self.file_name) | ||
self.name = os.path.basename(self.file_name).lower() | ||
self.name, self.ext = os.path.splitext(self.name) | ||
|
||
|
||
def set_syntax(self, syntax, path = None): | ||
if path is None: | ||
path = syntax | ||
|
||
new_syntax = 'Packages/' + path + '/' + syntax + '.tmLanguage' | ||
|
||
if not os.path.exists(os.path.join(ST2_dir, new_syntax)): | ||
new_syntax = 'Packages/' + path + '/Syntaxes/' + syntax + '.tmLanguage' | ||
current_syntax = self.view.settings().get('syntax') | ||
|
||
if current_syntax != new_syntax: | ||
self.view.settings().set('syntax', new_syntax) | ||
print "Switched syntax to: " + syntax |