From 90cb51a907a0f78b83cb66f497f6dc0f24f01706 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 12 Jul 2026 18:52:52 -0300 Subject: repl session commands: load, reset, quit; emacs load-file binding --- editors/emacs/sol-mode.el | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'editors/emacs') diff --git a/editors/emacs/sol-mode.el b/editors/emacs/sol-mode.el index f46c0dd..0b9579d 100644 --- a/editors/emacs/sol-mode.el +++ b/editors/emacs/sol-mode.el @@ -15,8 +15,10 @@ ;; heads, variables, references (#Name), literals, delimiters. ;; - Navigation: imenu over Relations, Rules and Queries; ;; beginning/end-of-defun over top-level forms. -;; - An inferior Sol REPL (`run-sol') and `sol-run-buffer' to execute -;; the current file. +;; - An inferior Sol REPL (`run-sol'); `sol-load-file' (C-c C-l) loads +;; the current file into the session, `sol-send-line' (C-c C-e) +;; sends the statement at point, `sol-run-buffer' (C-c C-k) runs the +;; file in a compilation buffer. ;; - Eglot wiring: `sol lsp' serves diagnostics, so admission errors ;; (totality, schemas, integrity) appear while typing. ;; @@ -246,15 +248,25 @@ With ARG, repeat that many times. Returns non-nil on success." (inferior-sol-mode))) (pop-to-buffer inferior-sol-buffer)) +(defun sol--send (statement) + "Send STATEMENT to the REPL, starting it if needed." + (run-sol) + (with-current-buffer inferior-sol-buffer + (goto-char (point-max)) + (insert statement) + (comint-send-input))) + (defun sol-send-line () "Send the current line (one statement) to the REPL." (interactive) - (let ((statement (string-trim (or (thing-at-point 'line t) "")))) - (run-sol) - (with-current-buffer inferior-sol-buffer - (goto-char (point-max)) - (insert statement) - (comint-send-input)))) + (sol--send (string-trim (or (thing-at-point 'line t) "")))) + +(defun sol-load-file () + "Load the current file into the REPL session with :load. +The load is atomic: a rejected file changes nothing in the session." + (interactive) + (when (buffer-modified-p) (save-buffer)) + (sol--send (format ":load %s" buffer-file-name))) (defun sol-run-buffer () "Run the current file with sol, showing answers in a compilation buffer." @@ -279,7 +291,8 @@ With ARG, repeat that many times. Returns non-nil on success." (defvar sol-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-z") #'run-sol) - (define-key map (kbd "C-c C-l") #'sol-send-line) + (define-key map (kbd "C-c C-l") #'sol-load-file) + (define-key map (kbd "C-c C-e") #'sol-send-line) (define-key map (kbd "C-c C-k") #'sol-run-buffer) (define-key map (kbd "C-c C-j") #'imenu) map) -- cgit v1.2.3