<s> import os , sys <EOL> from sublime import * <EOL> def get_selection ( view = None ) : <EOL> if not view : <EOL> view = active_window ( ) . active_view ( ) <EOL> return view . sel ( ) <EOL> def set_selection ( view , region ) : <EOL> sel = view . sel ( ) <EOL> sel . clear ( ) <EOL> sel . add ( region ) <EOL> def redraw_view ( view = None ) : <EOL> if not view : <EOL> view = active_window ( ) . active_view ( ) <EOL> pos = view . viewport_position ( ) <EOL> pos = ( pos [ <NUM_LIT:0> ] , pos [ <NUM_LIT:1> ] + <NUM_LIT:1> ) <EOL> view . set_viewport_position ( pos ) <EOL> pos = ( pos [ <NUM_LIT:0> ] , pos [ <NUM_LIT:1> ] - <NUM_LIT:1> ) <EOL> view . set_viewport_position ( pos ) <EOL> def select_line ( view , line ) : <EOL> pt = view . text_point ( line - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> ln = view . line ( pt ) <EOL> sel = view . sel ( ) <EOL> sel . clear ( ) <EOL> sel . add ( ln ) <EOL> view . show_at_center ( ln ) <EOL> def select_all ( view ) : <EOL> size = view . size ( ) <EOL> sel = view . sel ( ) <EOL> sel . clear ( ) <EOL> sel . add ( Region ( <NUM_LIT:0> , size ) ) <EOL> def get_view_text ( view ) : <EOL> region = Region ( <NUM_LIT:0> , view . size ( ) ) <EOL> return view . substr ( region ) <EOL> def set_view_text ( view , text ) : <EOL> if not isinstance ( text , unicode ) : <EOL> text = unicode ( text ) <EOL> view . settings ( ) . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> r = Region ( <NUM_LIT:0> , view . size ( ) ) <EOL> e = view . begin_edit ( ) <EOL> view . erase ( e , r ) <EOL> view . insert ( e , <NUM_LIT:0> , text ) <EOL> def flash_select ( view , region , callback = None ) : <EOL> sel = view . sel ( ) <EOL> old_sel = list ( sel ) <EOL> sel . clear ( ) <EOL> sel . add ( region ) <EOL> def restore ( ) : <EOL> sel . clear ( ) <EOL> b = old_sel [ <NUM_LIT:0> ] . b <EOL> sel . add ( Region ( b , b ) ) <EOL> redraw_view ( view ) <EOL> if callback : <EOL> set_timeout ( callback , <NUM_LIT:10> ) <EOL> set_timeout ( restore , <NUM_LIT:50> ) <EOL> def show_panel ( name ) : <EOL> window = active_window ( ) <EOL> window . run_command ( <EOL> "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" + name } <EOL> ) <EOL> def hide_panel ( ) : <EOL> window = active_window ( ) <EOL> window . run_command ( <EOL> "<STR_LIT>" , { "<STR_LIT>" : True } <EOL> ) <EOL> def show_msg ( msg ) : <EOL> window = active_window ( ) <EOL> panel = window . get_output_panel ( '<STR_LIT>' ) <EOL> set_view_text ( panel , msg ) <EOL> show_panel ( '<STR_LIT>' ) <EOL> set_timeout ( hide_panel , <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv ) <EOL> pass </s>
