Add support for the -passes option to the ref highlighter

This commit is contained in:
Maxime Coste 2017-05-10 10:31:34 +01:00
parent 6b518e4e46
commit 9300a981eb

View File

@ -1375,15 +1375,8 @@ private:
const String m_option_name;
};
HighlighterAndId create_highlighter_group(HighlighterParameters params)
HighlightPass parse_passes(StringView str)
{
static const ParameterDesc param_desc{
{ { "passes", { true, "" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
};
ParametersParser parser{params, param_desc};
auto parse_passes = [](StringView str) {
HighlightPass passes{};
for (auto pass : str | split<StringView>('|'))
{
@ -1400,7 +1393,15 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
throw runtime_error{"no passes specified"};
return passes;
}
HighlighterAndId create_highlighter_group(HighlighterParameters params)
{
static const ParameterDesc param_desc{
{ { "passes", { true, "" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
};
ParametersParser parser{params, param_desc};
HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize"));
return HighlighterAndId(parser[0], make_unique<HighlighterGroup>(passes));
@ -1408,14 +1409,14 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
HighlighterAndId create_reference_highlighter(HighlighterParameters params)
{
if (params.size() != 1)
throw runtime_error("wrong parameter count");
const String& name = params[0];
// throw if not found
//DefinedHighlighters::instance().get_group(name, '/');
static const ParameterDesc param_desc{
{ { "passes", { true, "" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
};
ParametersParser parser{params, param_desc};
HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize"));
const String& name = parser[0];
auto func = [=](const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range)
{
try
@ -1425,8 +1426,7 @@ HighlighterAndId create_reference_highlighter(HighlighterParameters params)
catch (child_not_found&)
{}
};
return {name, make_highlighter(func, HighlightPass::All)};
return {name, make_highlighter(func, passes)};
}
struct RegexMatch
@ -1905,8 +1905,10 @@ void register_highlighters()
registry.insert({
"ref",
{ create_reference_highlighter,
"Parameters: <path>\n"
"Reference the highlighter at <path> in shared highglighters" } });
"Parameters: [-passes <passes>] <path>\n"
"Reference the highlighter at <path> in shared highglighters\n"
"<passes> is a flags(colorize|move|wrap) defaulting to colorize\n"
"which specify what kind of highlighters can be referenced" } });
registry.insert({
"regions",
{ RegionsHighlighter::create,