This generalises the mechanism used by %loadpy to place text at the next prompt. The result is that the %recall, aka %rep, magic works the same way as it does in the terminal, putting history lines (or strings) at the next prompt.
Equally, %loadpy could be moved to the core magics, so that it works in a terminal as well. I've not done this yet, as the terminal isn't such a good environment for multiline cells, so I'm not sure how useful it would be. But it's a simple change if we want it.
When I do ip.set_next_input("def f():\n return 2") with a multiline string in the Terminal, I actually get a single multiline readline entry. That means the whole thing is one entry accessible all at once via up-arrow, and the entire block is editable (if not conveniently so). Is this what we want to happen?
ip.set_next_input("def f():\n return 2")
Yes, or at least it's what I intended. So, for instance, you can do %recall 2-5, and it will join the cells together and plonk them at the next prompt. It's not as convenient as in the qt console, but it still works if you have something like:
a = "some data"
b = process(a)
And you want to run the same sequence of commands with a different a: bring the whole lot to the prompt, hit home, tweak the value of a, and run it again.
Okay, then if we are allowing multiline pasts with %recall, it makes sense for %loadpy to be a core magic, and not qt-specific.
OK, I've moved %loadpy into the core, so it works at the terminal as well.
Looks good to me. I can imagine that some might object to inconsistent handling of multiline inputs in the terminal, but I think having %loadpy always available is more valuable than that.
I say go ahead and merge.
Thanks, Min. I'll merge later today unless anyone objects. @fperez, @ellisonbg: let me know if you see a problem, or if you want more time to look at it before I merge.
Merged with rebase, as it was only 2 commits.