diff --git a/src/highlighters.cc b/src/highlighters.cc index 750aa18c..f840293d 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -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(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("number_lines")); registry.register_factory("hlcpp", SimpleHighlighterFactory("hlcpp")); registry.register_factory("regex", colorize_regex_factory); + registry.register_factory("group", HighlighterGroup::create); } } diff --git a/src/highlighters.hh b/src/highlighters.hh index 53738e94..803a0bf9 100644 --- a/src/highlighters.hh +++ b/src/highlighters.hh @@ -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 m_highlighters; +}; + } #endif // highlighters_hh_INCLUDED