假设我用M-x ansi-term在Emacs中打开了一个终端模拟器。这将使用我选择的shell在Emacs中打开一个缓冲区。假设我随后从这个shell运行ipython。我能用Emacs中的Python代码从另一个缓冲区向这个ipython会话发送代码吗?如果是这样的话,是怎么做的?
发布于 2012-11-19 07:31:58
(defun send-buffer-to-ipython ()
"Send current buffer to the running ipython process."
(interactive)
(let* ((ipython-buffer "*ansi-term*") ; the buffer name of your running terminal
(proc (get-buffer-process ipython-buffer)))
(unless proc
(error "no process found"))
(save-buffer)
(process-send-string proc
(format "execfile(\"%s\")\n" (buffer-file-name)))
(pop-to-buffer ipython-buffer) ; show ipython and select it
;; (display-buffer ipython-buffer) ; show ipython but don't select it
))然后将命令send-buffer-to-ipython绑定到您喜欢的任何键。我将它绑定到C-c C-c
(define-key python-mode-map [?\C-c ?\C-c] 'send-buffer-to-ipython)发布于 2012-11-19 17:59:21
使用python-mode.el
M-x自定义变量RET py-shell名称RET ansi-term
M-x ansi-term RET ipython RET
C-c C-c从Python-buffer执行,然后在IPython shell中执行
注意: shebang位于默认的py-shell-name之前
https://launchpad.net/python-mode/trunk/6.0.12/+download/python-mode.el-6.0.12.tar.gz
https://stackoverflow.com/questions/13445153
复制相似问题