Search code examples
sublimetextsublime-text-pluginpackage-control

Move cursor after selected an item in autocompletion list


I implemented a Autocompletion plugin for SublimeText

import sublime_plugin
import sublime

tensorflow_functions = ["tf.AggregationMethod()","tf.Assert()","tf.AttrValue()","tf.AttrValue.ListValue()", etc...]

class TensorflowAutocomplete(sublime_plugin.EventListener):

    def __init__(self):

        self.tf_completions = [("%s \tTensorflow" % s, s) for s in tensorflow_functions]

    def on_query_completions(self, view, prefix, locations):

        if view.match_selector(locations[0], 'source.python'):
            return self.tf_completions
        else:
            return[]

Is there any ways I can move the cursor into the parenthesis when the user selected an item in the autocompletion list? I didn't tried anything because I can't find what I want in the API documentation.


Solution

  • You can just use snippets in the completions, so you change tf.Assert() to tf.Assert($1) (jump out with tab) or tf.Assert($0)

    If all parens are empty you can just change your code to:

    self.tf_completions = [("%s \tTensorflow" % s, s.replace("()", "($1)") for s in tensorflow_functions]