4feb7d9f71
Also move `SourcePath` into `libutil`. These changes allow `error.hh` and `error.cc` to access source path and position information, which we can use to produce better error messages (for example, we could consider omitting filenames when two or more consecutive stack frames originate from the same file).
25 lines
738 B
C++
25 lines
738 B
C++
#include "editor-for.hh"
|
|
#include "environment-variables.hh"
|
|
#include "source-path.hh"
|
|
|
|
namespace nix {
|
|
|
|
Strings editorFor(const SourcePath & file, uint32_t line)
|
|
{
|
|
auto path = file.getPhysicalPath();
|
|
if (!path)
|
|
throw Error("cannot open '%s' in an editor because it has no physical path", file);
|
|
auto editor = getEnv("EDITOR").value_or("cat");
|
|
auto args = tokenizeString<Strings>(editor);
|
|
if (line > 0 && (
|
|
editor.find("emacs") != std::string::npos ||
|
|
editor.find("nano") != std::string::npos ||
|
|
editor.find("vim") != std::string::npos ||
|
|
editor.find("kak") != std::string::npos))
|
|
args.push_back(fmt("+%d", line));
|
|
args.push_back(path->abs());
|
|
return args;
|
|
}
|
|
|
|
}
|