diff --git a/src/command_manager.cc b/src/command_manager.cc index 973e95de..33815be4 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -9,16 +9,18 @@ namespace Kakoune { void CommandManager::register_command(const std::string& command_name, Command command, + unsigned flags, const CommandCompleter& completer) { - m_commands[command_name] = CommandAndCompleter { command, completer }; + m_commands[command_name] = CommandDescriptor { command, flags, completer }; } void CommandManager::register_command(const std::vector& command_names, Command command, + unsigned flags, const CommandCompleter& completer) { for (auto command_name : command_names) - register_command(command_name, command, completer); + register_command(command_name, command, flags, completer); } typedef std::vector> TokenList; @@ -97,6 +99,9 @@ void CommandManager::execute(const CommandParameters& params, if (command_it == m_commands.end()) throw command_not_found(*begin); + if (command_it->second.flags & IgnoreSemiColons) + end = params.end(); + command_it->second.command(CommandParameters(begin + 1, end), context); } diff --git a/src/command_manager.hh b/src/command_manager.hh index 6b73b47d..125db6e1 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -53,6 +53,12 @@ private: class CommandManager : public Singleton { public: + enum Flags + { + None = 0, + IgnoreSemiColons = 1, + }; + void execute(const std::string& command_line, const Context& context); void execute(const CommandParameters& params, const Context& context); @@ -60,19 +66,22 @@ public: void register_command(const std::string& command_name, Command command, + unsigned flags = None, const CommandCompleter& completer = CommandCompleter()); void register_command(const std::vector& command_names, Command command, + unsigned flags = None, const CommandCompleter& completer = CommandCompleter()); private: - struct CommandAndCompleter + struct CommandDescriptor { Command command; + unsigned flags; CommandCompleter completer; }; - std::unordered_map m_commands; + std::unordered_map m_commands; }; } diff --git a/src/main.cc b/src/main.cc index 74cec3ba..6d3c726c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -895,38 +895,46 @@ int main(int argc, char* argv[]) HooksManager hooks_manager; command_manager.register_command(std::vector{ "e", "edit" }, edit, + CommandManager::None, PerArgumentCommandCompleter{ complete_filename }); command_manager.register_command(std::vector{ "q", "quit" }, quit); command_manager.register_command(std::vector{ "q!", "quit!" }, quit); command_manager.register_command(std::vector{ "w", "write" }, write_buffer, + CommandManager::None, PerArgumentCommandCompleter{ complete_filename }); command_manager.register_command(std::vector{ "wq" }, write_and_quit); command_manager.register_command(std::vector{ "wq!" }, write_and_quit); command_manager.register_command(std::vector{ "b", "buffer" }, show_buffer, + CommandManager::None, PerArgumentCommandCompleter { std::bind(&BufferManager::complete_buffername, &buffer_manager, _1, _2) }); command_manager.register_command(std::vector{ "ah", "addhl" }, add_highlighter, + CommandManager::None, PerArgumentCommandCompleter { std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2) }); command_manager.register_command(std::vector{ "rh", "rmhl" }, rm_highlighter, + CommandManager::None, PerArgumentCommandCompleter { [&](const std::string& prefix, size_t cursor_pos) { return main_context.window->complete_highlighterid(prefix, cursor_pos); } }); command_manager.register_command(std::vector{ "af", "addfilter" }, add_filter, + CommandManager::None, PerArgumentCommandCompleter { std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2) }); command_manager.register_command(std::vector{ "rf", "rmfilter" }, rm_filter, + CommandManager::None, PerArgumentCommandCompleter { [&](const std::string& prefix, size_t cursor_pos) { return main_context.window->complete_filterid(prefix, cursor_pos); } }); - command_manager.register_command(std::vector{ "hook" }, add_hook); + command_manager.register_command(std::vector{ "hook" }, add_hook, CommandManager::IgnoreSemiColons); command_manager.register_command(std::vector{ "source" }, exec_commands_in_file, + CommandManager::None, PerArgumentCommandCompleter{ complete_filename }); command_manager.register_command(std::vector{ "exec" }, exec_string);