2014-06-10 20:58:02 +02:00
|
|
|
#ifndef highlighter_group_hh_INCLUDED
|
|
|
|
#define highlighter_group_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
#include "id_map.hh"
|
|
|
|
#include "highlighter.hh"
|
|
|
|
#include "utils.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct group_not_found : public runtime_error
|
|
|
|
{
|
|
|
|
using runtime_error::runtime_error;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HighlighterGroup
|
|
|
|
{
|
|
|
|
public:
|
2014-06-10 22:35:03 +02:00
|
|
|
void operator()(const Context& context,
|
|
|
|
HighlightFlags flags,
|
2014-06-12 22:52:23 +02:00
|
|
|
DisplayBuffer& display_buffer) const;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
|
|
|
void append(HighlighterAndId&& hl);
|
|
|
|
void remove(StringView id);
|
|
|
|
|
2014-06-15 17:04:38 +02:00
|
|
|
HighlighterGroup& get_group(StringView path);
|
|
|
|
HighlighterFunc get_highlighter(StringView path) const;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
2014-06-15 17:04:38 +02:00
|
|
|
Completions complete_id(StringView path, ByteCount cursor_pos) const;
|
|
|
|
Completions complete_group_id(StringView path, ByteCount cursor_pos) const;
|
2014-06-10 20:58:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
id_map<HighlighterFunc> m_highlighters;
|
|
|
|
};
|
|
|
|
|
2014-06-10 22:35:03 +02:00
|
|
|
class HierachicalHighlighter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using GroupMap = id_map<HighlighterGroup>;
|
|
|
|
using Callback = std::function<void (GroupMap& groups,
|
|
|
|
const Context& context,
|
|
|
|
HighlightFlags flags,
|
|
|
|
DisplayBuffer& display_buffer)>;
|
|
|
|
|
|
|
|
HierachicalHighlighter(Callback callback, GroupMap groups)
|
|
|
|
: m_callback(std::move(callback)), m_groups(std::move(groups)) {}
|
|
|
|
|
|
|
|
void operator()(const Context& context,
|
|
|
|
HighlightFlags flags,
|
|
|
|
DisplayBuffer& display_buffer)
|
|
|
|
{
|
|
|
|
m_callback(m_groups, context, flags, display_buffer);
|
|
|
|
}
|
|
|
|
|
2014-06-15 17:04:38 +02:00
|
|
|
HighlighterGroup& get_group(StringView path);
|
|
|
|
HighlighterFunc get_highlighter(StringView path) const;
|
|
|
|
|
|
|
|
Completions complete_id(StringView path, ByteCount cursor_pos) const;
|
|
|
|
Completions complete_group_id(StringView path, ByteCount cursor_pos) const;
|
2014-06-10 22:35:03 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Callback m_callback;
|
|
|
|
GroupMap m_groups;
|
|
|
|
};
|
|
|
|
|
2014-06-10 20:58:02 +02:00
|
|
|
struct DefinedHighlighters : public HighlighterGroup,
|
|
|
|
public Singleton<DefinedHighlighters>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // highlighter_group_hh_INCLUDED
|