Return a list of words that match the prefix before the cursor.
(self)
| 52 | return "break" |
| 53 | |
| 54 | def getwords(self): |
| 55 | "Return a list of words that match the prefix before the cursor." |
| 56 | word = self.getprevword() |
| 57 | if not word: |
| 58 | return [] |
| 59 | before = self.text.get("1.0", "insert wordstart") |
| 60 | wbefore = re.findall(r"\b" + word + r"\w+\b", before) |
| 61 | del before |
| 62 | after = self.text.get("insert wordend", "end") |
| 63 | wafter = re.findall(r"\b" + word + r"\w+\b", after) |
| 64 | del after |
| 65 | if not wbefore and not wafter: |
| 66 | return [] |
| 67 | words = [] |
| 68 | dict = {} |
| 69 | # search backwards through words before |
| 70 | wbefore.reverse() |
| 71 | for w in wbefore: |
| 72 | if dict.get(w): |
| 73 | continue |
| 74 | words.append(w) |
| 75 | dict[w] = w |
| 76 | # search onwards through words after |
| 77 | for w in wafter: |
| 78 | if dict.get(w): |
| 79 | continue |
| 80 | words.append(w) |
| 81 | dict[w] = w |
| 82 | words.append(word) |
| 83 | return words |
| 84 | |
| 85 | def getprevword(self): |
| 86 | "Return the word prefix before the cursor." |