3
f @ s d Z ddlZddlmZ G dd dZej dd Zdd Zd
d Zdd
Z dd Z
dd Zedkrddl
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-widthintH )typedefault)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.
NinsertZselz1.0endbreak)r r textZget_selection_indicesgetget_comment_headerfind_paragraphindexreformat_commentreformat_paragraphZ
tag_removeZmark_setZundo_block_startdeleter Zundo_block_stopZsee) r Zeventlimitr firstlastdatacomment_headernewdatar 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| ddrbt|rb|d }| jd| d| }q*W |}t|}t|}x>t||krt||d r|d }| jd| d| }qzW d| }|d }| jd| d| }xL|dkr(t||kr(t||d r(|d }| jd| d| }qW d|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.end