Home Download Buy Blog Forum Support

Autocomplete Popup from plugin

Autocomplete Popup from plugin

Postby mpedrummer on Thu Mar 15, 2012 4:57 pm

Hi there -

I seem to be missing something - I've created an autocomplete plugin that works, but doesn't show the popup with the list of choices - only works to tab through the possibilities.

Is there a tutorial somewhere? Am I missing a setting? I started with the Google autocomplete example, and man, everything looks the same.

Here's the code:

Code: Select all
    import sublime_plugin, sublime, re
    class LangCompletions(sublime_plugin.EventListener):
        def on_query_completions(self, view, prefix, locations):
            pt = locations[0] - len(prefix) - 2
            ch = view.substr(sublime.Region(pt, pt + 2))
            if ch != '##':
                return []
            pattern  = re.compile( 'LG\_.' )
            if re.match( pattern, prefix ):
              handle   = file( 'text-file-with-LG_-stuff.txt', 'rb')
              pattern  = re.compile( prefix )
              results  = []
              for line in handle.readlines():
                match = re.match( pattern, line )
                if match:
                  langkey = line.split( '=' )
                  value   = langkey[0] + '##'
                  display = '##' + value
                  results.append( ( display, value ) )
              return results
            return 0

Anything missing?
Posts: 23
Joined: Thu Mar 08, 2012 9:50 pm

Re: Autocomplete Popup from plugin

Postby agibsonsw on Thu Mar 15, 2012 5:40 pm

The hash signs # are considered word separators:

Code: Select all
// Characters that are considered to separate words
"word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?",

and don't trigger the completions list. But you could leave this global setting, but try changing (copy first to your File Settings User, or Syntax specific)

Code: Select all
// Additional situations to trigger auto complete
"auto_complete_triggers": [ {"selector": "text.html", "characters": "<"} ],

It says 'characters' so perhaps you can type '##' in place of '<'.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 8 guests