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

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

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +108 to +119
(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))))))))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Member

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

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
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

3 participants