Move editorFor srom libutil to nix

libutil should not depend on libexpr.
This commit is contained in:
Eelco Dolstra 2019-11-08 15:13:32 +01:00
parent 48f0a76372
commit 0d6774468c
No known key found for this signature in database
GPG Key ID: 8170B4726D7198DE
4 changed files with 19 additions and 17 deletions

View File

@ -178,19 +178,6 @@ Strings argvToStrings(int argc, char * * argv)
return args;
}
Strings editorFor(Pos pos)
{
auto editor = getEnv("EDITOR", "cat");
auto args = tokenizeString<Strings>(editor);
if (pos.line > 0 && (
editor.find("emacs") != std::string::npos ||
editor.find("nano") != std::string::npos ||
editor.find("vim") != std::string::npos))
args.push_back(fmt("+%d", pos.line));
args.push_back(pos.file);
return args;
}
std::string renderLabels(const Strings & labels)
{
std::string res;

View File

@ -5,7 +5,6 @@
#include <memory>
#include "util.hh"
#include "nixexpr.hh"
namespace nix {
@ -191,9 +190,6 @@ public:
Strings argvToStrings(int argc, char * * argv);
/* Helper function to generate args that invoke $EDITOR on filename:lineno */
Strings editorFor(Pos pos);
/* Helper function for rendering argument labels. */
std::string renderLabels(const Strings & labels);

View File

@ -1,6 +1,7 @@
#include "command.hh"
#include "store-api.hh"
#include "derivations.hh"
#include "nixexpr.hh"
namespace nix {
@ -153,4 +154,17 @@ void StorePathCommand::run(ref<Store> store)
run(store, *storePaths.begin());
}
Strings editorFor(const Pos & pos)
{
auto editor = getEnv("EDITOR", "cat");
auto args = tokenizeString<Strings>(editor);
if (pos.line > 0 && (
editor.find("emacs") != std::string::npos ||
editor.find("nano") != std::string::npos ||
editor.find("vim") != std::string::npos))
args.push_back(fmt("+%d", pos.line));
args.push_back(pos.file);
return args;
}
}

View File

@ -10,6 +10,7 @@ extern std::string programPath;
struct Value;
class Bindings;
class EvalState;
struct Pos;
/* A command is an argument parser that can be executed by calling its
run() method. */
@ -216,4 +217,8 @@ PathSet toDerivations(ref<Store> store,
std::vector<std::shared_ptr<Installable>> installables,
bool useDeriver = false);
/* Helper function to generate args that invoke $EDITOR on
filename:lineno. */
Strings editorFor(const Pos & pos);
}