summaryrefslogtreecommitdiff
path: root/src/command_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-04-25 11:59:42 +0100
committerMaxime Coste <mawww@kakoune.org>2019-04-25 11:59:42 +0100
commit0cc89b2b9f3cdeff960bd55a865ee0f52fa98d25 (patch)
treebd4860272e271f215e4d9ba7d2049be9f44ac211 /src/command_manager.cc
parent429eeb252c6e7ac8512c2bd98ed3b18c62d7f37b (diff)
parentf49644e8ee8b2450f28b82d74fcf823d81f2ae1c (diff)
Merge remote-tracking branch 'laelath/provides-requires'
Diffstat (limited to 'src/command_manager.cc')
-rw-r--r--src/command_manager.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 5e8c8196..1fdfa34d 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -40,6 +40,36 @@ void CommandManager::register_command(String command_name,
std::move(completer) };
}
+bool CommandManager::module_defined(StringView module_name) const
+{
+ return m_modules.find(module_name) != m_modules.end();
+}
+
+void CommandManager::register_module(String module_name, String commands)
+{
+ auto module = m_modules.find(module_name);
+ if (module != m_modules.end() and module->value.loaded)
+ throw runtime_error{format("module already loaded: '{}'", module_name)};
+
+ m_modules[module_name] = { false, std::move(commands) };
+}
+
+void CommandManager::load_module(StringView module_name, Context& context)
+{
+ auto module = m_modules.find(module_name);
+ if (module == m_modules.end())
+ throw runtime_error{format("no such module: '{}'", module_name)};
+ if (module->value.loaded)
+ return;
+
+ module->value.loaded = true;
+ Context empty_context{Context::EmptyContextFlag{}};
+ execute(module->value.commands, empty_context);
+ module->value.commands.clear();
+
+ context.hooks().run_hook(Hook::ModuleLoad, module_name, context);
+}
+
struct parse_error : runtime_error
{
parse_error(StringView error)