summaryrefslogtreecommitdiff
path: root/cider-util.el
diff options
context:
space:
mode:
authorPaul Landes <landes@mailc.net>2017-07-15 02:36:26 -0500
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2017-07-15 10:36:26 +0300
commit0c6f998c61668b91ee52ff7a643b84675feebf98 (patch)
tree82be6f6b03b4923bc3a92b60da7b18661d443894 /cider-util.el
parent2f3c9f52c073c9b09a19df2f9dc8657085fa55b8 (diff)
Handle ANSI color REPL evaluation created by Puget (#2021)
Basically we simply apply the ANSI color and discard it, so it would interfere with the `clojure-mode` font-locking we're doing.
Diffstat (limited to 'cider-util.el')
-rw-r--r--cider-util.el26
1 files changed, 17 insertions, 9 deletions
diff --git a/cider-util.el b/cider-util.el
index 91b94f63..2e391858 100644
--- a/cider-util.el
+++ b/cider-util.el
@@ -1,4 +1,4 @@
-;;; cider-util.el --- Common utility functions that don't belong anywhere else -*- lexical-binding: t -*-
+;; cider-util.el --- Common utility functions that don't belong anywhere else -*- lexical-binding: t -*-
;; Copyright © 2012-2013 Tim King, Phil Hagelberg, Bozhidar Batsov
;; Copyright © 2013-2017 Bozhidar Batsov, Artur Malabarba and CIDER contributors
@@ -36,6 +36,7 @@
(require 'subr-x)
(require 'cider-compat)
(require 'nrepl-dict)
+(require 'ansi-color)
(defalias 'cider-pop-back 'pop-tag-mark)
@@ -250,16 +251,23 @@ This buffer is not designed to display anything to the user. For that, use
(funcall mode))
b)))
+(defun cider-ansi-color-string-p (string)
+ "Return non-nil if STRING is an ANSI string."
+ (string-match "^\\[" string))
+
(defun cider-font-lock-as (mode string)
"Use MODE to font-lock the STRING."
- (if (or (null cider-font-lock-max-length)
- (< (length string) cider-font-lock-max-length))
- (with-current-buffer (cider--make-buffer-for-mode mode)
- (erase-buffer)
- (insert string)
- (font-lock-fontify-region (point-min) (point-max))
- (buffer-string))
- string))
+ (let ((string (if (cider-ansi-color-string-p string)
+ (substring-no-properties (ansi-color-apply string))
+ string)))
+ (if (or (null cider-font-lock-max-length)
+ (< (length string) cider-font-lock-max-length))
+ (with-current-buffer (cider--make-buffer-for-mode mode)
+ (erase-buffer)
+ (insert string)
+ (font-lock-fontify-region (point-min) (point-max))
+ (buffer-string))
+ string)))
(defun cider-font-lock-region-as (mode beg end &optional buffer)
"Use MODE to font-lock text between BEG and END.