From 32735516658474a2a505d2c524c3175e5f042b88 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Feb 2012 21:40:09 +0000 Subject: [PATCH] add 'def' command to define new user commands --- src/main.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.cc b/src/main.cc index 9062da2b..1c37fbfc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -700,6 +700,18 @@ void add_hook(const CommandParameters& params, const Context& context) print_status("error: no such hook container " + params[0]); } +void define_command(const CommandParameters& params, const Context& context) +{ + if (params.size() < 2) + throw wrong_argument_count(); + + std::vector cmd_params(params.begin()+1, params.end()); + auto func = [=](const CommandParameters& params, const Context& context) { + CommandManager::instance().execute(cmd_params, context); + }; + CommandManager::instance().register_command(params[0], func); +} + void exec_commands_in_file(const CommandParameters& params, const Context& context) { @@ -1198,6 +1210,8 @@ int main(int argc, char* argv[]) command_manager.register_command("exec", exec_string); + command_manager.register_command("def", define_command, CommandManager::IgnoreSemiColons | CommandManager::DeferredShellEval); + register_highlighters(); register_filters();