forked from lix-project/lix
editorFor: take a pos object instead
This commit is contained in:
parent
ec448f8bb6
commit
3774fe55fd
|
@ -178,16 +178,16 @@ Strings argvToStrings(int argc, char * * argv)
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings editorFor(std::string filename, int lineno)
|
Strings editorFor(Pos pos)
|
||||||
{
|
{
|
||||||
auto editor = getEnv("EDITOR", "cat");
|
auto editor = getEnv("EDITOR", "cat");
|
||||||
auto args = tokenizeString<Strings>(editor);
|
auto args = tokenizeString<Strings>(editor);
|
||||||
if (lineno > 0 && (
|
if (pos.line > 0 && (
|
||||||
editor.find("emacs") != std::string::npos ||
|
editor.find("emacs") != std::string::npos ||
|
||||||
editor.find("nano") != std::string::npos ||
|
editor.find("nano") != std::string::npos ||
|
||||||
editor.find("vim") != std::string::npos))
|
editor.find("vim") != std::string::npos))
|
||||||
args.push_back(fmt("+%d", lineno));
|
args.push_back(fmt("+%d", pos.line));
|
||||||
args.push_back(filename);
|
args.push_back(pos.file);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
#include "nixexpr.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -191,7 +192,7 @@ public:
|
||||||
Strings argvToStrings(int argc, char * * argv);
|
Strings argvToStrings(int argc, char * * argv);
|
||||||
|
|
||||||
/* Helper function to generate args that invoke $EDITOR on filename:lineno */
|
/* 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. */
|
/* Helper function for rendering argument labels. */
|
||||||
std::string renderLabels(const Strings & labels);
|
std::string renderLabels(const Strings & labels);
|
||||||
|
|
|
@ -37,12 +37,10 @@ struct CmdEdit : InstallableCommand
|
||||||
auto v = installable->toValue(*state);
|
auto v = installable->toValue(*state);
|
||||||
|
|
||||||
Pos pos = findDerivationFilename(*state, *v, installable->what());
|
Pos pos = findDerivationFilename(*state, *v, installable->what());
|
||||||
std::string filename(pos.file);
|
|
||||||
int lineno(pos.line);
|
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
auto args = editorFor(filename, lineno);
|
auto args = editorFor(pos);
|
||||||
|
|
||||||
execvp(args.front().c_str(), stringsToCharPtrs(args).data());
|
execvp(args.front().c_str(), stringsToCharPtrs(args).data());
|
||||||
|
|
||||||
|
|
|
@ -472,22 +472,19 @@ bool NixRepl::processLine(string line)
|
||||||
Value v;
|
Value v;
|
||||||
evalString(arg, v);
|
evalString(arg, v);
|
||||||
|
|
||||||
std::string filename;
|
Pos pos;
|
||||||
int lineno = 0;
|
|
||||||
|
|
||||||
if (v.type == tPath || v.type == tString) {
|
if (v.type == tPath || v.type == tString) {
|
||||||
PathSet context;
|
PathSet context;
|
||||||
filename = state.coerceToString(noPos, v, context);
|
auto filename = state.coerceToString(noPos, v, context);
|
||||||
lineno = 0;
|
pos.file = state.symbols.create(filename);
|
||||||
} else {
|
} else {
|
||||||
// assume it's a derivation
|
// assume it's a derivation
|
||||||
Pos pos = findDerivationFilename(state, v, arg);
|
pos = findDerivationFilename(state, v, arg);
|
||||||
filename = pos.file;
|
|
||||||
lineno = pos.line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open in EDITOR
|
// Open in EDITOR
|
||||||
auto args = editorFor(filename, lineno);
|
auto args = editorFor(pos);
|
||||||
auto editor = args.front();
|
auto editor = args.front();
|
||||||
args.pop_front();
|
args.pop_front();
|
||||||
runProgram(editor, args);
|
runProgram(editor, args);
|
||||||
|
|
Loading…
Reference in a new issue