From 7af8937bacaf2e9faddf366a9d8c9299357385b0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Mar 2015 14:01:17 +0000 Subject: [PATCH] Extract remaining lambdas commands so that the cmds array can be compile time initialized --- src/normal.cc | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index bfdfcf65..8893b8f5 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1350,6 +1350,31 @@ void move(Context& context, NormalParams params) selections.sort_and_merge_overlapping(); } +void select_whole_buffer(Context& context, NormalParams) +{ + select_buffer(context.selections()); +} + +void keep_selection(Context& context, NormalParams p) +{ + keep_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); +} + +void remove_selection(Context& context, NormalParams p) +{ + remove_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); +} + +void clear_selections(Context& context, NormalParams) +{ + clear_selections(context.selections()); +} + +void flip_selections(Context& context, NormalParams) +{ + flip_selections(context.selections()); +} + static NormalCmdDesc cmds[] = { { 'h', "move left", move }, @@ -1399,7 +1424,7 @@ static NormalCmdDesc cmds[] = { '.', "repeat last insert command", repeat_last_insert }, - { '%', "select whole buffer", [](Context& context, NormalParams) { select_buffer(context.selections()); } }, + { '%', "select whole buffer", select_whole_buffer }, { ':', "enter command prompt", command }, { '|', "pipe each selection through filter and replace with output", pipe }, @@ -1407,10 +1432,10 @@ static NormalCmdDesc cmds[] = { '!', "insert command output", insert_output }, { alt('!'), "append command output", insert_output }, - { ' ', "remove all selection except main", [](Context& context, NormalParams p) { keep_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); } }, - { alt(' '), "remove main selection", [](Context& context, NormalParams p) { remove_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); } }, - { ';', "reduce selections to their cursor", [](Context& context, NormalParams) { clear_selections(context.selections()); } }, - { alt(';'), "swap selections cursor and anchor", [](Context& context, NormalParams) { flip_selections(context.selections()); } }, + { ' ', "remove all selection except main", keep_selection }, + { alt(' '), "remove main selection", remove_selection }, + { ';', "reduce selections to their cursor", clear_selections }, + { alt(';'), "swap selections cursor and anchor", flip_selections }, { 'w', "select to next word start", repeated<&select>> }, { 'e', "select to next word end", repeated>> },