|
1 |
| -;;; cider-util.el --- Common utility functions that don't belong anywhere else -*- lexical-binding: t -*- |
| 1 | +;; cider-util.el --- Common utility functions that don't belong anywhere else -*- lexical-binding: t -*- |
2 | 2 |
|
3 | 3 | ;; Copyright © 2012-2013 Tim King, Phil Hagelberg, Bozhidar Batsov
|
4 | 4 | ;; Copyright © 2013-2017 Bozhidar Batsov, Artur Malabarba and CIDER contributors
|
|
36 | 36 | (require 'subr-x)
|
37 | 37 | (require 'cider-compat)
|
38 | 38 | (require 'nrepl-dict)
|
| 39 | +(require 'ansi-color) |
39 | 40 |
|
40 | 41 | (defalias 'cider-pop-back 'pop-tag-mark)
|
41 | 42 |
|
@@ -250,16 +251,23 @@ This buffer is not designed to display anything to the user. For that, use
|
250 | 251 | (funcall mode))
|
251 | 252 | b)))
|
252 | 253 |
|
| 254 | +(defun cider-ansi-color-string-p (string) |
| 255 | + "Return non-nil if STRING is an ANSI string." |
| 256 | + (string-match "^\\[" string)) |
| 257 | + |
253 | 258 | (defun cider-font-lock-as (mode string)
|
254 | 259 | "Use MODE to font-lock the STRING."
|
255 |
| - (if (or (null cider-font-lock-max-length) |
256 |
| - (< (length string) cider-font-lock-max-length)) |
257 |
| - (with-current-buffer (cider--make-buffer-for-mode mode) |
258 |
| - (erase-buffer) |
259 |
| - (insert string) |
260 |
| - (font-lock-fontify-region (point-min) (point-max)) |
261 |
| - (buffer-string)) |
262 |
| - string)) |
| 260 | + (let ((string (if (cider-ansi-color-string-p string) |
| 261 | + (substring-no-properties (ansi-color-apply string)) |
| 262 | + string))) |
| 263 | + (if (or (null cider-font-lock-max-length) |
| 264 | + (< (length string) cider-font-lock-max-length)) |
| 265 | + (with-current-buffer (cider--make-buffer-for-mode mode) |
| 266 | + (erase-buffer) |
| 267 | + (insert string) |
| 268 | + (font-lock-fontify-region (point-min) (point-max)) |
| 269 | + (buffer-string)) |
| 270 | + string))) |
263 | 271 |
|
264 | 272 | (defun cider-font-lock-region-as (mode beg end &optional buffer)
|
265 | 273 | "Use MODE to font-lock text between BEG and END.
|
|
0 commit comments