<s> import vim <EOL> import os <EOL> from util . position import Position <EOL> class _Buffer ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ property <EOL> def name ( self ) : <EOL> if vim . current . buffer . name is not None : <EOL> return vim . current . buffer . name <EOL> @ property <EOL> def path ( self ) : <EOL> if vim . current . buffer . name is not None : <EOL> return os . path . split ( vim . current . buffer . name ) [ <NUM_LIT:0> ] <EOL> @ property <EOL> def filename ( self ) : <EOL> if vim . current . buffer . name is not None : <EOL> return os . path . split ( vim . current . buffer . name ) [ <NUM_LIT:1> ] <EOL> @ property <EOL> def stem ( self ) : <EOL> if vim . current . buffer . name is not None : <EOL> return os . path . splitext ( self . filename ) [ <NUM_LIT:0> ] <EOL> @ property <EOL> def extension ( self ) : <EOL> """<STR_LIT>""" <EOL> if vim . current . buffer . name is not None : <EOL> return os . path . splitext ( self . filename ) [ <NUM_LIT:1> ] <EOL> @ property <EOL> def number ( self ) : <EOL> return vim . current . buffer . number <EOL> @ property <EOL> def cursor ( self ) : <EOL> """<STR_LIT>""" <EOL> c = vim . current . window . cursor <EOL> return Position ( c [ <NUM_LIT:0> ] - <NUM_LIT:1> , c [ <NUM_LIT:1> ] ) <EOL> @ cursor . setter <EOL> def cursor ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , Position ) : <EOL> c = ( value . line + <NUM_LIT:1> , value . col ) <EOL> elif isinstance ( value , tuple ) and len ( value ) == <NUM_LIT:2> : <EOL> c = ( value [ <NUM_LIT:0> ] + <NUM_LIT:1> , value [ <NUM_LIT:1> ] ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % type ( value ) ) <EOL> vim . current . window . cursor = c <EOL> def __getitem__ ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( pos , Position ) : <EOL> return vim . current . buffer [ pos . line ] [ pos . col ] <EOL> if isinstance ( pos , slice ) : <EOL> if pos . start is not None and not isinstance ( pos . start , Position ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( type ( pos . start ) ) ) <EOL> s = pos . start or Position ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if pos . stop is not None and not isinstance ( pos . stop , Position ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( type ( pos . stop ) ) ) <EOL> e = pos . stop or self . _get_last_position ( ) <EOL> if s . line == e . line : <EOL> return vim . current . buffer [ s . line ] [ s . col : e . col + <NUM_LIT:1> ] <EOL> else : <EOL> return '<STR_LIT:\n>' . join ( [ vim . current . buffer [ s . line ] [ s . col : ] ] + <EOL> [ vim . current . buffer [ i ] <EOL> for i in range ( s . line + <NUM_LIT:1> , e . line - <NUM_LIT:1> ) ] + <EOL> [ vim . current . buffer [ e . line ] [ : e . col + <NUM_LIT:1> ] ] ) <EOL> raise TypeError ( '<STR_LIT>' . format ( type ( pos ) ) ) <EOL> def items ( self , start = None , stop = None , reversed = False ) : <EOL> """<STR_LIT>""" <EOL> if not reversed : <EOL> start = start or Position ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> line , col = start . line , start . col <EOL> while line < len ( vim . current . buffer ) : <EOL> while col < len ( vim . current . buffer [ line ] ) : <EOL> p = Position ( line , col ) <EOL> if stop is not None and p >= stop : <EOL> return <EOL> yield ( p , vim . current . buffer [ line ] [ col ] ) <EOL> col += <NUM_LIT:1> <EOL> line += <NUM_LIT:1> <EOL> col = <NUM_LIT:0> <EOL> else : <EOL> start = start or self . _get_last_position ( ) <EOL> line , col = start . line , start . col <EOL> while line >= <NUM_LIT:0> : <EOL> while col >= <NUM_LIT:0> : <EOL> p = Position ( line , col ) <EOL> if stop is not None and p <= stop : <EOL> return <EOL> yield ( p , vim . current . buffer [ line ] [ col ] ) <EOL> col -= <NUM_LIT:1> <EOL> line -= <NUM_LIT:1> <EOL> col = len ( vim . current . buffer [ line ] ) - <NUM_LIT:1> <EOL> def _get_last_position ( self ) : <EOL> """<STR_LIT>""" <EOL> return Position ( len ( vim . current . buffer ) - <NUM_LIT:1> , <EOL> len ( vim . current . buffer [ - <NUM_LIT:1> ] ) - <NUM_LIT:1> ) </s>
