<s> import re <EOL> import vim <EOL> import funcy as fn <EOL> from uuid import uuid4 <EOL> from itertools import ifilter <EOL> from . import ui , option , source <EOL> class States ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . states = [ ] <EOL> def add ( self , state ) : <EOL> self . states . append ( state ) <EOL> def remove ( self , state , wipeout_buffer = True ) : <EOL> if not wipeout_buffer : <EOL> state . buff . valid and ui . wipeout_buffer ( state . buff ) <EOL> self . states . remove ( state ) <EOL> def remove_invalid ( self ) : <EOL> [ self . remove ( s ) for s in self . states if s . is_invalid ( ) ] <EOL> def remove_some ( self , states ) : <EOL> [ self . remove ( s ) for s in list ( states ) ] <EOL> def get_states ( self ) : <EOL> return self . states <EOL> states = States ( ) <EOL> class State ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , source , options ) : <EOL> self . uid = uuid4 ( ) <EOL> self . buff = None <EOL> self . source = source <EOL> self . options = options <EOL> self . container = { <EOL> '<STR_LIT>' : vim , <EOL> '<STR_LIT>' : vim . current . tabpage , <EOL> '<STR_LIT>' : vim . current . window <EOL> } [ options [ '<STR_LIT>' ] ] <EOL> def is_invalid ( self ) : <EOL> return not self . buff . valid or not getattr ( self . container , '<STR_LIT>' , True ) <EOL> def parse_state ( cmdline ) : <EOL> spaces_with_no_backslashes = r'<STR_LIT>' <EOL> tokens = filter ( lambda x : x != '<STR_LIT:U+0020>' , re . split ( spaces_with_no_backslashes , cmdline ) ) <EOL> options = map ( option . parse_option , ( ifilter ( lambda x : x . startswith ( '<STR_LIT:->' ) , tokens ) ) ) <EOL> sources = map ( source . parse_source , ( ifilter ( lambda x : x and not x . startswith ( '<STR_LIT:->' ) , tokens ) ) ) <EOL> assert len ( sources ) > <NUM_LIT:0> , '<STR_LIT>' <EOL> assert len ( sources ) == <NUM_LIT:1> , '<STR_LIT>' <EOL> map ( option . validate_option , options ) <EOL> return State ( sources [ <NUM_LIT:0> ] , fn . merge ( dict ( options ) , option . default_options ) ) </s>
