Skip to content

Instantly share code, notes, and snippets.

@nodtem66
Forked from BlackMac/ctags_autocomplete.py
Last active December 25, 2015 19:49
Show Gist options
  • Save nodtem66/7030948 to your computer and use it in GitHub Desktop.
Save nodtem66/7030948 to your computer and use it in GitHub Desktop.
# CTags based autocompletion plugin for Sublime Text 2
# You can add the file to the User Package in ~/Library/Application Support/Sublime Text 2/Packages and restart Sublime Text 2.
# generate the .tags file in your project root with "ctags -R -f .tags"
# Author nodtem66
# fork from: https://gist.github.com/BlackMac/1825401
import sublime, sublime_plugin, os
class AutocompleteAll(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
tags_path = view.window().folders()[0]+"/.tags"
results=[]
if (not view.window().folders() or not os.path.exists(tags_path)): #check if a project is open and the .tags file exists
return results
f=os.popen("awk \"tolower($1) ~ /^"+ prefix.lower() + "/ {++n;print $1;}\" " + tags_path) # grep tags from project directory .tags file
for i in f.readlines():
results.append([i.strip()])
results = [(item,item) for sublist in results for item in sublist] #flatten
results = list(set(results)) # make unique
results.sort() # sort
return results
@nodtem66
Copy link
Author

How to use this script

1 Install https://github.com/SublimeText/CTags
2 Open Sublime Text > Preferences > Browse Packages...
3 Put this script to that folder.

Requirement for Window

Test

  • If did not have .tags, build it with Ctrl-T Ctrl-R
  • Type something and use Ctrl-Space to see all autocompletes

@nodtem66
Copy link
Author

So now use original Sublime/CTags.
It's already have autocomplete with the original script.
However, It's didn't work because you must have awk and ctagsplugin.py code has a bug about window command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment