diff --git a/src/commands.cc b/src/commands.cc index d4039e33..f271a2fc 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -505,7 +505,17 @@ const CommandDesc add_highlighter_cmd = { SwitchMap{ { "group", { true, "specify the group in which to put the highlighter" } } }, ParameterDesc::Flags::SwitchesOnlyAtStart, 1 }, CommandFlags::None, - CommandHelper{}, + [](const Context& context, CommandParameters params) -> String + { + if (params.size() > 0) + { + HighlighterRegistry& registry = HighlighterRegistry::instance(); + auto it = registry.find(params[0]); + if (it != registry.end()) + return params[0] + ":\n" + indent(it->second.docstring); + } + return ""; + }, add_highlighter_completer, [](const ParametersParser& parser, Context& context) { @@ -523,7 +533,7 @@ const CommandDesc add_highlighter_cmd = { auto it = registry.find(name); if (it == registry.end()) throw runtime_error("No such highlighter factory '" + name + "'"); - group.add_child(it->second(highlighter_params)); + group.add_child(it->second.factory(highlighter_params)); } }; diff --git a/src/highlighter.hh b/src/highlighter.hh index 028d4b2c..9a5463af 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -67,7 +67,13 @@ std::unique_ptr> make_simple_highlighter(T func) using HighlighterParameters = ArrayView; using HighlighterFactory = std::function; -struct HighlighterRegistry : IdMap, +struct HighlighterFactoryAndDocstring +{ + HighlighterFactory factory; + String docstring; +}; + +struct HighlighterRegistry : IdMap, Singleton {}; diff --git a/src/highlighters.cc b/src/highlighters.cc index 17f6fb14..2bf031cd 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1205,18 +1205,65 @@ void register_highlighters() { HighlighterRegistry& registry = HighlighterRegistry::instance(); - registry.append({ "number_lines", simple_factory("number_lines", show_line_numbers) }); - registry.append({ "show_matching", simple_factory("show_matching", show_matching_char) }); - registry.append({ "show_whitespaces", simple_factory("show_whitespaces", show_whitespaces) }); - registry.append({ "fill", create_fill_highlighter }); - registry.append({ "regex", RegexHighlighter::create }); - registry.append({ "regex_option", create_regex_option_highlighter }); - registry.append({ "search", create_search_highlighter }); - registry.append({ "group", create_highlighter_group }); - registry.append({ "flag_lines", create_flag_lines_highlighter }); - registry.append({ "line_option", create_line_option_highlighter }); - registry.append({ "ref", create_reference_highlighter }); - registry.append({ "regions", RegionsHighlighter::create }); + registry.append({ + "number_lines", + { simple_factory("number_lines", show_line_numbers), + "Display line numbers" } }); + registry.append({ + "show_matching", + { simple_factory("show_matching", show_matching_char), + "Apply the MatchingChar face to the char matching the one under the cursor" } }); + registry.append({ + "show_whitespaces", + { simple_factory("show_whitespaces", show_whitespaces), + "Display whitespaces using symbols" } }); + registry.append({ + "fill", + { create_fill_highlighter, + "Fill the whole highlighted range with the given face" } }); + registry.append({ + "regex", + { RegexHighlighter::create, + "Parameters: : :...\n" + "Highlights the matches for captures from the regex with the given faces" } }); + registry.append({ + "regex_option", + { create_regex_option_highlighter, + "Parameters: