diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-02-07 13:35:41 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-02-07 13:35:41 +0000 |
| commit | 1e5d930f358a96bcca19d7908ded385c85c8d2cc (patch) | |
| tree | 19a2b59c05c71fe9bdc0273677e05a50c778edd1 /src | |
| parent | 0483e951ade67989f762cfcd3796b261ffae41dd (diff) | |
extract exec_keys function from exec_string
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main.cc b/src/main.cc index 31107fb6..6c6ef345 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1019,16 +1019,9 @@ std::unordered_map<Key, std::function<void (Editor& editor, int count)>> 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(); |
