diff --git a/src/filters.cc b/src/filters.cc index 7443f870..a7b6f3f9 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -1,5 +1,7 @@ #include "filters.hh" +#include "filter_registry.hh" + namespace Kakoune { @@ -129,4 +131,26 @@ void show_line_numbers(DisplayBuffer& display_buffer) } } +template +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("line_numbers")); + registry.register_factory("hlcpp", SimpleFilterFactory("hlcpp")); +} + } diff --git a/src/filters.hh b/src/filters.hh index 6ac37182..310bc0c3 100644 --- a/src/filters.hh +++ b/src/filters.hh @@ -15,6 +15,8 @@ void colorize_cplusplus(DisplayBuffer& display_buffer); void expand_tabulations(DisplayBuffer& display_buffer); void show_line_numbers(DisplayBuffer& display_buffer); +void register_filters(); + } #endif // filters_hh_INCLUDED diff --git a/src/main.cc b/src/main.cc index 55aeb0d2..2835a892 100644 --- a/src/main.cc +++ b/src/main.cc @@ -8,6 +8,8 @@ #include "selectors.hh" #include "assert.hh" #include "debug.hh" +#include "filters.hh" +#include "filter_registry.hh" #include #include @@ -573,6 +575,7 @@ int main(int argc, char* argv[]) CommandManager command_manager; BufferManager buffer_manager; RegisterManager register_manager; + FilterRegistry filter_registry; command_manager.register_command(std::vector{ "e", "edit" }, edit, PerArgumentCommandCompleter{ complete_filename }); @@ -583,6 +586,8 @@ int main(int argc, char* argv[]) command_manager.register_command(std::vector{ "b", "buffer" }, show_buffer, PerArgumentCommandCompleter { complete_buffername }); + register_filters(); + try { auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer("*scratch*", Buffer::Type::Scratch);