diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-11-05 11:20:53 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-11-05 11:20:53 +0100 |
commit | 852554bb16c767950bace54bf44bb949608a394d (patch) | |
tree | 561d79a7dedefa8829f5558d4009e86342011bba /src/libutil | |
parent | 78760270713992a7fcba761c8be01ccbc0214fd8 (diff) | |
parent | 9a2505965667267f03a8385926f3b31a47732ed5 (diff) |
Merge branch 'nix-repl-e' of https://github.com/zimbatm/nix
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/args.cc | 13 | ||||
-rw-r--r-- | src/libutil/args.hh | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 7af2a1bf7..b7baad375 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -178,6 +178,19 @@ Strings argvToStrings(int argc, char * * argv) return args; } +Strings editorFor(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; +} + std::string renderLabels(const Strings & labels) { std::string res; diff --git a/src/libutil/args.hh b/src/libutil/args.hh index ad5fcca39..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 { @@ -190,6 +191,9 @@ public: Strings argvToStrings(int argc, char * * argv); +/* Helper function to generate args that invoke $EDITOR on filename:lineno */ +Strings editorFor(Pos pos); + /* Helper function for rendering argument labels. */ std::string renderLabels(const Strings & labels); |