<s> import vim <EOL> class VimBuffer : <EOL> def __init__ ( self , buffer ) : <EOL> self . _buffer = buffer <EOL> def replace ( self , content ) : <EOL> self . _buffer [ : ] = content <EOL> def line ( self , number ) : <EOL> return self . _buffer [ number ] <EOL> def write ( self , msg , overwrite ) : <EOL> last_line = len ( self . _buffer ) <EOL> if isinstance ( msg , list ) : <EOL> to_write = msg <EOL> else : <EOL> to_write = str ( msg ) . split ( '<STR_LIT:\n>' ) <EOL> if len ( to_write ) == <NUM_LIT:1> and to_write [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> return ( last_line , last_line ) <EOL> if overwrite or self . is_empty ( ) : <EOL> self . _buffer [ : ] = to_write <EOL> else : <EOL> self . _buffer . append ( to_write ) <EOL> return ( last_line , last_line + len ( to_write ) ) <EOL> def overwrite ( self , msg , lineno , allowEmpty ) : <EOL> """<STR_LIT>""" <EOL> if not msg and allowEmpty == False : <EOL> return <EOL> if isinstance ( msg , list ) : <EOL> to_write = msg <EOL> else : <EOL> to_write = str ( msg ) . split ( '<STR_LIT:\n>' ) <EOL> lstart = lineno - <NUM_LIT:1> <EOL> lend = lstart + len ( to_write ) <EOL> self . _buffer [ lstart : lend ] = to_write <EOL> return ( lstart , lend ) <EOL> def delete ( self , start_line , end_line = None ) : <EOL> try : <EOL> if not end_line : <EOL> end_line = start_line + <NUM_LIT:1> <EOL> self . _buffer [ end_line ] <EOL> remaining_buffer = self . _buffer [ end_line : ] <EOL> del self . _buffer [ start_line : ] <EOL> self . _buffer . append ( remaining_buffer ) <EOL> except IndexError : <EOL> del self . _buffer [ start_line : ] <EOL> def contents ( self ) : <EOL> return self . _buffer [ : ] <EOL> def clean ( self ) : <EOL> self . _buffer [ : ] = [ ] <EOL> def is_empty ( self ) : <EOL> if len ( self . _buffer ) == <NUM_LIT:1> and len ( self . _buffer [ <NUM_LIT:0> ] ) == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> return False <EOL> class HiddenBuffer : <EOL> def __init__ ( self , buffer = [ ] ) : <EOL> self . _buffer = buffer [ : ] <EOL> def line ( self , number ) : <EOL> return self . _buffer [ number ] <EOL> def replace ( self , contents ) : <EOL> self . _buffer [ : ] = contents [ : ] <EOL> def write ( self , msg , overwrite ) : <EOL> last_line = len ( self . _buffer ) <EOL> if isinstance ( msg , list ) : <EOL> to_write = msg <EOL> else : <EOL> to_write = str ( msg ) . split ( '<STR_LIT:\n>' ) <EOL> if len ( to_write ) == <NUM_LIT:1> and to_write [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> return ( last_line , last_line ) <EOL> to_write = str ( msg ) . split ( '<STR_LIT:\n>' ) <EOL> if overwrite or self . is_empty ( ) : <EOL> self . _buffer [ : ] = to_write <EOL> else : <EOL> self . _buffer . extend ( to_write ) <EOL> return ( last_line , last_line + len ( to_write ) ) <EOL> def overwrite ( self , msg , lineno , allowEmpty ) : <EOL> """<STR_LIT>""" <EOL> if not msg and allowEmpty == False : <EOL> return <EOL> if isinstance ( msg , list ) : <EOL> to_write = msg <EOL> else : <EOL> to_write = str ( msg ) . split ( '<STR_LIT:\n>' ) <EOL> last_line = len ( self . _buffer ) <EOL> lstart = lineno - <NUM_LIT:1> <EOL> lend = lstart + len ( to_write ) <EOL> self . _buffer [ lstart : lend ] = to_write <EOL> return ( lstart , lend ) <EOL> def delete ( self , start_line , end_line = None ) : <EOL> try : <EOL> if not end_line : <EOL> end_line = start_line + <NUM_LIT:1> <EOL> self . _buffer [ start_line : end_line ] = [ ] <EOL> except IndexError : <EOL> del self . _buffer [ start_line : ] <EOL> def clean ( self ) : <EOL> self . _buffer [ : ] = [ ] <EOL> def contents ( self ) : <EOL> return self . _buffer [ : ] <EOL> def is_empty ( self ) : <EOL> return not self . _buffer </s>
