├── .gitignore ├── README.md └── ctags_autocomplete.py /.gitignore: -------------------------------------------------------------------------------- 1 | ctags_autocomplete.pyc 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ctags_autocompletion_sublime2 2 | ============================= 3 | 4 | ctags autocompletion for Sublime Text 2 5 | 6 | Inspired by @BlackMac (https://github.com/BlackMac) and his script => https://gist.github.com/1825401 7 | 8 | *ctags autocompletion works only after putting text longer than 2 chars. 9 | 10 | INSTALLATION: 11 | 12 | Just clone this repo into your Sublime Package folder. 13 | 14 | It requires: 15 | - ctags (http://ctags.sourceforge.net/, or brew install (osx)) 16 | - and .tags file into your project folder (can be generated by command "ctags -R -f .tags") 17 | 18 | -------------------------------------------------------------------------------- /ctags_autocomplete.py: -------------------------------------------------------------------------------- 1 | # CTags based autocompletion plugin for Sublime Text 2 2 | # You can add the file to the User Package in ~/Library/Application Support/Sublime Text 2/Packages and restart Sublime Text 2. 3 | # generate the .tags file in your project root with "ctags -R -f .tags" 4 | # show ctags results after putting text longer than 2 chars. 5 | 6 | 7 | import sublime, sublime_plugin, os 8 | 9 | class AutocompleteAll(sublime_plugin.EventListener): 10 | 11 | def on_query_completions(self, view, prefix, locations): 12 | if (len(prefix) > 2): 13 | tags_path = view.window().folders()[0]+"/.tags" 14 | results=[] 15 | if (not view.window().folders() or not os.path.exists(tags_path)): #check if a project is open and the .tags file exists 16 | return results 17 | 18 | f=os.popen("fgrep -i '"+prefix+"' '"+tags_path+"' | awk '{ print $1 }'") # grep tags from project directory .tags file 19 | for i in f.readlines(): 20 | results.append([i.strip()]) 21 | results = [(item,item) for sublist in results for item in sublist] #flatten 22 | results = list(set(results)) # make unique 23 | results.sort() # sort 24 | return results --------------------------------------------------------------------------------