Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocomplete suggestion #407

Open
ta946 opened this issue Nov 8, 2023 · 0 comments
Open

autocomplete suggestion #407

ta946 opened this issue Nov 8, 2023 · 0 comments

Comments

@ta946
Copy link

ta946 commented Nov 8, 2023

I couldnt get autocomplete working with terminus. i assume its because of the insert method.

I've come up with a hacky workaround and figured id share incase it helps someone.

When the custom autocomplete command is run, it copies the word at the terminus cursor to an input panel and shows sublime's autocomplete list.
Then you can select the autocomplete and modify as usual.
Then pressing enter will delete the word from terminal and insert the finalized autocompletion

i added the following keybind
{ "keys": ["ctrl+space"], "command": "terminus_autocomplete", "context": [{"key": "terminus_view"}] }

and created teminus_autocomplete.py in Packages/User folder

import sublime
import sublime_plugin


class TerminusAutocompleteCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if not self.view.settings().get("terminus_view"):
            return
        self.view.run_command("terminus_show_cursor")
        if len(self.view.sel()) != 1:
            return
        self._do_delete_word = False
        word = ''
        region = self.view.word(self.view.sel()[0])
        if not region.empty():
            word = self.view.substr(region)
            if word in ('>', '$'):
                self._do_delete_word = True
            else:
                word = ''
        input_panel_view = self.view.window().show_input_panel('terminus autocomplete', word, self.on_done, self.on_change, self.on_cancel)
        input_panel_view.settings().set('syntax', 'Packages/User/shell.tmLanguage')
        if word:
            input_panel_view.run_command("auto_complete")

    def on_change(self, value):
        pass

    def on_cancel(self):
        pass

    def on_done(self, value):
        if not value:
            return
        if self._do_delete_word:
            self.view.run_command("terminus_delete_word")
        self.view.run_command("terminus_paste_text", args={"text": value})

i have my snippet scope as source.shell so i set the input_panel syntax to shell.tmLanguage to limit the autocompletes. but thats not a required step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant