diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-11-05 23:50:44 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-11-05 23:50:44 +0000 |
| commit | 7495d04a4714230d89b5d3fd6390dca36f50d85d (patch) | |
| tree | bc8482d8512c2c5078013e3212c62d3992e058dc /src | |
| parent | 088f670fe94cd234643d41bfe1be71e0bf55da14 (diff) | |
Add support for -itersel option in exec/eval
-itersel makes a -draft eval/exec run once for each selections
separately rather than with all selections at a time.
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 18 | ||||
| -rw-r--r-- | src/rc/cpp.kak | 6 |
2 files changed, 19 insertions, 5 deletions
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<typename Func> 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 "(?<!')\".*?(?<!\\)(\\\\)*\"" 0:string addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" 0:comment hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } } # cleanup trailing whitespaces when exiting insert mode - hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s\h+$<ret>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 k<a-x>s^\h+<ret>yj<a-h>P } # preserve previous line indent try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] # indent after lines ending with { or ( + try %{ exec -draft k<a-x>s\h+$<ret>d } # cleanup trailing white space son previous line try %{ exec -draft [(<a-k>\`\([^\n]+\n[^\n]*\n?\'<ret>s\`..|.\'<ret>& } # align to opening paren of previous line - @ + _ @ hook window InsertChar \} -id cpp-indent %[ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] ] # deindent on insert } alone on a line ~ |
