From f3ec218a1c2be6cf74e3c53b52e597d5c0e82500 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 27 Jan 2016 22:04:04 +0000 Subject: [PATCH] Support user given text objects --- README.asciidoc | 2 ++ src/normal.cc | 25 +++++++++++++++++++++++-- src/selectors.cc | 6 ++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index c5f4f75d..c247083e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -517,6 +517,8 @@ object you want. * `␣`: select the whitespaces * `i`: select the current indentation block * `n`: select the number + * `:`: select user defined object, will prompt + for open and close text. For nestable objects, a count can be used in order to specify which surrounding level to select. diff --git a/src/normal.cc b/src/normal.cc index 1c2ec6d3..60b8a23c 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -935,8 +935,28 @@ void select_object(Context& context, NormalParams params) } if (*cp == 'u') - { return select(context, std::bind(select_argument, _1, _2, level, flags)); + + if (*cp == ':') + { + context.input_handler().prompt( + "opening:", "", get_face("Prompt"), complete_nothing, + [level](StringView cmdline, PromptEvent event, Context& context) { + if (event != PromptEvent::Validate) + return; + + String opening = cmdline.str(); + context.input_handler().prompt( + "closing:", "", get_face("Prompt"), complete_nothing, + [level, opening](StringView cmdline, PromptEvent event, Context& context) { + if (event != PromptEvent::Validate) + return; + + String closing = cmdline.str(); + return select(context, std::bind(select_surrounding, _1, _2, + opening, closing, level, flags)); + }); + }); } static constexpr struct @@ -977,7 +997,8 @@ void select_object(Context& context, NormalParams params) "␣: whitespaces \n" "i: indent \n" "u: argument \n" - "n: number \n"); + "n: number \n" + ":: prompt for object \n"); } template diff --git a/src/selectors.cc b/src/selectors.cc index 965b7a86..662cd6b0 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -728,6 +728,12 @@ UnitTest test_find_surrounding{[]() auto res = find_surrounding(s, s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0); kak_assert(not res); } + s = "begin tchou begin tchaa end end"; + { + auto res = find_surrounding(s, s.begin() + 6, "begin", "end", + ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0); + kak_assert(res and StringView{res->first COMMA res->second+1} == s); + } }}; }