feature/eval: refactor +eval/open-repl
This commit is contained in:
parent
c5b72566ea
commit
5dcd673651
1 changed files with 32 additions and 28 deletions
|
@ -3,37 +3,41 @@
|
||||||
(defvar +eval-repl-buffer nil
|
(defvar +eval-repl-buffer nil
|
||||||
"The buffer of the last open repl.")
|
"The buffer of the last open repl.")
|
||||||
|
|
||||||
(defun +eval--ensure-in-repl-buffer (&optional command)
|
(defun +eval--ensure-in-repl-buffer (&optional command same-window-p)
|
||||||
(or (eq (current-buffer) +eval-repl-buffer)
|
(cond ((eq (current-buffer) +eval-repl-buffer))
|
||||||
(progn
|
((and +eval-repl-buffer
|
||||||
(if (and +eval-repl-buffer (buffer-live-p +eval-repl-buffer))
|
(buffer-live-p +eval-repl-buffer))
|
||||||
(if-let* ((win (get-buffer-window +eval-repl-buffer)))
|
(when-let* ((win (get-buffer-window +eval-repl-buffer)))
|
||||||
(select-window win)
|
(select-window win)))
|
||||||
(pop-to-buffer +eval-repl-buffer))
|
(command
|
||||||
(when command
|
|
||||||
(let ((repl-buffer (save-window-excursion (call-interactively command))))
|
(let ((repl-buffer (save-window-excursion (call-interactively command))))
|
||||||
(unless (bufferp repl-buffer)
|
(unless (bufferp repl-buffer)
|
||||||
(error "REPL command didn't return a buffer"))
|
(error "REPL command didn't return a buffer"))
|
||||||
(with-current-buffer repl-buffer (+eval-repl-mode +1))
|
(with-current-buffer repl-buffer (+eval-repl-mode +1))
|
||||||
(setq +eval-repl-buffer repl-buffer)
|
(setq +eval-repl-buffer repl-buffer))))
|
||||||
(pop-to-buffer repl-buffer))))
|
(unless (eq (current-buffer) +eval-repl-buffer)
|
||||||
(when (eq (current-buffer) +eval-repl-buffer)
|
(funcall (if same-window-p #'switch-to-buffer #'pop-to-buffer)
|
||||||
|
+eval-repl-buffer))
|
||||||
|
(with-current-buffer +eval-repl-buffer
|
||||||
(goto-char (if (and (derived-mode-p 'comint-mode)
|
(goto-char (if (and (derived-mode-p 'comint-mode)
|
||||||
(cdr comint-last-prompt))
|
(cdr comint-last-prompt))
|
||||||
(cdr comint-last-prompt)
|
(cdr comint-last-prompt)
|
||||||
(point-max)))
|
(point-max)))
|
||||||
t))))
|
t))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eval/open-repl ()
|
(defun +eval/open-repl (&optional same-window-p)
|
||||||
"Opens (or reopens) the REPL associated with the current major-mode and place
|
"Opens (or reopens) the REPL associated with the current major-mode and place
|
||||||
the cursor at the prompt."
|
the cursor at the prompt.
|
||||||
(interactive)
|
|
||||||
(when-let* ((command (cdr (assq major-mode +eval-repls))))
|
If SAME-WINDOW-P is non-nil, open REPL in current window."
|
||||||
(when (+eval--ensure-in-repl-buffer command)
|
(interactive "P")
|
||||||
|
(if-let* ((command (cdr (assq major-mode +eval-repls))))
|
||||||
|
(when (+eval--ensure-in-repl-buffer command same-window-p)
|
||||||
(when (bound-and-true-p evil-mode)
|
(when (bound-and-true-p evil-mode)
|
||||||
(call-interactively #'evil-append-line))
|
(call-interactively #'evil-append-line))
|
||||||
t)))
|
t)
|
||||||
|
(user-error "No REPL is defined for %s" major-mode)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eval/send-region-to-repl (beg end &optional auto-execute-p)
|
(defun +eval/send-region-to-repl (beg end &optional auto-execute-p)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue