From 1e5d930f358a96bcca19d7908ded385c85c8d2cc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 7 Feb 2012 13:35:41 +0000 Subject: [PATCH] extract exec_keys function from exec_string --- src/main.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.cc b/src/main.cc index 31107fb6a..6c6ef3456 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1019,16 +1019,9 @@ std::unordered_map> keymap { { Key::Modifiers::Alt, 'x' }, [](Editor& editor, int count) { editor.multi_select(select_whole_lines); } }, }; -void exec_string(const CommandParameters& params, - const Context& context) +void exec_keys(const KeyList& keys, + const Context& context) { - if (params.size() != 1) - throw wrong_argument_count(); - - size_t pos = 0; - - KeyList keys = parse_keys(params[0]); - auto prompt_save = prompt_func; auto get_key_save = get_key_func; @@ -1037,6 +1030,8 @@ void exec_string(const CommandParameters& params, get_key_func = get_key_save; }); + size_t pos = 0; + prompt_func = [&](const std::string&, Completer) { size_t begin = pos; while (pos < keys.size() and keys[pos].key != '\n') @@ -1080,6 +1075,17 @@ void exec_string(const CommandParameters& params, } } +void exec_string(const CommandParameters& params, + const Context& context) +{ + if (params.size() != 1) + throw wrong_argument_count(); + + KeyList keys = parse_keys(params[0]); + + exec_keys(keys, context); +} + int main(int argc, char* argv[]) { init_ncurses();