def state(cursor): """Returns the simplestate string for the position of the cursor.""" import simplestate pos = cursor.selectionStart() block = cursor.document().findBlock(pos) tokens = tokeniter.tokens(block) state = tokeniter.state(block) column = pos - block.position() for t in tokens: if t.end > column: break state.follow(t) return simplestate.state(state)