python - Emacs 中的 IPython。快速代码评估

标签 python shell emacs ipython

更新:这个问题还没有满意的答案。

我想将代码片段“发送”到 Emacs 23.2 (Linux) 中的 IPython 解释器。假设我已经在 Emacs 的缓冲区中启动了一个 IPython shell(例如使用 Python-mode.elIPython.el),是否有选择区域的方法在不同的缓冲区中并将该区域“发送”到已经启动的 IPython shell?

我试过 C-c C-c (send-buffer-to-shell) 和 C-c | (send-region-to-shell),但是这只是只要代码是用 Python 而不是 IPython 编写的(IPython 可以运行 Python 代码)。原因似乎是,对于这两个命令,Emacs 创建了一个带有 .py 扩展名(而不是 .ipy 扩展名)的临时文件,然后由 IPython 解释作为“特定于 Python 的代码”。这会阻止我使用 IPython 特定的功能 例如魔术命令。

另外,我还读到 Emacs 提供了 M-| ('shell-command-on-region') 在 shell 中运行选定的区域。要使用 IPython 解释器执行此操作,我尝试将 shell-file-name 设置为我的 IPython 路径。但是,当我在选择区域后运行 M-| 时,Emacs 会提示我以下内容:

Shell command on region:

如果我随后键入 RET,我会在 *Shell 命令输出* 缓冲区中获得 IPython 手册页,而不会执行该区域。是否有任何特定于 IPython 的命令可用于 M-| ('shell-command-on-region') 让 IPython 运行我的代码?

谢谢!

最佳答案

你在使用 ipython.el 吗? 它应该可以与 Emacs 23 一起工作。

如果没有,看看EmacsWiki: iPython Emacs 23 .

Emacs 上的 IPython Cookbook 中还有一节(搜索 IPythonEmacs23;抱歉,我不允许发布多个链接 :(

一旦你启动了一个 ipython-shell (C-c !),你就可以使用“Execute region ("C-c |")”从这个已经启动的 shell 中任何缓冲区的区域执行代码片段

安德烈亚斯

关于python - Emacs 中的 IPython。快速代码评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4542718/

相关文章:

python - 如何从 notebook 中找到 jupyter notebook 的版本

python - 如何修复属性错误: 'Web3' object has no attribute 'toChecksumAddress' ?

linux - 用于文件名路径列表的 mkdir 命令

vim - 文本编辑器和基于文本文件的超链接

python - 正则表达式提取多行散列注释

python提取特定帮助模块的信息

shell - 使用 gnuplot 将多个文件绘制到不同页面中的单个 ps 文件

java - 我怎样才能在 Emacs 中为 C++/Java 设置折叠?

emacs - 如何在 Clojure 模式下导航到当前缓冲区中的函数

python - 如何获取自在 praw 上发布帖子以来的时间