[Patches] [ python-Patches-1690201 ] Added support for custom readline functions

SourceForge.net noreply at sourceforge.net
Mon Apr 2 19:28:07 CEST 2007


Patches item #1690201, was opened at 2007-03-28 21:52
Message generated for change (Comment added) made by paulhankin
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1690201&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Ben Timby (btimby)
Assigned to: Nobody/Anonymous (nobody)
Summary: Added support for custom readline functions

Initial Comment:
This patch allows for binding a key or keyseq to a custom function named custom. A custom handler can be registered and will be called by readline when the registered sequence input.

Example:

rl.py
--
import readline

def handler():
    print "need some help?"

readline.set_custom_hook(handler)
readline.parse_and_bind("\"?\": custom")

text = raw_input("type ? for help# ")
--

----------------------------------------------------------------------

Comment By: Paul Hankin (paulhankin)
Date: 2007-04-02 17:28

Message:
Logged In: YES 
user_id=1740099
Originator: NO

Hi Ben, I'm sorry if you thought my short reply suggested I hadn't looked
at the patch properly. I'll try to clarify what I meant.

Gnu readline provides an interface to custom functions: you declare a
function that takes a 'count' and a 'key' and returns 0 or an error. You
then call rl_add_defunc to declare it. You use the name you used in
'rl_add_defunc' in the readline init file to bind the command to a key.

The patch uses a different interface: the user provides a function that
takes no arguments. He declares it by calling 'set_custom_hook', and calls
it by using the name 'custom' in the init file to bind it to a key.

An interface consistent between python and readline would be:

def say_hello(key, count):
   ...
readline.add_defunc("say_hello", say_hello)
readline.parse_and_bind('"?" : say_hello')

(Perhaps the 'add_defun' is an artefact of lack of dynamic features of C
and would be dropped from the python interface).

The patch's use of a 'custom' hook is more complicated than using the
function name directly in the init file, and provides less functionality (a
single command, and removes the arguments that the c command would have).
Accepting this patch will cause minor compatibility trouble in future if
anyone works out a way round the admittedly difficult technical problems of
doing things the 'right' way.

Given the interface troubles, I'm not convinced enough of the usefulness
of the patch.


----------------------------------------------------------------------

Comment By: Ben Timby (btimby)
Date: 2007-04-02 01:53

Message:
Logged In: YES 
user_id=932679
Originator: YES

If by adopt you mean adapt, that is what I have done. I simplified things
to allow a single named function "custom" but it uses the gnu readline
custom function interface (rl_add_defunc) . Have you even looked at the
patch?

----------------------------------------------------------------------

Comment By: Paul Hankin (paulhankin)
Date: 2007-04-01 21:47

Message:
Logged In: YES 
user_id=1740099
Originator: NO

Gnu readline supports custom functions in C - it would be better to adopt
the gnu readline custom function interface to python, rather than using the
'custom' handler which smells of a hack.


----------------------------------------------------------------------

Comment By: Ben Timby (btimby)
Date: 2007-03-28 23:01

Message:
Logged In: YES 
user_id=932679
Originator: YES

new Example:

rl.py
--
#!/usr/bin/python
import readline

def say_hello():
	print
	print "this is my help text..."
	readline.on_new_line()

readline.set_custom_hook(say_hello)
readline.parse_and_bind("\"?\": custom")

while True:
	data = raw_input("input# ")
	print "data: ", data
--

----------------------------------------------------------------------

Comment By: Ben Timby (btimby)
Date: 2007-03-28 23:00

Message:
Logged In: YES 
user_id=932679
Originator: YES

File Added: python-2.3.4-readline_custom.patch

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1690201&group_id=5470


More information about the Patches mailing list