Skip to content

Instantly share code, notes, and snippets.

@PuercoPop
Last active August 29, 2015 14:19
Show Gist options
  • Save PuercoPop/6bedf6275d11ead20e6a to your computer and use it in GitHub Desktop.
Save PuercoPop/6bedf6275d11ead20e6a to your computer and use it in GitHub Desktop.
add ```(push 'sly-repl-ansi-color sly-contribs)``` to your init.el
;; Ported from is Max Mikhanosha's code.
(require 'ansi-color)
(define-sly-contrib sly-repl-ansi-color
"Turn on ANSI colors in the mREPL output"
(:authors "Max Mikhanosha")
(:license "GPL")
(:sly-dependencies sly-mrepl)
(:on-load (progn
(sly-repl-ansi-on)
(add-hook 'sly-mrepl-output-filter-functions
'sly-repl-ansi-colorize))))
(defvar sly-repl-ansi-color t
"When Non-NIL will process ANSI colors in the lisp output")
(make-variable-buffer-local 'sly-repl-ansi-color)
(defun sly-repl-ansi-on ()
"Set `ansi-color-for-comint-mode' to t."
(interactive)
(setq sly-repl-ansi-color t))
(defun sly-repl-ansi-off ()
"Set `ansi-color-for-comint-mode' to t."
(interactive)
(setq sly-repl-ansi-color nil))
(defun sly-repl-ansi-colorize (string)
(when sly-repl-ansi-color
(with-temp-buffer
(insert (ansi-color-apply string))
(dotimes (char-pos (- (point-max) (point-min)))
(let* ((char-pos (1+ char-pos))
(prop (getf (text-properties-at char-pos) 'font-lock-face)))
(when prop
(put-text-property char-pos (1+ char-pos) 'face prop))))
(buffer-string))))
(provide 'sly-repl-ansi-color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment