~technomancy/fennel-mode

b07a726f4d8b6e7f69fdf7f2105abfa5707680dc — Rudolf Adamkovič 4 months ago 60e39d2
ProtoREPL: Interpret ANSI colors when echoing evaluation results

Reproduction steps:

  1. Open a new file.
  2. Enable the Fennel mode.
  3. Enable the Fennel Proto REPL minor mode.
  4. Type 'nonsense'.
  5. Type 'C-x C-e' to evaluate 'nonsense'.
  6. Answer 'y' when asked whether to start a new REPL.
  7. See the "unknown identifier: nonsense" error in the echo area.

Actual:

  The error contains ANSI color codes.

Expected:

  The error is shown in color, with no ANSI color codes.
1 files changed, 14 insertions(+), 3 deletions(-)

M fennel-proto-repl.el
M fennel-proto-repl.el => fennel-proto-repl.el +14 -3
@@ 101,6 101,7 @@
(require 'xref)
(require 'cl-generic)
(require 'fennel-mode)
(require 'ansi-color)
(declare-function markdown-mode "ext:markdown-mode")

(defvar fennel-proto-repl--protocol


@@ 1435,9 1436,19 @@ start the REPL only check for one."
      (buffer-name)))
    (fennel-proto-repl fennel-program))))

(defun fennel-proto-repl--display-result (results)
  "Display RESULTS in the echo area."
  (message "=> %s" (string-trim (string-join results "\t"))))
(defun fennel-proto-repl--display-result (values)
  "Display result VALUES in the echo area."
  (let* ((text (ansi-color-apply (string-trim (string-join values "\t"))))
         (end (length text)))
    (message
     ;; `ansi-color-apply' adds `font-lock-face' properties but `message'
     ;; expects `face' properties, so copy `font-lock-face' properties as
     ;; `face' properties.
     (named-let recur ((from 0))
       (let* ((value (get-text-property from 'font-lock-face text))
              (to (text-property-not-all from end 'font-lock-face value text)))
         (put-text-property from (or to end) 'face value text)
         (if to (recur to) text))))))

(defun fennel-proto-repl-eval-print-last-sexp (&optional pretty-print)
  "Evaluate the expression preceding point.