Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix repl: add :edit command #3163

Merged
merged 7 commits into from Nov 5, 2019
Merged

nix repl: add :edit command #3163

merged 7 commits into from Nov 5, 2019

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Oct 23, 2019

This allows to have a repl-centric workflow to working on nixpkgs.

Usage:

:edit <package> - heuristic that find the package file path

:edit <path> - just open the editor on the file path

Once invoked, nix repl will open $EDITOR on that file path. Once the
editor exits, nix repl will automatically reload itself.

This allows to have a repl-centric workflow to working on nixpkgs.

Usage:

    :edit <package> - heuristic that find the package file path

    :edit <path> - just open the editor on the file path

Once invoked, `nix repl` will open $EDITOR on that file path. Once the
editor exits, `nix repl` will automatically reload itself.
@zimbatm
Copy link
Member Author

zimbatm commented Oct 23, 2019

This PR borrows some code from nix edit which I would like to factor out but don't know where to place it. I think I found the right places to extract the common pieces.

The doc also needs to be amended with the new command. EDIT: the nix repl commands are completely undocumented right now but are also easy discoverable from the CLI

@zimbatm zimbatm requested a review from edolstra October 29, 2019 10:10
@bhipple
Copy link
Contributor

bhipple commented Oct 31, 2019

This looks nice! It'd be good to have some test cases though. Something basic like this:

[nix-shell:~/src/nixpkgs]$ echo ":edit boost" | EDITOR=ls ../nix/inst/bin/nix repl .
Welcome to Nix version 2.4. Type :? for help.

Loading '.'...
Added 11053 variables.

/home/bhipple/src/nixpkgs/pkgs/development/libraries/boost/generic.nix
Loading '.'...
Added 11053 variables.

That can assert that it uses $EDITOR, finds the package, reloads nix repl, etc.

execvp(args.front().c_str(), stringsToCharPtrs(args).data());

throw SysError("cannot run editor '%s'", editor);
std::string command;
for (const auto &arg : args) command += " '" + arg + "'";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note a huge deal, but it'd be more idiomatic (and performant) to use a std::stringstream here.

@@ -440,6 +441,7 @@ bool NixRepl::processLine(string line)
<< " <x> = <expr> Bind expression to variable\n"
<< " :a <expr> Add attributes from resulting set to scope\n"
<< " :b <expr> Build derivation\n"
<< " :e <expr> Open the derivation in $EDITOR\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but it probably makes sense to curate an (unreleased) doc/manual/release-notes/rl-2.4.xml that gets updated with upcoming changes as we add them. That way @edolstra doesn't have to go through the git log and write them all himself when he wants to do a release, and users can see what unreleased changes have accumulated on master.

As an extra aside, it looks like we don't have man pages or manual documentation for the nix 2.0 CLI, so I guess this is the only place it needs to be documented?

@edolstra edolstra merged commit 9a25059 into NixOS:master Nov 5, 2019
@zimbatm zimbatm deleted the nix-repl-e branch November 5, 2019 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants