Search code examples
sublimetext3sublime-text-pluginsublimerepl

Modify title of SublimeREPL in tab


I'm using the SublimeREPL package. The title in the tab where the code is running is very long and makes navigating the tabs a hassle:

enter image description here

Can the title shown in the REPL tab be modified and/or suppressed all together?


Solution

  • In the answer you linked, one of the steps was to create a custom plugin to run your virtualenv REPL. You can customize the tab's title by changing the repl_open method to pass an "external_id" key and value. Here is the modified plugin code:

    import sublime_plugin
    
    
    class ProjectVenvReplCommand(sublime_plugin.TextCommand):
        """
        Starts a SublimeREPL, attempting to use project's specified
        python interpreter.
        """
    
        def run(self, edit, open_file='$file', name='Python'):
            """Called on project_venv_repl command"""
            cmd_list = [self.get_project_interpreter(), '-i', '-u']
    
            if open_file:
                cmd_list.append(open_file)
    
            self.repl_open(cmd_list=cmd_list, name=name)
    
        def get_project_interpreter(self):
            """Return the project's specified python interpreter, if any"""
            settings = self.view.settings()
            return settings.get('python_interpreter', '/usr/bin/python')
    
        def repl_open(self, cmd_list, name):
            """Open a SublimeREPL using provided commands"""
            self.view.window().run_command(
                'repl_open', {
                    'encoding': 'utf8',
                    'type': 'subprocess',
                    'cmd': cmd_list,
                    'cwd': '$file_path',
                    'syntax': 'Packages/Python/Python.sublime-syntax',
                    'external_id': name
                }
            )
    

    And here you can modify the arguments you send to the plugin to define the tab's name (the default being Python):

    {
        "keys": ["f6"],
        "command": "project_venv_repl",
        "args": {
            "open_file": null,
            "name": "My Project Name"  // insert name of choice here.
        }
    },