code cleanup

This commit is contained in:
Liam Cain
2012-04-20 17:18:28 -04:00
parent db1f754abb
commit bd2e0b36f9

View File

@@ -6,8 +6,15 @@ class FileNameComplete(sublime_plugin.EventListener):
sel = view.sel()[0].a
return string in view.substr(sublime.Region(sel-1, sel))
def in_empty_string(self,view,sel):
string = view.substr(view.extract_scope(sel))
if string.startswith(("'","\"")):
string = string[1:-1]
return len(string) == 0
def on_query_completions(self, view, prefix, locations):
completions = []
valid_scopes = ["string", "css", "sass", "scss"]
backup = []
for x in view.find_all("[a-zA-Z]+"):
@@ -15,20 +22,12 @@ class FileNameComplete(sublime_plugin.EventListener):
sel = view.sel()[0].a
if self.prev_has(view, '/') or self.prev_has(view, '\\\\'):
if "string" in view.scope_name(sel):
pass
elif "css" in view.scope_name(sel):
pass
elif "sass" in view.scope_name(sel):
pass
else:
return backup
else:
if not any(s in view.scope_name(sel) for s in valid_scopes):
return backup
if not self.in_empty_string(view,sel) or self.prev_has(view, '/') or self.prev_has(view, '\\\\'):
return backup
this_dir = os.path.split(view.file_name())[0] + os.path.sep
cur_path = view.substr(view.extract_scope(sel-1)).replace('\r\n', '\n').split('\n')[0]
if cur_path.startswith(("'","\"")):
@@ -45,4 +44,4 @@ class FileNameComplete(sublime_plugin.EventListener):
return [(x, x) for x in list(set(completions))]
except OSError:
print "AutoFileName: could not find " + this_dir
return []
return backup