³ò £õEc@s@dZd„Zd„Zd„Zd„Zd„Zd„ZdS(s# This module contains a set of functions responsible for performing text operations relating to space and tab characters. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright © 2005 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com c Csÿg}|idtƒ|idƒ}|iƒ\}}|iƒ}|iƒ}t}||djot}ddkl}n|iƒxTt ||dƒD]?} |o |ƒnt || ƒ} | o|i | ƒqžqžW|i ƒ|idtƒ|S(su Convert beginning space characters in a gtksourceview buffer to tab characters. The function converts space characters to tab characters and then indents lines to the earliest tab stop. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @return: A list of converted lines if any. @rtype: A List object. teditabletbufferi¸ iÿÿÿÿ(tresponsei( t set_propertytFalset get_propertyt get_boundstget_linetTruet SCRIBES.utilsRtbegin_user_actiontrangetconvert_spaces_to_tabs_on_linetappendtend_user_action( t sourceviewtconverted_linest sourcebuffertbegintendt first_linet last_linet use_responseRtlinetresult((splugins/Spaces/spaces.pytconvert_spaces_to_tabss*      c Csc|idƒ}|idƒ}|i|ƒ}|iƒ}g}g}x_toW|iƒdjo|idƒn&|iƒdjo|idƒnP|iƒqHW|i|ƒotSnt |ƒ}t |ƒ} |ptSn||jodi |ƒ} n+||} |id| ƒdi |ƒ} |i ||ƒ|i|ƒ}|i || ƒtS(sd Convert beginning space characters to tab characters on a line. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @param line_number: The line to perform conversion operation on. @type line_number: An Integer object. @return: True if the line was converted. @rtype: An Boolean object. Rs tabs-widtht s t( Rtget_iter_at_linetcopyRtget_charR t forward_chartequalRtlentjointdeletetinsert( Rt line_numberRt tab_widthtbegin_positionttransition_positiont space_listttab_listtnumber_of_spacestnumber_of_tabststringttabs((splugins/Spaces/spaces.pyR As8       c Csÿg}|idtƒ|idƒ}|iƒ\}}|iƒ}|iƒ}t}||djot}ddkl}n|iƒxTt ||dƒD]?} |o |ƒnt || ƒ} | o|i | ƒqžqžW|i ƒ|idtƒ|S(su Convert beginning tab characters in a gtksourceview buffer to space characters. The function converts tab characters to space characters and then indents lines to the earliest tab stop. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @return: A list of converted lines if any. @rtype: A List object. RRi¸ iÿÿÿÿ(Ri( RRRRRRR RR R tconvert_tabs_to_spaces_on_lineR R( RRRRRRRRRRR((splugins/Spaces/spaces.pytconvert_tabs_to_spacesms*      c Cs’|idƒ}|idƒ}|i|ƒ}|iƒ}g}g}x_toW|iƒdjo|idƒn&|iƒdjo|idƒnP|iƒqHW|i|ƒotSnt |ƒ}t |ƒ} | o&x#|D]} |id|ƒqåWnt |ƒptSn||o,x)t ||ƒD]} |i dƒq5Wndi |ƒ} |i ||ƒ|i|ƒ}|i|| ƒtS(sd Convert beginning tab characters to space characters on a line. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @param line_number: The line to perform conversion operation on. @type line_number: An Integer object. @return: True if the line was converted. @rtype: An Boolean object. Rs tabs-widthRs R(RRRRRR RR RR!R tremoveR"R#R$( RR%RR&R'R(R)R*R+R,ttabtspaceR-((splugins/Spaces/spaces.pyR/s@       c Csÿg}|idtƒ|idƒ}|iƒ\}}|iƒ}|iƒ}t}||djot}ddkl}n|iƒxTt ||dƒD]?} |o |ƒnt || ƒ} | o|i | ƒqžqžW|i ƒ|idtƒ|S(sú Remove spaces at the end of lines in a gtksourceview buffer. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @return: A list of lines operated upon, if any. @rtype: A List object. RRi¸ iÿÿÿÿ(Ri( RRRRRRR RR R tremove_trailing_spaces_on_lineR R( Rtaffected_linesRRRRRRRRR((splugins/Spaces/spaces.pytremove_trailing_spaces¼s*      cCsÉ|idƒ}|i|ƒ}|iƒ}|iƒ}|iƒ|iƒ|i|ƒotSnx8to0|iƒ|iƒdjo|i ƒPqeqeW|i|ƒotSn|i ||ƒtS(sd Convert beginning tab characters to space characters on a line. @param sourceview: The gtksourceview buffer's container @type sourceview: A gtksourceview.SourceView object. @param line_number: The line to perform conversion operation on. @type line_number: An Integer object. @return: True if the line was converted. @rtype: An Boolean object. RRs (Rs ( RRRtforward_to_line_endR RRt backward_charRRR#(RR%RR'R(t end_position((splugins/Spaces/spaces.pyR4Ûs"         N(t__doc__RR R0R/R6R4(((splugins/Spaces/spaces.pyss  " , " -