-
Notifications
You must be signed in to change notification settings - Fork 41
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
custom color settings in .ripgreprc and xterm-color-filter break rg-results #65
Comments
After some experimentation, the following modifications let
|
Thanks for the report.
This should work on master. Which version did you test on?
I don't know how you inject xterm-color into compilation-mode but it should work with something like Regarding your second modification, note that some features in the results buffer will not work, like some navigation, alignment of line and color numbers, hiding of color numbers etc. |
I'm using version 1.8, from melpa yesterday -- I think it is the same as master? The specific --colors options that result in errors in the process-filter that I tried have to do with underline/font-weight, eg.
which looks like this with xterm-color-filter The actual error is caused by But, regardless of the error (if I set that variable to nil, there is no error), the
Yea, the things you mentioned don't work without I haven't run into any problems b/w font-locking and xterm-color AFAIR. |
Oh, yeah, those are probably added to the color is specified on command the line. I think I would have to use the The suggestion for the order of Having a more tight integration with xterm-color isn't high on my priority list right now but let's keep this issue open for now for visibility in case someone else think it's useful. |
Sounds good, thanks! |
I'm the author of xterm-color.el. I don't use rg.el or ag.el but someone filed an ag.el ANSI escape matching issue recently and I was curious to see if other packages were affected. My answer also applies to rg.el. You should absolutely not depend on ANSI escapes when you do matching on results. Hardcoding specific ANSI SGR sequences in the code should be considered a broken design since it makes terminal assumptions that could very well not hold and is also a boundary violation. I urge you to find something else to match on. |
Thanks for the input. In theory you are probably correct. This works well enough in practice though. |
I don't agree that raw terminal ANSI sequences being part of the compilation-filter output is a reasonable expectation. Main issue: rg.el (and ag.el) match on raw hardcoded terminal-specific ANSI sequences. As I explained, this is broken design. compilation-mode uses these variables that contain patterns to match on:
Notice that there are absolutely no terminal escapes in there. It's just matching on text output. |
I want to chime in here as a mere user of both Can't we get past this impasse? |
How hard can it be to have rg.el match on text output? I don't use it so I can't really say, but it doesn't sound hard. |
@diamond-lizard Not much I can do as a downstream package. @atomontage As for how hard it would be, essentially you'd had to emulate ripgrep's regexp engine to be able to highlight search matches. That is not all but should at least take more than 20 minutes for most people... |
I believe this should at least be fixed on emacs 28 master, where the aforementioned error in |
Let me expand on this since you didn't provide details. grep.el has an optional "highlight matches" mode, There is a separation of concerns between semantic matching and highlighting. Since xterm-color For anyone that wants rg.el to work with xterm-color, the following steps ought to work:
So you don't need to emulate ripgrep's regexp engine to highlight search matches. Assume that xterm-color will do that, EDIT: I will update xterm-color documentation and make it obvious that configuring compilation-mode in the way I recommend, breaks rg and ag.el. |
Well, the thing is of course that escape codes are used for semantic data. This is the case for this package and also for built-in grep.el despite the statements above. I have no idea what ag.el does here though. So, essentially this all boils down to trade-offs (which is the usual case in all software projects). So I am not closing the door to actually supporting this but any comments claiming it's a "20 min fix" or similar is clearly missing the target. This package has been moving in the opposite direction for a while now and might even come to the point where using xterm-color doesn't make sense. I have been experimenting with using the ripgrep json putput which will solve all matching issues without using color escapes. Unfortunately the performance has not been up to par with current implementation so unsure if I will switch. With all that said, my main concern is to avoid that this package is broken for users wanting to use xterm-color (which is a really cool package btw). Hooking xterm-color into |
I did some experiments with ripgrep's json output and parsing it is super fast in an Emacs built with jansson. |
It took me a bit to figure out what was wrong here, and I don't think it is documented
anywhere. Here are a couple issues I ran into:
If custom colors are defined in ~/.ripgreprc, eg.
--colors=path:fg:cyan
etc. thenfont-locking and other functions in the rg-results buffer don't work.
Using
xterm-color-filter
also breaks rg's compilation (fromxterm-color
library)I usually use
xterm-color-filter
in mycompilation-start-hook
to interpret shell escapes,however, since rg (like ag.el) relies on shell escapes for parsing, font-lock/other functions
also break in the rg-results buffer.
Quick fix is to remove xterm-color support around
rg-run
It looks like it would probably be out-of-the question to add support to
rg-results
thatdidn't rely on escape codes, but it might be helpful to mention incompatibilities somewhere.
The text was updated successfully, but these errors were encountered: