def complete(self, text=None, line_buffer=None, cursor_pos=None):
<EOL>if cursor_pos is None:<EOL><INDENT>cursor_pos = len(line_buffer) if text is None else len(text)<EOL><DEDENT>if not text:<EOL><INDENT>text = self.splitter.split_line(line_buffer, cursor_pos)<EOL><DEDENT>if line_buffer is None:<EOL><INDENT>line_buffer = text<EOL><DEDENT>self.line_buffer = line_buffer<EOL>self.text_until_cursor = self.line_buffer[:cursor_pos]<EOL>self.matches[:] = []<EOL>custom_res = self.dispatch_custom_completer(text)<EOL>if custom_res is not None:<EOL><INDENT>self.matches = custom_res<EOL><DEDENT>else:<EOL><INDENT>if self.merge_completions:<EOL><INDENT>self.matches = []<EOL>for matcher in self.matchers:<EOL><INDENT>try:<EOL><INDENT>self.matches.extend(matcher(text))<EOL><DEDENT>except:<EOL><INDENT>sys.excepthook(*sys.exc_info())<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for matcher in self.matchers:<EOL><INDENT>self.matches = matcher(text)<EOL>if self.matches:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>self.matches = sorted(set(self.matches))<EOL>return text, self.matches<EOL>
Find completions for the given text and line context.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        Note that both the text and the line_buffer are optional, but at least
        one of them must be given.

        Parameters
        ----------
          text : string, optional
            Text to perform the completion on.  If not given, the line buffer
            is split using the instance's CompletionSplitter object.

          line_buffer : string, optional
            If not given, the completer attempts to obtain the current line
            buffer via readline.  This keyword allows clients which are
            requesting for text completions in non-readline contexts to inform
            the completer of the entire text.

          cursor_pos : int, optional
            Index of the cursor in the full line buffer.  Should be provided by
            remote frontends where kernel has no access to frontend state.

        Returns
        -------
        text : str
          Text that was actually used in the completion.

        matches : list
          A list of completion matches.