Completions: add basic addfilter completion

This commit is contained in:
Maxime Coste 2011-11-12 14:08:05 +00:00
parent f5ad32f137
commit a8b2c4f568
3 changed files with 21 additions and 1 deletions

View File

@ -29,4 +29,17 @@ void FilterRegistry::add_filter_to_window(Window& window,
window.add_filter(it->second(window, parameters)); 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;
}
} }

View File

@ -6,6 +6,7 @@
#include "filter.hh" #include "filter.hh"
#include "utils.hh" #include "utils.hh"
#include "completion.hh"
namespace Kakoune namespace Kakoune
{ {
@ -27,6 +28,9 @@ public:
const std::string& factory_name, const std::string& factory_name,
const FilterParameters& parameters); const FilterParameters& parameters);
CandidateList complete_filter(const std::string& prefix,
size_t cursor_pos);
private: private:
std::unordered_map<std::string, FilterFactory> m_factories; std::unordered_map<std::string, FilterFactory> m_factories;
}; };

View File

@ -618,7 +618,10 @@ int main(int argc, char* argv[])
PerArgumentCommandCompleter { PerArgumentCommandCompleter {
std::bind(&BufferManager::complete_buffername, &buffer_manager, _1, _2) std::bind(&BufferManager::complete_buffername, &buffer_manager, _1, _2)
}); });
command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter); command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter,
PerArgumentCommandCompleter {
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);
register_filters(); register_filters();