aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2019-10-28 21:36:34 +0100
committerzimbatm <zimbatm@zimbatm.com>2019-10-28 21:36:34 +0100
commit3774fe55fd6c96e80cc91e13fe0a231ce836ac47 (patch)
tree1923c36ab6c05268163eb788d75224e2bf8790b9 /src
parentec448f8bb694b6f9546e49fe6a79b86ff2b2f90a (diff)
editorFor: take a pos object instead
Diffstat (limited to 'src')
-rw-r--r--src/libutil/args.cc8
-rw-r--r--src/libutil/args.hh3
-rw-r--r--src/nix/edit.cc4
-rw-r--r--src/nix/repl.cc13
4 files changed, 12 insertions, 16 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 35ec3e4ab..b7baad375 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -178,16 +178,16 @@ Strings argvToStrings(int argc, char * * argv)
return args;
}
-Strings editorFor(std::string filename, int lineno)
+Strings editorFor(Pos pos)
{
auto editor = getEnv("EDITOR", "cat");
auto args = tokenizeString<Strings>(editor);
- if (lineno > 0 && (
+ 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", lineno));
- args.push_back(filename);
+ args.push_back(fmt("+%d", pos.line));
+ args.push_back(pos.file);
return args;
}
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index 22702c2d8..1e29bd4fa 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -5,6 +5,7 @@
#include <memory>
#include "util.hh"
+#include "nixexpr.hh"
namespace nix {
@@ -191,7 +192,7 @@ public:
Strings argvToStrings(int argc, char * * argv);
/* Helper function to generate args that invoke $EDITOR on filename:lineno */
-Strings editorFor(std::string filename, int lineno);
+Strings editorFor(Pos pos);
/* Helper function for rendering argument labels. */
std::string renderLabels(const Strings & labels);
diff --git a/src/nix/edit.cc b/src/nix/edit.cc
index d0607747d..553765f13 100644
--- a/src/nix/edit.cc
+++ b/src/nix/edit.cc
@@ -37,12 +37,10 @@ struct CmdEdit : InstallableCommand
auto v = installable->toValue(*state);
Pos pos = findDerivationFilename(*state, *v, installable->what());
- std::string filename(pos.file);
- int lineno(pos.line);
stopProgressBar();
- auto args = editorFor(filename, lineno);
+ auto args = editorFor(pos);
execvp(args.front().c_str(), stringsToCharPtrs(args).data());
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index ed67c285f..683a117f3 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -472,22 +472,19 @@ bool NixRepl::processLine(string line)
Value v;
evalString(arg, v);
- std::string filename;
- int lineno = 0;
+ Pos pos;
if (v.type == tPath || v.type == tString) {
PathSet context;
- filename = state.coerceToString(noPos, v, context);
- lineno = 0;
+ auto filename = state.coerceToString(noPos, v, context);
+ pos.file = state.symbols.create(filename);
} else {
// assume it's a derivation
- Pos pos = findDerivationFilename(state, v, arg);
- filename = pos.file;
- lineno = pos.line;
+ pos = findDerivationFilename(state, v, arg);
}
// Open in EDITOR
- auto args = editorFor(filename, lineno);
+ auto args = editorFor(pos);
auto editor = args.front();
args.pop_front();
runProgram(editor, args);