ó
t®¸Qc           @   s`   d  d l  Z  d  d l m Z d d
 d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d	 „  Z d S(   iÿÿÿÿN(   t   idleConft   FormatParagraphc           B   s5   e  Z d  d g f g Z d „  Z d „  Z d „  Z RS(   t   formats   Format Paragraphs   <<format-paragraph>>c         C   s   | |  _  d  S(   N(   t   editwin(   t   selfR   (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyt   __init__   s    c         C   s   d  |  _ d  S(   N(   t   NoneR   (   R   (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyt   close   s    c         C   sç  t  t j d d d d d ƒƒ } |  j j } |  j j ƒ  \ } } | ri | ri | j | | ƒ } d } n$ t | | j d ƒ ƒ \ } } } } | rQ| j	 d ƒ } t
 t | ƒ d	 „ | ƒ } d j | ƒ } t | t | ƒ d
 ƒ }	 t | |	 ƒ }
 |
 j	 d ƒ }
 d } |
 d s&d } |
 d  }
 n  | d „ } d j t
 | |
 ƒ ƒ | }
 n t | | ƒ }
 | j d d d ƒ |
 | k rÆ| j d | ƒ | j ƒ  | j | | ƒ | j | |
 ƒ | j ƒ  n | j d | ƒ | j d ƒ d S(   Nt   mainR   t	   paragrapht   typet   intt    t   inserts   
c         S   s   |  | S(   N(    (   t   stt   l(    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyt   <lambda>0   s    i   iÿÿÿÿc         S   s   | |  S(   N(    (   t   itemt   prefix(    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR   @   s    t   sels   1.0t   endt   break(   R   R    t	   GetOptionR   t   textt   get_selection_indicest   gett   find_paragrapht   indext   splitt   mapt   lent   joint   maxt   reformat_paragrapht
   tag_removet   mark_sett   undo_block_startt   deleteR   t   undo_block_stopt   see(   R   t   eventt   maxformatwidthR   t   firstt   lastt   datat   comment_headert   linest   format_widtht   newdatat   block_suffixt   builder(    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyt   format_paragraph_event"   s@    	$

(   s   Format Paragraphs   <<format-paragraph>>(   t   __name__t
   __module__t   menudefsR   R   R3   (    (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR      s
   		c   
   
   C   s¦  t  t | j d ƒ ƒ \ } } |  j d | d | ƒ } xM |  j d | d d ƒ r‡ t | ƒ r‡ | d } |  j d | d | ƒ } q; W| } t | ƒ } t | ƒ } xK t | ƒ | k ró t | | ƒ ró | d } |  j d | d | ƒ } q© Wd | } | d } |  j d | d | ƒ } xW | d k r{t | ƒ | k r{t | | ƒ r{| d } |  j d | d | ƒ } q%Wd | d }	 |	 | | |  j |	 | ƒ f S(   Nt   .s   %d.0s   %d.0 lineendt   <R   i   i    (   R   R   R   R   t   comparet   is_all_whitet   get_comment_headerR   (
   R   t   markt   linenot   colt   linet   first_linenoR-   t   comment_header_lenR+   R*   (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR   Q   s,    (




c      	   C   s÷  |  j  d ƒ } d } t | ƒ } x* | | k  rM t | | ƒ rM | d } q$ W| | k r^ |  St | | ƒ } | d | k  rª t | | d ƒ rª t | | d ƒ } n | } | |  } | } x| | k  rÅt | | ƒ rÅt j  d | | ƒ }	 x¿ t d t |	 ƒ d ƒ D]¥ }
 |	 |
 } | s+qn  t | | j ƒ  ƒ | k ro| | k ro| j | j ƒ  ƒ | } n  | | d } |
 d t |	 ƒ k  r|	 |
 d d k r| d } qqW| d } qÃ W| j | j ƒ  ƒ | j	 | | ƒ d j
 | ƒ S(   Ns   
i    i   s   (\s+)i   t    (   R   R   R:   t
   get_indentt   ret   ranget
   expandtabst   appendt   rstript   extendR   (   R,   t   limitR.   t   it   nt   indent1t   indent2t   newt   partialt   wordst   jt   word(    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR!   j   s<    %
 
	*c         C   s   t  j d |  ƒ d  k	 S(   Ns   ^\s*$(   RD   t   matchR   (   R?   (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR:      s    c         C   s   t  j d |  ƒ j ƒ  S(   Ns   ^(\s*)(   RD   RT   t   group(   R?   (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyRC      s    c         C   s/   t  j d |  ƒ } | d  k r" d S| j d ƒ S(   Ns   ^(\s*#*)R   i   (   RD   RT   R   RU   (   R?   t   m(    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyR;   “   s     (    (	   RD   t   idlelib.configHandlerR    R   R   R!   R:   RC   R;   (    (    (    s-   /sys/lib/python2.7/idlelib/FormatParagraph.pyt   <module>   s   =		#		