Introduce matching_pairs option that controls the pairs used by m

This commit is contained in:
Maxime Coste 2017-11-04 15:53:53 +08:00
parent 2b993b7c4b
commit 7f51e51fcb
4 changed files with 21 additions and 3 deletions

View File

@ -124,7 +124,8 @@ is a sequence of non whitespace characters
same as [ft] but in the other direction
*m*::
select to matching character
select to matching character, see the `matching_pairs` options
in <<doc/pages/options#,`:doc options`>>
*M*::
extend selection to matching character

View File

@ -192,7 +192,12 @@ are exclusively available to built-in options.
*extra_word_chars* `codepoint-list`::
a list of all additional codepoints that should be considered
as word character for the purpose of insert mode completion.
as word character.
*matching_pairs* `codepoint-list`::
_default_ `(:):{:}:[:]:<:>`
a list of codepoints that are to be treated as matching pairs
for the *m* command.
*autoreload* `enum(yes|no|ask)`::
_default_ ask +

View File

@ -274,6 +274,14 @@ static void check_extra_word_chars(const Vector<Codepoint, MemoryDomain::Options
throw runtime_error{"blanks are not accepted for extra completion characters"};
}
static void check_matching_pairs(const Vector<Codepoint, MemoryDomain::Options>& pairs)
{
if ((pairs.size() % 2) != 0)
throw runtime_error{"matching pairs should have a pair number of element"};
if (contains_that(pairs, [](Codepoint c) { return not is_punctuation(c); }))
throw runtime_error{"matching pairs can only be punctuation"};
}
void register_options()
{
OptionsRegistry& reg = GlobalScope::instance().option_registry();
@ -345,6 +353,10 @@ void register_options()
"extra_word_chars",
"Additional characters to be considered as words for insert completion",
{});
reg.declare_option<Vector<Codepoint, MemoryDomain::Options>, check_matching_pairs>(
"matching_pairs",
"set of pair of characters to be considered as matching pairs",
{ '(', ')', '{', '}', '[', ']', '<', '>' });
}
static Client* local_client = nullptr;

View File

@ -227,7 +227,7 @@ Optional<Selection>
select_matching(const Context& context, const Selection& selection)
{
auto& buffer = context.buffer();
ConstArrayView<Codepoint> matching_pairs = { '(', ')', '{', '}', '[', ']', '<', '>' };
auto& matching_pairs = context.options()["matching_pairs"].get<Vector<Codepoint, MemoryDomain::Options>>();
Utf8Iterator it{buffer.iterator_at(selection.cursor()), buffer};
auto match = matching_pairs.end();
while (not is_eol(*it))