IPython in Emacs. Quick code evaluation

Update . The question is still not satisfactory.

I would like to β€œsend” code snippets to the IPython interpreter in Emacs 23.2 (Linux). Assuming that I have already started the IPython shell in a buffer in Emacs (for example, using Python-mode.el and IPython.el ), is there a way to select a region in another buffer and "send" this region to the already running IPython shell?

I tried Cc Cc (send-buffer-to-shell) and Cc | (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 is that for both commands, Emacs creates a temporary file with the extension .py (as opposed to the extension .ipy ), which IPython then interprets as "Python-specific code." This prevents me from using IPython-specific functions such as magic commands.

In a separate note, I also read that Emacs provides M-| ('shell-command-on-region') M-| ('shell-command-on-region') to run selected areas in the shell. To do this using the IPython interpreter, I tried setting the shell-file-name to my IPython path. However, when I run M-| after selecting an area, Emacs offers me the following:

Shell command in the area:

and if I then type RET , I get the IPython man page in the *Shell Command Output* buffer without executing the scope. Is there any IPython-specific command that I can use for M-| ('shell-command-on-region') M-| ('shell-command-on-region') to get IPython to run my code?

Thanks!

+6
python shell emacs ipython
source share
2 answers

Are you using ipython.el? It should work fine with Emacs 23.

If not, check out EmacsWiki: iPython Emacs 23 .

There is also a section in the IPython cookbook on Emacs (search on IPythonEmacs23; sorry, I'm not allowed to post multiple links :(

Once you have launched ipython-shell (Cc!), You can execute code fragments from areas of any buffer in this already running shell using "Execute region (" Cc | ")

Andreas

+1
source share

I found a partial answer Q1 :

Python-mode provides Cc Cc , which can send a buffer to the already open Python shell (similarly, Cc C-| can send a region to the shell), and if ipython.el installed, then the default python shell is set to IPython.

Unfortunately, this only works for python scripts, not IPython scripts. Cc Cc works by copying a buffer with a piece of code into a temporary file with the extension .py , which is then sent to the shell. Since the file has the extension .py , IPython executes it as if it were regular Python code, and therefore the code fragment cannot have IPython-specific code (for example, IPython magic commands).

0
source share

All Articles