"""
Utilities for end-users.
"""

import sys

from jedi import Interpreter


def readline_complete(text, state):
    """
    Function to be passed to :func:`readline.set_completer`.

    Usage::

        import readline
        readline.set_completer(readline_complete)

    """
    ns = vars(sys.modules['__main__'])
    completions = Interpreter(text, [ns]).completions()
    try:
        return text + completions[state].complete
    except IndexError:
        return None


def setup_readline():
    """
    Install Jedi completer to :mod:`readline`.

    This function setups :mod:`readline` to use Jedi in Python interactive
    shell.  If you want to use custom ``PYTHONSTARTUP`` file, you can call
    this function like this:

    >>> from jedi.utils import setup_readline
    >>> setup_readline()

    """
    try:
        import readline
    except ImportError:
        print("Module readline not available.")
    else:
        readline.set_completer(readline_complete)
        readline.parse_and_bind("tab: complete")

        # Default delimiters minus "()":
        readline.set_completer_delims(' \t\n`~!@#$%^&*-=+[{]}\\|;:\'",<>/?')

@@ -31,18 +31,41 @@
 %22%22%0A%0A
-import sys
+from rlcompleter import Completer
 %0A%0Afr
@@ -97,249 +97,124 @@
 r%0A%0A%0A
-def readline_complete(text, sta
+class JediRLCompleter(Comple
 te
+r
 ):%0A
-    %22%22%22%0A    Function to be passed to :func:%60readline.set_completer%60.%0A%0A    Usage::%0A%0A        import readline%0A        readline.set_completer(readline_complete)%0A%0A    %22%22%22%0A    ns = vars(sys.modules%5B'__main__'%5D)%0A
+%0A    def attr_matches(self, text):%0A        if '(' in text or ')' in text:%0A        
     
@@ -246,18 +246,30 @@
 (text, %5B
-n
 s
+elf.namespace
 %5D).compl
@@ -277,29 +277,24 @@
 tions()%0A    
-try:%0A
         retu
@@ -300,74 +300,121 @@
 urn 
+%5B
 text + 
+c.
 complet
-ions%5Bstate%5D.complete%0A    except IndexError:%0A
+e for c in completions%5D%0A        else:%0A            # NOTE: Completer is old type class%0A  
         
 retu
@@ -413,19 +413,51 @@
     
+  
 return 
-None
+Completer.attr_matches(self, text)
 %0A%0A%0Ad
@@ -943,17 +943,26 @@
 ter(
-readline_
+JediRLCompleter().
 comp

Add utils.JediRLCompleter