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

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!

  • 1
    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
  • 1
    What a hidden gem! This solves my problem of using IPython without --simple-prompt in emacs shell. It deserves more upvotes! – DataHungry Mar 5 '19 at 22:23

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.