def token_at_cursor(code, pos=0):
    """
    Find the token present at the passed position in the code buffer
    """
    l = len(code)
    end = start = pos
    while end < l and code[end].isalpha():
        end += 1
    while start > 0 and code[start - 1].isalpha():
        start -= 1
    if start > 0 and code[start - 1] == '%':
        start -= 1
    return code[start:end], start
