-
-
Save BlackMac/1825401 to your computer and use it in GitHub Desktop.
Hey there ;)
Nice piece of code.
Since i'm not very fluent in python and the command line for regex operations, may I ask you a question :
Is it possible to return function's argument like so : fonction_name($args1, $arg2, $so_on)
Thanks a lot!
Awesome!!
:) You could make a plugin of it and add it to package controle to sublime! (http://wbond.net/sublime_packages/package_control)
Br,
Grzegorz
How to run this under windows?
You can use this improved version (for windows) to look in all your project folders. Also you will need to download Grep and Gawk for windows (http://gnuwin32.sourceforge.net/packages.html) and add the installed folder to your system PATH and restart windows before try it.
# 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"
import sublime, sublime_plugin, os, subprocess
class AutocompleteAll(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
results=[]
tags_paths = [folder + '/.tags' for folder in view.window().folders()]
for tags_path in tags_paths:
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
tags_paths = ' '.join([str(x) for x in tags_paths])
f=os.popen('grep -ih "^'+prefix+'" ' + tags_paths + ' | gawk "{ print $1 }"') # egrep 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
You can use this improved version (for windows) to look in all your project folders. Also you will need to download Grep and Gawk for windows (http://gnuwin32.sourceforge.net/packages.html) and add the installed folder to your system PATH and restart windows before try it.
# 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"
import sublime, sublime_plugin, os, subprocess
class AutocompleteAll(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
results=[]
tags_paths = [folder + '/.tags' for folder in view.window().folders()]
for tags_path in tags_paths:
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
tags_paths = ' '.join([str(x) for x in tags_paths])
f=os.popen('grep -ih "^'+prefix+'" ' + tags_paths + ' | gawk "{ print $1 }"') # egrep 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
You can use this improved version (for windows) to look in all your project folders. Also you will need to download Grep and Gawk for windows (http://gnuwin32.sourceforge.net/packages.html) and add the installed folder to your system PATH and restart windows before try it.
# 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"
import sublime, sublime_plugin, os, subprocess
class AutocompleteAll(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
results=[]
tags_paths = [folder + '/.tags' for folder in view.window().folders()]
for tags_path in tags_paths:
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
tags_paths = ' '.join([str(x) for x in tags_paths])
f=os.popen('grep -ih "^'+prefix+'" ' + tags_paths + ' | gawk "{ print $1 }"') # egrep 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
sdf
It works, but it's a bit slow for big tags files. I wonder if there's something from the actual ctags plugin you might be able to use to speed it up?
removing -i improves performance considerably, see my fork if needed.
I am the maintainer of the CTags plugin. It would be by far best to integrate this into that plugin, rather than use a separate one. It keeps a dict loaded in RAM, and also sorts the tags file for easier lookup.
It already has a command to list all tags in the quick panel. I think this could tack onto that pretty easily. It just needs to load this list into the completions. I also had filed ticket to add support for ./-> completions (SublimeText/CTags#75). That will be a bit more involved, but along the same vein, and definitely desirable.
I tried this and got ctags: illegal option -- R
in Terminal.
@barneywilliams gettings this in CTags would be great.
Cool! It's great !
@Grawl this is because you are using the Mac OS X shipped version of ctags
. Install ctags
from homebrew and use the one located at /usr/local/bin/ctags
.
You can add the file to the User Package in ~/Library/Application Support/Sublime Text 2/Packages and restart Sublime Text 2. Don't forget to generate the .tags file as explained in the comments.