<s> import sublime , sublime_plugin <EOL> gte_st3 = int ( sublime . version ( ) ) >= <NUM_LIT> <EOL> if gte_st3 : <EOL> from . config import * <EOL> else : <EOL> from config import * <EOL> class HiveAddContextUrlBaseCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit , event = None ) : <EOL> conf = sublime . load_settings ( CONFIG_BASE_NAME ) <EOL> url = self . find_url ( event ) <EOL> index = self . index_in_list ( url , conf ) <EOL> if index == - <NUM_LIT:1> : <EOL> self . add_to_list ( url , conf ) <EOL> sublime . status_message ( '<STR_LIT>' % url ) <EOL> else : <EOL> self . remove_from_list ( index , conf ) <EOL> sublime . status_message ( '<STR_LIT>' % url ) <EOL> def is_visible ( self , event = None ) : <EOL> return self . find_url ( event ) is not None <EOL> def description ( self , event = None ) : <EOL> url = self . find_url ( event ) <EOL> if self . index_in_list ( url ) == - <NUM_LIT:1> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def index_in_list ( self , url , conf = None ) : <EOL> if conf == None : <EOL> conf = sublime . load_settings ( CONFIG_BASE_NAME ) <EOL> url_list = [ item [ <NUM_LIT:0> ] for item in conf . get ( '<STR_LIT>' , [ ] ) ] <EOL> return url_list . index ( url ) if url in url_list else - <NUM_LIT:1> <EOL> def add_to_list ( self , url , conf ) : <EOL> url_list = conf . get ( '<STR_LIT>' , [ ] ) <EOL> url_list . append ( [ url , '<STR_LIT>' ] ) <EOL> conf . set ( '<STR_LIT>' , url_list ) <EOL> sublime . save_settings ( CONFIG_BASE_NAME ) <EOL> def remove_from_list ( self , index , conf ) : <EOL> url_list = conf . get ( '<STR_LIT>' , [ ] ) <EOL> url_list . pop ( index ) <EOL> conf . set ( '<STR_LIT>' , url_list ) <EOL> sublime . save_settings ( CONFIG_BASE_NAME ) <EOL> def find_url ( self , pt ) : <EOL> line = self . view . line ( pt ) <EOL> a , b = [ max ( line . a , pt - <NUM_LIT> ) , min ( line . b , pt + <NUM_LIT> ) ] <EOL> line = sublime . Region ( a , b ) <EOL> text = self . view . substr ( line ) <EOL> it = REX_URL . finditer ( text ) <EOL> for match in it : <EOL> if match . start ( ) <= ( pt - line . a ) and match . end ( ) >= ( pt - line . a ) : <EOL> url = text [ match . start ( ) : match . end ( ) ] <EOL> return url <EOL> return None <EOL> if gte_st3 : <EOL> class HiveAddContextUrlCommand ( HiveAddContextUrlBaseCommand ) : <EOL> def find_url ( self , event ) : <EOL> pt = self . view . window_to_text ( ( event [ '<STR_LIT:x>' ] , event [ '<STR_LIT:y>' ] ) ) <EOL> return super ( HiveAddContextUrlCommand , self ) . find_url ( pt ) <EOL> def want_event ( self ) : <EOL> return True <EOL> else : <EOL> class HiveAddContextUrlCommand ( HiveAddContextUrlBaseCommand ) : <EOL> def find_url ( self , event ) : <EOL> selection = self . view . sel ( ) <EOL> if not len ( selection ) : return None <EOL> pt = selection [ - <NUM_LIT:1> ] . b <EOL> return super ( HiveAddContextUrlCommand , self ) . find_url ( pt ) </s>
