2012-01-19 21:37:29 +01:00
|
|
|
#include "highlighter_group.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
#include "utils.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
void HighlighterGroup::operator()(DisplayBuffer& display_buffer)
|
|
|
|
{
|
|
|
|
for (auto& highlighter : m_highlighters)
|
|
|
|
highlighter.second(display_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HighlighterGroup::append(HighlighterAndId&& highlighter)
|
|
|
|
{
|
|
|
|
if (m_highlighters.contains(highlighter.first))
|
2012-04-03 15:08:13 +02:00
|
|
|
throw runtime_error("duplicate highlighter id: " + highlighter.first);
|
2012-01-19 21:37:29 +01:00
|
|
|
|
|
|
|
m_highlighters.append(std::forward<HighlighterAndId>(highlighter));
|
|
|
|
}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
void HighlighterGroup::remove(const String& id)
|
2012-01-19 21:37:29 +01:00
|
|
|
{
|
|
|
|
m_highlighters.remove(id);
|
|
|
|
}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
HighlighterGroup& HighlighterGroup::get_group(const String& id)
|
2012-01-19 21:37:29 +01:00
|
|
|
{
|
|
|
|
auto it = m_highlighters.find(id);
|
|
|
|
if (it == m_highlighters.end())
|
|
|
|
throw runtime_error("no such id: " + id);
|
|
|
|
HighlighterGroup* group = it->second.target<HighlighterGroup>();
|
|
|
|
if (not group)
|
|
|
|
throw runtime_error("not a group: " + id);
|
|
|
|
|
|
|
|
return *group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList HighlighterGroup::complete_id(const String& prefix,
|
2012-08-23 23:56:35 +02:00
|
|
|
CharCount cursor_pos)
|
2012-01-19 21:37:29 +01:00
|
|
|
{
|
2012-06-25 19:11:13 +02:00
|
|
|
return m_highlighters.complete_id(prefix, cursor_pos);
|
2012-01-19 21:37:29 +01:00
|
|
|
}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList HighlighterGroup::complete_group_id(const String& prefix,
|
2012-08-23 23:56:35 +02:00
|
|
|
CharCount cursor_pos)
|
2012-01-19 21:53:15 +01:00
|
|
|
{
|
2012-06-25 19:11:13 +02:00
|
|
|
return m_highlighters.complete_id_if(
|
2012-01-19 21:53:15 +01:00
|
|
|
prefix, cursor_pos,
|
2012-04-14 03:17:09 +02:00
|
|
|
[](std::pair<String, HighlighterFunc>& func)
|
2012-01-19 21:53:15 +01:00
|
|
|
{ return func.second.target<HighlighterGroup>() != nullptr; });
|
|
|
|
}
|
|
|
|
|
2012-01-19 21:37:29 +01:00
|
|
|
}
|