\d jdZddlZddlZGddZedkrddlmZedd dSdS) a=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. There is only one instance of Autoexpand. NcJeZdZejejzdzZdZdZdZ dZ dS) AutoExpand_cN|j|_|jj|_d|_dS)N)textbellstate)selfeditwins #..\python\lib\idlelib\autoexpand.py__init__zAutoExpand.__init__s!L IN  c|jd}|jdd}|js|}d}n.|j\}}}}||ks||kr|}d}|s|dS|}|jdt|zd||} |dzt|z}|dkr||j d| |jd}|jdd}||||f|_dS)z1Replace the current word with the next expansion.insertinsert linestartzinsert lineendrbreakzinsert - %d chars) rindexgetr getwordsr getprevworddeletelenr) r event curinsertcurlinewordsrrlinewordnewwords r expand_word_eventzAutoExpand.expand_word_eventsXIOOH-- )-- 24DEEz MMOOEEE)- &E5&$""dgoo   IIKKK7!! ,s4yy8(CCC,c%jj( A:: IIKKK 7+++IOOH-- )-- 24DEEE9g5 wrcL|}|sgS|jdd}tjd|zdz|}~|jdd}tjd|zdz|}~|s|sgSg}i}||D]2}||r|||||<3|D]2}||r|||||<3|||S)z?Return a list of words that match the prefix before the cursor.z1.0zinsert wordstartz\bz\w+\bzinsert wordendend)rrrrefindallreverseappend) r rbeforewbeforeafterwafterrdictws r rzAutoExpand.getwords6sG!! Iu&899*UT\H4f==  .66EDL83U;;  v I  Axx{{  LLOOODGG  Axx{{  LLOOODGG T rc|jdd}t|}|dkr/||dz |jvr|dz }|dkr||dz |jv||dS)z)Return the word prefix before the cursor.rrrrN)rrr wordchars)r ris r rzAutoExpand.getprevwordUsuy}}/:: II!eeQqS T^33!A!eeQqS T^33ABBxrN) __name__ __module__ __qualname__string ascii_lettersdigitsr/r r!rrrr rrsd$v}4s:I 6>rr__main__)mainz!idlelib.idle_test.test_autoexpand) verbosity)__doc__r$r4rr1unittestr9r7rr r>s   HHHHHHHHV zD ,::::::r