From a8b2c4f568e4384e0f52e0c995ad2128ed43a334 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 12 Nov 2011 14:08:05 +0000 Subject: [PATCH] Completions: add basic addfilter completion --- src/filter_registry.cc | 13 +++++++++++++ src/filter_registry.hh | 4 ++++ src/main.cc | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/filter_registry.cc b/src/filter_registry.cc index c9f9149ae..a4f1d8178 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 fef04822c..572e30afe 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 cc8021110..d3bfd62fd 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();