From 6b7200e4d5c04cfb6d6f5740e3e95f5baad6d7f1 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 29 Sep 2018 20:41:41 +0300 Subject: [PATCH 1/2] src: Move to --- doc/pages/keys.asciidoc | 2 +- src/normal.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 64942837..d4b4f04d 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -258,7 +258,7 @@ Yanking (copying) and pasting use the *"* register by default (See <*:: join selected lines and select spaces inserted in place of line breaks -**:: +**:: merge contiguous selections together (works across lines as well) *>*:: diff --git a/src/normal.cc b/src/normal.cc index eb71ce4a..d7d88ab0 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -2185,7 +2185,7 @@ static const HashMap key { {';'}, {"reduce selections to their cursor", clear_selections} }, { {alt(';')}, {"swap selections cursor and anchor", flip_selections} }, { {alt(':')}, {"ensure selection cursor is after anchor", ensure_forward} }, - { {alt('m')}, {"merge consecutive selections", merge_consecutive} }, + { {alt('_')}, {"merge consecutive selections", merge_consecutive} }, { {'w'}, {"select to next word start", repeated<&select>>} }, { {'e'}, {"select to next word end", repeated>>} }, From 2d44712766081a0b3b4f71ac77f73e973e724b02 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sun, 30 Sep 2018 09:41:17 +0300 Subject: [PATCH 2/2] src: Implement and Closes #2425 --- doc/pages/keys.asciidoc | 12 ++++++++++++ src/normal.cc | 6 ++++-- src/selectors.cc | 17 ++++++++++++++++- src/selectors.hh | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index d4b4f04d..63e8b55f 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -139,6 +139,18 @@ the Shift modifier and moving will extend each selection instead. select to the next sequence enclosed by matching character, see the `matching_pairs` option in <> +*M*:: + extend the current selection to the next sequence enclosed by matching + character, see the `matching_pairs` option in <> + +**:: + select to the previous sequence enclosed by matching character, see the + `matching_pairs` option in <> + +**:: + extend the current selection to the previous sequence enclosed by matching + character, see the `matching_pairs` option in <> + *x*:: select line on which the end of each selection lies (or next line when end lies on an end-of-line) diff --git a/src/normal.cc b/src/normal.cc index d7d88ab0..7a1533ee 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -2215,8 +2215,10 @@ static const HashMap key { {alt('x')}, {"extend selections to whole lines", select} }, { {alt('X')}, {"crop selections to whole lines", select} }, - { {'m'}, {"select to matching character", select} }, - { {'M'}, {"extend to matching character", select} }, + { {'m'}, {"select to matching character", select>} }, + { {alt('m')}, {"backward select to matching character", select>} }, + { {'M'}, {"extend to matching character", select>} }, + { {alt('M')}, {"backward extend to matching character", select>} }, { {'/'}, {"select next given regex match", search} }, { {'?'}, {"extend with next given regex match", search} }, diff --git a/src/selectors.cc b/src/selectors.cc index a11a200d..cbbc3f03 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -220,6 +220,7 @@ select_to_first_non_blank(const Context& context, const Selection& selection) return {it.coord()}; } +template Optional select_matching(const Context& context, const Selection& selection) { @@ -227,13 +228,23 @@ select_matching(const Context& context, const Selection& selection) auto& matching_pairs = context.options()["matching_pairs"].get>(); Utf8Iterator it{buffer.iterator_at(selection.cursor()), buffer}; auto match = matching_pairs.end(); - while (it != buffer.end()) + + if (forward) while (it != buffer.end()) { match = find(matching_pairs, *it); if (match != matching_pairs.end()) break; ++it; } + else while (true) + { + match = find(matching_pairs, *it); + if (match != matching_pairs.end() + or it == buffer.begin()) + break; + --it; + } + if (match == matching_pairs.end()) return {}; @@ -271,6 +282,10 @@ select_matching(const Context& context, const Selection& selection) } return {}; } +template Optional +select_matching(const Context& context, const Selection& selection); +template Optional +select_matching(const Context& context, const Selection& selection); template Optional> diff --git a/src/selectors.hh b/src/selectors.hh index 00bc83dd..2e56c214 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -31,6 +31,7 @@ select_to_previous_word(const Context& context, const Selection& selection); Optional select_line(const Context& context, const Selection& selection); +template Optional select_matching(const Context& context, const Selection& selection);