Completions: add filterid completion for rmfilter

This commit is contained in:
Maxime Coste 2011-11-12 14:15:35 +00:00
parent a8b2c4f568
commit 0dc8442ca4
3 changed files with 23 additions and 1 deletions

View File

@ -622,7 +622,11 @@ int main(int argc, char* argv[])
PerArgumentCommandCompleter { PerArgumentCommandCompleter {
std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2) std::bind(&FilterRegistry::complete_filter, &filter_registry, _1, _2)
}); });
command_manager.register_command(std::vector<std::string>{ "rf", "rmfilter" }, rm_filter); command_manager.register_command(std::vector<std::string>{ "rf", "rmfilter" }, rm_filter,
PerArgumentCommandCompleter {
[&](const std::string& prefix, size_t cursor_pos)
{ return current_window->complete_filterid(prefix, cursor_pos); }
});
register_filters(); register_filters();

View File

@ -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) IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
: m_window(window) : m_window(window)
{ {

View File

@ -6,6 +6,7 @@
#include "buffer.hh" #include "buffer.hh"
#include "dynamic_buffer_iterator.hh" #include "dynamic_buffer_iterator.hh"
#include "display_buffer.hh" #include "display_buffer.hh"
#include "completion.hh"
#include "filter.hh" #include "filter.hh"
namespace Kakoune namespace Kakoune
@ -80,6 +81,9 @@ public:
void add_filter(FilterAndId&& filter); void add_filter(FilterAndId&& filter);
void remove_filter(const std::string& id); void remove_filter(const std::string& id);
CandidateList complete_filterid(const std::string& prefix,
size_t cursor_pos = std::string::npos);
private: private:
friend class Buffer; friend class Buffer;