Skip to content

Commit

Permalink
[Fix clojure-emacs#1452] Fix broken ANSI coloring in the repl
Browse files Browse the repository at this point in the history
  • Loading branch information
rfkm authored and cap10morgan committed Dec 27, 2015
1 parent e3dea09 commit dd1871a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [#1466](https://github.com/clojure-emacs/cider/issues/1466): Correctly font-lock pretty-printed results in the REPL.
* [#1475](https://github.com/clojure-emacs/cider/pull/1475): Fix `args-out-of-range` error in `cider--get-symbol-indent`.
* [#1479](https://github.com/clojure-emacs/cider/pull/1479): Make paredit and `cider-repl-mode` play nice.
* [#1452](https://github.com/clojure-emacs/cider/issues/1452): Prevent ANSI color overlays in the REPL buffer from being extended.

## 0.10.0 / 2015-12-03

Expand Down
14 changes: 13 additions & 1 deletion cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,19 @@ If BOL is non-nil insert at the beginning of line."
(let ((pos (cider-repl--end-of-line-before-input-start))
(string (replace-regexp-in-string "\n\\'" "" string)))
(cider-repl--emit-output-at-pos (current-buffer) string face pos t)
(ansi-color-apply-on-region pos (point-max)))))
(ansi-color-apply-on-region pos (point-max))

;; If the output has a trailing overlay created by ansi-color, it would be
;; extended by the following outputs. To avoid this, ansi-color adds
;; `ansi-color-freeze-overlay' to the `modification-hooks', but it never
;; seems to be called. By using `insert-behind-hooks' instead, we can make
;; it work. For more details, please see
;; https://github.com/clojure-emacs/cider/issues/1452
(dolist (ov (overlays-at (1- (cider-repl--end-of-line-before-input-start))))
;; Ensure ov is created by ansi-color
(when (and (member #'ansi-color-freeze-overlay (overlay-get ov 'modification-hooks))
(not (member #'ansi-color-freeze-overlay (overlay-get ov 'insert-behind-hooks))))
(push #'ansi-color-freeze-overlay (overlay-get ov 'insert-behind-hooks)))))))

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

0 comments on commit dd1871a

Please sign in to comment.