def begin(self, pattern, start="insert"):
        '''Begin a new search'''
        target = self.parent.get_search_target()

        self.reset()
        start = target.index(start)

        range1 = (start, "end")
        if target.compare(start, "!=", "1.0"):
            range2 = ("1.0", start)
        else:
            range2 = ()

        # tkinter's text widget doesn't support the -all option for searching,
        # so we'll have to directly interface with the tcl subsystem
        command = [target._w, "search", "-nocase", "-all", "-forwards"]
        command.append(pattern)

        # search first from start to EOF, then from 1.0 to 
        # the starting point. Why? Most likely the user is
        # wanting to find the next occurrance. This simply
        # optimizes the search so the first match is closest
        # to the insertion cursor
        result1 = self.tk.call(tuple(command + ["insert linestart", "end"]))
        result2 = self.tk.call(tuple(command + ["1.0", "insert lineend"]))

        # why reverse result2? It represents results above the
        # starting point, so if result1 is null, this guarantees
        # that the first result is nearest the search start
        result = list(result1) + list(reversed(result2))
        if len(result) > 0:
            i = result[0]
            self._mark_current(i, "%s + %sc" % (i, len(pattern)))
        for index in result:
            target.tag_add("find", index, "%s + %sc" % (index, len(pattern)))
dataset/ETHPy150Open boakley/robotframework-workbench/rwb/widgets/searchentry.py/SearchEntry.begin/original