aboutsummaryrefslogtreecommitdiffstats
path: root/editors/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'editors/emacs')
-rw-r--r--editors/emacs/sol-mode.el31
1 files changed, 22 insertions, 9 deletions
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)