From 0dc8442ca40cc6d914de20be40533382287b0ffd Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 12 Nov 2011 14:15:35 +0000 Subject: [PATCH] Completions: add filterid completion for rmfilter --- src/main.cc | 6 +++++- src/window.cc | 14 ++++++++++++++ src/window.hh | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.cc b/src/main.cc index d3bfd62f..977e05c2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -622,7 +622,11 @@ int main(int argc, char* argv[]) PerArgumentCommandCompleter { std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2) }); - command_manager.register_command(std::vector{ "rf", "rmfilter" }, rm_filter); + command_manager.register_command(std::vector{ "rf", "rmfilter" }, rm_filter, + PerArgumentCommandCompleter { + [&](const std::string& prefix, size_t cursor_pos) + { return current_window->complete_filterid(prefix, cursor_pos); } + }); register_filters(); diff --git a/src/window.cc b/src/window.cc index c0ecdc28..c1792d2d 100644 --- a/src/window.cc +++ b/src/window.cc @@ -331,6 +331,20 @@ void Window::remove_filter(const std::string& id) } } +CandidateList Window::complete_filterid(const std::string& prefix, + size_t cursor_pos) +{ + std::string real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& filter : m_filters) + { + if (filter.first.substr(0, real_prefix.length()) == real_prefix) + result.push_back(filter.first); + } + return result; +} + + IncrementalInserter::IncrementalInserter(Window& window, Mode mode) : m_window(window) { diff --git a/src/window.hh b/src/window.hh index 9d0de609..133d44d1 100644 --- a/src/window.hh +++ b/src/window.hh @@ -6,6 +6,7 @@ #include "buffer.hh" #include "dynamic_buffer_iterator.hh" #include "display_buffer.hh" +#include "completion.hh" #include "filter.hh" namespace Kakoune @@ -80,6 +81,9 @@ public: void add_filter(FilterAndId&& filter); void remove_filter(const std::string& id); + CandidateList complete_filterid(const std::string& prefix, + size_t cursor_pos = std::string::npos); + private: friend class Buffer;