2011-11-29 23:37:20 +01:00
|
|
|
#include "highlighter_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
#include "window.hh"
|
2012-01-15 14:46:45 +01:00
|
|
|
#include "highlighters.hh"
|
2011-11-29 23:37:20 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct factory_not_found : public runtime_error
|
|
|
|
{
|
2012-04-14 03:17:09 +02:00
|
|
|
factory_not_found(const String& name)
|
2011-12-02 20:00:01 +01:00
|
|
|
: runtime_error("highlighter factory not found '" + name + "'") {}
|
2011-11-29 23:37:20 +01:00
|
|
|
};
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
void HighlighterRegistry::register_factory(const String& name,
|
2011-11-29 23:37:20 +01:00
|
|
|
const HighlighterFactory& factory)
|
|
|
|
{
|
2011-12-02 15:22:51 +01:00
|
|
|
assert(not m_factories.contains(name));
|
|
|
|
m_factories.append(std::make_pair(name, factory));
|
2011-11-29 23:37:20 +01:00
|
|
|
}
|
|
|
|
|
2012-01-15 14:46:45 +01:00
|
|
|
void HighlighterRegistry::add_highlighter_to_group(Window& window,
|
|
|
|
HighlighterGroup& group,
|
2012-04-14 03:17:09 +02:00
|
|
|
const String& name,
|
2012-01-15 14:46:45 +01:00
|
|
|
const HighlighterParameters& parameters)
|
|
|
|
{
|
|
|
|
auto it = m_factories.find(name);
|
|
|
|
if (it == m_factories.end())
|
|
|
|
throw factory_not_found(name);
|
|
|
|
|
2012-01-19 21:37:29 +01:00
|
|
|
group.append(it->second(window, parameters));
|
2012-01-15 14:46:45 +01:00
|
|
|
}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList HighlighterRegistry::complete_highlighter(const String& prefix,
|
2011-11-29 23:37:20 +01:00
|
|
|
size_t cursor_pos)
|
|
|
|
{
|
2012-06-25 19:11:13 +02:00
|
|
|
return m_factories.complete_id(prefix, cursor_pos);
|
2011-11-29 23:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|