d+NXdZddlZddlZGddZedk(rddlmZedd yy) 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. Nc\eZdZejej zdzZdZdZdZ dZ y) AutoExpand_cj|j|_|jj|_d|_y)N)textbellstate)selfeditwins 9/opt/alt/python312/lib64/python3.12/idlelib/autoexpand.py__init__zAutoExpand.__init__s#LL IINN  c|jjd}|jjdd}|js|j }d}n-|j\}}}}||k7s||k7r|j }d}|s|j y|j }|jjdt|zd||} |dzt|z}|dk(r|j |jjd| |jjd}|jjdd}||||f|_y)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_events&IIOOH- ))-- 24DEzzMMOEE)- &E5&$"dgo  IIK! ,s4y8(C,c%j( A: IIK 7+IIOOH- ))-- 24DEE9g5 rc$|j}|sgS|jjdd}tjd|zdz|}~|jjdd}tjd|zdz|}~|s|sgSg}i}|j |D]*}|j|r|j ||||<,|D]*}|j|r|j ||||<,|j ||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.getwords6s!Iu&89**UT\H4f=  .6EDL83U; vIAxx{ LLODG  Axx{ LLODG   T rc|jjdd}t|}|dkDr3||dz |jvr|dz }|dkDr||dz |jvr||dS)z)Return the word prefix before the cursor.rrrrN)rrr wordchars)r ris r rzAutoExpand.getprevwordUsjyy}}/: I!eQqS T^^3!A!eQqS T^^3ABxrN) __name__ __module__ __qualname__string ascii_lettersdigitsr/r r!rrrr rrs/$$v}}4s:I 6>rr__main__)mainz!idlelib.idle_test.test_autoexpand) verbosity)__doc__r$r4rr1unittestr9r7rr r>s<  HHV z ,:r