def rl_autoindent():
    """Auto-indent upon typing a new line according to the contents of the
    previous line.  This function will be used as Readline's
    pre-input-hook.
    """
hist_len = readline.get_current_history_length()
last_input = readline.get_history_item(hist_len)
indent = ''
try:
    last_indent_index = last_input.rindex('    ')
except:
    last_indent = 0
else:
    pass
How to enable python repl autocomplete and still allow new line tabs