【发布时间】:2021-08-13 20:25:51
【问题描述】:
【问题讨论】:
-
如何配置和启动 REPL?
-
和这里描述的差不多:stackoverflow.com/a/25002696/1391441
标签: sublimetext3 sublime-text-plugin sublimerepl
【问题讨论】:
标签: sublimetext3 sublime-text-plugin sublimerepl
在answer you linked 中,其中一个步骤是创建一个自定义插件来运行您的 virtualenv REPL。您可以通过更改repl_open 方法以传递"external_id" 键和值来自定义选项卡的标题。这是修改后的插件代码:
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
}
)
在这里您可以修改发送给插件的参数以定义选项卡的名称(默认为Python):
{
"keys": ["f6"],
"command": "project_venv_repl",
"args": {
"open_file": null,
"name": "My Project Name" // insert name of choice here.
}
},
【讨论】: