Replace the current word with the next expansion.
(self, event)
| 25 | self.state = None |
| 26 | |
| 27 | def expand_word_event(self, event): |
| 28 | "Replace the current word with the next expansion." |
| 29 | curinsert = self.text.index("insert") |
| 30 | curline = self.text.get("insert linestart", "insert lineend") |
| 31 | if not self.state: |
| 32 | words = self.getwords() |
| 33 | index = 0 |
| 34 | else: |
| 35 | words, index, insert, line = self.state |
| 36 | if insert != curinsert or line != curline: |
| 37 | words = self.getwords() |
| 38 | index = 0 |
| 39 | if not words: |
| 40 | self.bell() |
| 41 | return "break" |
| 42 | word = self.getprevword() |
| 43 | self.text.delete("insert - %d chars" % len(word), "insert") |
| 44 | newword = words[index] |
| 45 | index = (index + 1) % len(words) |
| 46 | if index == 0: |
| 47 | self.bell() # Warn we cycled around |
| 48 | self.text.insert("insert", newword) |
| 49 | curinsert = self.text.index("insert") |
| 50 | curline = self.text.get("insert linestart", "insert lineend") |
| 51 | self.state = words, index, curinsert, curline |
| 52 | return "break" |
| 53 | |
| 54 | def getwords(self): |
| 55 | "Return a list of words that match the prefix before the cursor." |