Introduce matching_pairs option that controls the pairs used by m
This commit is contained in:
parent
2b993b7c4b
commit
7f51e51fcb
|
@ -124,7 +124,8 @@ is a sequence of non whitespace characters
|
||||||
same as [ft] but in the other direction
|
same as [ft] but in the other direction
|
||||||
|
|
||||||
*m*::
|
*m*::
|
||||||
select to matching character
|
select to matching character, see the `matching_pairs` options
|
||||||
|
in <<doc/pages/options#,`:doc options`>>
|
||||||
|
|
||||||
*M*::
|
*M*::
|
||||||
extend selection to matching character
|
extend selection to matching character
|
||||||
|
|
|
@ -192,7 +192,12 @@ are exclusively available to built-in options.
|
||||||
|
|
||||||
*extra_word_chars* `codepoint-list`::
|
*extra_word_chars* `codepoint-list`::
|
||||||
a list of all additional codepoints that should be considered
|
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)`::
|
*autoreload* `enum(yes|no|ask)`::
|
||||||
_default_ ask +
|
_default_ ask +
|
||||||
|
|
12
src/main.cc
12
src/main.cc
|
@ -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"};
|
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()
|
void register_options()
|
||||||
{
|
{
|
||||||
OptionsRegistry& reg = GlobalScope::instance().option_registry();
|
OptionsRegistry& reg = GlobalScope::instance().option_registry();
|
||||||
|
@ -345,6 +353,10 @@ void register_options()
|
||||||
"extra_word_chars",
|
"extra_word_chars",
|
||||||
"Additional characters to be considered as words for insert completion",
|
"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;
|
static Client* local_client = nullptr;
|
||||||
|
|
|
@ -227,7 +227,7 @@ Optional<Selection>
|
||||||
select_matching(const Context& context, const Selection& selection)
|
select_matching(const Context& context, const Selection& selection)
|
||||||
{
|
{
|
||||||
auto& buffer = context.buffer();
|
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};
|
Utf8Iterator it{buffer.iterator_at(selection.cursor()), buffer};
|
||||||
auto match = matching_pairs.end();
|
auto match = matching_pairs.end();
|
||||||
while (not is_eol(*it))
|
while (not is_eol(*it))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user