4 ###$ event <<expand-word>>
11 '<<expand-word>>': ['<Alt-slash>'],
15 '<<expand-word>>': ['<Meta-slash>', '<Alt-slash>'],
20 ('E_xpand word', '<<expand-word>>'),
24 wordchars
= string
.letters
+ string
.digits
+ "_"
26 def __init__(self
, editwin
):
27 self
.text
= editwin
.text
30 def expand_word_event(self
, event
):
31 curinsert
= self
.text
.index("insert")
32 curline
= self
.text
.get("insert linestart", "insert lineend")
34 words
= self
.getwords()
37 words
, index
, insert
, line
= self
.state
38 if insert
!= curinsert
or line
!= curline
:
39 words
= self
.getwords()
44 word
= self
.getprevword()
45 self
.text
.delete("insert - %d chars" % len(word
), "insert")
46 newword
= words
[index
]
47 index
= (index
+ 1) % len(words
)
49 self
.text
.bell() # Warn we cycled around
50 self
.text
.insert("insert", newword
)
51 curinsert
= self
.text
.index("insert")
52 curline
= self
.text
.get("insert linestart", "insert lineend")
53 self
.state
= words
, index
, curinsert
, curline
57 word
= self
.getprevword()
60 before
= self
.text
.get("1.0", "insert wordstart")
61 wbefore
= re
.findall(r
"\b" + word
+ r
"\w+\b", before
)
63 after
= self
.text
.get("insert wordend", "end")
64 wafter
= re
.findall(r
"\b" + word
+ r
"\w+\b", after
)
66 if not wbefore
and not wafter
:
70 # search backwards through words before
77 # search onwards through words after
86 def getprevword(self
):
87 line
= self
.text
.get("insert linestart", "insert")
89 while i
> 0 and line
[i
-1] in self
.wordchars
: