From 8fedbbf07bdb972a82af2923cbe914439389c808 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 May 2012 05:19:27 +0000 Subject: [PATCH] ShellManager::eval now takes an additional env_var map --- src/command_manager.cc | 2 +- src/main.cc | 2 +- src/shell_manager.cc | 17 ++++++++++++----- src/shell_manager.hh | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 800b3a04f..d348d9768 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -99,7 +99,7 @@ static void shell_eval(std::vector& params, const String& cmdline, const Context& context) { - String output = ShellManager::instance().eval(cmdline, context); + String output = ShellManager::instance().eval(cmdline, context, {}); TokenList tokens = split(output); for (auto it = tokens.begin(); it != tokens.end(); ++it) diff --git a/src/main.cc b/src/main.cc index 39f5a4ec4..afde43be8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -215,7 +215,7 @@ void do_pipe(Editor& editor, int count) editor.buffer().begin_undo_group(); for (auto& sel : const_cast(editor).selections()) { - String new_content = ShellManager::instance().eval(cmdline, main_context); + String new_content = ShellManager::instance().eval(cmdline, main_context, {}); editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end())); editor.buffer().modify(Modification::make_insert(sel.begin(), new_content)); } diff --git a/src/shell_manager.cc b/src/shell_manager.cc index f750ab05a..48688494f 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -12,7 +12,8 @@ ShellManager::ShellManager() { } -String ShellManager::eval(const String& cmdline, const Context& context) +String ShellManager::eval(const String& cmdline, const Context& context, + const EnvVarMap& env_vars) { int write_pipe[2]; int read_pipe[2]; @@ -61,11 +62,17 @@ String ShellManager::eval(const String& cmdline, const Context& context) assert(false); assert(name.length() > 0); - auto env_var = m_env_vars.find(name); - if (env_var != m_env_vars.end()) + auto local_var = env_vars.find(name); + if (local_var != env_vars.end()) + setenv(("kak_" + name).c_str(), local_var->second.c_str(), 1); + else { - String value = env_var->second(context); - setenv(("kak_" + name).c_str(), value.c_str(), 1); + auto env_var = m_env_vars.find(name); + if (env_var != m_env_vars.end()) + { + String value = env_var->second(context); + setenv(("kak_" + name).c_str(), value.c_str(), 1); + } } ++it; diff --git a/src/shell_manager.hh b/src/shell_manager.hh index b67136aa7..661e9a4f7 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -11,13 +11,15 @@ namespace Kakoune class Context; typedef std::function EnvVarRetriever; +typedef std::unordered_map EnvVarMap; class ShellManager : public Singleton { public: ShellManager(); - String eval(const String& cmdline, const Context& context); + String eval(const String& cmdline, const Context& context, + const EnvVarMap& env_vars); void register_env_var(const String& name, EnvVarRetriever retriever);