Support user given text objects

This commit is contained in:
Maxime Coste 2016-01-27 22:04:04 +00:00
parent b7530b021a
commit f3ec218a1c
3 changed files with 31 additions and 2 deletions

View File

@ -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.

View File

@ -935,8 +935,28 @@ void select_object(Context& context, NormalParams params)
}
if (*cp == 'u')
{
return select<mode>(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<mode>(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<Key::NamedKey key>

View File

@ -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);
}
}};
}