-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
colorize output sent to nrepl buffer #275
Conversation
when present, apply ansi color codes to nrepl output
@@ -726,7 +726,10 @@ DONE-HANDLER as appropriate." | |||
(lambda (buffer value) | |||
(message "%s" value)) | |||
(lambda (buffer value) | |||
(nrepl-emit-interactive-output value)) | |||
(nrepl-emit-interactive-output value) | |||
(with-current-buffer "*nrepl*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work properly, since now we support multiple REPL buffers.
The change seems reasonable to me, but there a few problems with the current PR. Instead of hardcoding |
when ANSI color codes are present use them to colorize nrepl output
Thanks for the comments. I should have taken a closer look to the buffer handling code. I ended up using |
Yep, you're right. I meant |
Use nrepl-emit-interactive-output. Restrict the colorized region to just the recent output.
You are right. I've restricted the area to be ansi colorized to just the most recently printed output. I've avoided the duplication of the coloring code by moving it to nrepl-emit-interactive-output |
Thank you! This is merged to master now. |
You are welcome! glad it was useful |
How do you turn this feature on? When I jack in to nrepl and run Midje autotest, the ANSI escapes come out as plain text rather than coloring the text they enclose. |
It's on by default. Maybe you're not using the latest |
I have the same problem as marick. Using a clone of the git repo from today. The repl prints |
That's my version as well. |
I dug into this further. It turns out that ansi escape sequences are only colorized for some 'response handlers' and not others. Midje outputs to stdout and this handler has not had the ansi-color-apply-on-region function call added to it. I got this working by replacing the
This is a rather ugly hack to prove my understanding is correct. I think the ansi-color-apply-on-region call should be moved to a single place higher in the call stack. It should be called on any output that nrepl is about to write into the buffer, rather than for specific response handlers. |
Here's a sample project you can clone:
If I run it in an emacs shell buffer, I see this: In an nrepl buffer, I see this: I'm running "GNU Emacs 24.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2013-03-12 on bob.porkrind.org". Possibly relevant settings:
|
I'm having the same problem as the recent posters, for the same basic reason that @gregsexton mentioned, My temporary fix has been to add the coloration to the end of (defun cider-emit-output-at-pos (buffer string position &optional bol)
"Using BUFFER, insert STRING at POSITION and mark it as output.
If BOL is non-nil insert at the beginning of line."
(with-current-buffer buffer
(save-excursion
(cider-save-marker cider-repl-output-start
(cider-save-marker cider-repl-output-end
(goto-char position)
(when (and bol (not (bolp))) (insert-before-markers "\n"))
(cider-propertize-region `(face cider-repl-output-face
rear-nonsticky (face))
(insert-before-markers string)
(when (and (= (point) cider-repl-prompt-start-mark)
(not (bolp)))
(insert-before-markers "\n")
(set-marker cider-repl-output-end (1- (point)))))))
(ansi-color-apply-on-region (marker-position cider-repl-output-start)
(point))) ; <<-- the last sexp in excursion is only change
(cider-show-maximum-output))) This has worked fine for a good while now, although as @gregsexton suggests, there may be a more appropriate place for the change. |
You’re using an outdated version of CIDER. I’ve recently fixed this. Cheers, On Friday, November 1, 2013 at 3:35 AM, Christopher Genovese wrote:
|
Ah, my apologies, I didn't catch the update. Thanks, Chris On Fri, Nov 1, 2013 at 2:15 AM, Bozhidar Batsov notifications@github.comwrote:
|
when present, apply ansi color codes to output sent to the nrepl buffer via nrepl-interactive-eval-handler and nrepl-load-file-handler