我如何建议emacs中的py execute buffer在函数之前运行py shell?

我如何建议emacs中的py execute buffer在函数之前运行py shell?,emacs,elisp,python-mode,advising-functions,defadvice,Emacs,Elisp,Python Mode,Advising Functions,Defadvice,我想编辑缓冲区或文件,点击C-C-C并将文件发送到IPython会话。如果我在通过C-C-C运行py执行缓冲区之前先运行M-x py shell,现在就可以实现这一点。但是如果我尝试通过 (defadvice py-execute-buffer (before open-py-shell-first) (let ((remember-window (selected-window)) (remember-point (point))) (generate-new-buf

我想编辑缓冲区或文件,点击C-C-C并将文件发送到IPython会话。如果我在通过C-C-C运行py执行缓冲区之前先运行M-x py shell,现在就可以实现这一点。但是如果我尝试通过

(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执行缓冲区,一切都会好起来


任何想法都将不胜感激,谢谢

我想我找到了一些解决办法:

(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,它工作正常。

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

(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,它工作正常。

使用当前的python-mode.el

bzr分支lp:python模式

只需M-x py执行缓冲区ipython RET

分别。将py shell名称设置为ipython

py执行缓冲区应为DTRT-除非shebang另有说明

上面的特定命令位于shebang之前


您可以使用当前python-mode.el指向一个版本,而不是默认的ipython,其中还包括路径

bzr分支lp:python模式

只需M-x py执行缓冲区ipython RET

分别。将py shell名称设置为ipython

py执行缓冲区应为DTRT-除非shebang另有说明

上面的特定命令位于shebang之前

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

我甚至没有py execute buffer命令。这是来自ipython.el的吗?我甚至没有py执行缓冲区命令。这是ipython.el的东西吗?