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
|
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,
|
unsigned flags,
|
||||||
const CommandCompleter& completer)
|
const CommandCompleter& completer)
|
||||||
{
|
{
|
||||||
m_commands[command_name] = CommandDescriptor { command, flags, 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,
|
unsigned flags,
|
||||||
const CommandCompleter& completer)
|
const CommandCompleter& completer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
|
|
||||||
Completions complete(const String& command_line, size_t cursor_pos);
|
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,
|
void register_command(const String& command_name,
|
||||||
Command command,
|
Command command,
|
||||||
unsigned flags = None,
|
unsigned flags = None,
|
||||||
|
|
|
@ -455,6 +455,7 @@ void define_command(const CommandParameters& params, const Context& context)
|
||||||
ParametersParser parser(params,
|
ParametersParser parser(params,
|
||||||
{ { "env-params", false },
|
{ { "env-params", false },
|
||||||
{ "append-params", false },
|
{ "append-params", false },
|
||||||
|
{ "allow-override", false },
|
||||||
{ "shell-completion", true } });
|
{ "shell-completion", true } });
|
||||||
|
|
||||||
if (parser.positional_count() < 2)
|
if (parser.positional_count() < 2)
|
||||||
|
@ -462,6 +463,11 @@ void define_command(const CommandParameters& params, const Context& context)
|
||||||
|
|
||||||
auto begin = parser.begin();
|
auto begin = parser.begin();
|
||||||
const String& cmd_name = *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());
|
std::vector<String> cmd_params(++begin, parser.end());
|
||||||
Command cmd;
|
Command cmd;
|
||||||
if (parser.has_option("env-params"))
|
if (parser.has_option("env-params"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user