Skip to content
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

ag.el is highlighting (to the extreme) even when ag-highlight-search is nil #124

Open
tomjakubowski opened this issue Sep 29, 2016 · 6 comments

Comments

@tomjakubowski
Copy link
Contributor

On my machine, the output of ag --version is:

% ag --version
ag version 0.33.0

Features:
  +jit +lzma +zlib

My Emacs version is: 25.0.92.1

I'm using: OS X 10.11


First off, thank you so much for ag.el. The C-c a keys on my keyboard are wearing down at an impressive rate thanks to your plugin :-)

I've been struggling with this bug for some time now, but finally managed to make it happen in a directory I'm allowed to share screenshots of.

If I execute C-h v ag-highlight-search, it tells me the value is nil.

And yet! When I run M-x ag I see some words highlighted. Sometimes, it's just the word I searched for -- though not all instances of that word are highlighted. Other times, the highlighting goes off the rails and it continues well past the end of the word I searched for.

Here's a screenshot:

screen shot 2016-09-29 at 11 03 43 am

(note to self: repro by searching registry in the meow root dir)

I'm working on a reproduction that's both small and which I'd be allowed to share with you, but maybe the screenshot will be enough for you to see where the problem is.

@tomjakubowski
Copy link
Contributor Author

Taking a quick look at that, it seems like highlighting goes off the rails whenever there is more than one match on a single line.

@Wilfred
Copy link
Owner

Wilfred commented Sep 30, 2016

What's the full ag command you're running? It should be at the top of the *Ag* buffer.

@tomjakubowski
Copy link
Contributor Author

ag --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- registry .

@bcobb
Copy link

bcobb commented Jun 19, 2017

👋 Just noting here that I was able to stop the over-aggressive highlighting by applying the following patch:

diff --git a/ag.el b/ag.el
index a41d7c5..bea9a7f 100644
--- a/ag.el
+++ b/ag.el
@@ -215,8 +215,7 @@ If REGEXP is non-nil, treat STRING as a regular expression."
     (unless (equal (car (last arguments)) "--")
       (setq arguments (append arguments '("--"))))
     (setq arguments
-          (append '("--line-number" "--column" "--color" "--color-match" "30;43"
-                    "--color-path" "1;32")
+          (append '("--line-number" "--column" "--nocolor")
                   arguments))
     (if ag-group-matches
         (setq arguments (cons "--group" arguments))

It makes for a plainer results buffer, but I am now able to see what I was searching for again 😄. Sadly, I don't yet understand why this change fixes the highlighting.


Edit: Unfortunately, something about this breaks my ability to navigate from search results to source buffers 😞

jarvisschultz added a commit to jarvisschultz/system_configurations that referenced this issue May 3, 2018
+ Updated org package source to get up-to-date releases (read here)[http://irreal.org/blog/?p=6899]

+ Had an issue very similar to what was
described (here)[Wilfred/ag.el#124], tracked this down
to the fact that Ag major mode inherits from compilation mode. My hook for
colorizing the ANSI colors was breaking Ag coloring. Hook now only runs if major
mode is compilation-mode. Seems to work for all packages in my normal workflow
right now. Note that many people recommend using `compilation-filter-start'
variable instead of `(point-min)' and `(point-max)' (see (for example
here)[https://stackoverflow.com/questions/13397737/ansi-coloring-in-compilation-mode],
but that wasn't working for me. Didn't bother to track down
@jarvisschultz
Copy link

Not sure is this is applicable to the errors others are reporting, but I was having seemingly the same issue, and I tracked it down to the fact that the Ag output buffers have compilation-mode as a parent mode. I had a hook for dealing with ANSI color codes in compilation buffers (as many people do ex1, ex2, ex3, ex4) that was breaking Ag coloring.

By modifying my hook to only run in buffers that have compilation-mode as their major-mode, this highlighting issue disappeared for me. New hook code:

(ignore-errors
  (require 'ansi-color)
  (defun colorize-compilation-buffer ()
    (when (eq major-mode 'compilation-mode)
      (ansi-color-apply-on-region (point-min) (point-max))))
  (add-hook 'compilation-filter-hook 'colorize-compilation-buffer))

bcobb added a commit to bcobb/ohai-emacs that referenced this issue Aug 25, 2018
loysollivier added a commit to loysollivier/spacemacs that referenced this issue Jul 16, 2020
Some modes have compilation-mode has parent mode but the ansi coloring
scheme is breaking their highlighting.
i.e. Wilfred/ag.el#124

Fix this by applying ansi-colors only when the major mode is
compilation-mode.

Signed-off-by: Loys Ollivier <[email protected]>
loysollivier added a commit to loysollivier/spacemacs that referenced this issue Jul 16, 2020
Some modes have compilation-mode as parent mode but the ansi coloring
scheme is breaking their highlighting.
i.e. Wilfred/ag.el#124

Fix this by applying ansi-colors only when the major mode is
compilation-mode.

Signed-off-by: Loys Ollivier <[email protected]>
smile13241324 pushed a commit to syl20bnr/spacemacs that referenced this issue Jul 18, 2020
Some modes have compilation-mode as parent mode but the ansi coloring
scheme is breaking their highlighting.
i.e. Wilfred/ag.el#124

Fix this by applying ansi-colors only when the major mode is
compilation-mode.

Signed-off-by: Loys Ollivier <[email protected]>
aam-at pushed a commit to aam-at/spacemacs that referenced this issue Mar 23, 2021
Some modes have compilation-mode as parent mode but the ansi coloring
scheme is breaking their highlighting.
i.e. Wilfred/ag.el#124

Fix this by applying ansi-colors only when the major mode is
compilation-mode.

Signed-off-by: Loys Ollivier <[email protected]>
@Dushistov
Copy link

Dushistov commented May 6, 2021

@tomjakubowski Your text can be read even with difficulty, here is my (I run M-x ag IgnoreUnlessSpelledInSource in llvm source tree, ag 20201031.2202):

search-in-llvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants