mò
­fIc           @   sb   d  Z  d k Z d k l Z l Z d k l Z d f  d „  ƒ  YZ d „  Z d f  d „  ƒ  YZ d S(	   sæ  ParenMatch -- An IDLE extension 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.

WARNING: This extension will fight with the CallTips extension,
because they both are interested in the KeyRelease-parenright event.
We'll have to fix IDLE to do something reasonable when two or more
extensions what to capture the same event.
N(   s   EditorWindows
   index2line(   s   idleConft
   ParenMatchc           B   sæ   t  Z d  Z g  Z e i d d d d d ƒZ e i d d d d d d d	 ƒZ e i e i	 ƒ  d
 ƒ Z
 e i d d d d d d d ƒZ d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÌ  Highlight matching parentheses

    There are three supported style of paren matching, based loosely
    on the Emacs options.  The style is select based on the
    HILITE_STYLE attribute; it can be changed used the set_style
    method.

    The supported styles are:

    default -- When a right paren is typed, highlight the matching
        left paren for 1/2 sec.

    expression -- When a right paren is typed, highlight the entire
        expression from the left paren to the right paren.

    TODO:
        - fix interaction with CallTips
        - extend IDLE with configuration dialog to change options
        - implement rest of Emacs highlight styles (see below)
        - print mismatch warning in IDLE status window

    Note: In Emacs, there are several styles of highlight where the
    matching paren is highlighted whenever the cursor is immediately
    to the right of a right paren.  I don't know how to do that in Tk,
    so I haven't bothered.
    t
   extensionsR    t   stylet   defaultt
   expressions   flash-delayt   typet   intiô  t   hilitet   bellt   booli   c         C   sJ   | |  _  | i |  _ t | ƒ |  _ d |  _ d  |  _ |  i |  i	 ƒ d  S(   Ni    (
   t   editwint   selft   textt   LastOpenBracketFindert   findert   countert   Nonet   _restoret	   set_stylet   STYLE(   R   R
   (    (    t/   /mit/python/lib/python2.4/idlelib/ParenMatch.pyt   __init__5   s    			c         C   s_   | |  _ | d j o |  i |  _ |  i |  _ n* | d j o |  i |  _ |  i |  _ n d  S(   NR   R   (	   R   R   R   t   create_tag_defaultt
   create_tagt   set_timeout_lastt   set_timeoutt   create_tag_expressiont   set_timeout_none(   R   R   (    (    R   R   =   s    	c         C   s^   |  i i t | i ƒ ƒ } | d  j o |  i ƒ  d  Sn d |  _	 |  i
 | ƒ |  i ƒ  d  S(   Ni   (   R   R   t   findt   keysym_typet   eventt   keysymt   indexR   t   warn_mismatchedR   R   R   (   R   R   R    (    (    R   t   flash_open_paren_eventF   s    
	c         C   s+   |  i o |  i i d ƒ d  |  _ n d  S(   Nt   paren(   R   R   R   t
   tag_deleteR   (   R   R   (    (    R   t   check_restore_eventO   s    
c         C   s&   | d |  i j o |  i ƒ  n d  S(   Ni   (   t   timer_countR   R   R%   (   R   R&   (    (    R   t   handle_restore_timerT   s    c         C   s   |  i o |  i i ƒ  n d  S(   N(   R   t   BELLR   R   (   R   (    (    R   R!   X   s    
c         C   s-   |  i i d | ƒ |  i i d |  i ƒ d S(   s'   Highlight the single paren that matchesR#   N(   R   R   t   tag_addR    t
   tag_configt   HILITE_CONFIG(   R   R    (    (    R   R   _   s     c         C   s0   |  i i d | d ƒ |  i i d |  i ƒ d S(   s   Highlight the entire expressionR#   t   insertN(   R   R   R)   R    R*   R+   (   R   R    (    (    R   R   d   s     c         C   s   d S(   s3   Highlight will remain until user input turns it offN(    (   R   (    (    R   R   l   s    c         C   s9   |  i i i |  i |  |  i d „ ƒ |  i d |  _ d S(   s7   The last highlight created will be removed after .5 secc         C   s   |  i | ƒ S(   N(   R   R'   t   c(   R   R-   (    (    R   t   <lambda>u   s    i   N(   R   R
   t
   text_framet   aftert   FLASH_DELAYR   (   R   (    (    R   R   p   s     (   t   __name__t
   __module__t   __doc__t   menudefst   idleConft	   GetOptionR   R1   t   GetHighlightt   CurrentThemeR+   R(   R   R   R"   R   R%   R'   R!   R   R   R   R   (    (    (    R   R       s&    										c         C   sj   |  d j p |  d j o d Sn |  d j p |  d j o d Sn |  d j p |  d j o d	 Sn d  S(
   Nt
   parenrightt   (R#   t   bracketrightt   [t   brackett
   bracerightt   {t   brace(   t   ks(   RB   (    (    R   R   y   s    R   c           B   sP   t  Z e i Z e i Z e i Z e i Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   Nc         C   s   | |  _  | i |  _ d  S(   N(   R
   R   R   (   R   R
   (    (    R   R   ‰   s    	c   	      C   sã   t  i |  i |  i ƒ } x› |  i D] } t | | d ƒ } t | ƒ d } |  i i | d ƒ d  d } | i | ƒ | i |  i |  i | ƒ ƒ } | d  j	 p | d j o Pq" q" W| i | p d ƒ | i ƒ  } | | i f S(   Ni   s   .0R,   iÿÿÿÿs   
i    (   t   PyParset   ParserR   t   indentwidtht   tabwidtht   yt   num_context_linest   contextt   maxt   lnot   startatt   reprt   startatindexR   t   gett   rawtextt   set_strt   find_good_parse_startt   context_use_ps1t   _build_char_in_string_funct   bodR   t   set_lot   get_last_open_bracket_post   it   str(	   R   RK   RP   RL   RX   RI   RG   RN   RU   (    (    R   t   _find_offset_in_buf   s    
 	c   	      C   s©   t  |  i i d ƒ ƒ } |  i | ƒ \ } } | d j p t	 | | ƒ | j o d Sn | | i d ƒ d } | |  } | i d ƒ d } | | } d | | | f S(   s*   Return the location of the last open parenR,   s   
i   s   %d.%dN(   t
   index2lineR   R   R    RK   RZ   RX   t   bufR   R   t   right_keysym_typet   countt
   lines_backt	   upto_opent   rfindt   jt   offset(	   R   R]   R_   RX   Rb   RK   Rc   R\   R`   (    (    R   R       s     $

c         C   s   | |  i i d „ } | S(   Nc         C   s   | | d |  ƒ S(   Ns   %dc(   t   icist
   startindexRc   (   Rc   Re   Rd   (    (    R   t   inner¯   s    (   Re   R   R
   t   is_char_in_stringRf   (   R   Re   Rf   (    (    R   RT   ®   s    (   R2   R3   t   EditorWindowRH   RE   RF   RS   R   RZ   R   RT   (    (    (    R   R   ƒ   s   							(	   R4   RC   Rh   R[   t   configHandlerR6   R    R   R   (   R   R[   RC   Rh   R6   R   R    (    (    R   t   ?   s   	h	
