diff --git a/README.asciidoc b/README.asciidoc index a02be221..f6cab390 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -385,6 +385,7 @@ for example: %sh{ ls } is replaced with the output of the ls command. Some of kakoune state is available through environment variables: * +kak_selection+: content of the main selection + * +kak_selections+: content of the selection separated by commas * +kak_bufname+: name of the current buffer * +kak_timestamp+: timestamp of the current buffer, the timestamp is an integer value which is incremented each time the buffer is modified. diff --git a/src/main.cc b/src/main.cc index cc56723e..07d55b8c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -691,7 +691,12 @@ void register_env_vars() { return int_to_str(context.buffer().timestamp()); }); shell_manager.register_env_var("selection", [](const String& name, const Context& context) - { return context.editor().selections_content().back(); }); + { return context.editor().main_selection().content(); }); + shell_manager.register_env_var("selections", + [](const String& name, const Context& context) + { auto sels = context.editor().selections_content(); + return std::accumulate(sels.begin(), sels.end(), ""_str, + [](const String& lhs, const String& rhs) { return lhs.empty() ? rhs : lhs + "," + rhs; }); }); shell_manager.register_env_var("runtime", [](const String& name, const Context& context) { return runtime_directory(); });