3  f$@sfdZddlmZddlmZddddZdZGd d d Zeje d krbdd l m Z e d dddS)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([{))]}dc@seZdZdZdZd%ZddZed d Zd d Z d dZ ddZ ddZ ddZ d&ddZddZddZddZddZeeeed Zd!d"Zd#d$ZdS)' ParenMatcha'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<> cCs0||_|j|_|jj|j|jd|_d|_dS)Nr)editwintextZbindRESTORE_VIRTUAL_EVENT_NAME restore_eventcounteris_restore_active)selfrr7/opt/alt/python36/lib64/python3.6/idlelib/parenmatch.py__init__(s  zParenMatch.__init__cCsVtjddddd|_tjdddddd |_tjddd d d d |_tjtjd |_dS)N extensionsr Zstyleopener)defaultz flash-delayinti)typerbellboolZhilite)rZ GetOptionSTYLE FLASH_DELAYBELLZ GetHighlightZ CurrentTheme HILITE_CONFIG)clsrrrreload3s zParenMatch.reloadcCs0|js,x|jD]}|jj|j|qWd|_dS)z5Activate mechanism to restore text from highlighting.TN)rRESTORE_SEQUENCESrZ event_addr)rseqrrractivate_restore>s zParenMatch.activate_restorecCs0|jr,x|jD]}|jj|j|qWd|_dS)zRemove restore event bindings.FN)rr(rZ event_deleter)rr)rrrdeactivate_restoreEs zParenMatch.deactivate_restorecCst|jdj}|j|dS)zAHandle editor 'show surrounding parens' event (menu or shortcut).insertbreak)rrget_surrounding_bracketsfinish_paren_event)reventindicesrrrflash_paren_eventLs zParenMatch.flash_paren_eventcCsN|jjd}|tkrdSt|jd}|js0dS|jt|d}|j|dS)zHandle user input of closer.z insert-1cNT)rget_openersrrZ is_in_coder.r/)rr0ZcloserZhpr1rrrparen_closed_eventSs   zParenMatch.paren_closed_eventcCsT|dkr|jr|jjdS|j|jj|j|j|||jrH|j n|j dS)N) r$rrr*tagfuncsr3r"create_tag_expressionr#set_timeout_lastset_timeout_none)rr1rrrr/`s  zParenMatch.finish_paren_eventNcCs&|jjd|j|jd7_dS)zRemove effect of doing match.parenr!N)rZ tag_deleter+r)rr0rrrrks zParenMatch.restore_eventcCs||jkr|jdS)N)rr)rZ timer_countrrrhandle_restore_timerqs zParenMatch.handle_restore_timercCs&|jjd|d|jjd|jdS)z'Highlight the single paren that matchesr:rN)rtag_add tag_configr%)rr1rrrcreate_tag_openerxszParenMatch.create_tag_openercCsb|jj|dd kr"|dd}n|d}|jjd|d|dd|d||jjd|jd S) z#Highlight the left and right parensr!rrr z+1cr:rz-1cN)rrr )rr3r<r=r%)rr1 rightindexrrrcreate_tag_parens}s $zParenMatch.create_tag_parenscCsR|jj|dd kr"|dd}n|d}|jjd|d||jjd|jdS) zHighlight the entire expressionr!rrr z+1cr:rN)rrr )rr3r<r=r%)rr1r?rrrr7s z ParenMatch.create_tag_expression)rrZparensZ expressioncCs>|jd7_||j|jjdfdd}|jjjt||dS)zSHighlight will remain until user input turns it off or the insert has movedr!r,cSs2||jjdkr|j|n|jjjt||dS)Nr,)rindexr;r text_frameafter CHECK_DELAY)callmercrArrrrEs z+ParenMatch.set_timeout_none..callmeN)rrrArrBrCrD)rrErrrr9szParenMatch.set_timeout_nonecCs0|jd7_|jjj|j||jfdddS)zFThe last highlight created will be removed after FLASH_DELAY millisecsr!cSs |j|S)N)r;)rrFrrrsz-ParenMatch.set_timeout_last..N)rrrBrCr#)rrrrr8szParenMatch.set_timeout_last)r r rr)N)__name__ __module__ __qualname____doc__rr(r classmethodr'r*r+r2r5r/rr;r>r@r7r6r9r8rrrrr s,     r __main__)mainz!idlelib.idle_test.test_parenmatch) verbosityN) rKZidlelib.hyperparserrZidlelib.configrr4rDr r'rHZunittestrNrrrrs   &