BufferRange option syntax support <line>.<column>+<len> and is inclusive
Fixes #864
This commit is contained in:
parent
4b2004c6ff
commit
7c6c6871ce
|
@ -824,9 +824,9 @@ Options are typed, their type can be
|
||||||
if an element needs to contain a colon, it can be escaped with a
|
if an element needs to contain a colon, it can be escaped with a
|
||||||
backslash.
|
backslash.
|
||||||
* `range-faces`: a `:` separated list of a pairs of a buffer range
|
* `range-faces`: a `:` separated list of a pairs of a buffer range
|
||||||
(`<begin line>.<begin column>,<end line>.<end column>`) and a face
|
(`<begin line>.<begin column>,<end line>.<end column>` or
|
||||||
(separated by `|`), except for the first element which is just the
|
`<begin line>.<end line>+<length>`) and a face (separated by `|`),
|
||||||
timestamp of the buffer.
|
except for the first element which is just the timestamp of the buffer.
|
||||||
* `completions`: a `:` separated list of `<text>|<docstring>|<menu text>`
|
* `completions`: a `:` separated list of `<text>|<docstring>|<menu text>`
|
||||||
candidates, except for the first element which follows the
|
candidates, except for the first element which follows the
|
||||||
`<line>.<column>[+<length>]@<timestamp>` format to define where the
|
`<line>.<column>[+<length>]@<timestamp>` format to define where the
|
||||||
|
|
|
@ -24,9 +24,9 @@ Types
|
||||||
with a backslash
|
with a backslash
|
||||||
*range-faces*::
|
*range-faces*::
|
||||||
a `:` separated list of a pairs of a buffer range
|
a `:` separated list of a pairs of a buffer range
|
||||||
(`<begin line>.<begin column>,<end line>.<end column>`) and a face
|
(`<begin line>.<begin column>,<end line>.<end column>` or
|
||||||
(separated by `|`), except for the first element which is just the
|
`<begin line>.<begin column>+<length>`) and a face (separated by `|`),
|
||||||
timestamp of the buffer.
|
except for the first element which is just the timestamp of the buffer.
|
||||||
*completions*::
|
*completions*::
|
||||||
a `:` separated list of `<text>|<docstring>|<menu text>`
|
a `:` separated list of `<text>|<docstring>|<menu text>`
|
||||||
candidates, except for the first element which follows the
|
candidates, except for the first element which follows the
|
||||||
|
|
|
@ -34,13 +34,12 @@ Formats of language supported:
|
||||||
case "$line" in
|
case "$line" in
|
||||||
[\#\&]*)
|
[\#\&]*)
|
||||||
if expr "$line" : '^&' >/dev/null; then
|
if expr "$line" : '^&' >/dev/null; then
|
||||||
begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//')
|
pos=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//')
|
||||||
else
|
else
|
||||||
begin=$(printf %s\\n "$line" | cut -d ' ' -f 3)
|
pos=$(printf %s\\n "$line" | cut -d ' ' -f 3)
|
||||||
fi
|
fi
|
||||||
word=$(printf %s\\n "$line" | cut -d ' ' -f 2)
|
word=$(printf %s\\n "$line" | cut -d ' ' -f 2)
|
||||||
end=$((begin + ${#word}))
|
regions="$regions:$line_num.$pos+${#word}|Error"
|
||||||
regions="$regions:$line_num.$begin,$line_num.$end|Error"
|
|
||||||
;;
|
;;
|
||||||
'') line_num=$((line_num + 1));;
|
'') line_num=$((line_num + 1));;
|
||||||
\*) ;;
|
\*) ;;
|
||||||
|
|
|
@ -14,29 +14,33 @@ String option_to_string(BufferRange range)
|
||||||
{
|
{
|
||||||
return format("{}.{},{}.{}",
|
return format("{}.{},{}.{}",
|
||||||
range.begin.line+1, range.begin.column+1,
|
range.begin.line+1, range.begin.column+1,
|
||||||
range.end.line+1, range.end.column+1);
|
range.end.line, range.end.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void option_from_string(StringView str, BufferRange& opt)
|
void option_from_string(StringView str, BufferRange& opt)
|
||||||
{
|
{
|
||||||
auto comma = find(str, ',');
|
auto sep = find_if(str, [](char c){ return c == ',' or c == '+'; });
|
||||||
auto dot_begin = find(StringView{str.begin(), comma}, '.');
|
auto dot_beg = find(StringView{str.begin(), sep}, '.');
|
||||||
auto dot_end = find(StringView{comma, str.end()}, '.');
|
auto dot_end = find(StringView{sep, str.end()}, '.');
|
||||||
|
|
||||||
if (comma == str.end() or dot_begin == comma or dot_end == str.end())
|
if (sep == str.end() or dot_beg == sep or
|
||||||
throw runtime_error(format("'{}' does not follow <line>.<column>,<line>.<column> format", str));
|
(*sep == ',' and dot_end == str.end()))
|
||||||
|
throw runtime_error(format("'{}' does not follow <line>.<column>,<line>.<column> or <line>.<column>+<len> format", str));
|
||||||
|
|
||||||
BufferCoord begin{str_to_int({str.begin(), dot_begin}) - 1,
|
const BufferCoord beg{str_to_int({str.begin(), dot_beg}) - 1,
|
||||||
str_to_int({dot_begin+1, comma}) - 1};
|
str_to_int({dot_beg+1, sep}) - 1};
|
||||||
|
|
||||||
BufferCoord end{str_to_int({comma+1, dot_end}) - 1,
|
const bool len = (*sep == '+');
|
||||||
str_to_int({dot_end+1, str.end()}) - 1};
|
const BufferCoord end{len ? beg.line : str_to_int({sep+1, dot_end}) - 1,
|
||||||
|
len ? beg.column + str_to_int({sep+1, str.end()})
|
||||||
|
: str_to_int({dot_end+1, str.end()}) };
|
||||||
|
|
||||||
opt.begin = begin;
|
if (beg.line < 0 or beg.column < 0 or end.line < 0 or end.column < 0)
|
||||||
opt.end = end;
|
throw runtime_error("coordinates elements should be >= 1");
|
||||||
|
|
||||||
|
opt = { beg, end };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StringView DisplayAtom::content() const
|
StringView DisplayAtom::content() const
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user