diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 3476e8fb..d6a17939 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -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 <> *M*:: extend selection to matching character diff --git a/doc/pages/options.asciidoc b/doc/pages/options.asciidoc index e4fcb1e8..678c7caa 100644 --- a/doc/pages/options.asciidoc +++ b/doc/pages/options.asciidoc @@ -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 + diff --git a/src/main.cc b/src/main.cc index 883ed1ef..6feb37b8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -274,6 +274,14 @@ static void check_extra_word_chars(const Vector& 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, check_matching_pairs>( + "matching_pairs", + "set of pair of characters to be considered as matching pairs", + { '(', ')', '{', '}', '[', ']', '<', '>' }); } static Client* local_client = nullptr; diff --git a/src/selectors.cc b/src/selectors.cc index 073a336e..6074e38c 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -227,7 +227,7 @@ Optional select_matching(const Context& context, const Selection& selection) { auto& buffer = context.buffer(); - ConstArrayView matching_pairs = { '(', ')', '{', '}', '[', ']', '<', '>' }; + auto& matching_pairs = context.options()["matching_pairs"].get>(); Utf8Iterator it{buffer.iterator_at(selection.cursor()), buffer}; auto match = matching_pairs.end(); while (not is_eol(*it))