我想对@user1936097 的答案进行快速编辑。
我复制了这个想法,但想改为加载 IPython(代码原样可以很好地加载标准 Python)。我换了...
self.window.run_command('repl_open',{"type": "subprocess",
"encoding": "utf8",
"cmd": ["python2.7", "-i", "-u", "$file"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python2.7"
})
和...
self.window.run_command('repl_open', {
"type": "subprocess",
"encoding": "utf8",
"autocomplete_server": true,
"cmd": ["python","-u","${packages}/SublimeREPL/config/Python/ipy_repl.py"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {
"PYTHONIOENCODING": "utf-8",
"SUBLIMEREPL_EDITOR": "$editor"}
})
但它没有用。
这条线"autocomplete_server": true
似乎是问题所在。如果我删除它,代码会运行,但 IPython 会打开关闭的。如果我离开它,什么都不会发生。
我终于借用了一个在文件中找到的命令/SublimeREPL/config/Python/Default.sublime-commands
并想出了...
self.window.run_command('run_existing_window_command', {
"id": "repl_python_ipython",
"file": "config/Python/Main.sublime-menu"
})
这使得最终的插件代码:
import sublime, sublime_plugin
class PydevCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('set_layout', {"cols":[0.0, 1.0], "rows":[0.0, 0.5, 1.0], "cells":[[0, 0, 1, 1], [0, 1, 1, 2]]})
self.window.run_command('run_existing_window_command', {
"id": "repl_python_ipython",
"file": "config/Python/Main.sublime-menu"
})
self.window.run_command('move_to_group', { "group": 1 })
将其分配给原始帖子中所示的键绑定,您现在将加载 IPython 而不是标准 Python!