Completions: add basic addfilter completion
This commit is contained in:
parent
f5ad32f137
commit
a8b2c4f568
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<std::string, FilterFactory> m_factories;
|
||||
};
|
||||
|
|
|
@ -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<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);
|
||||
|
||||
register_filters();
|
||||
|
|
Loading…
Reference in New Issue
Block a user