[PATCH] Show evaluation results in the echo area
Export this patch
Currently, users of the Fennel mode must use the REPL window to see evaluation
results, which is not practical nor idiomatic for Lisp development in Emacs.
With this patch, evaluation results are also shown in the echo area, as seen in
the "bigger" Lisp modes, such as the built-in Emacs Lisp mode, the SLIME and
SLY modes for Common Lisp, or the Geiser mode for Scheme.
I thought this was a part of fennel-proto-repl. Have you decided to use
the plain repl instead?
---
fennel-mode.el | 15 +++++++++++++++
test/fennel-mode-test.el | 13 +++++++++++++
2 files changed, 28 insertions(+)
diff --git a/fennel-mode.el b/fennel-mode.el
index 8c47694..3b0c2b1 100644
--- a/fennel-mode.el
+++ b/fennel-mode.el
@@ -814,6 +814,21 @@ result."
(setq-local lisp-indent-function 'fennel-indent-function)
(setq-local lisp-doc-string-elt-property 'fennel-doc-string-elt)
(setq-local comint-get-old-input #'fennel-repl--get-old-input)
+ (add-hook 'comint-preoutput-filter-functions
+ (lambda (output)
+ (message
+ (named-let clean-up ((old output))
+ (let ((new (string-trim
+ (replace-regexp-in-string
+ comint-prompt-regexp
+ ""
+ ;; TODO Add support for colors. :)
+ ;; https://stackoverflow.com/a/50963030/1306956
+ (ansi-color-filter-apply old)))))
+ (if (equal new old) new (clean-up new)))))
+ output)
+ -99
+ t)
(setq-local comment-end "")
(fennel-font-lock-setup)
(set-syntax-table fennel-mode-syntax-table)
diff --git a/test/fennel-mode-test.el b/test/fennel-mode-test.el
index be229fc..5c673c1 100644
--- a/test/fennel-mode-test.el
+++ b/test/fennel-mode-test.el
@@ -151,3 +151,16 @@
(should (indent-region (point-min) (point-max)))
(should (equal (string-trim expected)
(string-trim (buffer-substring-no-properties (point-min) (point-max)))))))))
+
+ (ert-deftest fennel-mode-eval-test ()
+ (with-temp-buffer
+ (insert "(+ 5 5)")
+ (fennel-mode)
+ (message nil)
+ (fennel-eval-last-sexp)
+ (should
+ (let ((deadline (+ (string-to-number (emacs-uptime "%s")) 5)))
+ (named-let try-again ()
+ (cond ((equal "10" (current-message)) t)
+ ((> (string-to-number (emacs-uptime "%s")) deadline) nil)
+ (t (sleep-for 0.01) (try-again))))))))
-Phil
--
2.44.0
Apr 30, 2024 18:09:27 Rudolf Adamkovič <rudolf@adamkovic.org>:
Overall looks good, but this tests only passes if you already have a
repl open, so it fails when running the tests in batch mode.