diff --git a/src/command_manager.cc b/src/command_manager.cc index fe9cc9ee..3c59dbc9 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -10,14 +10,21 @@ namespace Kakoune { -void CommandManager::register_command(const String& command_name, Command command, +bool CommandManager::command_defined(const String& command_name) const +{ + return m_commands.find(command_name) != m_commands.end(); +} + +void CommandManager::register_command(const String& command_name, + Command command, unsigned flags, const CommandCompleter& completer) { m_commands[command_name] = CommandDescriptor { command, flags, completer }; } -void CommandManager::register_commands(const memoryview& command_names, Command command, +void CommandManager::register_commands(const memoryview& command_names, + Command command, unsigned flags, const CommandCompleter& completer) { diff --git a/src/command_manager.hh b/src/command_manager.hh index 54d67b80..b3f0917e 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -62,6 +62,8 @@ public: Completions complete(const String& command_line, size_t cursor_pos); + bool command_defined(const String& command_name) const; + void register_command(const String& command_name, Command command, unsigned flags = None, diff --git a/src/commands.cc b/src/commands.cc index 700ad552..24990f75 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -455,6 +455,7 @@ void define_command(const CommandParameters& params, const Context& context) ParametersParser parser(params, { { "env-params", false }, { "append-params", false }, + { "allow-override", false }, { "shell-completion", true } }); if (parser.positional_count() < 2) @@ -462,6 +463,11 @@ void define_command(const CommandParameters& params, const Context& context) auto begin = parser.begin(); const String& cmd_name = *begin; + + if (CommandManager::instance().command_defined(cmd_name) and + not parser.has_option("allow-override")) + throw runtime_error("command '" + cmd_name + "' already defined"); + std::vector cmd_params(++begin, parser.end()); Command cmd; if (parser.has_option("env-params"))