ž ©ÿfþc@sÑdZddlZddlmZGdd„dƒZdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z e dkrÍddl m Z dge _ddlZejdddddƒndS(uÐExtension to format a paragraph or selection to a max width. Does basic, standard text formatting, and also understands Python comment blocks. Thus, for editing Python source code, this extension is really only suitable for reformatting these comment blocks or triple-quoted strings. Known problems with comment reformatting: * If there is a selection marked, and the first line of the selection is not complete, the block will probably not be detected as comments, and will have the normal "text formatting" rules applied. * If a comment block has leading whitespace that mixes tabs and spaces, they will not be considered part of the same block. * Fancy comments, like this bulleted list, aren't handled :-) iN(uidleConfcBsJ|EeZdZdd gfgZdd„Zdd„Zdd „Zd S( uFormatParagraphuformatuFormat Paragraphu<>cCs ||_dS(N(ueditwin(uselfueditwin((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyu__init__suFormatParagraph.__init__cCs d|_dS(N(uNoneueditwin(uself((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyuclose suFormatParagraph.closec Cs>tjdddddƒ}|jj}|jjƒ\}}|ri|ri|j||ƒ}t|ƒ}n$t||jdƒƒ\}}}}|r¨t |||ƒ}nt ||ƒ}|j ddd ƒ||kr|j d|ƒ|j ƒ|j||ƒ|j||ƒ|jƒn|j d|ƒ|jdƒd S( uŽFormats paragraph to a max width specified in idleConf. If text is selected, format_paragraph_event will start breaking lines at the max width, starting from the beginning selection. If no text is selected, format_paragraph_event uses the current cursor location to determine the paragraph (lines of text surrounded by blank lines) and formats it. umainuFormatParagraphu paragraphutypeuintuinsertuselu1.0uendubreak(uidleConfu GetOptionueditwinutextuget_selection_indicesugetuget_comment_headerufind_paragraphuindexureformat_commentureformat_paragraphu tag_removeumark_setuundo_block_startudeleteuinsertuundo_block_stopusee( uselfueventumaxformatwidthutextufirstulastudataucomment_headerunewdata((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyuformat_paragraph_event#s*   $    u&FormatParagraph.format_paragraph_eventN(uFormat Paragraphu<>(u__name__u __module__u __qualname__umenudefsu__init__ucloseuformat_paragraph_event(u __locals__((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyuFormatParagraphs   uFormatParagraphc Cs²tt|jdƒƒ\}}|jd|d|ƒ}xM|jd|ddƒr‡t|ƒr‡|d}|jd|d|ƒ}q;W|}t|ƒ}t|ƒ}xQt|ƒ|krùt||d…ƒ rù|d}|jd|d|ƒ}q©Wd|}|d}|jd|d|ƒ}x]|dkr‡t|ƒ|kr‡t||d…ƒ r‡|d}|jd|d|ƒ}q+Wd|d} | |||j| |ƒfS( u»Returns the start/stop indices enclosing the paragraph that mark is in. Also returns the comment format string, if any, and paragraph of text between the start/stop indices. u.u%d.0u%d.endu–su#reformat_comment..iuiNc3s|]}ˆ|VqdS(N((u.0uline(ucomment_header(u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyu ¥siÿÿÿÿiÿÿÿÿ(ulenujoinusplitumaxureformat_paragraph(udataulimitucomment_headeru format_widthunewdatau block_suffix((ucomment_headerulcu</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyureformat_comment‘s + ureformat_commentcCstjd|ƒdk S(u/Return True if line is empty or all whitespace.u^\s*$N(ureumatchuNone(uline((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyu is_all_white§su is_all_whitecCstjd|ƒjƒS(u/Return the initial space or tab indent of line.u ^([ \t]*)(ureumatchugroup(uline((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyu get_indent¬su get_indentcCs/tjd|ƒ}|dkr"dS|jdƒS(uReturn string with leading whitespace and '#' from line or ''. A null return indicates that the line is not a comment line. A non- null return, such as ' #', will be used to find the other lines of a comment block with the same indent. u ^([ \t]*#*)uiN(ureumatchuNoneugroup(ulineum((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyuget_comment_header°s uget_comment_headeru__main__(usupportuguiu&idlelib.idle_test.test_formatparagraphu verbosityiuexitF(u__doc__ureuidlelib.configHandleruidleConfuFormatParagraphufind_paragraphureformat_paragraphureformat_commentu is_all_whiteu get_indentuget_comment_headeru__name__utestusupportu use_resourcesuunittestumainuFalse(((u</opt/alt/python33/lib64/python3.3/idlelib/FormatParagraph.pyus 3 % $