[IPython-dev] Magic repeat commands
takowl at gmail.com
Thu Mar 17 10:03:17 EDT 2011
I started looking at magic_rep, while reworking the history. It's struck me
that it's not a very intuitive behaviour - it can either bring a line to the
prompt, or execute code, and it overlaps with the magic_r function. So I'd
like to propose a cleaner separation - let's have one magic command to
repeat or rerun a command, and another to bring a line to the prompt.
If we were starting with a clean slate, I would call these %repeat/%rep to
run commands, and %recall/%rec to bring them to the prompt. But I think %rep
is probably more often used to "recall" a line, so perhaps it would be
better to leave it in this role, and call the new repeat function something
More specifically, the recall function, whatever we call it, would have the
- With no arguments, put the last output (_) at the prompt
- If the argument is a string variable in the user namespace, put the value
of that variable at the prompt (so you could recall Out). I think this
should be possible using eval.
- If the argument specifies one or more cells in the history, join them into
a single cell and put this at the prompt. (Or should we just take the first
cell instead of combining them?)
- Otherwise, search through the history, and recall the most recent line
containing the search term.
The repeat/rerun function would accept similar options and arguments to
%history (except those relating to output), and would retrieve lines in the
same way, except that the search option (-g) would only retrieve the most
recent match. Specifying no arguments would get the cell immediately before
it. These lines would then be run in exec mode (single mode for single
It makes sense to do this in my sqlite-history branch, because I need to
modify these commands to work with the new history system anyway. Are there
any thoughts or objections? If I separate the functions, what names would
you like them to be under?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev