diff options
author | jao <jao@gnu.org> | 2022-08-23 17:18:51 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-08-23 17:18:51 +0100 |
commit | c681e2b2e92da2e856835449d7097bbe67394a52 (patch) | |
tree | bc1c6814b59dbd6812df777873840cf1e5b2156a | |
parent | ecfbef1c771f3a5c34f46fb2b387b9669c661d2f (diff) | |
download | geiser-c681e2b2e92da2e856835449d7097bbe67394a52.tar.gz geiser-c681e2b2e92da2e856835449d7097bbe67394a52.tar.bz2 |
Interactive REPL start in C-c C-k and C-c C-l
Should address, sort of, issue #46
-rw-r--r-- | elisp/geiser-compile.el | 18 | ||||
-rw-r--r-- | elisp/geiser-mode.el | 4 | ||||
-rw-r--r-- | elisp/geiser-repl.el | 23 |
3 files changed, 35 insertions, 10 deletions
diff --git a/elisp/geiser-compile.el b/elisp/geiser-compile.el index e05459c..b1a07ff 100644 --- a/elisp/geiser-compile.el +++ b/elisp/geiser-compile.el @@ -16,8 +16,7 @@ (require 'geiser-autodoc) (require 'geiser-eval) (require 'geiser-base) - -(declare-function geiser-restart-repl "geiser-mode" ()) +(require 'geiser-repl) ;;; Auxiliary functions: @@ -46,6 +45,12 @@ (geiser-autodoc--clean-cache) (geiser-eval--send code cont))) +(defun geiser-compile--ensure-repl (force) + (when (or force + (and (not (geiser-repl--repl-buffer-p)) + (yes-or-no-p "No REPL is running: start it?"))) + (geiser-repl-restart-repl))) + ;;; User commands: @@ -54,25 +59,26 @@ (interactive "FScheme file: ") (geiser-compile--file-op path t "Compiling")) -(defun geiser-compile-current-buffer (&optional restart-p) +(defun geiser-compile-current-buffer (&optional restart) "Compile and load current Scheme file. With prefix, restart REPL before compiling the file." (interactive "P") - (when restart-p (geiser-restart-repl)) + (geiser-compile--ensure-repl restart) (geiser-compile-file (buffer-file-name (current-buffer)))) (defun geiser-load-file (path) "Load Scheme file." (interactive "FScheme file: ") + (geiser-compile--ensure-repl nil) (geiser-compile--file-op (file-local-name (expand-file-name path)) nil "Loading")) -(defun geiser-load-current-buffer (&optional restart-p) +(defun geiser-load-current-buffer (&optional restart) "Load current Scheme file. With prefix, restart REPL before loading the file." (interactive "P") - (when restart-p (geiser-restart-repl)) + (geiser-compile--ensure-repl restart) (geiser-load-file (buffer-file-name (current-buffer)))) ;;;###autoload diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el index 615bbdd..bc074f0 100644 --- a/elisp/geiser-mode.el +++ b/elisp/geiser-mode.el @@ -267,9 +267,7 @@ With prefix, recursively macro-expand the resulting expression." With prefix, try to enter the current buffer's module." (interactive "P") - (if arg - (switch-to-geiser-module (geiser-eval--get-module) (current-buffer)) - (switch-to-geiser nil nil (current-buffer)))) + (geiser-repl--switch-to-repl arg)) (defun geiser-mode-switch-to-repl-and-enter () "Switches to Geiser REPL and enters current buffer's module." diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el index 0a1f544..22fbf28 100644 --- a/elisp/geiser-repl.el +++ b/elisp/geiser-repl.el @@ -18,7 +18,6 @@ (require 'geiser-syntax) (require 'geiser-impl) (require 'geiser-eval) -(require 'geiser-compile) (require 'geiser-connection) (require 'geiser-menu) (require 'geiser-image) @@ -1058,6 +1057,28 @@ If no REPL is running, execute `run-geiser' to start a fresh one." (switch-to-geiser nil nil (or buffer (current-buffer)))) (geiser-repl--send cmd))) +(defun geiser-repl--switch-to-repl (arg) + (if arg + (switch-to-geiser-module (geiser-eval--get-module) (current-buffer)) + (switch-to-geiser nil nil (current-buffer)))) + +(defun geiser-repl--repl-buffer-p () + (and (buffer-live-p geiser-repl--repl) geiser-repl--repl)) + +(defun geiser-repl-restart-repl () + "Restarts the REPL associated with the current buffer." + (interactive) + (let ((b (current-buffer)) + (impl geiser-impl--implementation)) + (when (geiser-repl--repl-buffer-p) + (geiser-repl--switch-to-repl nil) + (comint-kill-subjob) + (sit-for 0.1)) ;; ugly hack; but i don't care enough to fix it + (run-geiser impl) + (sit-for 0.2) + (goto-char (point-max)) + (pop-to-buffer b))) + (defun geiser-repl-import-module (&optional module) "Import a given module in the current namespace of the REPL." (interactive) |