Sublime Forum

Open Terminus REPL tab in a given group

#1

This thread Terminus Panel in a group says to use something like:

        self.window.run_command('terminus_open', {
            "pre_window_hooks": [["focus_group", {"group": 2}]]
            })

but it does not seem to work. Here’s my full script:

import sublime_plugin


class OpenTerminusReplCommand(sublime_plugin.TextCommand):
    def run(self, edit, open_file="$file"):
        # Save unsaved changes before proceeding
        window = self.view.window()
        for view in window.views():
            if view.is_dirty() and view.file_name():
                view.run_command("save")

        # Return the project's specified python interpreter, if any
        settings = self.view.settings()
        cmd_list = settings.get("python_interpreter")
        # Add file if given
        if open_file:
            cmd_list = [cmd_list, "$file"]

        target = 2  # Group where to open the REPL

        window.run_command(
            "terminus_open",
            {
                "cmd": cmd_list,
                "cwd": "$file_path",
                "title": "Terminus",
                "auto_close": False,
                "pre_window_hooks": [["focus_group", {"group": target}]],
            },
        )

The pre_window_hooks argument does nothing, The tabs with the REPL still open next to the tab from where I launched the command. These are my key bindings:

    // Run the file in a Python REPL using a Terminus
    { "keys": ["f5"], "command": "open_terminus_repl",
    },
    // Open an empty Python REPL using a Terminus
    { "keys": ["f4"], "command": "open_terminus_repl",
      "args": {"open_file": null},
    },
0 Likes