ipython/ipython — pull request #2895 by kanzure (2013-02-07 23:13:27+00:00)
Title: Better reverse search KeyboardInterrupt handling

The previous KeyboardInterrupt handling is dangerous because previous
lines or commands can be mistakenly executed.

When a user interrupts a readline reverse search (C-r) with C-c, a
KeyboardInterrupt is thrown, but the readline buffer still has a line in
the buffer from the search attempt. The previous behavior of IPython was
to show a blank line instead of the current readline buffer, causing a
previous command to be executed if the user presses enter on the
seemingly blank line.

Additionally, keyboard input was not shown on the blank line because
readline was still in reverse search mode. For example, pressing C-k on
the blank line would reset readline, but most users would expect the
input buffer that IPython displays to be correct because of the
prominently displayed KeyboardInterrupt.

This modifies how a KeyboardInterrupt is handled in IPython. Under
normal circumstances in the operation of readline, a KeyboardInterrupt
should never be thrown. IPython now displays a helpful reminder to use
default readline keybindings (which might be overridden by ~/.inputrc,
but whatever), and then displays the current line buffer on the next
line.

Another possible solution would be to send C-g (abort reverse search) or
C-k to readline through raw_input somehow. However, this solution would
require checking ~/.inputrc to figure out what the current "abort
reverse search" keybinding is.

fixes #1286
fixes #2486