forked from lix-project/lix
eldritch horrors
89e99d94e4
Combine `AbstractPos`, `PosAdapter`, and `Pos`
(cherry picked from commit 113499d16fc87d53b73fb62fe6242154909756ed)
===
this is a bit cursed because originally it was based on InputAccessor
code that we don't have and moved/patched features we likewise don't
have (fetchToStore caching, all the individual accessors,
ContentAddressMethod). the commit is adjusted accordingly to
match (remove caching, ignore accessors, use FileIngestionMethod).
note that `state.rootPath . CanonPath == abs` and
computeStorePathForPath works relative to cwd, so the slight rewrite in
the moved fetchToStore is legal.
Change-Id: I05fd340c273f0bcc8ffabfebdc4a88b98083bce5
25 lines
721 B
C++
25 lines
721 B
C++
#include "util.hh"
|
|
#include "editor-for.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;
|
|
}
|
|
|
|
}
|