def _findstart(line_segment):
    """Find start of text to autocomplete.

    >>> _findstart("where x.pers")
    8
    >>> _findstart("from d.person, d.na")
    17
    >>> _findstart("    and x.")
    10
    >>> _findstart("where i")
    6
    >>> _findstart("   ")
    3
    """
    if '.' in line_segment:
        return line_segment.rindex('.') + 1
    elif ' ' in line_segment:
        return line_segment.rindex(' ') + 1
    else:
        return -1