BufferRange option syntax support <line>.<column>+<len> and is inclusive

Fixes #864
This commit is contained in:
Maxime Coste 2016-10-26 22:47:24 +01:00
parent 4b2004c6ff
commit 7c6c6871ce
4 changed files with 26 additions and 23 deletions

View File

@ -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
backslash.
* `range-faces`: a `:` separated list of a pairs of a buffer range
(`<begin line>.<begin column>,<end line>.<end column>`) and a face
(separated by `|`), except for the first element which is just the
timestamp of the buffer.
(`<begin line>.<begin column>,<end line>.<end column>` or
`<begin line>.<end line>+<length>`) and a face (separated by `|`),
except for the first element which is just the timestamp of the buffer.
* `completions`: a `:` separated list of `<text>|<docstring>|<menu text>`
candidates, except for the first element which follows the
`<line>.<column>[+<length>]@<timestamp>` format to define where the

View File

@ -24,9 +24,9 @@ Types
with a backslash
*range-faces*::
a `:` separated list of a pairs of a buffer range
(`<begin line>.<begin column>,<end line>.<end column>`) and a face
(separated by `|`), except for the first element which is just the
timestamp of the buffer.
(`<begin line>.<begin column>,<end line>.<end column>` or
`<begin line>.<begin column>+<length>`) and a face (separated by `|`),
except for the first element which is just the timestamp of the buffer.
*completions*::
a `:` separated list of `<text>|<docstring>|<menu text>`
candidates, except for the first element which follows the

View File

@ -34,13 +34,12 @@ Formats of language supported:
case "$line" in
[\#\&]*)
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
begin=$(printf %s\\n "$line" | cut -d ' ' -f 3)
pos=$(printf %s\\n "$line" | cut -d ' ' -f 3)
fi
word=$(printf %s\\n "$line" | cut -d ' ' -f 2)
end=$((begin + ${#word}))
regions="$regions:$line_num.$begin,$line_num.$end|Error"
regions="$regions:$line_num.$pos+${#word}|Error"
;;
'') line_num=$((line_num + 1));;
\*) ;;

View File

@ -14,29 +14,33 @@ String option_to_string(BufferRange range)
{
return format("{}.{},{}.{}",
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)
{
auto comma = find(str, ',');
auto dot_begin = find(StringView{str.begin(), comma}, '.');
auto dot_end = find(StringView{comma, str.end()}, '.');
auto sep = find_if(str, [](char c){ return c == ',' or c == '+'; });
auto dot_beg = find(StringView{str.begin(), sep}, '.');
auto dot_end = find(StringView{sep, str.end()}, '.');
if (comma == str.end() or dot_begin == comma or dot_end == str.end())
throw runtime_error(format("'{}' does not follow <line>.<column>,<line>.<column> format", str));
if (sep == str.end() or dot_beg == sep or
(*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,
str_to_int({dot_begin+1, comma}) - 1};
const BufferCoord beg{str_to_int({str.begin(), dot_beg}) - 1,
str_to_int({dot_beg+1, sep}) - 1};
BufferCoord end{str_to_int({comma+1, dot_end}) - 1,
str_to_int({dot_end+1, str.end()}) - 1};
const bool len = (*sep == '+');
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;
opt.end = end;
if (beg.line < 0 or beg.column < 0 or end.line < 0 or end.column < 0)
throw runtime_error("coordinates elements should be >= 1");
opt = { beg, end };
}
StringView DisplayAtom::content() const
{
switch (m_type)