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.
This commit is contained in:
Maxime Coste 2017-05-17 19:35:54 +01:00
parent 44d2db2706
commit dfaafcd49a
7 changed files with 35 additions and 24 deletions

View File

@ -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
(`<begin line>.<begin column>,<end line>.<end column>` or
`<begin line>.<end line>+<length>`) and a face (separated by `|`),
`<begin line>.<end line>+<length>`) 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 (`<line>|<flag text>`), 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 <face>`: fill using given face, mostly useful with <<regions-highlighters,Regions highlighters>>
* `ranges <option_name>`: use the data in the range-faces option of the given name to highlight the buffer.
* `ranges <option_name>`: 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 <option_name>`: 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
^^^^^^^^^^^^^^^^^^^

View File

@ -91,8 +91,14 @@ General highlighters
wrap at word boundaries instead of codepoint boundaries.
*ranges* <option_name>::
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* <option_name>::
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* <face>::
fill using the given *face*, mostly useful with regions highlighters

View File

@ -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
(`<begin line>.<begin column>,<end line>.<end column>` or
`<begin line>.<begin column>+<length>`) and a face (separated by `|`),
`<begin line>.<begin column>+<length>`) 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

View File

@ -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

View File

@ -48,9 +48,9 @@ StringView option_type_name(Meta::Type<TimestampedList<LineAndFlag>>)
return "line-flags";
}
StringView option_type_name(Meta::Type<TimestampedList<RangeAndFace>>)
StringView option_type_name(Meta::Type<TimestampedList<RangeAndString>>)
{
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 = &reg.declare_option<CompletionList>(parser[1], docstring, {}, flags);
else if (parser[0] == "line-flags")
opt = &reg.declare_option<TimestampedList<LineAndFlag>>(parser[1], docstring, {}, flags);
else if (parser[0] == "range-faces")
opt = &reg.declare_option<TimestampedList<RangeAndFace>>(parser[1], docstring, {}, flags);
else if (parser[0] == "range-specs")
opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
else
throw runtime_error(format("unknown type {}", parser[0]));

View File

@ -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<RangeAndFace>& range_and_faces)
static void update_ranges_ifn(const Buffer& buffer, TimestampedList<RangeAndString>& 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<TimestampedList<RangeAndFace>>();
GlobalScope::instance().options()[option_name].get<TimestampedList<RangeAndString>>();
return {"hlranges_" + params[0], make_unique<RangesHighlighter>(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<TimestampedList<RangeAndFace>>();
auto& range_and_faces = context.options()[m_option_name].get_mutable<TimestampedList<RangeAndString>>();
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<TimestampedList<RangeAndFace>>();
GlobalScope::instance().options()[option_name].get<TimestampedList<RangeAndString>>();
return {"replace_ranges_" + params[0], make_unique<ReplaceRangesHighlighter>(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<TimestampedList<RangeAndFace>>();
auto& range_and_faces = context.options()[m_option_name].get_mutable<TimestampedList<RangeAndString>>();
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: <option name>\n"
"Use the range-faces option given as parameter to highlight buffer\n" } });
"Use the range-specs option given as parameter to highlight buffer\n"
"each spec is interpreted as a face to apply to the range\n" } });
registry.insert({
"replace-ranges",
{ ReplaceRangesHighlighter::create,
"Parameters: <option name>\n"
"Use the range-faces option given as parameter to highlight buffer\n" } });
"Use the range-specs option given as parameter to highlight buffer\n"
"each spec is interpreted as a display line to display in place of the range\n" } });
registry.insert({
"line",
{ create_line_highlighter,

View File

@ -19,7 +19,7 @@ String option_to_string(InclusiveBufferRange range);
void option_from_string(StringView str, InclusiveBufferRange& opt);
using LineAndFlag = std::tuple<LineCount, String>;
using RangeAndFace = std::tuple<InclusiveBufferRange, String>;
using RangeAndString = std::tuple<InclusiveBufferRange, String>;
}