Search code examples
pythonsublimetext3sublime-text-plugin

Sublime text 3 Custom command palette plugin


I'm trying to build a plugin whose commands are accessible on the command palette. The idea is that each command will ask for text input in the command palette and then present options which are then written to the view. How on Earth do I do this? There is no good documentation anywhere!

So far I have:

import sublime
import sublime_plugin   


class QueryListInput(sublime_plugin.ListInputHandler):
    def name(self):
        return "my_list"

But then I get: AttributeError: 'module' object has no attribute 'ListInputHandler' I research and find this answer, which tells me that only dev builds have access to this feature. Really? Does that mean my plugin won't work on regular builds?

All I want is:

  1. User opens command palette
  2. User selects MyCommand
  3. User types some text in the command palette
  4. User is presented with some options based on that text
  5. User selects one and it is written to sublime view

This is quite simple but I have found it to be quite difficult to accomplish. Thanks in advance if you can help!


Solution

  • The ListInputHandler and TextInputHandler features in particular are part of the new command palette that was released with build 3154 on November 11th. As of right now, it is still exclusive to the developer channel and the changes have not landed in the final release yet. But this is obviously just a matter of time.

    Plugins that are currently already offering the user a choice in the command palette do not use these two types for that purpose. Instead, they make use of window.show_quick_panel which works this:

    options = ['Foo', 'Bar', 'Baz']
    
    def on_done(index):
        if index >= 0:
            print('Selected option was', options[index])
    
    self.view.window().show_quick_panel(options, on_done)