Sending Code From Python Buffer To IPython Session Running From M-x Ansi-term
Solution 1:
I have a minor mode for this purpose (except it is not IPython-specific and I mostly use it for shell scripts): isend-mode.
Here is how you would use it:
Open an
ansi-termbuffer:M-x
ansi-termRET/usr/bin/ipythonRETOpen the buffer with the code you want to execute, and associate it to the interpreter buffer:
M-x
isend-associateRET*ansi-term*RETHit C-RET in the python buffer to send the current line to the interpreter in the
ansi-termbuffer.
Solution 2:
(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
))
Then bind command send-buffer-to-ipython to any key you like. I bind it to C-c C-c
(define-key python-mode-map [?\C-c ?\C-c] 'send-buffer-to-ipython)
Solution 3:
with python-mode.el
M-x customize-variable RET py-shell-name RET ansi-term
M-x ansi-term RET ipython RET
C-c C-c from Python-buffer than executes in IPython shell
Caveat: a shebang precedes default py-shell-name
https://launchpad.net/python-mode/trunk/6.0.12/+download/python-mode.el-6.0.12.tar.gz
Post a Comment for "Sending Code From Python Buffer To IPython Session Running From M-x Ansi-term"