From 60599917cc74d9505d1a7fd2dc639cd4ed1c7931 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 21 Mar 2013 19:10:18 +0100 Subject: [PATCH] add a kak_selections env var, which contains all selections separated by a comma --- README.asciidoc | 1 + src/main.cc | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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(); });