From 577734dae725739aa1fe6f87334253441385f24a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 18 Feb 2013 18:57:08 +0100 Subject: [PATCH] expose exec_keys function in commands.hh --- src/commands.cc | 142 ++++++++++++++++++++++++------------------------ src/commands.hh | 5 ++ 2 files changed, 76 insertions(+), 71 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 938d365e4..b3805658e 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -472,77 +472,6 @@ void set_option(OptionManager& options, const CommandParameters& params, options.set_option(params[0], Option(params[1])); } -class RegisterRestorer -{ -public: - RegisterRestorer(char name, const Context& context) - : m_name(name) - { - memoryview save = RegisterManager::instance()[name].values(context); - m_save = std::vector(save.begin(), save.end()); - } - - ~RegisterRestorer() - { RegisterManager::instance()[m_name] = m_save; } - -private: - std::vector m_save; - char m_name; -}; - -class BatchUI : public UserInterface -{ -public: - BatchUI(const KeyList& keys) - : m_keys(keys), m_pos(0) {} - - Key get_key() override - { - assert(m_pos < m_keys.size()); - return m_keys[m_pos++]; - } - bool is_key_available() override { return m_pos < m_keys.size(); } - - void print_status(const String& , CharCount) override {} - void draw(const DisplayBuffer&, const String&) override {} - void menu_show(const memoryview&, - const DisplayCoord&, MenuStyle) override {} - void menu_select(int) override {} - void menu_hide() override {} - - void info_show(const String&, const DisplayCoord&, MenuStyle) override {} - void info_hide() override {} - - DisplayCoord dimensions() override { return { 0, 0 }; } - - void set_input_callback(InputCallback callback) {} - -private: - const KeyList& m_keys; - size_t m_pos; -}; - -void exec_keys(const KeyList& keys, Context& context) -{ - RegisterRestorer quote('"', context); - RegisterRestorer slash('/', context); - - scoped_edition edition(context.editor()); - - BatchUI batch_ui(keys); - InputHandler batch_input_handler(batch_ui); - batch_input_handler.context().change_editor(context.editor()); - - batch_input_handler.handle_available_inputs(); - - auto& new_editor = batch_input_handler.context().editor(); - if (&new_editor != &context.editor()) - { - context.push_jump(); - context.change_editor(new_editor); - } -} - template void context_wrap(const CommandParameters& params, Context& context, Func func) { @@ -691,6 +620,77 @@ void set_client_name(const CommandParameters& params, Context& context) ClientManager::instance().set_client_name(context, params[0]); } +class RegisterRestorer +{ +public: + RegisterRestorer(char name, const Context& context) + : m_name(name) + { + memoryview save = RegisterManager::instance()[name].values(context); + m_save = std::vector(save.begin(), save.end()); + } + + ~RegisterRestorer() + { RegisterManager::instance()[m_name] = m_save; } + +private: + std::vector m_save; + char m_name; +}; + +class BatchUI : public UserInterface +{ +public: + BatchUI(const KeyList& keys) + : m_keys(keys), m_pos(0) {} + + Key get_key() override + { + assert(m_pos < m_keys.size()); + return m_keys[m_pos++]; + } + bool is_key_available() override { return m_pos < m_keys.size(); } + + void print_status(const String& , CharCount) override {} + void draw(const DisplayBuffer&, const String&) override {} + void menu_show(const memoryview&, + const DisplayCoord&, MenuStyle) override {} + void menu_select(int) override {} + void menu_hide() override {} + + void info_show(const String&, const DisplayCoord&, MenuStyle) override {} + void info_hide() override {} + + DisplayCoord dimensions() override { return { 0, 0 }; } + + void set_input_callback(InputCallback callback) {} + +private: + const KeyList& m_keys; + size_t m_pos; +}; + +} + +void exec_keys(const KeyList& keys, Context& context) +{ + RegisterRestorer quote('"', context); + RegisterRestorer slash('/', context); + + scoped_edition edition(context.editor()); + + BatchUI batch_ui(keys); + InputHandler batch_input_handler(batch_ui); + batch_input_handler.context().change_editor(context.editor()); + + batch_input_handler.handle_available_inputs(); + + auto& new_editor = batch_input_handler.context().editor(); + if (&new_editor != &context.editor()) + { + context.push_jump(); + context.change_editor(new_editor); + } } void register_commands() diff --git a/src/commands.hh b/src/commands.hh index b38633925..5802a97d2 100644 --- a/src/commands.hh +++ b/src/commands.hh @@ -1,10 +1,15 @@ #ifndef commands_hh_INCLUDED #define commands_hh_INCLUDED +#include "keys.hh" + namespace Kakoune { +struct Context; + void register_commands(); +void exec_keys(const KeyList& keys, Context& context); }