î f fwã@sµdZddlZddlmZGdd„dƒZdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z e dkr±ddl Z e j dddddƒndS)aÐ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 :-) éN)ÚidleConfc@sIeZdZdd gfgZdd„Zdd„Zdd d „ZdS) ÚFormatParagraphÚformatúFormat Paragraphú<>cCs ||_dS)N)Úeditwin)Úselfr©r ú›sz#reformat_comment..éÚr(Nc3s|]}ˆ|VqdS)Nr )rBr0)r r r rDªséÿÿÿÿrG)r,r;r*Úmaxr)rrr Z format_widthr!Z block_suffixr )r rCr r–s + rcCstjd|ƒdk S)z/Return True if line is empty or all whitespace.z^\s*$N)r5Úmatch)r0r r r r+¬sr+cCstjd|ƒjƒS)z/Return the initial space or tab indent of line.z ^([ \t]*))r5rIÚgroup)r0r r r r4±sr4cCs/tjd|ƒ}|dkr"dS|jdƒS)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]*#*)NrFr()r5rIrJ)r0Úmr r r rµs rÚ__main__z&idlelib.idle_test.test_formatparagraphÚ verbosityr2ÚexitF)Ú__doc__r5Zidlelib.configHandlerrrrrrr+r4rr#ZunittestÚmainr r r r Ús 8 % $