diff --git a/src/filter_registry.cc b/src/filter_registry.cc index c9f9149a..a4f1d817 100644 --- a/src/filter_registry.cc +++ b/src/filter_registry.cc @@ -29,4 +29,17 @@ void FilterRegistry::add_filter_to_window(Window& window, window.add_filter(it->second(window, parameters)); } +CandidateList FilterRegistry::complete_filter(const std::string& prefix, + size_t cursor_pos) +{ + std::string real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& filter : m_factories) + { + if (filter.first.substr(0, real_prefix.length()) == real_prefix) + result.push_back(filter.first); + } + return result; +} + } diff --git a/src/filter_registry.hh b/src/filter_registry.hh index fef04822..572e30af 100644 --- a/src/filter_registry.hh +++ b/src/filter_registry.hh @@ -6,6 +6,7 @@ #include "filter.hh" #include "utils.hh" +#include "completion.hh" namespace Kakoune { @@ -27,6 +28,9 @@ public: const std::string& factory_name, const FilterParameters& parameters); + CandidateList complete_filter(const std::string& prefix, + size_t cursor_pos); + private: std::unordered_map m_factories; }; diff --git a/src/main.cc b/src/main.cc index cc802111..d3bfd62f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -618,7 +618,10 @@ int main(int argc, char* argv[]) PerArgumentCommandCompleter { std::bind(&BufferManager::complete_buffername, &buffer_manager, _1, _2) }); - command_manager.register_command(std::vector{ "af", "addfilter" }, add_filter); + command_manager.register_command(std::vector{ "af", "addfilter" }, add_filter, + PerArgumentCommandCompleter { + std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2) + }); command_manager.register_command(std::vector{ "rf", "rmfilter" }, rm_filter); register_filters();