관리-도구
편집 파일: paragraph.cpython-36.pyc
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�<r � Nr )�mapr �splitr Zcompare�is_all_whiter �len) r Zmark�lineno�col�lineZfirst_linenor! Zcomment_header_lenr r r r r r L s, r c C s� | j d�}d}t|�}x ||k r6t|| �r6|d }qW ||krD| S t|| �}|d |k r�t||d � r�t||d �}n|}|d|� }|}x�||k o�t|| � �rTtj d|| �} x�tdt| �d�D ]v} | | }|s�q�t|| j� �|ko�||k�r|j|j� � |}|| d }| d t| �k r�| | d dkr�|d }q�W |d }q�W |j|j� � |j ||d� � dj |�S )z3Return data reformatted to specified width (limit).� r r* Nz(\s+)� � )r, r. r- � get_indent�re�range� expandtabs�append�rstrip�extend�join)r r �lines�i�nZindent1Zindent2�new�partialZwords�jZwordr r r r q s<