[IPython-dev] IPython+libedit
Andrea Riciputi
ariciputi at pito.com
Fri Sep 5 03:07:29 EDT 2008
Hi all,
I've been working for a couple of days on the issues regarding IPython
and the libedit shipped with OSX Leopard, and I've got a little more
insight in it. I'd like to share this stuff with you in order to get a
better understanding of these issues and to make IPython working
better under OSX.
Although I can understand that installing the readline egg build by
Ludwig Schwardt makes everything work smoothly, I think making IPython
behaves correctly also using libedit could be a plus not only to all
OSX users, but to any other user using that library as well.
So let me start listing the issues I've found so far:
1) Multi-line commands in history get scrambled when recalled at the
prompt
2) Autoindentation doesn't work
3) Key binding initialization it's not correct
Regarding multi-line commands, the problem is due to the way libedit
write out its history file. Despite readline, libedit encodes all the
white spaces, newline and tabs before writing the history (look at
libedit source code and to man strvis under OSX). As a consequence a
muli-line command in the libedit history looked like this:
for\040i\040in\040[1,2,3]:\012\040\040print\040i
appearing as a single line command (it's a single entry in the
history). However, a simple patch to iplib.py fixes this:
% diff -u IPython/iplib.py.orig IPython/iplib.py
--- IPython/iplib.py.orig 2008-09-03 12:12:11.000000000 +0200
+++ IPython/iplib.py 2008-09-04 10:12:05.000000000 +0200
@@ -2170,7 +2174,7 @@
if line.strip():
if continue_prompt:
self.input_hist_raw[-1] += '%s\n' % line
- if self.has_readline: # and some config option is set?
+ if self.has_readline and not
self.readline.uses_libedit: # and some config option is set?
try:
histlen =
self.readline.get_current_history_length()
if histlen > 1:
Regarding the autoindentation problem seems more rooted in libedit/
readline compatibility, and haven't been able to fix it yet. Infact it
turns out that using libedit the _ip.IP.readline_startup_hook function
(i.e. pre_readline()) is never called. I can't understand why, but if
someone could give me so hints on how to test the readline module,
I'll try to investagete it a little further.
Finally, I need your help again regarding the readline/libedit key-
binging. It seems that (when libedit are present) readline key-binding
are set despite the if-clause in init_readline() (in ipylib.py):
if not readline.uses_libedit:
for rlcommand in self.rc.readline_parse_and_bind:
readline.parse_and_bind(rlcommand)
Which file is actually read between ipythonrc and ipy_user_conf.py to
configure IPython? And where in the code the rc Struct is initialized?
I'm sorry for this long email, but I hope someone could help me to
make IPython a little better.
TIA,
Andrea
More information about the IPython-dev
mailing list