2011-11-29 23:37:20 +01:00
|
|
|
#include "highlighter_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
#include "window.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct factory_not_found : public runtime_error
|
|
|
|
{
|
2011-12-02 20:00:01 +01:00
|
|
|
factory_not_found(const std::string& name)
|
|
|
|
: runtime_error("highlighter factory not found '" + name + "'") {}
|
2011-11-29 23:37:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void HighlighterRegistry::register_factory(const std::string& name,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void HighlighterRegistry::add_highlighter_to_window(Window& window,
|
|
|
|
const std::string& name,
|
|
|
|
const HighlighterParameters& parameters)
|
|
|
|
{
|
|
|
|
auto it = m_factories.find(name);
|
|
|
|
if (it == m_factories.end())
|
2011-12-02 20:00:01 +01:00
|
|
|
throw factory_not_found(name);
|
2011-11-29 23:37:20 +01:00
|
|
|
|
|
|
|
window.add_highlighter(it->second(window, parameters));
|
|
|
|
}
|
|
|
|
|
|
|
|
CandidateList HighlighterRegistry::complete_highlighter(const std::string& prefix,
|
|
|
|
size_t cursor_pos)
|
|
|
|
{
|
2011-12-02 15:22:51 +01:00
|
|
|
return m_factories.complete_id<str_to_str>(prefix, cursor_pos);
|
2011-11-29 23:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|