Frage

I'd like to be editing a buffer or file, hit C-c C-c and have the file sent to an IPython session. I can accomplish this now if I first run M-x py-shell before running py-execute-buffer via C-c C-c. But if I try to advise the function via

(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)

I get an error:

## 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]: 

It would seem that the temporary file created isn't being seen by IPython? If I now switch back to my Python file and re-run py-execute-buffer, all is well.

Any thoughts would be appreciated--thanks!

War es hilfreich?

Lösung

I think I found some solution:

(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))

With sleep-for it's working correctly.

Andere Tipps

with current python-mode.el,

bzr branch lp:python-mode

just M-x py-execute-buffer-ipython RET

Resp. with py-shell-name set to "ipython"

py-execute-buffer should DTRT - unless shebang tells otherwise

Specific command above precedes shebang

Instead of default "ipython" you may point to a version, also including path

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top