mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
merge from 3.4
This commit is contained in:
parent
24330ffb4d
commit
13f4aba10b
3 changed files with 164 additions and 0 deletions
|
|
@ -1,3 +1,17 @@
|
|||
'''Complete the current word before the cursor with words in the editor.
|
||||
|
||||
Each menu selection or shortcut key selection replaces the word with a
|
||||
different word with the same prefix. The search for matches begins
|
||||
before the target and moves toward the top of the editor. It then starts
|
||||
after the cursor and moves down. It then returns to the original word and
|
||||
the cycle starts again.
|
||||
|
||||
Changing the current text line or leaving the cursor in a different
|
||||
place before requesting the next selection causes AutoExpand to reset
|
||||
its state.
|
||||
|
||||
This is an extension file and there is only one instance of AutoExpand.
|
||||
'''
|
||||
import string
|
||||
import re
|
||||
|
||||
|
|
@ -20,6 +34,7 @@ def __init__(self, editwin):
|
|||
self.state = None
|
||||
|
||||
def expand_word_event(self, event):
|
||||
"Replace the current word with the next expansion."
|
||||
curinsert = self.text.index("insert")
|
||||
curline = self.text.get("insert linestart", "insert lineend")
|
||||
if not self.state:
|
||||
|
|
@ -46,6 +61,7 @@ def expand_word_event(self, event):
|
|||
return "break"
|
||||
|
||||
def getwords(self):
|
||||
"Return a list of words that match the prefix before the cursor."
|
||||
word = self.getprevword()
|
||||
if not word:
|
||||
return []
|
||||
|
|
@ -76,8 +92,13 @@ def getwords(self):
|
|||
return words
|
||||
|
||||
def getprevword(self):
|
||||
"Return the word prefix before the cursor."
|
||||
line = self.text.get("insert linestart", "insert")
|
||||
i = len(line)
|
||||
while i > 0 and line[i-1] in self.wordchars:
|
||||
i = i-1
|
||||
return line[i:]
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
unittest.main('idlelib.idle_test.test_autoexpand', verbosity=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue