C-c C-c python-shell-send-buffer
C-c C-d python-describe-at-point
C-c C-f python-eldoc-at-point
C-c C-j imenu
C-c C-l python-shell-send-file
C-c C-p run-python
C-c C-r python-shell-send-region
C-c C-s python-shell-send-string
C-c C-t Prefix Command
C-c C-v python-check
C-c C-z python-shell-switch-to-shell
C-c < python-indent-shift-left
C-c > python-indent-shift-right
C-c C-t c python-skeleton-class
C-c C-t d python-skeleton-def
C-c C-t f python-skeleton-for
C-c C-t i python-skeleton-if
C-c C-t m python-skeleton-import
C-c C-t t python-skeleton-try
C-c C-t w python-skeleton-while
查看PythonShell发送缓冲区的帮助(通过单击它),我们看到:
python-shell-send-buffer is an interactive compiled Lisp function in
‘python.el’.
(python-shell-send-buffer &optional SEND-MAIN MSG)
Send the entire buffer to inferior Python process.
When optional argument SEND-MAIN is non-nil, allow execution of
code inside blocks delimited by "if __name__== '__main__':".
When called interactively SEND-MAIN defaults to nil, unless it’s
called with prefix argument. When optional argument MSG is
non-nil, forces display of a user-friendly message if there’s no
process running; defaults to t when called interactively.
如果您使用的是emacs24,这应该是默认值(在emacs23中,您需要python.el,而不是python mode.el):
在python缓冲区中:
默认的python shell是“python”,如果需要使用ipython,可以在.emacs中使用此配置
如果您的系统中安装了ipython,当然:)
ipython>;=5有一个自动完成功能,它可以断开emacs子外壳,您可以通过更改这一行来解决这个问题
python-shell-interpreter-args "--colors=Linux --profile=default"
并添加--simple-prompt
。它将允许您正确地看到ipython,但由于某些原因,我还没有得到emacs中的自动完成功能,它不如以前那么有效。
我正在运行Emacs 26,vanilla dev版本(从Savannah克隆的源代码中自行编译)。
(注意,在emacs文档中,我们通常看到,例如,Ctrl-c表示为c-c)
在Python模式下(我通常通过使用C-xc-f“查找”以.py结尾的(可能是新的)文件来进入该模式),可以使用启动Python shell,然后执行缓冲区的
if __name__ == '__main__':
使用:C-C C-p(它执行run python以创建一个具有次python主模式、shell Compile次模式的shell)
C-u C-C C-C(使用前缀参数执行python shell发送缓冲区)
我们需要prefix参数将
if __name__ == '__main__':
块发送到下一个Python shell。我们可以看到所有的Ctrl-c命令和Ctrl-c?
查看PythonShell发送缓冲区的帮助(通过单击它),我们看到:
根据docsC-u是一个前缀参数,似乎是最通用的参数。
避免使用前缀参数C-u的解决方法是使用括号:
而不是通常的:
然后C-C C-C自己执行主功能。
在我看来,M-!和M-&;被低估。通常你只想启动当前正在运行的脚本,不需要把事情复杂化。
当然,只要不需要提供交互输入,就可以使用
M-x compile
。如果您必须提供交互式输入,M-x shell
是您的朋友。如果您想用一个按键来运行数据,请查看F3和F4来录制键盘宏并重放它(宏也可以绑定到键,例如F5)。
在每一种情况下,都没有“魔法”发生。Emacs不知道如何“编译”或“运行”python脚本。必须提供/覆盖合理的命令行调用,例如:
python子shell很酷,其中REPL开发风格很有意义,但至少在Windows
matplotlib
、tkinter
和其他必须处理Windows消息循环的库中,显示GUI元素时往往会阻塞/挂起。相关问题 更多 >
编程相关推荐