Add alt-| for piping and appending rather than replacing

This commit is contained in:
Maxime Coste 2013-12-24 16:48:52 +00:00
parent fd17ea00dd
commit 983abefc30
2 changed files with 9 additions and 4 deletions

View File

@ -159,7 +159,9 @@ Changes
indent (3 leading spaces when indent is 4) indent (3 leading spaces when indent is 4)
* _|_: pipe each selections through the given external filter program * _|_: pipe each selections through the given external filter program
and replace with it's output. and replace the selection with it's output.
* _alt-|_: pipe each selections through the given external filter program
and append the selection with it's output.
* _u_: undo last change * _u_: undo last change
* _U_: redo last change * _U_: redo last change

View File

@ -418,6 +418,7 @@ void command(Context& context, int)
}); });
} }
template<InsertMode mode>
void pipe(Context& context, int) void pipe(Context& context, int)
{ {
auto completer = [](const Context& context, CompletionFlags flags, auto completer = [](const Context& context, CompletionFlags flags,
@ -450,7 +451,8 @@ void pipe(Context& context, int)
return completions; return completions;
}; };
context.input_handler().prompt("pipe:", get_color("Prompt"), completer, const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):";
context.input_handler().prompt(prompt, get_color("Prompt"), completer,
[](const String& cmdline, PromptEvent event, Context& context) [](const String& cmdline, PromptEvent event, Context& context)
{ {
if (event != PromptEvent::Validate) if (event != PromptEvent::Validate)
@ -484,7 +486,7 @@ void pipe(Context& context, int)
strings.push_back(str); strings.push_back(str);
} }
ScopedEdition edition(context); ScopedEdition edition(context);
insert<InsertMode::Replace>(buffer, selections, strings); insert<mode>(buffer, selections, strings);
}); });
} }
@ -1280,7 +1282,8 @@ KeyMap keymap =
{ '%', [](Context& context, int) { select_whole_buffer(context.buffer(), context.selections()); } }, { '%', [](Context& context, int) { select_whole_buffer(context.buffer(), context.selections()); } },
{ ':', command }, { ':', command },
{ '|', pipe }, { '|', pipe<InsertMode::Replace> },
{ alt('|'), pipe<InsertMode::Append> },
{ ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.buffer(), context.selections()); { ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.buffer(), context.selections());
else keep_selection(context.selections(), count-1); } }, else keep_selection(context.selections(), count-1); } },
{ alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.selections()); { alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.selections());