pyreadline: getting callbacks for keypresses from pyreadline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

pyreadline: getting callbacks for keypresses from pyreadline

Ville M. Vainio
Is it possible to register certain keys to certain functions that are
called when that key is pressed? I'm thinking of something like:

def my_translator(line, curpos):
  return (line +"appended", curpos)

readline.bind_translator("Alt-e", my_translator)

where my_translator returns the new content for corrent line, along
with cursor position.

This could be used e.g. to launch external editor for current command
line, something that seems to exist in Vi mode. We should rig the
IPython default editor for something like this.

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
T
_______________________________________________
IPython-dev mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: pyreadline: getting callbacks for keypresses from pyreadline

Fernando Perez
On 6/14/07, Ville M. Vainio <[hidden email]> wrote:

> Is it possible to register certain keys to certain functions that are
> called when that key is pressed? I'm thinking of something like:
>
> def my_translator(line, curpos):
>   return (line +"appended", curpos)
>
> readline.bind_translator("Alt-e", my_translator)
>
> where my_translator returns the new content for corrent line, along
> with cursor position.
>
> This could be used e.g. to launch external editor for current command
> line, something that seems to exist in Vi mode. We should rig the
> IPython default editor for something like this.

I think that GNU readline does allow this, but I'm not 100% sure.
Then, there's the question of whether it will be available to ipython
itself.  You can check the GNU readline docs and see if it's possible
via a call to

readline.parse_and_bind(" some syntax here to bind key->cmd ")

but I honestly don't really know (and can't check right now) if it works.

Cheers,

f
_______________________________________________
IPython-dev mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: pyreadline: getting callbacks for keypresses from pyreadline

Ville M. Vainio
On 6/15/07, Fernando Perez <[hidden email]> wrote:

> I think that GNU readline does allow this, but I'm not 100% sure.
> Then, there's the question of whether it will be available to ipython
> itself.  You can check the GNU readline docs and see if it's possible
> via a call to
>
> readline.parse_and_bind(" some syntax here to bind key->cmd ")

This does not allow binding an arbitrary callable.

--
Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'
_______________________________________________
IPython-dev mailing list
[hidden email]
http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev