###$ event <<expand-word>>
('E_xpand Word', '<<expand-word>>'),
wordchars
= string
.ascii_letters
+ string
.digits
+ "_"
def __init__(self
, editwin
):
def expand_word_event(self
, event
):
curinsert
= self
.text
.index("insert")
curline
= self
.text
.get("insert linestart", "insert lineend")
words
, index
, insert
, line
= self
.state
if insert
!= curinsert
or line
!= curline
:
word
= self
.getprevword()
self
.text
.delete("insert - %d chars" % len(word
), "insert")
index
= (index
+ 1) % len(words
)
self
.text
.bell() # Warn we cycled around
self
.text
.insert("insert", newword
)
curinsert
= self
.text
.index("insert")
curline
= self
.text
.get("insert linestart", "insert lineend")
self
.state
= words
, index
, curinsert
, curline
word
= self
.getprevword()
before
= self
.text
.get("1.0", "insert wordstart")
wbefore
= re
.findall(r
"\b" + word
+ r
"\w+\b", before
)
after
= self
.text
.get("insert wordend", "end")
wafter
= re
.findall(r
"\b" + word
+ r
"\w+\b", after
)
if not wbefore
and not wafter
:
# search backwards through words before
# search onwards through words after
line
= self
.text
.get("insert linestart", "insert")
while i
> 0 and line
[i
-1] in self
.wordchars
: