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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
(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)))))))) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! |
This makes it a little easier to get to the completion. Taken from the setting in shell-mode-map.
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 |
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.