Home Download Buy Blog Forum Support

Auto-complete on specified file with default code

Auto-complete on specified file with default code

Postby GeorgeBlade on Fri Oct 25, 2013 4:43 pm

Looking at some other plugins (https://github.com/Zinggi/DictionaryAut ... omplete.py, see def on_query_completions), to add to the auto complete list is to add words like:

Code: Select all
def on_query_completions(self, view):
    autocomplete_list = ["word1", "word2"]
    return autocomplete_list # Returns words to use in auto-complete.


When a file is opened normally, autocomplete_list is filled by some amount of parsing. A function like
Code: Select all
generate_autocomplete_list_for_current_file()
will be being called.

I'm wondering whether from plugins; we have access to a function like
Code: Select all
generate_autocomplete_list_for_file(filename/filebuffer)
, so to not have to re-write the parsing.
GeorgeBlade
 
Posts: 2
Joined: Fri Oct 25, 2013 4:31 pm

Re: Auto-complete on specified file with default code

Postby lunixbochs on Sat Oct 26, 2013 9:08 am

Looks like Sublime's completion works on any words in the file (even inside strings). This will give you a pretty good list of words from a view, excluding ones that start with numbers:

Code: Select all
import re
code = view.substr(sublime.Region(0, view.size()))
words = set(re.findall(r'\b[A-Za-z_]\w+\b', code))
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Auto-complete on specified file with default code

Postby GeorgeBlade on Sun Oct 27, 2013 6:23 pm

Hm.

I figured there'd be some parsing based on the file language.

That's alright though, cheers.
GeorgeBlade
 
Posts: 2
Joined: Fri Oct 25, 2013 4:31 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests