Sublime Forum

Macro to close auto_complete and do down does not work

#1

Hi Folks,
I am trying to create a keybind for quitting the auto complete window and going down a line.

If I execute this macro:
[
{“command”: “hide_auto_complete” },
{“command”: “move”, “args”: {“by”: “lines”, “forward”: true } },
]

with this keybind:
{ “keys”: [“alt+j”], “command”: “run_macro_file”, “args”: {“file”: “Packages/User/makros/closeAutocompleteAndDown.sublime-macro”}, “context”: [{“key”: “auto_complete_visible”, “operator”: “equal”, “operand”: true}] },

I have to press it twice to work. The issue seems to be, that the auto complete window eats the move command.
There is one exception: When there is only one entry in the autocomplete window.

Things I tried:

  1. The multicommand and chain of command packages instead of using a macro, but the result was precisely the same.
  2. safe mode
  3. a different key (simply “j”)
  4. call the macro from the Tools menu

Any suggestions?

0 Likes

#2

It looks like hide_auto_complete is a asynchronous command since the following works.

import sublime
import sublime_plugin


class RunAsyncCommand(sublime_plugin.WindowCommand):
    """Run a given command asynchronously."""

    def run(self, command: str, args: dict = {}, wait: timeout_ms = 0) -> None:
        sublime.set_timeout_async(lambda: self.window.run_command(command, args), timeout_ms)
    {
        "keys": ["alt+q"],
        "command": "chain",
        "args": {
            "commands": [
                {"command": "hide_auto_complete" },
                {
                    "command": "run_async",
                    "args": {
                        "command": "move",
                        "args": {"by": "lines", "forward": true },
                    },
                },
            ],
        },
        "context": [
            {"key": "auto_complete_visible", "operator": "equal", "operand": true},
        ],
    },
2 Likes

#3

Wow, nice it works an you were so quick :slight_smile:
I didn’t even know there are async commands, but it makes a lot of sense. It would be nice to see it in the docs, though…

Just one small issue, it should read
def run(self, command: str, args: dict = {}, timeout_ms: int = 0) -> None:

And if somebody (like me) who did not create a plugin before wants to use this: Just store the python file as Packages/User/run_async.py and that’s it.
Thanks a lot!

PS: The “chain” command is provided by the “Chain of Command” package.

0 Likes

#4

Fwiw, it’s builtin as of ST 4.

1 Like

#5

Ah very nice, didn’t realize, thanks!

0 Likes