MCPcopy Create free account
hub / github.com/python/cpython / expand_word_event

Method expand_word_event

Lib/idlelib/autoexpand.py:27–52  ·  view source on GitHub ↗

Replace the current word with the next expansion.

(self, event)

Source from the content-addressed store, hash-verified

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."

Callers

nothing calls this directly

Calls 7

getwordsMethod · 0.95
getprevwordMethod · 0.95
indexMethod · 0.45
getMethod · 0.45
bellMethod · 0.45
deleteMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected