Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/idlelib/FormatParagraph.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZddlZddlmZddd��YZd�Zd�Zd�Zd	�Zd
�Z	d�Z
edkr�ddlZej
d
ddde�ndS(s�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 :-)
i�N(tidleConftFormatParagraphcBs8eZddgfgZd�Zd�Zdd�ZRS(tformatsFormat Paragraphs<<format-paragraph>>cCs
||_dS(N(teditwin(tselfR((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyt__init__scCs
d|_dS(N(tNoneR(R((s-/sys/lib/python2.7/idlelib/FormatParagraph.pytclose sc	CsM|dkr*tjddddd�}n|jj}|jj�\}}|rx|rx|j||�}t|�}n$t||j	d��\}}}}|r�t
|||�}nt||�}|jddd	�||kr,|j
d|�|j�|j||�|j||�|j�n|j
d|�|jd�d
S(s�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.
        tmainRt	paragraphttypetinttinserttsels1.0tendtbreakN(RRt	GetOptionRttexttget_selection_indicestgettget_comment_headertfind_paragraphtindextreformat_commenttreformat_paragrapht
tag_removetmark_settundo_block_starttdeleteRtundo_block_stoptsee(	RteventtlimitRtfirsttlasttdatatcomment_headertnewdata((s-/sys/lib/python2.7/idlelib/FormatParagraph.pytformat_paragraph_event#s,$


(sFormat Paragraphs<<format-paragraph>>N(t__name__t
__module__tmenudefsRRRR&(((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyRs
		c
Cs�tt|jd��\}}|jd|d|�}xM|jd|dd�r�t|�r�|d}|jd|d|�}q;W|}t|�}t|�}xKt|�|kr�||�r�d}|jd|d|�}q�Wd|}|d}|jd|d|�}xW|dkr{t|�|kr{t||�r{|d}|jd|d|�}q%Wd|d}	|	|||j|	|�fS(s�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.
    t.s%d.0s%d.endt<Rii(tmapRtsplitRtcomparetis_all_whiteRtlen(
Rtmarktlinenotcoltlinetfirst_linenoR$tcomment_header_lenR"R!((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyRKs,(




cCs�|jd�}d}t|�}x*||krMt||�rM|d}q$W||kr^|St||�}|d|kr�t||d�r�t||d�}n|}|| }|}x||kr�t||�r�tjd||�}	x�tdt|	�d�D]�}
|	|
}|s+qnt||j��|kro||kro|j|j��|}n||d}|
dt|	�kr|	|
ddkr|d}qqW|d}q�W|j|j��|j	||�dj
|�S(s3Return data reformatted to specified width (limit).s
iis(\s+)it (R-R0R/t
get_indenttretranget
expandtabstappendtrstriptextendtjoin(R#R tlinestitntindent1tindent2tnewtpartialtwordstjtword((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyRps<%
 
	*cs�t���dj�fd�|jd�D��}t|t��d�}t||�}|jd�}d}|ds�d}|d }ndj�fd�|D��|S(s?Return data reformatted to specified width with comment header.s
c3s|]}|�VqdS(N((t.0R4(tlc(s-/sys/lib/python2.7/idlelib/FormatParagraph.pys	<genexpr>�siti�c3s|]}�|VqdS(N((RJR4(R$(s-/sys/lib/python2.7/idlelib/FormatParagraph.pys	<genexpr>�s(R0R?R-tmaxR(R#R R$tformat_widthR%tblock_suffix((R$RKs-/sys/lib/python2.7/idlelib/FormatParagraph.pyR�s(

cCstjd|�dk	S(s/Return True if line is empty or all whitespace.s^\s*$N(R9tmatchR(R4((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyR/�scCstjd|�j�S(s/Return the initial space or tab indent of line.s	^([ \t]*)(R9RPtgroup(R4((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyR8�scCs/tjd|�}|dkr"dS|jd�S(sReturn 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.
    s^([ \t]*#*)RLiN(R9RPRRQ(R4tm((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyR�st__main__s&idlelib.idle_test.test_formatparagrapht	verbosityitexit((t__doc__R9tidlelib.configHandlerRRRRRR/R8RR'tunittestRtFalse(((s-/sys/lib/python2.7/idlelib/FormatParagraph.pyt<module>s6	%	$				

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].