On 05/10/12 22:09, Antoine Pitrou wrote:
On Fri, 05 Oct 2012 11:27:28 +0200 Andy Buckleyandy@insectnation.org wrote:
A couple of weeks ago I posted a question on superuser.com about whether there is a way to get the same *very* convenient stepping-through-command-history behaviour in an interactive Python interpreter session as is possible in (at least) the bash shell with the Ctrl-o keybinding:
The interactive interpreter (and I mean the default one, not third-party choices like IPython) uses libreadline for its editing and history functionality, so it's really a question about libreadline you're asking.
I don't think so. I'm not an expert on readline, but it seems to me to be a Python bug.
In bash, I check for the existence of the "operate-and-get-next" command, and sure enough it is bound to C-o (Ctrl-o) as expected:
[steve@ando ~]$ bind -p | grep operate "\C-o": operate-and-get-next
I don't believe that there is any direct mechanism for querying the current readline bindings in Python, but I can fake it with the "dump-functions" command:
import readline readline.parse_and_bind(r'"\C-xd": dump-functions')
If I then type Ctrl-x d at the interactive interpreter, readline dumps the function bindings to screen:
py> readline.parse_and_bind(r'"\C-xd": dump-functions') py>
abort can be found on "\C-g", "\C-x\C-g", "\M-\C-g". accept-line can be found on "\C-j", "\C-m". arrow-key-prefix is not bound to any keys backward-byte is not bound to any keys backward-char can be found on "\C-b", "\M-OD", "\M-[D". [...]
operate-and-get-next is absent from the list. I don't mean that it is not bound. It just isn't there at all.
If I nevertheless try to use it:
it does *not* enable Ctrl-o as expected, operate-and-get-next remains absent from the list of bindings.
I have checked this on both Python 2.7 and 3.3.0rc3 under Centos 5, and on 3.3.0rc3 under Debian Squeeze.