diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-06-04 20:50:59 -0400 |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-06-04 20:50:59 -0400 |
commit | 7936e6f7558e6944feef07c992d160c4cd2d0a48 (patch) | |
tree | 75551503b34c2a17db8130bbd297f4d29f05d247 /Lib/idlelib/AutoExpand.py | |
parent | e3fcfc240d834083ebe05b6ca2faae5988b8477e (diff) | |
download | cpython-git-7936e6f7558e6944feef07c992d160c4cd2d0a48.tar.gz |
Issue #18292: Idle - test AutoExpand. Patch by Saihadhav Heblikar.
Diffstat (limited to 'Lib/idlelib/AutoExpand.py')
-rw-r--r-- | Lib/idlelib/AutoExpand.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/idlelib/AutoExpand.py b/Lib/idlelib/AutoExpand.py index 9e93d57d65..7059054281 100644 --- a/Lib/idlelib/AutoExpand.py +++ b/Lib/idlelib/AutoExpand.py @@ -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 @@ class AutoExpand: 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 @@ class AutoExpand: 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 @@ class AutoExpand: 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) |