<s> from __future__ import unicode_literals , print_function <EOL> import os <EOL> import six <EOL> import sys <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> COMMANDS_TO_HANDLERS = { } <EOL> COMMANDS_TAKING_LOCATIONS = set ( ) <EOL> SET_COMMANDS = { } <EOL> SET_COMMANDS_TAKING_VALUE = set ( ) <EOL> _NO_WRITE_SINCE_LAST_CHANGE_TEXT = '<STR_LIT>' <EOL> _NO_FILE_NAME = '<STR_LIT>' <EOL> def has_command_handler ( command ) : <EOL> return command in COMMANDS_TO_HANDLERS <EOL> def call_command_handler ( command , editor , variables ) : <EOL> """<STR_LIT>""" <EOL> COMMANDS_TO_HANDLERS [ command ] ( editor , variables ) <EOL> def get_commands ( ) : <EOL> return COMMANDS_TO_HANDLERS . keys ( ) <EOL> def get_commands_taking_locations ( ) : <EOL> return COMMANDS_TAKING_LOCATIONS <EOL> def _cmd ( name ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> COMMANDS_TO_HANDLERS [ name ] = func <EOL> return func <EOL> return decorator <EOL> def location_cmd ( name , accepts_force = False ) : <EOL> """<STR_LIT>""" <EOL> COMMANDS_TAKING_LOCATIONS . add ( name ) <EOL> def decorator ( func ) : <EOL> @ _cmd ( name ) <EOL> def command_wrapper ( editor , variables ) : <EOL> location = variables . get ( '<STR_LIT:location>' ) <EOL> force = bool ( variables [ '<STR_LIT>' ] ) <EOL> if force and not accepts_force : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> elif accepts_force : <EOL> func ( editor , location , force = force ) <EOL> else : <EOL> func ( editor , location ) <EOL> return func <EOL> return decorator <EOL> def cmd ( name , accepts_force = False ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> @ _cmd ( name ) <EOL> def command_wrapper ( editor , variables ) : <EOL> force = bool ( variables [ '<STR_LIT>' ] ) <EOL> if force and not accepts_force : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> elif accepts_force : <EOL> func ( editor , force = force ) <EOL> else : <EOL> func ( editor ) <EOL> return func <EOL> return decorator <EOL> def set_cmd ( name , accepts_value = False ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> SET_COMMANDS [ name ] = func <EOL> if accepts_value : <EOL> SET_COMMANDS_TAKING_VALUE . add ( name ) <EOL> return func <EOL> return decorator <EOL> @ _cmd ( '<STR_LIT>' ) <EOL> def set_command_execute ( editor , variables ) : <EOL> """<STR_LIT>""" <EOL> option = variables . get ( '<STR_LIT>' ) <EOL> value = variables . get ( '<STR_LIT>' ) <EOL> if option in SET_COMMANDS : <EOL> if option in SET_COMMANDS_TAKING_VALUE : <EOL> SET_COMMANDS [ option ] ( editor , value ) <EOL> else : <EOL> SET_COMMANDS [ option ] ( editor ) <EOL> else : <EOL> editor . show_message ( '<STR_LIT>' % option ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def _bn ( editor , force = False ) : <EOL> """<STR_LIT>""" <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if not force and eb . has_unsaved_changes : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> else : <EOL> editor . window_arrangement . go_to_next_buffer ( ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def _bp ( editor , force = False ) : <EOL> """<STR_LIT>""" <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if not force and eb . has_unsaved_changes : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> else : <EOL> editor . window_arrangement . go_to_previous_buffer ( ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def only ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . keep_only_current_window ( ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def hide ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . close_window ( ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> def horizontal_split ( editor , location ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . hsplit ( location or None ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> def vertical_split ( editor , location ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . vsplit ( location or None ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def new_buffer ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . hsplit ( new = True ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def new_vertical_buffer ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . vsplit ( new = True ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> def buffer_add ( editor , location ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . open_buffer ( location ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def buffer_list ( editor ) : <EOL> """<STR_LIT>""" <EOL> def handler ( ) : <EOL> wa = editor . window_arrangement <EOL> for info in wa . list_open_buffers ( ) : <EOL> char = '<STR_LIT:%>' if info . is_active else '<STR_LIT>' <EOL> eb = info . editor_buffer <EOL> print ( '<STR_LIT>' % ( <EOL> info . index , char , eb . location , ( eb . buffer . document . cursor_position_row + <NUM_LIT:1> ) ) ) <EOL> six . moves . input ( '<STR_LIT>' ) <EOL> editor . cli . run_in_terminal ( handler ) <EOL> @ _cmd ( '<STR_LIT:b>' ) <EOL> @ _cmd ( '<STR_LIT>' ) <EOL> def _buffer ( editor , variables , force = False ) : <EOL> """<STR_LIT>""" <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> force = bool ( variables [ '<STR_LIT>' ] ) <EOL> buffer_name = variables . get ( '<STR_LIT>' ) <EOL> if buffer_name : <EOL> if not force and eb . has_unsaved_changes : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> else : <EOL> editor . window_arrangement . go_to_buffer ( buffer_name ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def buffer_wipe ( editor , force = False ) : <EOL> """<STR_LIT>""" <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if not force and eb . has_unsaved_changes : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> else : <EOL> editor . window_arrangement . close_buffer ( ) <EOL> @ location_cmd ( '<STR_LIT:o>' , accepts_force = True ) <EOL> @ location_cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> @ location_cmd ( '<STR_LIT:e>' , accepts_force = True ) <EOL> @ location_cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def buffer_edit ( editor , location , force = False ) : <EOL> """<STR_LIT>""" <EOL> if location is None : <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if eb . location is None : <EOL> editor . show_message ( _NO_FILE_NAME ) <EOL> elif not force and eb . has_unsaved_changes : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> else : <EOL> eb . reload ( ) <EOL> else : <EOL> editor . window_arrangement . open_buffer ( location , show_in_current_window = True ) <EOL> @ cmd ( '<STR_LIT:q>' , accepts_force = True ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def quit ( editor , all_ = False , force = False ) : <EOL> """<STR_LIT>""" <EOL> ebs = editor . window_arrangement . editor_buffers <EOL> if not force and any ( eb . has_unsaved_changes for eb in ebs ) : <EOL> editor . show_message ( _NO_WRITE_SINCE_LAST_CHANGE_TEXT ) <EOL> elif not all_ and len ( ebs ) > <NUM_LIT:1> : <EOL> editor . show_message ( '<STR_LIT>' % ( len ( ebs ) - <NUM_LIT:1> ) ) <EOL> else : <EOL> editor . cli . set_return_value ( '<STR_LIT>' ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> @ cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def quit_all ( editor , force = False ) : <EOL> """<STR_LIT>""" <EOL> quit ( editor , all_ = True , force = force ) <EOL> @ location_cmd ( '<STR_LIT:w>' , accepts_force = True ) <EOL> @ location_cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def write ( editor , location , force = False ) : <EOL> """<STR_LIT>""" <EOL> if location and not force and os . path . exists ( location ) : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> else : <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if location is None and eb . location is None : <EOL> editor . show_message ( _NO_FILE_NAME ) <EOL> else : <EOL> eb . write ( location ) <EOL> @ location_cmd ( '<STR_LIT>' , accepts_force = True ) <EOL> def write_and_quit ( editor , location , force = False ) : <EOL> """<STR_LIT>""" <EOL> write ( editor , location , force = force ) <EOL> editor . cli . set_return_value ( '<STR_LIT>' ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def quit_nonzero ( editor ) : <EOL> """<STR_LIT>""" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def write_and_quit_all ( editor ) : <EOL> """<STR_LIT>""" <EOL> eb = editor . window_arrangement . active_editor_buffer <EOL> if eb . location is None : <EOL> editor . show_message ( _NO_FILE_NAME ) <EOL> else : <EOL> eb . write ( ) <EOL> quit ( editor , all_ = True , force = False ) <EOL> @ cmd ( '<STR_LIT:h>' ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def help ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_help ( ) <EOL> @ location_cmd ( '<STR_LIT>' ) <EOL> def tab_new ( editor , location ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . create_tab ( location or None ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def tab_close ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . close_tab ( ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def tab_next ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . go_to_next_tab ( ) <EOL> @ cmd ( '<STR_LIT>' ) <EOL> def tab_previous ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . window_arrangement . go_to_previous_tab ( ) <EOL> @ _cmd ( '<STR_LIT>' ) <EOL> def color_scheme ( editor , variables ) : <EOL> """<STR_LIT>""" <EOL> colorscheme = variables . get ( '<STR_LIT>' ) <EOL> if colorscheme : <EOL> editor . use_colorscheme ( colorscheme ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def line_numbers_show ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_line_numbers = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def line_numbers_hide ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_line_numbers = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def search_highlight ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . highlight_search = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def search_no_highlight ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . highlight_search = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def paste_mode ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . paste_mode = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def paste_mode_leave ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . paste_mode = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def ruler_show ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_ruler = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def ruler_hide ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_ruler = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def wild_menu_show ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_wildmenu = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def wild_menu_hide ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . show_wildmenu = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def tab_expand ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . expand_tab = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def tab_no_expand ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . expand_tab = False <EOL> @ set_cmd ( '<STR_LIT>' , accepts_value = True ) <EOL> @ set_cmd ( '<STR_LIT>' , accepts_value = True ) <EOL> def tab_stop ( editor , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> editor . show_message ( '<STR_LIT>' % editor . tabstop ) <EOL> else : <EOL> try : <EOL> value = int ( value ) <EOL> if value > <NUM_LIT:0> : <EOL> editor . tabstop = value <EOL> else : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' , accepts_value = True ) <EOL> @ set_cmd ( '<STR_LIT>' , accepts_value = True ) <EOL> def set_scroll_offset ( editor , value ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> editor . show_message ( '<STR_LIT>' % editor . scroll_offset ) <EOL> else : <EOL> try : <EOL> value = int ( value ) <EOL> if value >= <NUM_LIT:0> : <EOL> editor . scroll_offset = value <EOL> else : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> editor . show_message ( '<STR_LIT>' ) <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def incsearch_enable ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . incsearch = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def incsearch_disable ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . incsearch = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def search_ignorecase ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . ignore_case = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def searc_no_ignorecase ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . ignore_case = False <EOL> @ set_cmd ( '<STR_LIT:list>' ) <EOL> def unprintable_show ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . display_unprintable_characters = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def unprintable_hide ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . display_unprintable_characters = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def jedi_enable ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . enable_jedi = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def jedi_disable ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . enable_jedi = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def relative_number ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . relative_number = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def no_relative_number ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . relative_number = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def enable_wrap ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . wrap_lines = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def disable_wrap ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . wrap_lines = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def enable_mouse ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . enable_mouse_support = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def disable_mouse ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . enable_mouse_support = False <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def enable_tildeop ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . cli . vi_state . tilde_operator = True <EOL> @ set_cmd ( '<STR_LIT>' ) <EOL> def disable_tildeop ( editor ) : <EOL> "<STR_LIT>" <EOL> editor . cli . vi_state . tilde_operator = False </s>
