aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc14
-rw-r--r--src/nix/command.hh5
2 files changed, 19 insertions, 0 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 532f331a7..97c2fcf1c 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -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;
+}
+
}
diff --git a/src/nix/command.hh b/src/nix/command.hh
index fad404c73..26c15e646 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -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);
+
}