Mic*_*gge 2 python sublimetext sublimerepl
我正在使用Sublime Text 3并运行OSX Mavericks.我正在使用Sublime REPL包,我已经调整了该包的设置,以便我有"show_transferred_text":true
当打开Python REPL窗口时,我有一个很好的选择,可以使用Ctrl +,s从编辑器向它发送一大块代码.但是,除非我包含打印命令,否则这样做不会显示我的命令的任何输出.例如,如果我写下面的内容
x = 2.5
type(x)
并使用Ctrl +,,, s发送它进行评估,然后我得到这些命令的显示,但我没有得到类型(x)的输出显示,就像我将命令复制/粘贴到Mac终端中的Python解释器.
有没有办法在Sublime Text中获得此功能?
[UPDATE]
以下代码现已弃用.对于最新的,更好的工作版本,请访问https://gist.github.com/dantonnoriega/46c40275a93bab74cff6访问此插件的要点.
随意分叉和明星.随着代码的发展,我将在gist中添加任何更改.但是,为了保持最新状态,请关注以下回购:https: //github.com/dantonnoriega/sublime_text_plugins/blob/master/python_blocks_for_repl.py
***************
我想要相同的功能.我想出了什么作品,是以下帖子的大杂烩:
如何在sublime text 2编辑器中将一行传递给控制台
以下插件要求您在与代码相同的窗口中打开repl,但需要作为单独的组打开.我使用上面的第一个链接学会了如何做到这一点.为了发送你想要的文本,然后执行文本,我使用了上面第二个链接的想法并编写了以下插件(工具 - >新插件......)
class ReplViewAndExecute(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
ex_id = v.scope_name(0).split(" ")[0].split(".", 1)[1]
lines = v.lines(self.view.sel()[0]) # get the region, ordered
last_point = v.line(self.view.sel()[0]).b # get last point (must use v.line)
last_line = v.line(last_point) # get region of last line
for line in lines:
self.view.sel().clear() # clear selection
self.view.sel().add(line) # add the first region/line
text = v.substr(line)
print('%s' % text) # prints in console (ctrl+`)
if not line.empty() and text[0] != '#': # ignore empty lines or comments
v.window().run_command('focus_group', {"group": 1}) # focus REPL
v.window().active_view().run_command("insert",
{"characters": text})
v.window().run_command('repl_enter')
# if the last line was empty, hit return
# else, move the cursor down. check if empty, hit return once more
if last_line.empty():
self.view.sel().clear()
self.view.sel().add(last_line)
v.window().run_command('focus_group', {"group": 1}) # focus REPL
v.window().run_command('repl_enter')
v.window().run_command('focus_group', {"group": 0})
v.window().run_command('move', {
"by": "lines",
"forward": True,
"extend": False
})
else:
v.window().run_command('focus_group', {"group": 0})
v.window().run_command('move', {
"by": "lines",
"forward": True,
"extend": False
})
if self.empty_space():
v.window().run_command('focus_group', {"group": 1}) # focus REPL
v.window().run_command('repl_enter')
# move through empty space
while self.empty_space() and self.eof():
v.window().run_command('focus_group', {"group": 0})
v.window().run_command('move', {
"by": "lines",
"forward": True,
"extend": False
})
def eof(self):
v = self.view
s = v.sel()
return True if v.line(s[0]).b < v.size() else False
def empty_space(self):
v = self.view
s = v.sel()
return True if v.line(s[0]).empty() else False
Run Code Online (Sandbox Code Playgroud)
上面的代码将选定的行发送到REPL,聚焦包含REPL的组,执行REPL(即命中'enter')然后聚焦回代码窗口.
该插件现在自动将光标移动到下一行,以便您可以快速评估线条.此外,如果下一行恰好是空的,插件会一直自动点击"输入",直到遇到非空行.对我来说,这是关键,因为如果我在python中选择了一个功能块,我仍然需要切换到REPL并按Enter键才能完成该功能.while循环部分修复了这个问题.
要运行以下插件,我将以下内容放入我的用户密钥绑定中(我从上面的第3个链接中学到的)...
//REPL send and evaluate
{ "keys": ["super+enter"], "command": "repl_view_and_execute"}
Run Code Online (Sandbox Code Playgroud)
这应该工作!
记住,你需要
pydev插件执行此操作).'repl_view_and_execute'插件然后绑定它.如果有人知道如何制作一个更优雅的版本,可以在活动窗口和包含REPL视图的地方之间切换(就像另一个窗口),我欢迎这个建议.我完成了sublimerepl.py但无法弄清楚如何使用所有active_window()等命令.
| 归档时间: |
|
| 查看次数: |
1157 次 |
| 最近记录: |