tools/eval: send to repl (via gr) by line #2056

This commit is contained in:
Henrik Lissner 2019-11-16 20:57:04 -05:00
parent 4dc3f0956a
commit f54d7a15cd
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -115,11 +115,27 @@ immediately after."
(buffer (+eval--ensure-in-repl-buffer)))
(unless buffer
(error "No REPL open"))
(with-selected-window (get-buffer-window buffer)
(when (bound-and-true-p evil-local-mode)
(call-interactively #'evil-append-line))
(insert (string-trim selection))
(unless inhibit-auto-execute-p
;; `comint-send-input' isn't enough because some REPLs may not use
;; comint, so just emulate the keypress.
(execute-kbd-macro (kbd "RET"))))))
(let ((origin-window (selected-window))
(selection
(with-temp-buffer
(insert selection)
(goto-char (point-min))
(when (> (skip-chars-forward "\n") 0)
(delete-region (point-min) (point)))
(indent-rigidly (point) (point-max)
(- (skip-chars-forward " \t")))
(string-trim-right (buffer-string)))))
(with-selected-window (get-buffer-window buffer)
(with-current-buffer buffer
(dolist (line (split-string selection "\n"))
(insert line)
(if inhibit-auto-execute-p
(insert "\n")
;; `comint-send-input' isn't enough because some REPLs may not use
;; comint, so just emulate the keypress.
(execute-kbd-macro (kbd "RET")))
(sit-for 0.001)
(redisplay 'force)))
(when (and (eq origin-window (selected-window))
(bound-and-true-p evil-local-mode))
(call-interactively #'evil-append-line))))))