mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-21 10:40:53 +03:00
ShellManager::eval now takes an additional env_var map
This commit is contained in:
parent
e57ddd3bab
commit
8fedbbf07b
@ -99,7 +99,7 @@ static void shell_eval(std::vector<String>& params,
|
|||||||
const String& cmdline,
|
const String& cmdline,
|
||||||
const Context& context)
|
const Context& context)
|
||||||
{
|
{
|
||||||
String output = ShellManager::instance().eval(cmdline, context);
|
String output = ShellManager::instance().eval(cmdline, context, {});
|
||||||
TokenList tokens = split(output);
|
TokenList tokens = split(output);
|
||||||
|
|
||||||
for (auto it = tokens.begin(); it != tokens.end(); ++it)
|
for (auto it = tokens.begin(); it != tokens.end(); ++it)
|
||||||
|
@ -215,7 +215,7 @@ void do_pipe(Editor& editor, int count)
|
|||||||
editor.buffer().begin_undo_group();
|
editor.buffer().begin_undo_group();
|
||||||
for (auto& sel : const_cast<const Editor&>(editor).selections())
|
for (auto& sel : const_cast<const Editor&>(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_erase(sel.begin(), sel.end()));
|
||||||
editor.buffer().modify(Modification::make_insert(sel.begin(), new_content));
|
editor.buffer().modify(Modification::make_insert(sel.begin(), new_content));
|
||||||
}
|
}
|
||||||
|
@ -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 write_pipe[2];
|
||||||
int read_pipe[2];
|
int read_pipe[2];
|
||||||
@ -61,12 +62,18 @@ String ShellManager::eval(const String& cmdline, const Context& context)
|
|||||||
assert(false);
|
assert(false);
|
||||||
assert(name.length() > 0);
|
assert(name.length() > 0);
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
auto env_var = m_env_vars.find(name);
|
auto env_var = m_env_vars.find(name);
|
||||||
if (env_var != m_env_vars.end())
|
if (env_var != m_env_vars.end())
|
||||||
{
|
{
|
||||||
String value = env_var->second(context);
|
String value = env_var->second(context);
|
||||||
setenv(("kak_" + name).c_str(), value.c_str(), 1);
|
setenv(("kak_" + name).c_str(), value.c_str(), 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,15 @@ namespace Kakoune
|
|||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
typedef std::function<String (const Context&)> EnvVarRetriever;
|
typedef std::function<String (const Context&)> EnvVarRetriever;
|
||||||
|
typedef std::unordered_map<String, String> EnvVarMap;
|
||||||
|
|
||||||
class ShellManager : public Singleton<ShellManager>
|
class ShellManager : public Singleton<ShellManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShellManager();
|
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);
|
void register_env_var(const String& name, EnvVarRetriever retriever);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user