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
  • 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
    Commented Jul 20, 2015 at 15:41

2 Answers 2

4

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!

3
  • 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? Commented Jul 23, 2017 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
    Commented Mar 5, 2019 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. Commented Mar 24, 2020 at 9: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.

1
  • 1
    I get UsageError: Line magic function %cpaste` not found.`
    – scribe
    Commented Jan 16, 2021 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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