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)
|
||||
(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
|
||||
(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)
|
||||
(evil-define-operator +eval:replace-region (beg end)
|
||||
"Evaluate selection and replace it with its result."
|
||||
:move-point nil
|
||||
(interactive "<r>")
|
||||
(+eval/region-and-replace beg end))
|
||||
|
||||
;;;###autoload (autoload '+eval:repl "tools/eval/autoload/evil" nil t)
|
||||
(evil-define-operator +eval:repl (beg end &optional bang)
|
||||
"Open REPL and send the current selection to it."
|
||||
:move-point nil
|
||||
(interactive "<r><!>")
|
||||
(if (evil-normal-state-p)
|
||||
(+eval/open-repl-other-window bang)
|
||||
(+eval/send-region-to-repl beg end bang)))
|
||||
(+eval/open-repl-other-window))
|
||||
|
|
|
@ -17,32 +17,35 @@
|
|||
(key (cons major-mode project-root))
|
||||
(buffer (gethash key +eval-repl-buffers)))
|
||||
(cl-check-type buffer (or buffer null))
|
||||
(unless (eq buffer (current-buffer))
|
||||
(funcall (or displayfn #'get-buffer-create)
|
||||
(if (buffer-live-p buffer)
|
||||
buffer
|
||||
(setq buffer
|
||||
(save-window-excursion
|
||||
(if (commandp fn)
|
||||
(call-interactively fn)
|
||||
(funcall fn))))
|
||||
(cond ((null buffer)
|
||||
(error "REPL handler %S couldn't open the REPL buffer" fn))
|
||||
((not (bufferp buffer))
|
||||
(error "REPL handler %S failed to return a buffer" fn)))
|
||||
(with-current-buffer buffer
|
||||
(when plist
|
||||
(setq +eval-repl-plist plist))
|
||||
(+eval-repl-mode +1))
|
||||
(puthash key buffer +eval-repl-buffers)
|
||||
buffer)))
|
||||
(with-current-buffer buffer
|
||||
(unless (or (derived-mode-p 'term-mode)
|
||||
(eq (current-local-map) (bound-and-true-p term-raw-map)))
|
||||
(goto-char (if (and (derived-mode-p 'comint-mode)
|
||||
(cdr comint-last-prompt))
|
||||
(cdr comint-last-prompt)
|
||||
(point-max))))
|
||||
(unless (or (eq buffer (current-buffer))
|
||||
(null fn))
|
||||
(setq buffer
|
||||
(funcall (or displayfn #'get-buffer-create)
|
||||
(if (buffer-live-p buffer)
|
||||
buffer
|
||||
(setq buffer
|
||||
(save-window-excursion
|
||||
(if (commandp fn)
|
||||
(call-interactively fn)
|
||||
(funcall fn))))
|
||||
(cond ((null buffer)
|
||||
(error "REPL handler %S couldn't open the REPL buffer" fn))
|
||||
((not (bufferp buffer))
|
||||
(error "REPL handler %S failed to return a buffer" fn)))
|
||||
(with-current-buffer buffer
|
||||
(when plist
|
||||
(setq +eval-repl-plist plist))
|
||||
(+eval-repl-mode +1))
|
||||
(puthash key buffer +eval-repl-buffers)
|
||||
buffer))))
|
||||
(when (bufferp buffer)
|
||||
(with-current-buffer buffer
|
||||
(unless (or (derived-mode-p 'term-mode)
|
||||
(eq (current-local-map) (bound-and-true-p term-raw-map)))
|
||||
(goto-char (if (and (derived-mode-p 'comint-mode)
|
||||
(cdr comint-last-prompt))
|
||||
(cdr comint-last-prompt)
|
||||
(point-max)))))
|
||||
buffer)))
|
||||
|
||||
(defun +eval-open-repl (prompt-p &optional displayfn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue