Highlighters: add an HighlighterGroup class

This commit is contained in:
Maxime Coste 2012-01-15 13:45:18 +00:00
parent 5092456186
commit 0c1e763d66
2 changed files with 48 additions and 0 deletions

View File

@ -292,6 +292,33 @@ private:
const Window& m_window;
};
void HighlighterGroup::operator()(DisplayBuffer& display_buffer)
{
for (auto& highlighter : m_highlighters)
highlighter.second(display_buffer);
}
void HighlighterGroup::add_highlighter(HighlighterAndId&& highlighter)
{
if (m_highlighters.contains(highlighter.first))
throw runtime_error("highlighter id not found " + highlighter.first);
m_highlighters.append(std::forward<HighlighterAndId>(highlighter));
}
void HighlighterGroup::remove_highlighter(const std::string& id)
{
m_highlighters.remove(id);
}
HighlighterAndId HighlighterGroup::create(Window& window,
const HighlighterParameters& params)
{
if (params.size() != 1)
throw runtime_error("wrong parameter count");
return HighlighterAndId(params[0], HighlighterGroup());
}
void register_highlighters()
{
HighlighterRegistry& registry = HighlighterRegistry::instance();
@ -301,6 +328,7 @@ void register_highlighters()
registry.register_factory("number_lines", SimpleHighlighterFactory<show_line_numbers>("number_lines"));
registry.register_factory("hlcpp", SimpleHighlighterFactory<colorize_cplusplus>("hlcpp"));
registry.register_factory("regex", colorize_regex_factory);
registry.register_factory("group", HighlighterGroup::create);
}
}

View File

@ -1,11 +1,31 @@
#ifndef highlighters_hh_INCLUDED
#define highlighters_hh_INCLUDED
#include "highlighter.hh"
#include "idvaluemap.hh"
namespace Kakoune
{
void register_highlighters();
class DisplayBuffer;
class Window;
class HighlighterGroup
{
public:
void operator()(DisplayBuffer& display_buffer);
void add_highlighter(HighlighterAndId&& highlighter);
void remove_highlighter(const std::string& id);
static HighlighterAndId create(Window& window,
const HighlighterParameters& params);
private:
idvaluemap<std::string, HighlighterFunc> m_highlighters;
};
}
#endif // highlighters_hh_INCLUDED