ó {fc@s£dZddlZddlmZddd„ƒYZd„Zd„Zd„Zd „Zd „Z d „Z e d krŸddl Z e j d dddeƒndS(sÐ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 :-) iÿÿÿÿN(tidleConftFormatParagraphcBs8eZddgfgZd„Zd„Zdd„ZRS(tformatsFormat Paragraphs<>cCs ||_dS(N(teditwin(tselfR((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyt__init__scCs d|_dS(N(tNoneR(R((s//usr/lib64/python2.7/idlelib/FormatParagraph.pytclose sc CsS|d kr0tjdddddddƒ}n|jj}|jjƒ\}}|r~|r~|j||ƒ}t|ƒ}n$t||j dƒƒ\}}}}|r½t |||ƒ}nt ||ƒ}|j d d d ƒ||kr2|j d|ƒ|jƒ|j||ƒ|j||ƒ|jƒn|j d|ƒ|jdƒd S(sÕ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. The length limit parameter is for testing with a known value. t extensionsRs max-widthttypetinttdefaultiHtinserttsels1.0tendtbreakN(RRt GetOptionRttexttget_selection_indicestgettget_comment_headertfind_paragraphtindextreformat_commenttreformat_paragrapht tag_removetmark_settundo_block_starttdeleteR tundo_block_stoptsee( RteventtlimitRtfirsttlasttdatatcomment_headertnewdata((s//usr/lib64/python2.7/idlelib/FormatParagraph.pytformat_paragraph_event#s.    $    (sFormat Paragraphs<>N(t__name__t __module__tmenudefsRRRR&(((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyRs   c Cs¦tt|jdƒƒ\}}|jd|d|ƒ}xM|jd|ddƒr‡t|ƒr‡|d}|jd|d|ƒ}q;W|}t|ƒ}t|ƒ}xKt|ƒ|krót||ƒ ró|d}|jd|d|ƒ}q©Wd|}|d}|jd|d|ƒ}xW|dkr{t|ƒ|kr{t||ƒ r{|d}|jd|d|ƒ}q%Wd|d} | |||j| |ƒfS(s»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. t.s%d.0s%d.endt›sitiÿÿÿÿc3s|]}ˆ|VqdS(N((RJR4(R$(s//usr/lib64/python2.7/idlelib/FormatParagraph.pys ªs(R0R?R-tmaxR(R#R R$t format_widthR%t block_suffix((R$RKs//usr/lib64/python2.7/idlelib/FormatParagraph.pyR–s (  cCstjd|ƒdk S(s/Return True if line is empty or all whitespace.s^\s*$N(R9tmatchR(R4((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyR/¬scCstjd|ƒjƒS(s/Return the initial space or tab indent of line.s ^([ \t]*)(R9RPtgroup(R4((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyR8±scCs/tjd|ƒ}|dkr"dS|jdƒS(sReturn 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. s ^([ \t]*#*)RLiN(R9RPRRQ(R4tm((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyRµs t__main__s&idlelib.idle_test.test_formatparagrapht verbosityitexit((t__doc__R9tidlelib.configHandlerRRRRRR/R8RR'tunittesttmaintFalse(((s//usr/lib64/python2.7/idlelib/FormatParagraph.pyts 8 % $