
   G镢                       S r SSKJr  SSKJr  SSSS.rSr " S	 S
5      r\R                  5         \	S:X  a  SSK
Jr  \" SSS9  gg)zParenMatch -- for parenthesis matching.

When you hit a right paren, the cursor should move briefly to the left
paren.  Paren here is used generically; the matching applies to
parentheses, square brackets, and curly braces.
    )HyperParser)idleConf([{)]}d   c                       \ rS rSrSrSrSrS r\S 5       r	S r
S rS	 rS
 rS rSS jrS rS rS rS r\\\\S.rS rS rSrg)
ParenMatch   a  Highlight matching openers and closers, (), [], and {}.

There are three supported styles of paren matching.  When a right
paren (opener) is typed:

opener -- highlight the matching left paren (closer);
parens -- highlight the left and right parens (opener and closer);
expression -- highlight the entire expression from opener to closer.
(For back compatibility, 'default' is a synonym for 'opener').

Flash-delay is the maximum milliseconds the highlighting remains.
Any cursor movement (key press or click) before that removes the
highlight.  If flash-delay is 0, there is no maximum.

TODO:
- Augment bell() with mismatch warning in status window.
- Highlight when cursor is moved to the right of a closer.
  This might be too expensive to check.
z<<parenmatch-check-restore>>)z
<KeyPress>z<ButtonPress>z<Key-Return>z<Key-BackSpace>c                     Xl         UR                  U l        UR                  R                  U R                  U R                  5        SU l        SU l        g )Nr   )editwintextbindRESTORE_VIRTUAL_EVENT_NAMErestore_eventcounteris_restore_active)selfr   s     )/usr/lib/python3.13/idlelib/parenmatch.py__init__ParenMatch.__init__(   sF    LL	 	$99,,	.!"    c                    [         R                  " SSSSS9U l        [         R                  " SSSSSS	9U l        [         R                  " SSS
SSS	9U l        [         R
                  " [         R                  " 5       S5      U l        g )N
extensionsr   styleopener)defaultzflash-delayinti  )typer!   bellbool   hilite)r   	GetOptionSTYLEFLASH_DELAYBELLGetHighlightCurrentThemeHILITE_CONFIG)clss    r   reloadParenMatch.reload3   s{    &&gxA	",,\-eCQ%%\&vqJ$11(2G2G2I2:<r   c                     U R                   (       dA  U R                   H)  nU R                  R                  U R                  U5        M+     SU l         gg)z5Activate mechanism to restore text from highlighting.TN)r   RESTORE_SEQUENCESr   	event_addr   r   seqs     r   activate_restoreParenMatch.activate_restore>   sB    %%--		##D$C$CSI .%)D" &r   c                     U R                   (       aA  U R                   H)  nU R                  R                  U R                  U5        M+     SU l         gg)zRemove restore event bindings.FN)r   r3   r   event_deleter   r5   s     r   deactivate_restoreParenMatch.deactivate_restoreE   sB    !!--		&&t'F'FL .%*D" "r   c                 n    [        U R                  S5      R                  5       nU R                  U5        g)zAHandle editor 'show surrounding parens' event (menu or shortcut).insertbreak)r   r   get_surrounding_bracketsfinish_paren_event)r   eventindicess      r   flash_paren_eventParenMatch.flash_paren_eventL   s/    t||X6,,. 	(r   c                     U R                   R                  S5      nU[        ;  a  g[        U R                  S5      nUR                  5       (       d  gUR                  [        U   S5      nU R                  U5        g)zHandle user input of closer.z	insert-1cNT)r   get_openersr   r   
is_in_coder@   rA   )r   rB   closerhprC   s        r   paren_closed_eventParenMatch.paren_closed_eventS   sg     {+!{3}}--hv.>E(r   c                 J   Uc,  U R                   (       a  U R                  R                  5         g U R                  5         U R                  R                  U R                  U R                  5      " X5        U R                  (       a  U R                  OU R                  " 5         g N)r+   r   r$   r7   tagfuncsrG   r)   create_tag_expressionr*   set_timeout_lastset_timeout_noner   rC   s     r   rA   ParenMatch.finish_paren_event`   sq    ?tyyIINN$**d&@&@A$P"&"2"2		 11
2 	5r   Nc                     U R                   R                  S5        U R                  5         U =R                  S-  sl        g)zRemove effect of doing match.parenr&   N)r   
tag_deleter;   r   )r   rB   s     r   r   ParenMatch.restore_eventk   s.    		W%!r   c                 D    XR                   :X  a  U R                  5         g g rO   )r   r   )r   timer_counts     r   handle_restore_timerParenMatch.handle_restore_timerq   s    ,,&  'r   c                     U R                   R                  SUS   5        U R                   R                  SU R                  5        g)z'Highlight the single paren that matchesrW   r   N)r   tag_add
tag_configr.   rT   s     r   create_tag_openerParenMatch.create_tag_openerx   s4    		'71:.		Wd&8&89r   c                    U R                   R                  US   5      S;   a	  US   S-   nOUS   nU R                   R                  SUS   US   S-   US-   U5        U R                   R                  SU R                  5        g)z#Highlight the left and right parensr&   r   +1crW   r   z-1cNr   rG   r_   r`   r.   r   rC   
rightindexs      r   create_tag_parensParenMatch.create_tag_parens}   sy    99==$7 E)J J		'71:wqz%/?EAQS]^		Wd&8&89r   c                     U R                   R                  US   5      S;   a	  US   S-   nOUS   nU R                   R                  SUS   U5        U R                   R                  SU R                  5        g)zHighlight the entire expressionr&   r   rd   rW   r   Nre   rf   s      r   rQ    ParenMatch.create_tag_expression   sf    99==$7 E)J J		'71:z:		Wd&8&89r   )r    r!   parens
expressionc                     U =R                   S-  sl         X R                   U R                  R                  S5      4S jnU R                  R                  R                  [        X5        g)zKHighlight will remain until user input turns it off
or the insert has movedr&   r>   c                     X1R                   R                  S5      :w  a  UR                  U5        g UR                  R                  R                  [        X 5        g )Nr>   )r   indexr\   r   
text_frameafterCHECK_DELAY)callmer   crp   s       r   rt   +ParenMatch.set_timeout_none.<locals>.callme   s=    		11))!,''--k6Jr   N)r   r   rp   r   rq   rr   rs   )r   rt   s     r   rS   ParenMatch.set_timeout_none   sK     	 $2	K 	%%k6Br   c                     U =R                   S-  sl         U R                  R                  R                  U R                  X R                   4S j5        g)zFThe last highlight created will be removed after FLASH_DELAY millisecsr&   c                 $    U R                  U5      $ rO   )r\   )r   ru   s     r   <lambda>-ParenMatch.set_timeout_last.<locals>.<lambda>   s    d.G.G.Jr   N)r   r   rq   rr   r*   )r   s    r   rR   ParenMatch.set_timeout_last   s>     	%%J	Lr   )r   r   r   r   rO   )__name__
__module____qualname____firstlineno____doc__r   r3   r   classmethodr0   r7   r;   rD   rL   rA   r   r\   ra   rh   rQ   rP   rS   rR   __static_attributes__ r   r   r   r      s    ( "@<	# < <*+	5!:
:: $$#+	
HCLr   r   __main__)mainz!idlelib.idle_test.test_parenmatch   )	verbosityN)r   idlelib.hyperparserr   idlelib.configr   rH   rs   r   r0   r}   unittestr   r   r   r   <module>r      s]    , #$bL bLJ     z	,: r   