Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

A feature in bpython called rewind.

Is there some similar key bindings?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Short answer: No, IPython does not have this feature.

However, based on my understanding of bpython's docs, their rewind isn't actually stepping backward, it's starting over and replaying to a point earlier in the session. If this is actually the case, then in IPython you can do something that might be similar by resetting and re-running the history:

def rewind(ip, s=''):
    """attempt to reset IPython to an earlier state

    implemented by resetting IPython, and replaying the
    history up to (but not including) the specified index.
    """
    if s:
        stop = min(int(s), ip.execution_count)
    else:
        # backup 1 by default
        stop = ip.execution_count-1
    # fetch the history
    hist = list(ip.history_manager.get_range(stop=stop))
    # reset IPython
    ip.reset()
    ip.execution_count=0
    # replay the history
    for _,i,cell in hist:
        ip.run_cell(cell, store_history=True)

# expose this function as %rewind
get_ipython().define_magic('rewind', rewind)

Then at a later point, call %rewind 6, and you should have IPython back in the state prior to input #6. This implementation is far from perfect, because I just tossed it together (for instance, it will not suppress tracebacks or output for the replayed cells), but it should be a start.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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