Title: Patch for using TAB with ReadlineConsole
Type: Severity: normal
Components: Core Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: bab, pedronis, pjenvey
Priority: normal Keywords: patch

Created on 2003-08-27.06:52:17 by bab, last changed 2009-07-08.00:49:45 by pjenvey.

File name Uploaded Description Edit Remove
jython-diff bab, 2003-08-27.06:55:59 Patch repeated with whitespace/indenting preserved
msg2297 (view) Author: Ben Burton (bab) Date: 2003-08-27.06:52:17
Below is the patch I recently posted to jython-dev allowing the 
use of the TAB key when working in an interactive jython 
interpreter with ReadlineConsole.  Since python makes active 
use of indentation in defining the language, this resolves a 
serious usability problem when using jython with readline 
This patch works with the current CVS version of java-readline 
(to be released as version 0.8.1), though will not have any 
negative effects with earlier java-readline versions. 
diff -ru old/jython-2.1.0/org/python/util/ 
--- old/jython-2.1.0/org/python/util/	
2003-08-27 13:49:20.000000000 +1000 
+++ jython-2.1.0/org/python/util/	
2003-08-27 15:45:11.000000000 +1000 
@@ -26,6 +26,24 @@ 
             // Will use a pure java fallback. 
+        // Disable readline completion if we have a new enough 
+        // class, so that <TAB> characters can be input directly. 
+        try { 
+            java.lang.reflect.Field inhibitConstField = 
+            if (inhibitConstField != null) { 
+                Object inhibitConst = inhibitConstField.get(null); 
+                Class[] setVarArgTypes = { inhibitConst.getClass(), 
+                    Integer.TYPE }; 
+                java.lang.reflect.Method setVar = 
+                    "setVar", setVarArgTypes); 
+                if (setVar != null) { 
+                    Object[] args = { inhibitConst, new Integer(1) }; 
+                    setVar.invoke(null, args); 
+                } 
+            } 
+        } catch (Exception exc) {} 
msg2298 (view) Author: Ben Burton (bab) Date: 2003-08-27.06:54:44
Logged In: YES 

Hmm, somewhere in the patch submission process the whitespace has 
been mangled.  I'm attaching the patch again as a separate file with 
whitespace and indenting intact. 
msg2299 (view) Author: Samuele Pedroni (pedronis) Date: 2005-01-09.19:44:32
Logged In: YES 

this touches the theme to wich extent do we want to invest
improving readline support while staying with no default GPL
linking. Needs discussion.
msg2300 (view) Author: Ben Burton (bab) Date: 2005-01-17.06:33:33
Logged In: YES 

> this touches the theme to wich extent do we want to invest 
> improving readline support while staying with no default GPL 
> linking. Needs discussion. 
The java-readline project works with several readline-style libraries, 
including the BSD-licensed libedit.  Indeed the jython packages I make 
for debian use libedit and _not_ libreadline, precisely because of the 
GPL issue.  This patch is certainly not exclusive to the GPLed 
At any rate, given that you ship ReadlineConsole it's not clear to me 
why you'd prefer not to include the patch.  It fixes a serious usability 
issue, and it's not as though you need to make a serious investment. 
The patch is ready and well tested, and has been for some time. 
msg2301 (view) Author: Philip Jenvey (pjenvey) Date: 2007-09-03.01:37:21
JLine is great in the fact that it's pure java, and in the future I'd like to see it even included with Jython to be used as the default console.

However that's still no reason to not support readline, especially since it has more features than JLine and last time I checked, EditLine

This patch is actually the wrong solution, I've discovered after digging into it some. The underlying problem is that readline defaults the tab key to complete and that CPython rebinds it to send an actual tab key.

We don't want to disable completion completely, like this patch does. We still want the ability to do completion, but only if the user sets up his environment to do so, such as when they're using rlcompleter:

(Note the rlcompleter docs instruct you to rebind tab back to readline's complete function)

Sorry this ticket has lingered for so long Ben, I'll commit the CPython-like solution pretty soon
msg2302 (view) Author: Philip Jenvey (pjenvey) Date: 2007-09-03.05:36:39
addendum: well it's the wrong solution for pure readline, anyway

I committed r3466 to remap the tab key -- but the method used to remap keys is only available under pure Readline. EditLine can't remap keybindings, or at least Java readline provides no facility for doing so

I can't get java-readline to work with the versions of libedit I have here. Does EditLine/libedit suffer from this issue? If so we could fallback to this patch for EditLine. It would break rlcompleter, but is probably worth doing so just that tab works
msg2303 (view) Author: Philip Jenvey (pjenvey) Date: 2007-10-24.23:53:00
In reply to Patch #1817799 (a dupe of this):

I'd be willing to commit a patch that disables completion via RL_INHIBIT_COMPLETION for *only* Editline

#1817799's patch disables it comletely for both Editline and Readline. This will prevent the rlcompleter module from working with readline-using jythons if one wants to enable it:

(notice the instructions have you rebind tab back to complete, opposite of what Python and now Jython do at startup)
msg4887 (view) Author: Philip Jenvey (pjenvey) Date: 2009-07-08.00:49:43
So what's pending here is does ReadlineConsole with editline disable the 
tab key? I wasn't able to build java-readline with editline, so I'm not 
sure. So I'm closing this out until someone using editline encounters it

This is of lower priority now anyway now that we ship with jline as 
Date User Action Args
2009-07-08 00:49:45pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg4887
2008-12-15 15:59:23fwierzbickisetcomponents: + Core, - None
2003-08-27 06:52:17babcreate