Ë �Y¤y+¥2ãó —dZddlZddlmZddlmZddlmZGd„d«Zej«d„Z d „Z d „Z d „Z d „Zd „Zej d«Zd„ZGd„d«ZGd„d«ZGd„d«Zedk(rddlmZeddd¬«yy)zíFormat all or a selected region (line slice) of text. Region formatting options: paragraph, comment block, indent, deindent, comment, uncomment, tabify, and untabify. File renamed from paragraph.py with functions added from editor.py. éN)Úaskyesno)Ú askinteger)ÚidleConfcó4—eZdZdZd„Zed„«Zd„Zdd„Zy)ÚFormatParagraphaFormat 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 :-) có—||_y©N©Úeditwin©Úselfr s ú%/usr/lib/python3.12/idlelib/format.pyÚ__init__zFormatParagraph.__init__ó €Øˆ� ócóB—tjddddd¬«|_y)NÚ extensionsrz max-widthÚintéH)ÚtypeÚdefault)rÚ GetOptionÚ max_width)Úclss rÚreloadzFormatParagraph.reload"s!€ä ×*Ñ*¨<Ð9JØ+6¸UÈBôPˆ� rcó—d|_yr r ©r s rÚclosezFormatParagraph.close's €Øˆ� rNcój—|€ |jn|}|jj}|jj«\}}|r |r|j ||«}t |«}n t ||jd««\}}}}|rt|||«}n t||«}|jddd«||k7rW|jd|«|j«|j||«|j||«|j«n|jd|«|j!d«y)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. ÚinsertÚselú1.0ÚendÚbreak)rr ÚtextÚget_selection_indicesÚgetÚget_comment_headerÚfind_paragraphÚindexÚreformat_commentÚreformat_paragraphÚ tag_removeÚmark_setÚundo_block_startÚdeleter Úundo_block_stopÚsee) r ÚeventÚlimitr%ÚfirstÚlastÚdataÚcomment_headerÚnewdatas rÚformat_paragraph_eventz&FormatParagraph.format_paragraph_event*s €ð#( -�—’°UˆØ�|‰|× Ñ ˆØ—l‘l×8Ñ8Ó:‰ ˆˆtÙ ‘TØ—8‘8˜E 4Ó(ˆDÜ/°Ó5‰Nô# 4¨¯©°HÓ)=Ó>ñ .ˆE�4˜¨á Ü& t¨U°NÓC‰Gä(¨¨uÓ5ˆGØ �‰˜˜u eÔ,à �dŠ?Ø �M‰M˜( EÔ *Ø × !Ñ !Ô #Ø �K‰K˜˜tÔ $Ø �K‰K˜˜wÔ 'Ø × Ñ Õ "à �M‰M˜( DÔ )Ø �‰�ÔØrr ) Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚ classmethodrrr:©rrrrs,„ñò ðñPóðPòô$rrcóR—tt|jd««\}}|jd|zd|z«}|j d|zdd«rJt |«r?|dz}|jd|zd|z«}|j d|zdd«r t |«rŒ?|}t |«}t|«}t |«|k(rHt ||d«s:|dz}|jd|zd|z«}t |«|k(rt ||d«sŒ:d|z}|dz }|jd|zd|z«}|dkDr[t |«|k(rMt ||d«s?|dz }|jd|zd|z«}|dkDrt |«|k(rt ||d«sŒ?d|dzz} | |||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Ú™>Ó+Ô,Ø!�Ø ‘n sÑ*ˆGØ�‰s”S˜“ZÓ E¨!¨A©#¡J°#Ó$5Ø! C™-‘ð)ð ˆa‰Cˆð ˆaŠ%œ  U¨1¡XÕ.ð‡J�Jˆw�~‰~ÓÔ à‡J�Jˆu�Q�RˆyÔØ �9‰9�S‹>Ðrcó.‡‡—t‰«Šdjˆfd„|jd«D««}t|t‰«z d«}t ||«}|jd«}d}|dsd}|dd}djˆfd„|D««|zS)z?Return data reformatted to specified width with comment header.rQc3ó(•K—|] }|‰d–—Œ y­wr r@)Ú.0rMÚlcs €rÚ z#reformat_comment..¡søèø€Ð<Ñ+; 4�T˜"˜#”YÑ+;ùóƒéÚéÿÿÿÿNc3ó(•K—|] }‰|z–—Œ y­wr r@)rhrMr8s €rrjz#reformat_comment..°søèø€Ð=±W¨T�^ DÕ(±Wùrk)rIr[rFÚmaxr,)r7r4r8Ú format_widthr9Ú block_suffixris ` @rr+r+œs–ù€ô ˆ^Ó €BØ �9‰9Ó<¨4¯:©:°dÔ+;Ó<Ó <€Dô�uœs >Ó2Ñ2°BÓ7€LÜ   |Ó4€Gà�m‰m˜DÓ!€Gð €LØ �2Š;؈ ؘ#˜2�,ˆØ �9‰9Ó=±WÓ=Ó =À Ñ LÐLrcó2—tjd|«duS)z/Return True if line is empty or all whitespace.z^\s*$N)rUÚmatch©rMs rrHrH²s€ô �8‰8�H˜dÓ #¨4Ð /Ð/rcóJ—tjd|«j«S)z/Return the initial space or tab indent of line.z ^([ \t]*)©rUrtÚgrouprus rrTrT·s€ä �8‰8�L $Ó '× -Ñ -Ó /Ð/rcóV—tjd|«}|€y|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]*#*)rmrDrw)rMÚms rr(r(»s)€ô �‰� Ó&€AØ€y˜Ø �7‰7�1‹:Ðrz[ \t]*cóœ—tj|«}|j«t|j «j |««fS)zÌReturn a line's indentation as (# chars, effective # of spaces). The effective # of spaces is the length after properly "expanding" the tabs into spaces, as done by str.expandtabs(tabwidth). )Ú_line_indent_rertr#rIrxrW)rMÚtabwidthrzs rÚget_line_indentr~Ês;€ô ×јdÓ#€AØ �5‰5‹7”C˜Ÿ™› ×,Ñ,¨XÓ6Ó7Ð 7Ð7rcóX—eZdZdZd„Zd„Zd„Zd d„Zd d„Zd d„Z d d „Z d d „Z d d „Z d „Z y)Ú FormatRegionzFormat selected text (region).có—||_yr r r s rrzFormatRegion.__init__×rrcóX—|jj}|jj«\}}|r+|r)|j|dz«}|j|dz«}n"|jd«}|jd«}|j ||«}|j d«}||||fS)aqReturn line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index, string representation of text, list of text lines). z linestartz-1c lineend +1czinsert linestartzinsert lineend +1crQ)r r%r&r*r'rF)r r%r5r6ÚheadÚtailÚcharsr\s rÚ get_regionzFormatRegion.get_regionÚs €ð�|‰|× Ñ ˆØ—l‘l×8Ñ8Ó:‰ ˆˆtÙ ‘TØ—:‘:˜e lÑ2Ó3ˆDØ—:‘:˜dÐ%6Ñ6Ó7‰Dà—:‘:Ð0Ó1ˆDØ—:‘:Ð2Ó3ˆDØ—‘˜˜tÓ$ˆØ— ‘ ˜DÓ!ˆØ�T˜5 %Ð'Ð'rcóv—|jj}dj|«}||k(r|j«y|j ddd«|j d|«|j «|j||«|j||«|j«|jd|d«y)aaReplace the text between the given indices. Args: head: Starting index of text to replace. tail: Ending index of text to replace. chars: Expected to be string of current text between head and tail. lines: List of new lines to insert between head and tail. rQNr!r"r#r ) r r%r[Úbellr-r.r/r0r r1Útag_add)r rƒr„r…r\r%Únewcharss rÚ set_regionzFormatRegion.set_regionðs—€ð�|‰|× Ñ ˆØ—9‘9˜UÓ#ˆØ �uÒ Ø �I‰IŒKØ Ø �‰˜˜u eÔ,Ø � ‰ �h Ô%Ø ×ÑÔØ � ‰ �D˜$ÔØ � ‰ �D˜(Ô#Ø ×ÑÔØ � ‰ �U˜D (Õ+rNcóX—|j«\}}}}tt|««D]j}||}|sŒ t||jj «\}} | |jj z} |jj| «||dz||<Œl|j||||«y)z$Indent region by indentwidth spaces.Nr$) r†rVrIr~r r}Ú indentwidthÚ _make_blanksr‹© r r3rƒr„r…r\ÚposrMÚrawÚ effectives rÚindent_region_eventz FormatRegion.indent_region_eventsž€à#'§?¡?Ó#4Ñ ˆˆd�E˜5Üœ˜U›Ö$ˆCؘ‘:ˆDÚÜ!0°°t·|±|×7LÑ7LÓ!M‘��YØ%¨¯ © ×(@Ñ(@Ñ@� Ø!Ÿ\™\×6Ñ6°yÓAÀDÈÈÀJÑN��c’ ð %ð �‰˜˜d E¨5Ô1Ørcól—|j«\}}}}tt|««D]t}||}|sŒ t||jj «\}} t | |jjz d«} |jj| «||dz||<Œv|j||||«y)z$Dedent region by indentwidth spaces.rNr$) r†rVrIr~r r}rpr�rŽr‹r�s rÚdedent_region_eventz FormatRegion.dedent_region_events¥€à#'§?¡?Ó#4Ñ ˆˆd�E˜5Üœ˜U›Ö$ˆCؘ‘:ˆDÚÜ!0°°t·|±|×7LÑ7LÓ!M‘��YÜ  ¨D¯L©L×,DÑ,DÑ DÀaÓH� Ø!Ÿ\™\×6Ñ6°yÓAÀDÈÈÀJÑN��c’ ð %ð �‰˜˜d E¨5Ô1Ørcó¨—|j«\}}}}tt|«dz «D]}||}d|z||<Œ|j||||«y)zrComment out each line in region. ## is appended to the beginning of each line to comment it out. rDú##r$©r†rVrIr‹©r r3rƒr„r…r\r�rMs rÚcomment_region_eventz!FormatRegion.comment_region_event s]€ð $(§?¡?Ó#4Ñ ˆˆd�E˜5Üœ˜U› a™Ö(ˆCؘ‘:ˆDØ ™ˆE�#ŠJð)ð �‰˜˜d E¨5Ô1ØrcóØ—|j«\}}}}tt|««D]*}||}|sŒ |dddk(r|dd}n |dddk(r|dd}|||<Œ,|j||||«y)z½Uncomment each line in region. Remove ## or # in the first positions of a line. If the comment is not in the beginning position, this command will have no effect. NrRr—rDÚ#r$r˜r™s rÚuncomment_region_eventz#FormatRegion.uncomment_region_event,sŒ€ð $(§?¡?Ó#4Ñ ˆˆd�E˜5Üœ˜U›Ö$ˆCؘ‘:ˆDÙØØ�B�Qˆx˜4ÒØ˜A˜B�x‘Ø�b�q�˜S’ؘA˜B�x�؈E�#ŠJð%ð �‰˜˜d E¨5Ô1Ørcó"—|j«\}}}}|j«}|€ytt|««D]<}||}|sŒ t ||«\} } t | |«\} } d| zd| zz|| dz||<Œ>|j ||||«y)z@Convert leading spaces to tabs for each line in selected region.NÚ rSr$)r†Ú _asktabwidthrVrIr~Údivmodr‹) r r3rƒr„r…r\r}r�rMr‘r’ÚntabsÚnspacess rÚtabify_region_eventz FormatRegion.tabify_region_event?s¥€à#'§?¡?Ó#4Ñ ˆˆd�E˜5Ø×$Ñ$Ó&ˆØ Ð Ø Üœ˜U›Ö$ˆCؘ‘:ˆDÚÜ!0°°xÓ!@‘��YÜ!'¨ °8Ó!<‘��wØ! E™\¨C°'©MÑ9¸DÀÀ¸JÑF��c’ ð %ð �‰˜˜d E¨5Ô1ØrcóÜ—|j«\}}}}|j«}|€ytt|««D]}||j |«||<Œ|j ||||«y)z.Expand tabs to spaces for each line in region.Nr$)r†r rVrIrWr‹)r r3rƒr„r…r\r}r�s rÚuntabify_region_eventz"FormatRegion.untabify_region_eventNsn€à#'§?¡?Ó#4Ñ ˆˆd�E˜5Ø×$Ñ$Ó&ˆØ Ð Ø Üœ˜U›Ö$ˆCؘs™×.Ñ.¨xÓ8ˆE�#ŠJð%à �‰˜˜d E¨5Ô1Ørcót—tdd|jj|jjdd¬«S)zReturn value for tab width.z Tab widthzColumns per tab? (2-16)rRé©ÚparentÚ initialvalueÚminvalueÚmaxvalue)rr r%r�rs rr zFormatRegion._asktabwidthYs5€äØ Ø %Ø—<‘<×$Ñ$ØŸ™×1Ñ1ØØô ð rr )r;r<r=r>rr†r‹r“r•ršr�r¤r¦r r@rrr€r€Ôs7„Ù$òò(ò,,ó0 ó ó óó& ó órr€có"—eZdZdZd„Zd„Zd„Zy)ÚIndentszChange future indents.có—||_yr r r s rrzIndents.__init__grrcó¬—|j}|j}tddd|zdzd|zdzdz|j¬«r| |_d |_y ) Nz Toggle tabsz Turn tabs )ÚonÚoffz? Indent width )zwill bez remains atz 8.z! Note: a tab is always 8 columns)rªér$)r Úusetabsrr%r�)r r3r rµs rÚtoggle_tabs_eventzIndents.toggle_tabs_eventjst€Ø—,‘,ˆØ—/‘/ˆÜ ØØ˜]¨7Ñ3Ñ3Ø ñ!à'¨Ñ0ñ1à38ñ9ð3ñ3ð—\‘\õ  #ð#*˜kˆGŒOð#$ˆGÔ Ørcó®—|j}tdd|j|jdd¬«}|r"||jk7r|js||_y)Nz Indent widthz6New indent width (2-16) (Always use 8 when using tabs)rRr¨r©r$)r rr%r�rµ)r r3r ras rÚchange_indentwidth_eventz Indents.change_indentwidth_eventzsT€Ø—,‘,ˆÜØ ØKØ Ÿ™Ø&×2Ñ2ØØô ˆñ �3˜'×-Ñ-Ò-°g·o²oØ"%ˆGÔ ØrN)r;r<r=r>rr¶r¸r@rrr¯r¯ds„Ùòòó rr¯có—eZdZd„Zdd„Zy)ÚRstripcó—||_yr r r s rrzRstrip.__init__‰rrNcóÔ—|jj}|jj}|j«t t |j d«««}td|«D]^}|jd|zd|z«}t|«}t|j««}||ksŒE|jd||fzd|z«Œ`|jd«dk(rxt|jd«sb|j d «d kDrN|jd «dk(r:|jd «|j d «d kDr|jd «dk(rŒ:|j«y) Nr#rDz%i.0z%i.endz%i.%izend-2crQÚinterpzend-1cr"zend-3c)r r%Úundor/rÚfloatr*rVr'rIrYr0Úhasattrr1) r r3r%r¾Úend_lineÚcurÚtxtr‘Úcuts rÚ do_rstripzRstrip.do_rstripŒs+€Ø�|‰|× Ñ ˆØ�|‰|× Ñ ˆØ ×ÑÔä”u˜TŸZ™Z¨Ó.Ó/Ó0ˆÜ˜˜HÖ%ˆCØ—(‘(˜6 C™<¨°C©Ó8ˆCÜ�c“(ˆCÜ�c—j‘j“lÓ#ˆCð�S‹yØ— ‘ ˜G s¨C jÑ0°(¸S±.ÕAð&ð �H‰H�XÓ  $Ò &ܘDŸL™L¨(Ô3à—:‘:˜hÓ'¨%Ò/Ø—x‘x Ó)¨TÒ1Ø— ‘ ˜HÔ%ð—:‘:˜hÓ'¨%Ò/Ø—x‘x Ó)¨TÓ1ð ×ÑÕrr )r;r<r=rrÅr@rrrºrºˆs „òôrrºÚ__main__)Úmainzidlelib.idle_test.test_formatrRF)Ú verbosityÚexit)r>rUÚtkinter.messageboxrÚtkinter.simpledialogrÚidlelib.configrrrr)r,r+rHrTr(Úcompiler|r~r€r¯rºr;ÚunittestrÇr@rrÚrÏs­ðñó Ý'Ý+Ý#÷@ñ@ðF×ÑÔò">òJ"òHMò,0ò 0ò ð�"—*‘*˜YÓ'€ò8÷MñM÷`!ñ!÷Hñð@ ˆzÒÝÙÐ (°A¸EÖBðr