5

Say, I typed

In [1]: def foo(a, b):
...:     return a+b
...: 

in the normal, non-emacs ipython shell. Pressing the up arrow key afterwards, allows me to get the complete multi-line input back which I then can edit.

In [2]: def foo(a, b):
    return a+b_

where _ represents the cursor. Can I replicate this behaviour in Emacs's ipython shell?

  • 1
    I've done some digging, and I can't find anything suggesting this is possible. You may be stuck with killing and yanking. – GJStein Jul 20 '15 at 15:41

2 Answers2

3

I realize it's an old question, but since it was left unanswered, I will bring the fix I found here after running into the same issue.

  1. Make sure your version of IPython is at least 5.4

  2. Install rlipython (sudo pip install rlipython)

  3. Run IPython and then run inside import rlipython; rlipython.install()

And that's it.

All the best!

S4M
  • 131
  • 1
  • 4
  • 2
    As far as I can tell, this allows to drop `--simple-prompt` (which is great,t thanks!) but I don't see how it solves the question above? – Martin R. Albrecht Jul 23 '17 at 10:04
  • 2
    What a hidden gem! This solves my problem of using IPython without --simple-prompt in emacs shell. It deserves more upvotes! – DataHungry Mar 05 '19 at 22:23
  • Indeed, tested working for integration of iPython, (Python3.7), Emacs and iSend mode. Without this i could not use IPython with isend-mode. – Nicola Mingotti Mar 24 '20 at 09:04
1

You can use %cpaste and -- to tell ipython to expect multiple lines:

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:def foo():
:  return 1
:
:--

Alternatively, put the code in another buffer and use python-shell-send-region or python-shell-send-defun.

Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59