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

Support completing .# in pcomplete/nix (ex. nix build .#myconfig`) #174

Open
ParetoOptimalDev opened this issue Dec 4, 2022 · 4 comments

Comments

@ParetoOptimalDev
Copy link

And other situations, here's copy paste of my org mode todo:

* TODO try adding a completion at point function for .# 

** that works with basically anything with nix and .#

*** nix build .#something

*** nix run .#something

*** nixos-rebuild switch --flake .#something

Right now eshell just falls back to completiing it into a directory for some reason.

@ParetoOptimalDev ParetoOptimalDev changed the title Support completing .# in pcomplete/nix (ex. nix run nixpkgs#firefo` completes firefox) Support completing .# in pcomplete/nix (ex. nix build .#myconfig`) Dec 4, 2022
@ParetoOptimalDev
Copy link
Author

I tried naively adding .# to nix--pcomplete-flags even though it's not a flag and that didn't work:

 ("build"
         (nix--pcomplete-flags
          (append nix-toplevel-options '("--arg" "--argstr" "--dry-run"
                                         "-f" "--file" "-I" "--include"
                                         "--no-link" "-o" "--out-link" ".#"))))

For others toying around with this or other nix related (p)completion I found this to be a useful resource:

https://www.masteringemacs.org/article/pcomplete-context-sensitive-completion-emac

@ParetoOptimalDev
Copy link
Author

I tried using edebug to understand pcomplete/nix and figured out that while nix build hits its code path, nix build . hits it, nix build .# does not.

.# seems to be special in emacs completion somehow and this special behavior will need to be overriden to get completion for it.

@ParetoOptimalDev
Copy link
Author

.# is special because it's an eshell glob. I can progress a bit further following the control flow in edebug by removing # from eshell-glob-chars-list but things aren't quite working. I think it's because the command getting run and it's result is:

~ $ NIX_GET_COMPLETIONS=2 nix build .#
attrs

It wouldn't be correct, but I'd expect at this point to get attrs as a completion candidate.

@ParetoOptimalDev
Copy link
Author

Oh, actually it's working! I just wasn't in a directory with a flake. So this works (if the code is correct):

(setq eshell-glob-chars-list '(93 91 42 63 126 40 41 124 94))

And then adding .# in:

 ("build"
         (nix--pcomplete-flags
          (append nix-toplevel-options '("--arg" "--argstr" "--dry-run"
                                         "-f" "--file" "-I" "--include"
                                         "--no-link" "-o" "--out-link" ".#"))))

Ideally though we could avoid removing .# as a glob and only treat it as a glob when it's not preceded by nix build. I don't have time to look into right now though.

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

No branches or pull requests

1 participant