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

Send input to nix repl? #185

Open
alejandrogallo opened this issue Apr 10, 2023 · 2 comments
Open

Send input to nix repl? #185

alejandrogallo opened this issue Apr 10, 2023 · 2 comments

Comments

@alejandrogallo
Copy link

Maybe I'm just missing something, but I could not find a functionality like this
for instacne

(defun ale/nix-send-buffer-to-repl (&optional arg)
    (interactive "P")
    (let ((contents (buffer-string)))
      (save-excursion
        (nix-repl-show)
        (when arg
          (insert (format "%s = "
                          (read-string "Variable to store expression: "))))
        (insert contents)
        (comint-send-input))))

is there something planned to send input and so on to the repl?

@idlip
Copy link

idlip commented Jun 26, 2023

Hey @alejandrogallo I was also thinking why wasn't there interactive interpreting feature for nix-mode. Just now, I went through python and ess way of evaluating lines.

Came up with an function:

(defun nix-eval-line ()
  "Evaluates the line at point in nix-repl."
  (interactive)
  (let* ((start (line-beginning-position))
         (end (line-end-position))
         (msg (format "%s" (buffer-substring start end))))
    (pop-to-buffer "*Nix-REPL*")
    (insert msg)
    (comint-send-input)
    (other-window 1)))

With little more work, we can bring similar function like, nix-eval-buffer, nix-eval-region (I thing, line and region should be made as dwin)

Note: It does not start nix-repl, instead uses existing one.
Let's see if author wants something like this.

@idlip
Copy link

idlip commented Jun 26, 2023

Made a working nix-eval-dwim variant:

(defun nix-eval-dwim ()
  (interactive)
  (let* ((start (line-beginning-position))
         (end (line-end-position))
	 (region-string (buffer-substring (region-beginning) (region-end)))
         (msg (format "%s" (if (use-region-p) region-string (buffer-substring start end)))))
    (pop-to-buffer "*Nix-REPL*")
    (insert msg)
    (comint-send-input)
    (other-window 1)))

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

2 participants