Sublime Forum

Auto-complete on specified file with default code


Looking at some other plugins ( …, see def on_query_completions), to add to the auto complete list is to add words like:

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 generate_autocomplete_list_for_current_file() will be being called.

I’m wondering whether from plugins; we have access to a function like generate_autocomplete_list_for_file(filename/filebuffer), so to not have to re-write the parsing.


If lots of sublime-completions, then variable names never sh

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:

import re
code = view.substr(sublime.Region(0, view.size()))
words = set(re.findall(r'\b[A-Za-z_]\w+\b', code))



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

That’s alright though, cheers.