'set_to: None => advance the state, otherwise a value from TAG_SEARCH_STATES'

def toggle(self, set_to=None):

    if (set_to is None):
        while True:
            self.tag.state = ((self.tag.state + 1) % 5)
            if ((self.tag.state == TAG_SEARCH_STATES[u'mark_plus']) or (self.tag.state == TAG_SEARCH_STATES[u'mark_minus'])):
                if self.tag.is_searchable:
                    break
            elif ((self.tag.state == TAG_SEARCH_STATES[u'mark_plusplus']) or (self.tag.state == TAG_SEARCH_STATES[u'mark_minusminus'])):
                if (self.tag.is_searchable and len(self.children) and (self.tag.is_hierarchical == u'5state')):
                    break
            else:
                break
    else:
        self.tag.state = set_to
