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

Fix nix-get-completions, add to nix-repl-mode #105

Merged
merged 2 commits into from Sep 7, 2020

Conversation

@rossabaker
Copy link
Contributor

@rossabaker rossabaker commented Sep 6, 2020

A mashup of python's completion-at-point function and @purcell's sketch.

This is working for me via company-capf on nix-2.3.7.

Copy link
Contributor Author

@rossabaker rossabaker left a comment

Most of my emacs-lisp is trivial and personal. I'm open to any and all criticism. Thanks for looking!

" *nix-repl completions redirect*"
"Buffer to be used to redirect output of readline commands.")

(defcustom nix-repl-completion-output-timeout 1.0

This comment has been minimized.

@rossabaker

rossabaker Sep 6, 2020
Author Contributor

Python's default is 5. Our old default was 1, which is easily sufficient to complete pkgs.haskellPackages on my machine, which is the heftiest one I could think of.

(setq-local comint-prompt-read-only t))
(setq-local comint-prompt-read-only t)
(add-hook 'completion-at-point-functions
#'nix-repl-completion-at-point nil 'local))

This comment has been minimized.

@rossabaker

rossabaker Sep 6, 2020
Author Contributor

Note: the old one isn't installed by default.

This comment has been minimized.

@matthewbauer

matthewbauer Sep 7, 2020
Member

This adds it just for the repl buffer right? It should be fine in the Nix buffer too, but we need to make sure it fails gracefully if Nix Repl doesn't exist / isn't running.

This comment has been minimized.

@rossabaker

rossabaker Sep 8, 2020
Author Contributor

Should be only for nix-repl-mode buffers, which I'd expect to only be created by nix-repl. I've tried to make it a bit more graceful in #107.

(beginning-of-line)
(if (eq (char-after) ?\r)
(cdr
(split-string
(buffer-substring-no-properties
(line-beginning-position) (point-min))
"[ \f\t\n\r\v]+" t))
(search-forward "" nil t)
(backward-char)
(if (eq (char-before) ?\a)
nil
(list (buffer-substring-no-properties (line-beginning-position) (point))))))))
Comment on lines +108 to +119

This comment has been minimized.

@rossabaker

rossabaker Sep 6, 2020
Author Contributor

This here is the bulk of the original work.

We don't get nice dummy completions like Python. Scala's sbt has a nifty completions command that sbt-mode can use, and am thinking about proposing similar for nix repl. I'm particularly scared of the fragility of depending on output like ?\a and what other platforms or .inputrc files might do to this "protocol".

"Completion at point function for Nix using \"nix-repl\".
See `completion-at-point-functions'."
(save-excursion
(let ((prefix (and (derived-mode-p 'nix-repl-mode)

This comment has been minimized.

@rossabaker

rossabaker Sep 6, 2020
Author Contributor

This is from @purcell's draft, but I am not yet ambitious enough to do this in nix-mode. We might try refreshing the current buffer into a repl, but that could be very slow, and I'm not sure what to do with nix files that require arguments. I think that's more the domain of a Nix LSP.

@purcell
Copy link
Contributor

@purcell purcell commented Sep 6, 2020

Nice!

This makes it a little easier to get to the completion. Taken from the
setting in shell-mode-map.
@matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Sep 7, 2020

Looks good to me, and confirmed it works with Nix 3.0 too!

Nix does have a NIX_GET_COMPLETIONS variable which can get completions of buildable things (try NIX_GET_COMPLETIONS=2 nix eval nixpkgs# in Nix 3.0). You could actually use it in the repl, but I don't think it's as thorough as the REPL completion.

@matthewbauer matthewbauer merged commit 5fa017c into NixOS:master Sep 7, 2020
3 checks passed
3 checks passed
tests (ubuntu-latest)
Details
tests (macos-latest)
Details
Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.