3
§ fÿ ã @ s„ d Z ddlZddlmZ G dd„ dƒZejƒ dd„ Zdd „ Zd
d„ Zdd
„ Z dd„ Z
dd„ Zedkr€ddl
mZ edddd� dS )aÓ Format 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 @ s2 e Zd Zdd„ Zedd„ ƒZdd„ Zd
dd „ZdS )ÚFormatParagraphc C s
|| _ d S )N)Úeditwin)Úselfr © r ú6/opt/alt/python36/lib64/python3.6/idlelib/paragraph.pyÚ__init__ s zFormatParagraph.__init__c C s t jdddddd�| _d S )NÚ
extensionsr z max-widthÚintéH )ÚtypeÚdefault)r Z GetOptionÚ max_width)Úclsr r r Úreload s zFormatParagraph.reloadc C s
d | _ d S )N)r )r r r r Úclose s zFormatParagraph.closeNc C sà |dkr| j n|}| jj}| jjƒ \}}|rF|rF|j||ƒ}t|ƒ}nt||jdƒƒ\}}}}|rpt|||ƒ}n
t ||ƒ}|j
dddƒ ||krÆ|jd|ƒ |jƒ |j
||ƒ |j||ƒ |jƒ n|jd|ƒ |jdƒ dS )aÕ 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.
NÚinsertZselz1.0ÚendÚbreak)r r ÚtextZget_selection_indicesÚgetÚget_comment_headerÚfind_paragraphÚindexÚreformat_commentÚreformat_paragraphZ
tag_removeZmark_setZundo_block_startÚdeleter Zundo_block_stopZsee) r ZeventÚlimitr ÚfirstÚlastÚdataÚcomment_headerÚnewdatar r r Úformat_paragraph_event# s(
z&FormatParagraph.format_paragraph_event)N)Ú__name__Ú
__module__Ú__qualname__r Úclassmethodr r r# r r r r r s r c
C sJ t t|jdƒƒ\}}| jd| d| ƒ}x:| jd| ddƒrbt|ƒrb|d }| jd| d| ƒ}q*W |}t|ƒ}t|ƒ}x>t|ƒ|kr¶t||d… ƒ r¶|d }| jd| d| ƒ}qzW d| }|d }| jd| d| ƒ}xL|dk�r(t|ƒ|k�r(t||d… ƒ �r(|d }| jd| d| ƒ}qÞW d|d } | ||| j| |ƒfS ) z»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.
Ú.z%d.0z%d.endú