mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-24 07:53:41 +03:00
The def command do not override commands by default, use -allow-override
This commit is contained in:
parent
0a848fa450
commit
f972428823
@ -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<String>& command_names, Command command,
|
||||
void CommandManager::register_commands(const memoryview<String>& command_names,
|
||||
Command command,
|
||||
unsigned flags,
|
||||
const CommandCompleter& completer)
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -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<String> cmd_params(++begin, parser.end());
|
||||
Command cmd;
|
||||
if (parser.has_option("env-params"))
|
||||
|
Loading…
Reference in New Issue
Block a user