'Autocompletion logic is called here'

def _onTab(self):

    if self.in_raw_line_mode():
        return
    line = self._getLineStr()[:self._position]
    tokens = self._parseLine(line)
    if ((not line.endswith('    ')) and (len(tokens) > 0)):
        incomplete = tokens.pop()
    else:
        incomplete = ''
    completions = self._context.suggest(tokens, incomplete)
    if (completions is None):
        return
    prefix = commonPrefix(completions)
    if (prefix != ''):
        self._paste(prefix)
    elif (len(completions) > 0):
        term.writeln()
        for variant in map((lambda c: c[1]), completions):
            term.write((variant + '    '))
        term.writeln()
        self._showPrompt()
        self._showLine()
    else:
        term.bell()
