add 'def' command to define new user commands

This commit is contained in:
Maxime Coste 2012-02-13 21:40:09 +00:00
parent 5f86941b8f
commit 3273551665

View File

@ -700,6 +700,18 @@ void add_hook(const CommandParameters& params, const Context& context)
print_status("error: no such hook container " + params[0]); 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<std::string> 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, void exec_commands_in_file(const CommandParameters& params,
const Context& context) const Context& context)
{ {
@ -1198,6 +1210,8 @@ int main(int argc, char* argv[])
command_manager.register_command("exec", exec_string); command_manager.register_command("exec", exec_string);
command_manager.register_command("def", define_command, CommandManager::IgnoreSemiColons | CommandManager::DeferredShellEval);
register_highlighters(); register_highlighters();
register_filters(); register_filters();