Skip to content

Commit dd1871a

Browse files
rfkmcap10morgan
authored andcommitted
[Fix #1452] Fix broken ANSI coloring in the repl
1 parent e3dea09 commit dd1871a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#1466](https://github.com/clojure-emacs/cider/issues/1466): Correctly font-lock pretty-printed results in the REPL.
1313
* [#1475](https://github.com/clojure-emacs/cider/pull/1475): Fix `args-out-of-range` error in `cider--get-symbol-indent`.
1414
* [#1479](https://github.com/clojure-emacs/cider/pull/1479): Make paredit and `cider-repl-mode` play nice.
15+
* [#1452](https://github.com/clojure-emacs/cider/issues/1452): Prevent ANSI color overlays in the REPL buffer from being extended.
1516

1617
## 0.10.0 / 2015-12-03
1718

cider-repl.el

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,19 @@ If BOL is non-nil insert at the beginning of line."
484484
(let ((pos (cider-repl--end-of-line-before-input-start))
485485
(string (replace-regexp-in-string "\n\\'" "" string)))
486486
(cider-repl--emit-output-at-pos (current-buffer) string face pos t)
487-
(ansi-color-apply-on-region pos (point-max)))))
487+
(ansi-color-apply-on-region pos (point-max))
488+
489+
;; If the output has a trailing overlay created by ansi-color, it would be
490+
;; extended by the following outputs. To avoid this, ansi-color adds
491+
;; `ansi-color-freeze-overlay' to the `modification-hooks', but it never
492+
;; seems to be called. By using `insert-behind-hooks' instead, we can make
493+
;; it work. For more details, please see
494+
;; https://github.com/clojure-emacs/cider/issues/1452
495+
(dolist (ov (overlays-at (1- (cider-repl--end-of-line-before-input-start))))
496+
;; Ensure ov is created by ansi-color
497+
(when (and (member #'ansi-color-freeze-overlay (overlay-get ov 'modification-hooks))
498+
(not (member #'ansi-color-freeze-overlay (overlay-get ov 'insert-behind-hooks))))
499+
(push #'ansi-color-freeze-overlay (overlay-get ov 'insert-behind-hooks)))))))
488500

489501
(defun cider-repl-emit-interactive-stdout (string)
490502
"Emit STRING as interactive output."

0 commit comments

Comments
 (0)