Filters: register existing filters with the registry
This commit is contained in:
parent
e4ff1d8ad8
commit
1f3f5ea1ba
|
@ -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<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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "selectors.hh"
|
||||
#include "assert.hh"
|
||||
#include "debug.hh"
|
||||
#include "filters.hh"
|
||||
#include "filter_registry.hh"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
@ -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<std::string>{ "e", "edit" }, edit,
|
||||
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,
|
||||
PerArgumentCommandCompleter { complete_buffername });
|
||||
|
||||
register_filters();
|
||||
|
||||
try
|
||||
{
|
||||
auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer("*scratch*", Buffer::Type::Scratch);
|
||||
|
|
Loading…
Reference in New Issue
Block a user