diff --git a/README.asciidoc b/README.asciidoc index a6c4caf2..e0bd1b4d 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -299,10 +299,14 @@ Commands are entered using +:+. is relative to kak executable path. * +nameclient +: set current client name * +namebuf +: set current buffer name - * +exec [-client ] +: execute as if pressed in normal mode. - if client if specified, exec keys in the named client context. - * +eval [-client ] +: execute as if entered in command line - if client if specified, exec command in the named client context. + * +exec [-client ] [-draft [-itersel]] +: execute as if + pressed in normal mode. if +client+ if specified, exec keys in the named + client context. if +draft+ is specified, execute the keys in a draft + context. if +itersel+ is specified, apply the keys on each selection + separately. + * +eval [-client ] [-draft [-itersel]] +: execute as + if entered in command line. +draft+, +client+ and +itersel+ works the same + as for the +exec+ command. * +echo +: show in status line * +name +: sets current client name to name * +nop+: does nothing, but as with every other commands, arguments may be diff --git a/src/commands.cc b/src/commands.cc index a331c94f..a577895c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -540,7 +540,7 @@ public: template void context_wrap(CommandParameters params, Context& context, Func func) { - ParametersParser parser(params, { { "client", true }, { "draft", false }}, + ParametersParser parser(params, { { "client", true }, { "draft", false }, { "itersel", false } }, ParametersParser::Flags::OptionsOnlyAtStart, 1); Context& real_context = parser.has_option("client") ? @@ -554,10 +554,24 @@ void context_wrap(CommandParameters params, Context& context, Func func) real_context.has_client() ? real_context.client().name() : ""); DynamicSelectionList sels{editor.buffer(), editor.selections()}; auto restore_sels = on_scope_end([&]{ editor.select(sels); }); - func(parser, client.context()); + + if (parser.has_option("itersel")) + { + for (auto& sel : sels) + { + editor.select(sel); + func(parser, client.context()); + } + } + else + func(parser, client.context()); } else + { + if (parser.has_option("itersel")) + throw runtime_error("-itersel makes no sense without -draft"); func(parser, real_context); + } // force redraw of this client window if (parser.has_option("client") and real_context.has_window()) diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index d02da331..c5b0f422 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -19,13 +19,13 @@ hook global WinSetOption filetype=cpp %~ addhl -group cpp-highlight regex "(?s\h+$d } } # cleanup trailing whitespaces when exiting insert mode - hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft ks\h+$d } ] # cleanup trailing white space son previous line - hook window InsertChar \n -id cpp-indent %@ + hook window InsertChar \n -id cpp-indent %@ eval -draft -itersel %_ try %{ exec -draft ks^\h+yjP } # preserve previous line indent try %[ exec -draft k[{(]\h*$j ] # indent after lines ending with { or ( + try %{ exec -draft ks\h+$d } # cleanup trailing white space son previous line try %{ exec -draft [(\`\([^\n]+\n[^\n]*\n?\'s\`..|.\'& } # align to opening paren of previous line - @ + _ @ hook window InsertChar \} -id cpp-indent %[ try %[ exec -draft ^\h+\}$< ] ] # deindent on insert } alone on a line ~