2

我想编辑一个缓冲区或文件,点击C-c C-c并将文件发送到 IPython 会话。如果我在运行M-x py-shell之前先运行,我现在可以py-execute-buffer完成此操作C-c C-c。但是,如果我尝试通过

(defadvice py-execute-buffer (before open-py-shell-first)
   (let ((remember-window (selected-window))
     (remember-point (point)))
     (generate-new-buffer "*Python*")
     (call-interactively 'py-shell)
     (select-window remember-window)
     (goto-char remember-point)))
(ad-activate 'py-execute-buffer)

我收到一个错误:

## working on region in file /var/folders/6o/6o08knx-FVOhrvCbYyrRDU+++TI/-Tmp-/python-29189FKe.py...
Python 2.7.1 (r271:86832, Feb  5 2011, 13:58:58) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: ---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)

/Users/aresnick/Desktop/<ipython console> in <module>()

IOError: [Errno 2] No such file or directory: '/var/folders/6o/6o08knx-FVOhrvCbYyrRDU+++TI/-Tmp-/python-29189FKe.py'

In [2]: 

IPython 似乎看不到创建的临时文件?如果我现在切换回我的 Python 文件并重新运行py-execute-buffer,一切都很好。

任何想法将不胜感激-谢谢!

4

2 回答 2

0

我想我找到了一些解决方案:

(defun my-py-execute-buffer ()
  (interactive)
  (set 'code-buffer (current-buffer))
  (unless (get-buffer "*Python*")
    (py-shell)
    (set-buffer code-buffer)
    (sleep-for 0.2))
  (py-execute-buffer))

使用 sleep-for 它可以正常工作。

于 2012-02-13T19:33:28.217 回答
0

使用当前的 python-mode.el,

bzr 分支 lp:python 模式

只是 Mx py-execute-buffer-ipython RET

响应。将 py-shell-name 设置为“ipython”

py-execute-buffer 应该 DTRT - 除非 shebang 另有说明

上面的特定命令在 shebang 之前

您可以指向一个版本,而不是默认的“ipython”,还包括路径

于 2012-12-01T19:43:45.907 回答