Created
January 13, 2012 19:35
-
-
Save liamcain/1608287 to your computer and use it in GitHub Desktop.
Autocomplete Filenames in Sublime Text 2
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
import sublime, sublime_plugin, os, re | |
class FileNameComplete(sublime_plugin.EventListener): | |
def on_query_completions(self, view, prefix, locations): | |
completions = [] | |
sel = view.sel()[0].a | |
if "string" in view.syntax_name(sel): | |
pass | |
elif "./" in view.substr(sublime.Region(sel-3,sel)): | |
pass | |
else: | |
return [] | |
this_file = view.file_name() | |
dir_len = this_file.rfind('/') #(for OSX) | |
if not dir_len > 0: | |
dir_len = this_file.rfind('\\') #(for Windows) | |
this_dir = this_file[:(dir_len + 1)] # + 1 for the '/' | |
this_dir += view.substr(view.extract_scope(sel-1)).replace('\"','') # strings are quoted | |
print this_dir | |
dir_files = os.listdir(this_dir) | |
for d in dir_files: | |
if not '.' in d: | |
d += '/' | |
completions.append(d) | |
return [(x, x) for x in list(set(completions))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where I bout this is the file?