<s> import sys <EOL> import os <EOL> import vim <EOL> import vim_ext <EOL> vim_ext . extend_vim ( ) <EOL> fn_proxy = { } <EOL> PROXY_INDEX = <NUM_LIT:0> <EOL> wrap_proxy = { } <EOL> WRAP_INDEX = <NUM_LIT:0> <EOL> def import_py ( sfile , module_name ) : <EOL> sys . path . append ( os . path . dirname ( sfile ) ) <EOL> __import__ ( module_name ) <EOL> sys . path . remove ( os . path . dirname ( sfile ) ) <EOL> def py_fn_to_vim_function ( vimscript_fn_name , py_fn ) : <EOL> global WRAP_INDEX <EOL> wrap_proxy [ WRAP_INDEX ] = py_fn <EOL> vim . command ( "<STR_LIT>" % ( vimscript_fn_name , WRAP_INDEX ) ) <EOL> WRAP_INDEX += <NUM_LIT:1> <EOL> def py_fn_to_vim_command ( command_name , py_fn , allow_range = False ) : <EOL> global WRAP_INDEX <EOL> args = "<STR_LIT>" <EOL> if allow_range : <EOL> args += "<STR_LIT>" <EOL> wrap_proxy [ WRAP_INDEX ] = py_fn <EOL> vim . command ( "<STR_LIT>" % ( args , command_name , WRAP_INDEX ) ) <EOL> WRAP_INDEX += <NUM_LIT:1> <EOL> def _create_mapping_fn ( map_cmd ) : <EOL> def _inner_map ( keys , fn ) : <EOL> global PROXY_INDEX <EOL> fn_proxy [ PROXY_INDEX ] = fn <EOL> vim . command ( "<STR_LIT>" % ( map_cmd , keys , PROXY_INDEX ) ) <EOL> PROXY_INDEX += <NUM_LIT:1> <EOL> return _inner_map <EOL> noremap = _create_mapping_fn ( "<STR_LIT>" ) <EOL> nnoremap = _create_mapping_fn ( "<STR_LIT>" ) <EOL> inoremap = _create_mapping_fn ( "<STR_LIT>" ) <EOL> vnoremap = _create_mapping_fn ( "<STR_LIT>" ) <EOL> xnoremap = _create_mapping_fn ( "<STR_LIT>" ) <EOL> def get_selection_coords ( ) : <EOL> start_line , start_col = vim . eval ( "<STR_LIT>" ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> end_line , end_col = vim . eval ( "<STR_LIT>" ) [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> return ( ( int ( start_line ) - <NUM_LIT:1> , int ( start_col ) - <NUM_LIT:1> ) , ( int ( end_line ) - <NUM_LIT:1> , int ( end_col ) - <NUM_LIT:1> ) ) <EOL> def get_visual_selection ( read_only = False ) : <EOL> ( ( start_line , start_col ) , ( end_line , end_col ) ) = get_selection_coords ( ) <EOL> if read_only : <EOL> buf = vim . current . buffer <EOL> if start_line == end_line : <EOL> return [ buf [ start_line ] [ start_col : end_col + <NUM_LIT:1> ] ] <EOL> elif start_line + <NUM_LIT:1> == end_line : <EOL> return [ buf [ start_line ] [ start_col : ] ] + [ buf [ end_line ] [ : end_col + <NUM_LIT:1> ] ] <EOL> else : <EOL> return [ buf [ start_line ] [ start_col : ] ] + buf [ start_line + <NUM_LIT:1> : end_line ] + [ buf [ end_line ] [ : end_col + <NUM_LIT:1> ] ] <EOL> def replace_visual_selection ( text ) : <EOL> tmp = vim . registers . a <EOL> vim . registers . a = text <EOL> vim . command ( "<STR_LIT>" ) <EOL> vim . registers . a = tmp <EOL> def get_current_line ( read_only = True ) : <EOL> if read_only : <EOL> return vim . eval ( '<STR_LIT>' ) <EOL> def open_file ( file_name ) : <EOL> vim . command ( '<STR_LIT>' % file_name ) <EOL> def open_file_vsplit ( file_name ) : <EOL> vim . command ( '<STR_LIT>' % file_name ) <EOL> def open_file_hsplit ( file_name ) : <EOL> vim . command ( '<STR_LIT>' % file_name ) <EOL> def open_file_tab ( file_name ) : <EOL> vim . command ( '<STR_LIT>' % file_name ) <EOL> def get_current_file_path ( ) : <EOL> return vim . eval ( "<STR_LIT>" ) </s>
