From 1f3f5ea1ba07164bb9e7013bf51eeceb4f0b22f3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 8 Nov 2011 14:28:01 +0000 Subject: [PATCH] Filters: register existing filters with the registry --- src/filters.cc | 24 ++++++++++++++++++++++++ src/filters.hh | 2 ++ src/main.cc | 5 +++++ 3 files changed, 31 insertions(+) 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);