tools/eval: gr now sends to REPL if one is open #1941
And polish other evil repl commands + add docstrings.
This commit is contained in:
parent
80f56f4a40
commit
bcdf5eb19a
2 changed files with 37 additions and 31 deletions
|
@ -3,21 +3,24 @@
|
||||||
|
|
||||||
;;;###autoload (autoload '+eval:region "tools/eval/autoload/evil" nil t)
|
;;;###autoload (autoload '+eval:region "tools/eval/autoload/evil" nil t)
|
||||||
(evil-define-operator +eval:region (beg end)
|
(evil-define-operator +eval:region (beg end)
|
||||||
"Send region to the currently open repl, if available."
|
"Evaluate selection or sends it to the open REPL, if available."
|
||||||
:move-point nil
|
:move-point nil
|
||||||
(interactive "<r>")
|
(interactive "<r>")
|
||||||
(+eval/region beg end))
|
(if (and (fboundp '+eval--ensure-in-repl-buffer)
|
||||||
|
(+eval--ensure-in-repl-buffer))
|
||||||
|
(+eval/send-region-to-repl (point-min) (point-max))
|
||||||
|
(+eval/region beg end)))
|
||||||
|
|
||||||
;;;###autoload (autoload '+eval:replace-region "tools/eval/autoload/evil" nil t)
|
;;;###autoload (autoload '+eval:replace-region "tools/eval/autoload/evil" nil t)
|
||||||
(evil-define-operator +eval:replace-region (beg end)
|
(evil-define-operator +eval:replace-region (beg end)
|
||||||
|
"Evaluate selection and replace it with its result."
|
||||||
:move-point nil
|
:move-point nil
|
||||||
(interactive "<r>")
|
(interactive "<r>")
|
||||||
(+eval/region-and-replace beg end))
|
(+eval/region-and-replace beg end))
|
||||||
|
|
||||||
;;;###autoload (autoload '+eval:repl "tools/eval/autoload/evil" nil t)
|
;;;###autoload (autoload '+eval:repl "tools/eval/autoload/evil" nil t)
|
||||||
(evil-define-operator +eval:repl (beg end &optional bang)
|
(evil-define-operator +eval:repl (beg end &optional bang)
|
||||||
|
"Open REPL and send the current selection to it."
|
||||||
:move-point nil
|
:move-point nil
|
||||||
(interactive "<r><!>")
|
(interactive "<r><!>")
|
||||||
(if (evil-normal-state-p)
|
(+eval/open-repl-other-window))
|
||||||
(+eval/open-repl-other-window bang)
|
|
||||||
(+eval/send-region-to-repl beg end bang)))
|
|
||||||
|
|
|
@ -17,32 +17,35 @@
|
||||||
(key (cons major-mode project-root))
|
(key (cons major-mode project-root))
|
||||||
(buffer (gethash key +eval-repl-buffers)))
|
(buffer (gethash key +eval-repl-buffers)))
|
||||||
(cl-check-type buffer (or buffer null))
|
(cl-check-type buffer (or buffer null))
|
||||||
(unless (eq buffer (current-buffer))
|
(unless (or (eq buffer (current-buffer))
|
||||||
(funcall (or displayfn #'get-buffer-create)
|
(null fn))
|
||||||
(if (buffer-live-p buffer)
|
(setq buffer
|
||||||
buffer
|
(funcall (or displayfn #'get-buffer-create)
|
||||||
(setq buffer
|
(if (buffer-live-p buffer)
|
||||||
(save-window-excursion
|
buffer
|
||||||
(if (commandp fn)
|
(setq buffer
|
||||||
(call-interactively fn)
|
(save-window-excursion
|
||||||
(funcall fn))))
|
(if (commandp fn)
|
||||||
(cond ((null buffer)
|
(call-interactively fn)
|
||||||
(error "REPL handler %S couldn't open the REPL buffer" fn))
|
(funcall fn))))
|
||||||
((not (bufferp buffer))
|
(cond ((null buffer)
|
||||||
(error "REPL handler %S failed to return a buffer" fn)))
|
(error "REPL handler %S couldn't open the REPL buffer" fn))
|
||||||
(with-current-buffer buffer
|
((not (bufferp buffer))
|
||||||
(when plist
|
(error "REPL handler %S failed to return a buffer" fn)))
|
||||||
(setq +eval-repl-plist plist))
|
(with-current-buffer buffer
|
||||||
(+eval-repl-mode +1))
|
(when plist
|
||||||
(puthash key buffer +eval-repl-buffers)
|
(setq +eval-repl-plist plist))
|
||||||
buffer)))
|
(+eval-repl-mode +1))
|
||||||
(with-current-buffer buffer
|
(puthash key buffer +eval-repl-buffers)
|
||||||
(unless (or (derived-mode-p 'term-mode)
|
buffer))))
|
||||||
(eq (current-local-map) (bound-and-true-p term-raw-map)))
|
(when (bufferp buffer)
|
||||||
(goto-char (if (and (derived-mode-p 'comint-mode)
|
(with-current-buffer buffer
|
||||||
(cdr comint-last-prompt))
|
(unless (or (derived-mode-p 'term-mode)
|
||||||
(cdr comint-last-prompt)
|
(eq (current-local-map) (bound-and-true-p term-raw-map)))
|
||||||
(point-max))))
|
(goto-char (if (and (derived-mode-p 'comint-mode)
|
||||||
|
(cdr comint-last-prompt))
|
||||||
|
(cdr comint-last-prompt)
|
||||||
|
(point-max)))))
|
||||||
buffer)))
|
buffer)))
|
||||||
|
|
||||||
(defun +eval-open-repl (prompt-p &optional displayfn)
|
(defun +eval-open-repl (prompt-p &optional displayfn)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue