Wish tab completion was sorted by class

Bug #319620 reported by Daniel Holth on 2009-01-21
2
Affects Status Importance Assigned to Milestone
IPython
Confirmed
Wishlist
Unassigned

Bug Description

Tab completion is hard to use when objects have many methods. It would be nice if IPython could group tab completion possibilities by the class or subclass they were defined in, most-specific-class first.

Daniel Holth (dholth) wrote :

The undocumented inspect.classify_class_attrs(cls) function, along with inspect.getmro(cls) give most of the information needed to implement this feature.

By default readline displays completions alphabetically, but the function used to display completions can be replaced using ctypes or the readline module included with Python 2.6 and above. The completion_display_matches_hook function could hold a reference to the completer which would provide the last autocompleted object.

Example of problem:

In [30]: portal.<tab>
Display all 919 possibilities? (y or n)

How to override the completion_display_matches_hook in Pythons earlier than Python 2.6:

from ctypes import *

rl = cdll.LoadLibrary('libreadline.so')

def completion_display_func(matches, num_matches, max_length):
    print "made you look"

COMPLETION_DISPLAY_FUNC = CFUNCTYPE(None, POINTER(c_char_p), c_int, c_int)
hook = COMPLETION_DISPLAY_FUNC(completion_display_func)
ptr = c_void_p.in_dll(rl, 'rl_completion_display_matches_hook')
ptr.value = cast(hook, c_void_p).value

Daniel Holth (dholth) on 2009-01-29
description: updated
Changed in ipython:
importance: Undecided → Wishlist
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers