From dfaafcd49a34f55bc832da96ab365e1c4bb3350a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 17 May 2017 19:35:54 +0100 Subject: [PATCH] Rename range-faces to range-specs range-faces are now used to replace-range highlighters, where the string part is not interpretted as a face but as a display line, so the name was not relevant anymore. --- README.asciidoc | 9 ++++++--- doc/manpages/highlighters.asciidoc | 10 ++++++++-- doc/manpages/options.asciidoc | 4 ++-- rc/base/spell.kak | 2 +- src/commands.cc | 12 ++++++------ src/highlighters.cc | 20 +++++++++++--------- src/highlighters.hh | 2 +- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index e075b35f..c777ced9 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -863,9 +863,9 @@ Options are typed, their type can be * `{int,str}-list`: a list, elements are separated by a colon (:) if an element needs to contain a colon, it can be escaped with a backslash. - * `range-faces`: a `:` separated list of a pair of a buffer range + * `range-specs`: a `:` separated list of a pair of a buffer range (`.,.` or - `.+`) and a face (separated by `|`), + `.+`) and a string (separated by `|`), except for the first element which is just the timestamp of the buffer. * `line-flags`: a `:` separated list of a line number and a corresponding flag (`|`), except for the first element which is just @@ -1245,7 +1245,10 @@ General highlighters are: the rest of the buffer, default is `|`. * `wrap \<-word>`: Soft wrap buffer content to window width, wrap at word boundaries if `-word` is specified. * `fill `: fill using given face, mostly useful with <> - * `ranges `: use the data in the range-faces option of the given name to highlight the buffer. + * `ranges `: use the data in the range-specs option of the given name to highlight the buffer. + The string part of the is interpretted as a face to apply to the range. + * `replace-ranges `: use the data in the range-specs option of the given name to highlight the buffer. + The string part of the is interpretted as a display line to display in place of the range. Highlighting Groups ^^^^^^^^^^^^^^^^^^^ diff --git a/doc/manpages/highlighters.asciidoc b/doc/manpages/highlighters.asciidoc index ad941afb..0d804bbb 100644 --- a/doc/manpages/highlighters.asciidoc +++ b/doc/manpages/highlighters.asciidoc @@ -91,8 +91,14 @@ General highlighters wrap at word boundaries instead of codepoint boundaries. *ranges* :: - use the data in the range-faces option of the given name to highlight - the buffer. + use the data in the range-specs option of the given name to highlight + the buffer. The string part of the is interpretted as a face to apply + to the range. + +*replace-ranges* :: + use the data in the range-specs option of the given name to highlight + the buffer. The string part of the is interpretted as a display line to + display in place of the range. *fill* :: fill using the given *face*, mostly useful with regions highlighters diff --git a/doc/manpages/options.asciidoc b/doc/manpages/options.asciidoc index 95159087..93245f1a 100644 --- a/doc/manpages/options.asciidoc +++ b/doc/manpages/options.asciidoc @@ -21,10 +21,10 @@ Types *int-list*, *str-list*:: a list, elements are separated by a colon (:) if an element needs to contain a colon, it can be escaped with a backslash -*range-faces*:: +*range-specs*:: a `:` separated list of a pair of a buffer range (`.,.` or - `.+`) and a face (separated by `|`), + `.+`) and a string (separated by `|`), except for the first element which is just the timestamp of the buffer. *line-flags*:: a `:` separated list of a line number and a corresponding flag diff --git a/rc/base/spell.kak b/rc/base/spell.kak index 87e82dc0..67bd5713 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -1,4 +1,4 @@ -decl -hidden range-faces spell_regions +decl -hidden range-specs spell_regions decl -hidden str spell_lang decl -hidden str spell_tmp_file diff --git a/src/commands.cc b/src/commands.cc index d9ab5a2e..c32c29de 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -48,9 +48,9 @@ StringView option_type_name(Meta::Type>) return "line-flags"; } -StringView option_type_name(Meta::Type>) +StringView option_type_name(Meta::Type>) { - return "range-faces"; + return "range-specs"; } namespace @@ -1335,7 +1335,7 @@ const CommandDesc declare_option_cmd = { " str-list: list of character strings\n" " completions: list of completion candidates\n" " line-flags: list of line flags\n" - " range-faces: list of range faces\n", + " range-specs: list of range specs\n", ParameterDesc{ { { "hidden", { false, "do not display option name when completing" } }, { "docstring", { true, "specify option description" } } }, @@ -1346,7 +1346,7 @@ const CommandDesc declare_option_cmd = { make_completer( [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) -> Completions { - auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-flags", "range-faces"}; + auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-flags", "range-specs"}; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; }), [](const ParametersParser& parser, Context& context, const ShellContext&) @@ -1377,8 +1377,8 @@ const CommandDesc declare_option_cmd = { opt = ®.declare_option(parser[1], docstring, {}, flags); else if (parser[0] == "line-flags") opt = ®.declare_option>(parser[1], docstring, {}, flags); - else if (parser[0] == "range-faces") - opt = ®.declare_option>(parser[1], docstring, {}, flags); + else if (parser[0] == "range-specs") + opt = ®.declare_option>(parser[1], docstring, {}, flags); else throw runtime_error(format("unknown type {}", parser[0])); diff --git a/src/highlighters.cc b/src/highlighters.cc index bd1f4160..2de9c6bb 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1345,10 +1345,10 @@ void option_from_string(StringView str, InclusiveBufferRange& opt) opt = { first, last }; } -BufferCoord& get_first(RangeAndFace& r) { return std::get<0>(r).first; } -BufferCoord& get_last(RangeAndFace& r) { return std::get<0>(r).last; } +BufferCoord& get_first(RangeAndString& r) { return std::get<0>(r).first; } +BufferCoord& get_last(RangeAndString& r) { return std::get<0>(r).last; } -static void update_ranges_ifn(const Buffer& buffer, TimestampedList& range_and_faces) +static void update_ranges_ifn(const Buffer& buffer, TimestampedList& range_and_faces) { if (range_and_faces.prefix == buffer.timestamp()) return; @@ -1386,7 +1386,7 @@ struct RangesHighlighter : Highlighter const String& option_name = params[0]; // throw if wrong option type - GlobalScope::instance().options()[option_name].get>(); + GlobalScope::instance().options()[option_name].get>(); return {"hlranges_" + params[0], make_unique(option_name)}; } @@ -1395,7 +1395,7 @@ private: void do_highlight(const Context& context, HighlightPass, DisplayBuffer& display_buffer, BufferRange) override { auto& buffer = context.buffer(); - auto& range_and_faces = context.options()[m_option_name].get_mutable>(); + auto& range_and_faces = context.options()[m_option_name].get_mutable>(); update_ranges_ifn(buffer, range_and_faces); for (auto& range : range_and_faces.list) @@ -1428,7 +1428,7 @@ struct ReplaceRangesHighlighter : Highlighter const String& option_name = params[0]; // throw if wrong option type - GlobalScope::instance().options()[option_name].get>(); + GlobalScope::instance().options()[option_name].get>(); return {"replace_ranges_" + params[0], make_unique(option_name)}; } @@ -1437,7 +1437,7 @@ private: void do_highlight(const Context& context, HighlightPass, DisplayBuffer& display_buffer, BufferRange) override { auto& buffer = context.buffer(); - auto& range_and_faces = context.options()[m_option_name].get_mutable>(); + auto& range_and_faces = context.options()[m_option_name].get_mutable>(); update_ranges_ifn(buffer, range_and_faces); for (auto& range : range_and_faces.list) @@ -1973,12 +1973,14 @@ void register_highlighters() "ranges", { RangesHighlighter::create, "Parameters: