[IPython-dev] pyreadline and Tab insertion

Vivian De Smedt vds@aisystems...
Sat Jun 7 03:40:02 CDT 2008


Dear All,

This is mail concerning pyreadline. I'm  a Window user and I'm using 
pyreadline. Because of my VisualStudio background I have configured code 
completion to be Ctrl+' ' and tab to be tab insertion.

Here is the corresponding section ipythonrc.ini

    #readline_parse_and_bind tab: complete
    #readline_parse_and_bind tab: menu-complete
    readline_parse_and_bind tab: tab-insert
    readline_parse_and_bind Control-space: complete

The completion part of that configuration works well but if I hit the 
tab touch I get a traceback in IPython basically because tabstop and 
line_cursor are not defined.

C:>ipython

In [1]: Readline internal error
Traceback (most recent call last):
  File "C:\Python25\lib\site-packages\pyreadline\console\console.py", 
line 671,
in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\Python25\lib\site-packages\pyreadline\rlmain.py", line 342, 
in readli
ne
    return self.mode.readline(prompt)
  File "C:\Python25\lib\site-packages\pyreadline\modes\emacs.py", line 
133, in r
eadline
    self._readline_from_keyboard()
  File "C:\Python25\lib\site-packages\pyreadline\modes\emacs.py", line 
90, in _r
eadline_from_keyboard
    r = dispatch_func(event)
  File "C:\Python25\lib\site-packages\pyreadline\modes\emacs.py", line 
289, in t
ab_insert
    ws = ' ' * (self.tabstop - (self.line_cursor%self.tabstop))
AttributeError: 'EmacsMode' object has no attribute 'line_cursor'

To address the problem I have define a default for tabstop in 
rlmain.Readline:

    class Readline(object):
        def __init__(self):
            self.startup_hook = None
            self.pre_input_hook = None
            self.completer = None
            self.completer_delims = " \t\n\"\\'`@$><=;|&{("
            self.console = console.Console()
            self.size = self.console.size()
            self.prompt_color = None
            self.command_color = None
            self.selection_color = self.console.saveattr<<4
            self.key_dispatch = {}
            self.previous_func = None
            self.first_prompt = True
            self.next_meta = False # True to force meta on next character
            self.tabstop = 4
            self.allow_ctrl_c=False
            self.ctrl_c_tap_time_interval=0.3
            self.debug=False

And slightly change the emacs and notemacs modes:

    class EmacsMode(basemode.BaseMode):
        ...
        def tab_insert(self, e): # (M-TAB)
            '''Insert a tab character. '''
            line_cursor = len(self.l_buffer)
            ws = ' ' * (self.tabstop - (line_cursor%self.tabstop))
            #ws = ' ' * (self.tabstop - (self.line_cursor%self.tabstop))
            self.insert_text(ws)

    class NotEmacsMode(basemode.BaseMode):
        ...
        def tab_insert(self, e): # (M-TAB)
            '''Insert a tab character. '''
            line_cursor = len(self.l_buffer)
            ws = ' ' * (self.tabstop - (line_cursor%self.tabstop))
            #ws = ' ' * (self.tabstop - (self.line_cursor%self.tabstop))
            self.insert_text(ws)

Please tell if you think about these propositions of changes.

Regards,
Vivian.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-dev/attachments/20080607/8dab756f/attachment.html 


More information about the IPython-dev mailing list