Filters: register existing filters with the registry

This commit is contained in:
Maxime Coste 2011-11-08 14:28:01 +00:00
parent e4ff1d8ad8
commit 1f3f5ea1ba
3 changed files with 31 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "filters.hh" #include "filters.hh"
#include "filter_registry.hh"
namespace Kakoune namespace Kakoune
{ {
@ -129,4 +131,26 @@ void show_line_numbers(DisplayBuffer& display_buffer)
} }
} }
template<void (*filter_func)(DisplayBuffer&)>
class SimpleFilterFactory
{
public:
SimpleFilterFactory(const std::string& id) : m_id(id) {}
FilterAndId operator()(const FilterParameters& params) const
{
return FilterAndId(m_id, FilterFunc(filter_func));
}
private:
std::string m_id;
};
void register_filters()
{
FilterRegistry& registry = FilterRegistry::instance();
registry.register_factory("line_numbers", SimpleFilterFactory<show_line_numbers>("line_numbers"));
registry.register_factory("hlcpp", SimpleFilterFactory<colorize_cplusplus>("hlcpp"));
}
} }

View File

@ -15,6 +15,8 @@ void colorize_cplusplus(DisplayBuffer& display_buffer);
void expand_tabulations(DisplayBuffer& display_buffer); void expand_tabulations(DisplayBuffer& display_buffer);
void show_line_numbers(DisplayBuffer& display_buffer); void show_line_numbers(DisplayBuffer& display_buffer);
void register_filters();
} }
#endif // filters_hh_INCLUDED #endif // filters_hh_INCLUDED

View File

@ -8,6 +8,8 @@
#include "selectors.hh" #include "selectors.hh"
#include "assert.hh" #include "assert.hh"
#include "debug.hh" #include "debug.hh"
#include "filters.hh"
#include "filter_registry.hh"
#include <unordered_map> #include <unordered_map>
#include <map> #include <map>
@ -573,6 +575,7 @@ int main(int argc, char* argv[])
CommandManager command_manager; CommandManager command_manager;
BufferManager buffer_manager; BufferManager buffer_manager;
RegisterManager register_manager; RegisterManager register_manager;
FilterRegistry filter_registry;
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit, command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
PerArgumentCommandCompleter{ complete_filename }); PerArgumentCommandCompleter{ complete_filename });
@ -583,6 +586,8 @@ int main(int argc, char* argv[])
command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer, command_manager.register_command(std::vector<std::string>{ "b", "buffer" }, show_buffer,
PerArgumentCommandCompleter { complete_buffername }); PerArgumentCommandCompleter { complete_buffername });
register_filters();
try try
{ {
auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer("*scratch*", Buffer::Type::Scratch); auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer("*scratch*", Buffer::Type::Scratch);