3  f@sdZddlZddlmZGdddZejddZdd Zd d Zd d Z ddZ ddZ e dkrddl mZedddddS)aFormat a paragraph, comment block, 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 :-) N)idleConfc@s2eZdZddZeddZddZd dd ZdS) FormatParagraphcCs ||_dS)N)editwin)selfrr6/opt/alt/python36/lib64/python3.6/idlelib/paragraph.py__init__szFormatParagraph.__init__cCstjdddddd|_dS)N extensionsrz max-widthintH)typedefault)rZ GetOption max_width)clsrrrreloadszFormatParagraph.reloadcCs d|_dS)N)r)rrrrclose szFormatParagraph.closeNc Cs|dkr|jn|}|jj}|jj\}}|rF|rF|j||}t|}nt||jd\}}}}|rpt|||}n t ||}|j ddd||kr|j d||j |j |||j|||jn |j d||jddS)aFormats 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. NinsertZselz1.0endbreak)rrtextZget_selection_indicesgetget_comment_headerfind_paragraphindexreformat_commentreformat_paragraphZ tag_removeZmark_setZundo_block_startdeleterZundo_block_stopZsee) rZeventlimitrfirstlastdatacomment_headernewdatarrrformat_paragraph_event#s(          z&FormatParagraph.format_paragraph_event)N)__name__ __module__ __qualname__r classmethodrrr#rrrrrs rc CsJtt|jd\}}|jd|d|}x:|jd|ddrbt|rb|d}|jd|d|}q*W|}t|}t|}x>t||krt||d r|d}|jd|d|}qzWd|}|d}|jd|d|}xL|dkr(t||kr(t||d r(|d}|jd|d|}qWd|d} | |||j| |fS) zReturns 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. .z%d.0z%d.endsz#reformat_comment..r*Nc3s|]}|VqdS)Nr)rCr1)r!rrrEsrH)r.r<r,maxr)r rr!Z format_widthr"Z block_suffixr)r!rDrrs   rcCstjd|dk S)z/Return True if line is empty or all whitespace.z^\s*$N)r6match)r1rrrr-sr-cCstjd|jS)z/Return the initial space or tab indent of line.z ^([ \t]*))r6rJgroup)r1rrrr5sr5cCs"tjd|}|dkrdS|jdS)aReturn 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. z ^([ \t]*#*)NrGr*)r6rJrK)r1mrrrrs r__main__)mainz idlelib.idle_test.test_paragraphr3F) verbosityexit)__doc__r6Zidlelib.configrrrrrrr-r5rr$ZunittestrNrrrrs 4%$