Update: The question still lacks a satisfactory answer.
I would like to "send" code snippets to a IPython interpreter in Emacs 23.2 (Linux). Assuming that I have already started an IPython shell in a buffer in Emacs (e.g. using Python-mode.el
and IPython.el
), is there a way of selecting a region in a different buffer and "sending" this region to the already-started IPython shell?
I have tried C-c C-c
(send-buffer-to-shell) and C-c |
(send-region-to-shell), but this only works as long as the code is written in Python and not in IPython (IPython can run Python code). The reason seems to be that, for both commands, Emacs creates a temporary file with .py
extension (as opposed to with .ipy
extension), which then is interpreted by IPython as "Python-specific code". This prevents me from using IPython-specific features
such as magic commands.
On a separate note, I have also read that Emacs provides M-| ('shell-command-on-region')
to run selected regions in a shell. To do this with an IPython interpreter, I have tried setting shell-file-name
to my IPython path. However, when I run M-|
after selecting a region, Emacs prompts me the following:
Shell command on region:
and if I then type RET
, I get the IPython man page on the *Shell Command Output*
buffer, without the region being executed. Is there any IPython-specific command that I can use for M-| ('shell-command-on-region')
to get IPython run my code?
Thanks!
Are you using ipython.el? It should work okay with Emacs 23.
If not, have a look at EmacsWiki: iPython Emacs 23.
There is also a section in the IPython Cookbook on Emacs (search for IPythonEmacs23; sorry am not allowed to post more than one link :(
Once you've started an ipython-shell (C-c !) you can execute code snippets from regions of any buffer in this already started shell using "Execute region ("C-c |")
Andreas
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With