Skip to content

[Fix #1452] Fix broken ANSI coloring in the repl #1455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and try to associate the created connection with this project automatically.
* [#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