mirror of
https://github.com/zhigang1992/AutoFileName.git
synced 2026-01-12 22:45:57 +08:00
code cleanup
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user