Search backwards and return an re match object or None. This is done by searching forwards until there is no match. Prog: compiled re object with a search method returning a match. Chars: line of text, without \\n. Col: stop index for the search; the limit for match.end().
(prog, chars, col)
| 187 | |
| 188 | |
| 189 | def search_reverse(prog, chars, col): |
| 190 | '''Search backwards and return an re match object or None. |
| 191 | |
| 192 | This is done by searching forwards until there is no match. |
| 193 | Prog: compiled re object with a search method returning a match. |
| 194 | Chars: line of text, without \\n. |
| 195 | Col: stop index for the search; the limit for match.end(). |
| 196 | ''' |
| 197 | m = prog.search(chars) |
| 198 | if not m: |
| 199 | return None |
| 200 | found = None |
| 201 | i, j = m.span() # m.start(), m.end() == match slice indexes |
| 202 | while i < col and j <= col: |
| 203 | found = m |
| 204 | if i == j: |
| 205 | j = j+1 |
| 206 | m = prog.search(chars, j) |
| 207 | if not m: |
| 208 | break |
| 209 | i, j = m.span() |
| 210 | return found |
| 211 | |
| 212 | def get_selection(text): |
| 213 | '''Return tuple of 'line.col' indexes from selection or insert mark. |
no test coverage detected
searching dependent graphs…