Use '/' register as the default register for <a-k> and <a-K>

Fixes #1808
This commit is contained in:
Maxime Coste 2018-01-26 14:13:53 +11:00
parent bf73cb0109
commit 9c25e955df
2 changed files with 42 additions and 27 deletions

View File

@ -29,8 +29,8 @@ Most commands using a register default to a specific one if not specified:
and *R* and *R*
*/* (slash):: */* (slash)::
default search register, used by regex based commands like *s*, *** default search register, used by regex based commands like *s*, ***,
or */* */* or *<a-k>*.
*@* (arobase):: *@* (arobase)::
default macro register, used by *q* and *Q* default macro register, used by *q* and *Q*

View File

@ -766,7 +766,7 @@ void search(Context& context, NormalParams params)
regex_prompt<direction>(context, prompt.str(), saved_reg[main_index], regex_prompt<direction>(context, prompt.str(), saved_reg[main_index],
[reg, count, saved_reg] [reg, count, saved_reg]
(Regex regex, PromptEvent event, Context& context) { (const Regex& regex, PromptEvent event, Context& context) {
if (event == PromptEvent::Abort) if (event == PromptEvent::Abort)
{ {
RegisterManager::instance()[reg].set(context, saved_reg); RegisterManager::instance()[reg].set(context, saved_reg);
@ -775,22 +775,22 @@ void search(Context& context, NormalParams params)
if (not context.history_disabled()) if (not context.history_disabled())
RegisterManager::instance()[reg].set(context, regex.str()); RegisterManager::instance()[reg].set(context, regex.str());
if (not regex.empty() and not regex.str().empty()) if (regex.empty() or regex.str().empty())
{ return;
int c = count;
auto& selections = context.selections(); int c = count;
do { auto& selections = context.selections();
bool wrapped = false; do {
for (auto& sel : selections) bool wrapped = false;
{ for (auto& sel : selections)
if (mode == SelectMode::Replace) {
sel = keep_direction(find_next_match<direction>(context, sel, regex, wrapped), sel); if (mode == SelectMode::Replace)
if (mode == SelectMode::Extend) sel = keep_direction(find_next_match<direction>(context, sel, regex, wrapped), sel);
sel.cursor() = find_next_match<direction>(context, sel, regex, wrapped).cursor(); if (mode == SelectMode::Extend)
} sel.cursor() = find_next_match<direction>(context, sel, regex, wrapped).cursor();
selections.sort_and_merge_overlapping(); }
} while (--c > 0); selections.sort_and_merge_overlapping();
} } while (--c > 0);
}); });
} }
@ -987,15 +987,30 @@ void join_lines(Context& context, NormalParams params)
} }
template<bool matching> template<bool matching>
void keep(Context& context, NormalParams) void keep(Context& context, NormalParams params)
{ {
constexpr const char* prompt = matching ? "keep matching:" : "keep not matching:"; constexpr StringView prompt = matching ? "keep matching:" : "keep not matching:";
regex_prompt(context, prompt, String{},
[](const Regex& ex, PromptEvent event, Context& context) {
if (ex.empty() or event == PromptEvent::Abort)
return;
const Buffer& buffer = context.buffer();
const char reg = to_lower(params.reg ? params.reg : '/');
auto saved_reg = RegisterManager::instance()[reg].get(context) | gather<Vector<String>>();
const int main_index = std::min(context.selections().main_index(), saved_reg.size()-1);
regex_prompt(context, prompt.str(), saved_reg[main_index],
[saved_reg, reg, main_index]
(const Regex& regex, PromptEvent event, Context& context) {
if (event == PromptEvent::Abort)
{
RegisterManager::instance()[reg].set(context, saved_reg);
return;
}
if (not context.history_disabled())
RegisterManager::instance()[reg].set(context, regex.str());
if (regex.empty() or regex.str().empty())
return;
const Buffer& buffer = context.buffer();
Vector<Selection> keep; Vector<Selection> keep;
for (auto& sel : context.selections()) for (auto& sel : context.selections())
{ {
@ -1008,7 +1023,7 @@ void keep(Context& context, NormalParams)
is_eow(buffer, end.coord()), is_eow(buffer, end.coord()),
true, true) | true, true) |
RegexExecFlags::AnyMatch; RegexExecFlags::AnyMatch;
if (regex_search(begin, end, ex, flags) == matching) if (regex_search(begin, end, regex, flags) == matching)
keep.push_back(sel); keep.push_back(sel);
} }
if (keep.empty()) if (keep.empty())