(self, text, start, target)
Return the simplest possible searching motion to reach the given target.

        :param text: Contents of the file.
        :param start: Index in ``text`` to start the search from.
        :param target: Index of the target position in ``text``.
Return the simplest possible searching motion to reach the given target.
Return the simplest possible searching motion to reach the given target .
def _search(self, text, start, target):
        """
        Return the simplest possible searching motion to reach the given target.

        :param text: Contents of the file.
        :param start: Index in ``text`` to start the search from.
        :param target: Index of the target position in ``text``.
        """
        search_text = text[target:]

        # ("a", "ab", "abc", "abcd"...) until we reach
        # the end of search_text or find a working query
        for query_length in range(1, len(search_text) + 1):
            query = search_text[:query_length]

            # Get a list of all match positions for this search query
            # query="x" text="x___x_xx" == [0, 4, 6, 7]
            pattern = re.escape(query)
            matches = [m.start() for m in re.finditer(pattern, text)]

            if matches:
                # Sort the list so it begins with matches after `start`, rather
                # than matches at the beginning of the file
                # sorted([True, False]) == [False, True]
                matches.sort(key=lambda position: position <= start)

                if matches[0] == target:
                    return self._create_motion(query)
                if matches[-1] == target:
                    return self._create_motion(query, "?")
def _search ( self , text , start , target ) : search_text = text [ target : ] # ("a", "ab", "abc", "abcd"...) until we reach # the end of search_text or find a working query for query_length in range ( 1 , len ( search_text ) + 1 ) : query = search_text [ : query_length ] # Get a list of all match positions for this search query # query="x" text="x___x_xx" == [0, 4, 6, 7] pattern = re . escape ( query ) matches = [ m . start ( ) for m in re . finditer ( pattern , text ) ] if matches : # Sort the list so it begins with matches after `start`, rather # than matches at the beginning of the file # sorted([True, False]) == [False, True] matches . sort ( key = lambda position : position <= start ) if matches [ 0 ] == target : return self . _create_motion ( query ) if matches [ - 1 ] == target : return self . _create_motion ( query , "?" )