diff --git a/src/command_manager.cc b/src/command_manager.cc index 0ec579b3..f07cebcf 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -181,7 +181,7 @@ struct command_not_found : runtime_error }; void CommandManager::execute_single_command(const CommandParameters& params, - const Context& context) const + Context& context) const { if (params.empty()) return; @@ -194,7 +194,7 @@ void CommandManager::execute_single_command(const CommandParameters& params, } void CommandManager::execute(const String& command_line, - const Context& context, + Context& context, const EnvVarMap& env_vars) { TokenList tokens = parse(command_line); diff --git a/src/command_manager.hh b/src/command_manager.hh index 298b9056..113bac3e 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -24,7 +24,7 @@ struct wrong_argument_count : runtime_error using CommandParameters = memoryview; typedef std::function Command; + Context& context)> Command; typedef std::function { public: - void execute(const String& command_line, const Context& context, + void execute(const String& command_line, Context& context, const EnvVarMap& env_vars = EnvVarMap()); Completions complete(const Context& context, @@ -70,7 +70,7 @@ public: private: void execute_single_command(const CommandParameters& params, - const Context& context) const; + Context& context) const; struct CommandDescriptor { Command command; diff --git a/src/commands.cc b/src/commands.cc index 1f979a9d..5296cbfb 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -25,10 +25,9 @@ namespace Kakoune using namespace std::placeholders; // berk -extern Context main_context; extern bool quit_requested; -extern std::unordered_map> keymap; +extern std::unordered_map> keymap; namespace { @@ -231,7 +230,7 @@ Buffer* open_or_create(const String& filename) } template -void edit(const CommandParameters& params, const Context& context) +void edit(const CommandParameters& params, Context& context) { if (params.size() == 0 or params.size() > 3) throw wrong_argument_count(); @@ -255,10 +254,10 @@ void edit(const CommandParameters& params, const Context& context) window.select(window.buffer().iterator_at({line, column})); } - main_context = Context(window); + context = Context(window); } -void write_buffer(const CommandParameters& params, const Context& context) +void write_buffer(const CommandParameters& params, Context& context) { if (params.size() > 1) throw wrong_argument_count(); @@ -272,7 +271,7 @@ void write_buffer(const CommandParameters& params, const Context& context) } template -void quit(const CommandParameters& params, const Context& context) +void quit(const CommandParameters& params, Context& context) { if (params.size() != 0) throw wrong_argument_count(); @@ -302,13 +301,13 @@ void quit(const CommandParameters& params, const Context& context) } template -void write_and_quit(const CommandParameters& params, const Context& context) +void write_and_quit(const CommandParameters& params, Context& context) { write_buffer(params, context); quit(CommandParameters(), context); } -void show_buffer(const CommandParameters& params, const Context& context) +void show_buffer(const CommandParameters& params, Context& context) { if (params.size() != 1) throw wrong_argument_count(); @@ -318,10 +317,10 @@ void show_buffer(const CommandParameters& params, const Context& context) if (not buffer) throw runtime_error("buffer " + buffer_name + " does not exists"); - main_context = Context(*buffer->get_or_create_window()); + context = Context(*buffer->get_or_create_window()); } -void delete_buffer(const CommandParameters& params, const Context& context) +void delete_buffer(const CommandParameters& params, Context& context) { if (params.size() > 1) throw wrong_argument_count(); @@ -340,7 +339,7 @@ void delete_buffer(const CommandParameters& params, const Context& context) if (buffer->type()!= Buffer::Type::Scratch and buffer->is_modified()) throw runtime_error("buffer " + buffer->name() + " is modified"); - if (&main_context.buffer() == buffer) + if (&context.buffer() == buffer) { if (manager.count() == 1) throw runtime_error("buffer " + buffer->name() + " is the last one"); @@ -348,7 +347,7 @@ void delete_buffer(const CommandParameters& params, const Context& context) { if (&buf != buffer) { - main_context = Context(*buf.get_or_create_window()); + context = Context(*buf.get_or_create_window()); break; } } @@ -356,7 +355,7 @@ void delete_buffer(const CommandParameters& params, const Context& context) delete buffer; } -void add_highlighter(const CommandParameters& params, const Context& context) +void add_highlighter(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "group", true } }); if (parser.positional_count() < 1) @@ -379,7 +378,7 @@ void add_highlighter(const CommandParameters& params, const Context& context) highlighter_params); } -void rm_highlighter(const CommandParameters& params, const Context& context) +void rm_highlighter(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "group", true } }); if (parser.positional_count() != 1) @@ -393,7 +392,7 @@ void rm_highlighter(const CommandParameters& params, const Context& context) group.remove(*parser.begin()); } -void add_filter(const CommandParameters& params, const Context& context) +void add_filter(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "group", true } }); if (parser.positional_count() < 1) @@ -415,7 +414,7 @@ void add_filter(const CommandParameters& params, const Context& context) registry.add_filter_to_group(group, name, filter_params); } -void rm_filter(const CommandParameters& params, const Context& context) +void rm_filter(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "group", true } }); if (parser.positional_count() != 1) @@ -429,7 +428,7 @@ void rm_filter(const CommandParameters& params, const Context& context) group.remove(*parser.begin()); } -void add_hook(const CommandParameters& params, const Context& context) +void add_hook(const CommandParameters& params, Context& context) { if (params.size() != 4) throw wrong_argument_count(); @@ -440,7 +439,10 @@ void add_hook(const CommandParameters& params, const Context& context) auto hook_func = [=](const String& param, const Context& context) { if (boost::regex_match(param.begin(), param.end(), Regex(regex.begin(), regex.end()))) - CommandManager::instance().execute(command, context); + { + Context new_context(context); + CommandManager::instance().execute(command, new_context); + } }; const String& scope = params[0]; @@ -467,7 +469,7 @@ EnvVarMap params_to_env_var_map(const CommandParameters& params) return vars; } -void define_command(const CommandParameters& params, const Context& context) +void define_command(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "env-params", false }, @@ -489,14 +491,14 @@ void define_command(const CommandParameters& params, const Context& context) Command cmd; if (parser.has_option("env-params")) { - cmd = [=](const CommandParameters& params, const Context& context) { + cmd = [=](const CommandParameters& params, Context& context) { CommandManager::instance().execute(commands, context, params_to_env_var_map(params)); }; } else { - cmd = [=](const CommandParameters& params, const Context& context) { + cmd = [=](const CommandParameters& params, Context& context) { if (not params.empty()) throw wrong_argument_count(); CommandManager::instance().execute(commands, context); @@ -521,7 +523,7 @@ void define_command(const CommandParameters& params, const Context& context) CommandManager::instance().register_command(cmd_name, cmd); } -void echo_message(const CommandParameters& params, const Context& context) +void echo_message(const CommandParameters& params, Context& context) { String message; for (auto& param : params) @@ -530,7 +532,7 @@ void echo_message(const CommandParameters& params, const Context& context) } void exec_commands_in_file(const CommandParameters& params, - const Context& context) + Context& context) { if (params.size() != 1) throw wrong_argument_count(); @@ -540,7 +542,7 @@ void exec_commands_in_file(const CommandParameters& params, } void exec_commands_in_runtime_file(const CommandParameters& params, - const Context& context) + Context& context) { if (params.size() != 1) throw wrong_argument_count(); @@ -564,12 +566,12 @@ void exec_commands_in_runtime_file(const CommandParameters& params, if (ptr) { strcpy(ptr+1, filename.c_str()); - exec_commands_in_file(CommandParameters(buffer), main_context); + exec_commands_in_file(CommandParameters(buffer), context); } } void set_option(OptionManager& option_manager, const CommandParameters& params, - const Context& context) + Context& context) { if (params.size() != 2) throw wrong_argument_count(); @@ -649,8 +651,7 @@ private: Client* m_previous_client; }; -void exec_keys(const KeyList& keys, - const Context& context) +void exec_keys(const KeyList& keys, Context& context) { BatchClient batch_client(keys); @@ -684,8 +685,7 @@ void exec_keys(const KeyList& keys, } } -void exec_string(const CommandParameters& params, - const Context& context) +void exec_string(const CommandParameters& params, Context& context) { if (params.size() != 1) throw wrong_argument_count(); @@ -695,8 +695,7 @@ void exec_string(const CommandParameters& params, exec_keys(keys, context); } -void menu(const CommandParameters& params, - const Context& context) +void menu(const CommandParameters& params, Context& context) { ParametersParser parser(params, { { "auto-single", false } }); @@ -724,8 +723,7 @@ void menu(const CommandParameters& params, CommandManager::instance().execute(parser[(i-1)*2+1], context); } -void try_catch(const CommandParameters& params, - const Context& context) +void try_catch(const CommandParameters& params, Context& context) { if (params.size() != 3) throw wrong_argument_count(); @@ -835,21 +833,21 @@ void register_commands() cm.register_command("echo", echo_message); cm.register_commands({ "setg", "setglobal" }, - [](const CommandParameters& params, const Context& context) + [](const CommandParameters& params, Context& context) { set_option(GlobalOptionManager::instance(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, size_t cursor_pos) { return GlobalOptionManager::instance().complete_option_name(prefix, cursor_pos); } })); cm.register_commands({ "setb", "setbuffer" }, - [](const CommandParameters& params, const Context& context) + [](const CommandParameters& params, Context& context) { set_option(context.buffer().option_manager(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, size_t cursor_pos) { return context.buffer().option_manager().complete_option_name(prefix, cursor_pos); } })); cm.register_commands({ "setw", "setwindow" }, - [](const CommandParameters& params, const Context& context) + [](const CommandParameters& params, Context& context) { set_option(context.window().option_manager(), params, context); }, PerArgumentCommandCompleter({ [](const Context& context, const String& prefix, size_t cursor_pos) diff --git a/src/main.cc b/src/main.cc index ff4e21e9..844b0539 100644 --- a/src/main.cc +++ b/src/main.cc @@ -28,7 +28,6 @@ using namespace std::placeholders; namespace Kakoune { -Context main_context; bool quit_requested = false; struct InsertSequence @@ -93,7 +92,7 @@ void insert_sequence(IncrementalInserter& inserter, } template -void do_insert(const Context& context) +void do_insert(Context& context) { last_insert_sequence.mode = mode; last_insert_sequence.keys.clear(); @@ -106,7 +105,7 @@ void do_insert(const Context& context) [&]() { draw_editor_ifn(context.editor()); }); } -void do_repeat_insert(const Context& context) +void do_repeat_insert(Context& context) { if (last_insert_sequence.keys.empty()) return; @@ -119,7 +118,7 @@ void do_repeat_insert(const Context& context) } template -void do_go(const Context& context) +void do_go(Context& context) { int count = context.numeric_param(); Editor& editor = context.editor(); @@ -165,7 +164,7 @@ void do_go(const Context& context) } } -void do_command(const Context& context) +void do_command(Context& context) { try { @@ -179,7 +178,7 @@ void do_command(const Context& context) catch (prompt_aborted&) {} } -void do_pipe(const Context& context) +void do_pipe(Context& context) { try { @@ -199,7 +198,7 @@ void do_pipe(const Context& context) } template -void do_search(const Context& context) +void do_search(Context& context) { try { @@ -215,7 +214,7 @@ void do_search(const Context& context) } template -void do_search_next(const Context& context) +void do_search_next(Context& context) { const String& ex = RegisterManager::instance()['/'].values(context)[0]; if (not ex.empty()) @@ -224,18 +223,18 @@ void do_search_next(const Context& context) print_status("no search pattern"); } -void do_yank(const Context& context) +void do_yank(Context& context) { RegisterManager::instance()['"'] = context.editor().selections_content(); } -void do_erase(const Context& context) +void do_erase(Context& context) { RegisterManager::instance()['"'] = context.editor().selections_content(); context.editor().erase(); } -void do_change(const Context& context) +void do_change(Context& context) { RegisterManager::instance()['"'] = context.editor().selections_content(); do_insert(context); @@ -249,7 +248,7 @@ enum class PasteMode }; template -void do_paste(const Context& context) +void do_paste(Context& context) { Editor& editor = context.editor(); int count = context.numeric_param(); @@ -274,7 +273,7 @@ void do_paste(const Context& context) } } -void do_select_regex(const Context& context) +void do_select_regex(Context& context) { try { @@ -284,7 +283,7 @@ void do_select_regex(const Context& context) catch (prompt_aborted&) {} } -void do_split_regex(const Context& context) +void do_split_regex(Context& context) { try { @@ -294,7 +293,7 @@ void do_split_regex(const Context& context) catch (prompt_aborted&) {} } -void do_join(const Context& context) +void do_join(Context& context) { Editor& editor = context.editor(); editor.select(select_whole_lines); @@ -306,7 +305,7 @@ void do_join(const Context& context) } template -void do_select_object(const Context& context) +void do_select_object(Context& context) { typedef std::function Selector; static const std::unordered_map key_to_selector = @@ -337,7 +336,7 @@ class Repeated public: Repeated(T t) : m_func(t) {} - void operator() (const Context& context) + void operator() (Context& context) { int count = context.numeric_param(); do { m_func(context); } while(--count > 0); @@ -349,22 +348,22 @@ private: template Repeated repeated(T func) { return Repeated(func); } -std::unordered_map> keymap = +std::unordered_map> keymap = { - { { Key::Modifiers::None, 'h' }, [](const Context& context) { context.editor().move_selections(BufferCoord(0, -std::max(context.numeric_param(),1))); } }, - { { Key::Modifiers::None, 'j' }, [](const Context& context) { context.editor().move_selections(BufferCoord( std::max(context.numeric_param(),1), 0)); } }, - { { Key::Modifiers::None, 'k' }, [](const Context& context) { context.editor().move_selections(BufferCoord(-std::max(context.numeric_param(),1), 0)); } }, - { { Key::Modifiers::None, 'l' }, [](const Context& context) { context.editor().move_selections(BufferCoord(0, std::max(context.numeric_param(),1))); } }, + { { Key::Modifiers::None, 'h' }, [](Context& context) { context.editor().move_selections(BufferCoord(0, -std::max(context.numeric_param(),1))); } }, + { { Key::Modifiers::None, 'j' }, [](Context& context) { context.editor().move_selections(BufferCoord( std::max(context.numeric_param(),1), 0)); } }, + { { Key::Modifiers::None, 'k' }, [](Context& context) { context.editor().move_selections(BufferCoord(-std::max(context.numeric_param(),1), 0)); } }, + { { Key::Modifiers::None, 'l' }, [](Context& context) { context.editor().move_selections(BufferCoord(0, std::max(context.numeric_param(),1))); } }, - { { Key::Modifiers::None, 'H' }, [](const Context& context) { context.editor().move_selections(BufferCoord(0, -std::max(context.numeric_param(),1)), true); } }, - { { Key::Modifiers::None, 'J' }, [](const Context& context) { context.editor().move_selections(BufferCoord( std::max(context.numeric_param(),1), 0), true); } }, - { { Key::Modifiers::None, 'K' }, [](const Context& context) { context.editor().move_selections(BufferCoord(-std::max(context.numeric_param(),1), 0), true); } }, - { { Key::Modifiers::None, 'L' }, [](const Context& context) { context.editor().move_selections(BufferCoord(0, std::max(context.numeric_param(),1)), true); } }, + { { Key::Modifiers::None, 'H' }, [](Context& context) { context.editor().move_selections(BufferCoord(0, -std::max(context.numeric_param(),1)), true); } }, + { { Key::Modifiers::None, 'J' }, [](Context& context) { context.editor().move_selections(BufferCoord( std::max(context.numeric_param(),1), 0), true); } }, + { { Key::Modifiers::None, 'K' }, [](Context& context) { context.editor().move_selections(BufferCoord(-std::max(context.numeric_param(),1), 0), true); } }, + { { Key::Modifiers::None, 'L' }, [](Context& context) { context.editor().move_selections(BufferCoord(0, std::max(context.numeric_param(),1)), true); } }, - { { Key::Modifiers::None, 't' }, [](const Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), false)); } }, - { { Key::Modifiers::None, 'f' }, [](const Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), true)); } }, - { { Key::Modifiers::None, 'T' }, [](const Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), false), true); } }, - { { Key::Modifiers::None, 'F' }, [](const Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), true), true); } }, + { { Key::Modifiers::None, 't' }, [](Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), false)); } }, + { { Key::Modifiers::None, 'f' }, [](Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), true)); } }, + { { Key::Modifiers::None, 'T' }, [](Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), false), true); } }, + { { Key::Modifiers::None, 'F' }, [](Context& context) { context.editor().select(std::bind(select_to, _1, get_key().key, context.numeric_param(), true), true); } }, { { Key::Modifiers::None, 'd' }, do_erase }, { { Key::Modifiers::None, 'c' }, do_change }, @@ -388,60 +387,60 @@ std::unordered_map> keymap = { { Key::Modifiers::None, '.' }, do_repeat_insert }, - { { Key::Modifiers::None, '%' }, [](const Context& context) { context.editor().clear_selections(); context.editor().select(select_whole_buffer); } }, + { { Key::Modifiers::None, '%' }, [](Context& context) { context.editor().clear_selections(); context.editor().select(select_whole_buffer); } }, { { Key::Modifiers::None, ':' }, do_command }, { { Key::Modifiers::None, '|' }, do_pipe }, - { { Key::Modifiers::None, ' ' }, [](const Context& context) { int count = context.numeric_param(); - if (count == 0) context.editor().clear_selections(); - else context.editor().keep_selection(count-1); } }, - { { Key::Modifiers::Alt, ' ' }, [](const Context& context) { int count = context.numeric_param(); - if (count == 0) context.editor().clear_selections(); - else context.editor().remove_selection(count-1); } }, - { { Key::Modifiers::None, 'w' }, repeated([](const Context& context) { context.editor().select(select_to_next_word); }) }, - { { Key::Modifiers::None, 'e' }, repeated([](const Context& context) { context.editor().select(select_to_next_word_end); }) }, - { { Key::Modifiers::None, 'b' }, repeated([](const Context& context) { context.editor().select(select_to_previous_word); }) }, - { { Key::Modifiers::None, 'W' }, repeated([](const Context& context) { context.editor().select(select_to_next_word, true); }) }, - { { Key::Modifiers::None, 'E' }, repeated([](const Context& context) { context.editor().select(select_to_next_word_end, true); }) }, - { { Key::Modifiers::None, 'B' }, repeated([](const Context& context) { context.editor().select(select_to_previous_word, true); }) }, - { { Key::Modifiers::None, 'x' }, repeated([](const Context& context) { context.editor().select(select_line, false); }) }, - { { Key::Modifiers::None, 'X' }, repeated([](const Context& context) { context.editor().select(select_line, true); }) }, - { { Key::Modifiers::None, 'm' }, [](const Context& context) { context.editor().select(select_matching); } }, - { { Key::Modifiers::None, 'M' }, [](const Context& context) { context.editor().select(select_matching, true); } }, + { { Key::Modifiers::None, ' ' }, [](Context& context) { int count = context.numeric_param(); + if (count == 0) context.editor().clear_selections(); + else context.editor().keep_selection(count-1); } }, + { { Key::Modifiers::Alt, ' ' }, [](Context& context) { int count = context.numeric_param(); + if (count == 0) context.editor().clear_selections(); + else context.editor().remove_selection(count-1); } }, + { { Key::Modifiers::None, 'w' }, repeated([](Context& context) { context.editor().select(select_to_next_word); }) }, + { { Key::Modifiers::None, 'e' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end); }) }, + { { Key::Modifiers::None, 'b' }, repeated([](Context& context) { context.editor().select(select_to_previous_word); }) }, + { { Key::Modifiers::None, 'W' }, repeated([](Context& context) { context.editor().select(select_to_next_word, true); }) }, + { { Key::Modifiers::None, 'E' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end, true); }) }, + { { Key::Modifiers::None, 'B' }, repeated([](Context& context) { context.editor().select(select_to_previous_word, true); }) }, + { { Key::Modifiers::None, 'x' }, repeated([](Context& context) { context.editor().select(select_line, false); }) }, + { { Key::Modifiers::None, 'X' }, repeated([](Context& context) { context.editor().select(select_line, true); }) }, + { { Key::Modifiers::None, 'm' }, [](Context& context) { context.editor().select(select_matching); } }, + { { Key::Modifiers::None, 'M' }, [](Context& context) { context.editor().select(select_matching, true); } }, { { Key::Modifiers::None, '/' }, do_search }, { { Key::Modifiers::None, '?' }, do_search }, { { Key::Modifiers::None, 'n' }, do_search_next }, { { Key::Modifiers::None, 'N' }, do_search_next }, - { { Key::Modifiers::None, 'u' }, repeated([](const Context& context) { if (not context.editor().undo()) { print_status("nothing left to undo"); } }) }, - { { Key::Modifiers::None, 'U' }, repeated([](const Context& context) { if (not context.editor().redo()) { print_status("nothing left to redo"); } }) }, + { { Key::Modifiers::None, 'u' }, repeated([](Context& context) { if (not context.editor().undo()) { print_status("nothing left to undo"); } }) }, + { { Key::Modifiers::None, 'U' }, repeated([](Context& context) { if (not context.editor().redo()) { print_status("nothing left to redo"); } }) }, { { Key::Modifiers::Alt, 'i' }, do_select_object }, { { Key::Modifiers::Alt, 'a' }, do_select_object }, - { { Key::Modifiers::Alt, 't' }, [](const Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), false)); } }, - { { Key::Modifiers::Alt, 'f' }, [](const Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), true)); } }, - { { Key::Modifiers::Alt, 'T' }, [](const Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), false), true); } }, - { { Key::Modifiers::Alt, 'F' }, [](const Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), true), true); } }, + { { Key::Modifiers::Alt, 't' }, [](Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), false)); } }, + { { Key::Modifiers::Alt, 'f' }, [](Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), true)); } }, + { { Key::Modifiers::Alt, 'T' }, [](Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), false), true); } }, + { { Key::Modifiers::Alt, 'F' }, [](Context& context) { context.editor().select(std::bind(select_to_reverse, _1, get_key().key, context.numeric_param(), true), true); } }, - { { Key::Modifiers::Alt, 'w' }, repeated([](const Context& context) { context.editor().select(select_to_next_word); }) }, - { { Key::Modifiers::Alt, 'e' }, repeated([](const Context& context) { context.editor().select(select_to_next_word_end); }) }, - { { Key::Modifiers::Alt, 'b' }, repeated([](const Context& context) { context.editor().select(select_to_previous_word); }) }, - { { Key::Modifiers::Alt, 'W' }, repeated([](const Context& context) { context.editor().select(select_to_next_word, true); }) }, - { { Key::Modifiers::Alt, 'E' }, repeated([](const Context& context) { context.editor().select(select_to_next_word_end, true); }) }, - { { Key::Modifiers::Alt, 'B' }, repeated([](const Context& context) { context.editor().select(select_to_previous_word, true); }) }, + { { Key::Modifiers::Alt, 'w' }, repeated([](Context& context) { context.editor().select(select_to_next_word); }) }, + { { Key::Modifiers::Alt, 'e' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end); }) }, + { { Key::Modifiers::Alt, 'b' }, repeated([](Context& context) { context.editor().select(select_to_previous_word); }) }, + { { Key::Modifiers::Alt, 'W' }, repeated([](Context& context) { context.editor().select(select_to_next_word, true); }) }, + { { Key::Modifiers::Alt, 'E' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end, true); }) }, + { { Key::Modifiers::Alt, 'B' }, repeated([](Context& context) { context.editor().select(select_to_previous_word, true); }) }, - { { Key::Modifiers::Alt, 'l' }, repeated([](const Context& context) { context.editor().select(select_to_eol, false); }) }, - { { Key::Modifiers::Alt, 'L' }, repeated([](const Context& context) { context.editor().select(select_to_eol, true); }) }, - { { Key::Modifiers::Alt, 'h' }, repeated([](const Context& context) { context.editor().select(select_to_eol_reverse, false); }) }, - { { Key::Modifiers::Alt, 'H' }, repeated([](const Context& context) { context.editor().select(select_to_eol_reverse, true); }) }, + { { Key::Modifiers::Alt, 'l' }, repeated([](Context& context) { context.editor().select(select_to_eol, false); }) }, + { { Key::Modifiers::Alt, 'L' }, repeated([](Context& context) { context.editor().select(select_to_eol, true); }) }, + { { Key::Modifiers::Alt, 'h' }, repeated([](Context& context) { context.editor().select(select_to_eol_reverse, false); }) }, + { { Key::Modifiers::Alt, 'H' }, repeated([](Context& context) { context.editor().select(select_to_eol_reverse, true); }) }, { { Key::Modifiers::Alt, 's' }, do_split_regex }, { { Key::Modifiers::Alt, 'j' }, do_join }, - { { Key::Modifiers::Alt, 'x' }, [](const Context& context) { context.editor().select(select_whole_lines); } }, + { { Key::Modifiers::Alt, 'x' }, [](Context& context) { context.editor().select(select_whole_lines); } }, }; } @@ -485,10 +484,11 @@ int main(int argc, char* argv[]) { NCursesClient client; current_client = &client; + Context context; try { - command_manager.execute("runtime kakrc", main_context); + command_manager.execute("runtime kakrc", context); } catch (Kakoune::runtime_error& error) { @@ -500,14 +500,14 @@ int main(int argc, char* argv[]) write_debug("utf-8 test: é á ï"); if (argc > 1) - command_manager.execute(String("edit ") + argv[1], main_context); + command_manager.execute(String("edit ") + argv[1], context); else { auto buffer = new Buffer("*scratch*", Buffer::Type::Scratch); - main_context = Context(*buffer->get_or_create_window()); + context = Context(*buffer->get_or_create_window()); } - current_client->draw_window(main_context.window()); + current_client->draw_window(context.window()); int count = 0; while(not quit_requested) { @@ -521,9 +521,9 @@ int main(int argc, char* argv[]) auto it = keymap.find(key); if (it != keymap.end()) { - main_context.numeric_param(count); - it->second(main_context); - current_client->draw_window(main_context.window()); + context.numeric_param(count); + it->second(context); + current_client->draw_window(context.window()); } count = 0; } @@ -540,6 +540,5 @@ int main(int argc, char* argv[]) puts(error.description().c_str()); return -1; } - main_context = Context(); return 0; }