full-ack icon indicating copy to clipboard operation
full-ack copied to clipboard

Use ack-grep line number and file name color code for font lock

Open YorkZ opened this issue 9 years ago • 5 comments

Hi Nikolaj,

I've been using full-ack for a few years now. Thank you very much for this useful tool. Please check out my two pull request, the font lock one has been a life saver for me.

Thanks,

York

YorkZ avatar Sep 30 '15 02:09 YorkZ

Thanks. The changes look good. But can you tell me why the font locking changes are necessary, and an example what ack-before-search-starts might be used for?

nschum avatar Oct 03 '15 10:10 nschum

But can you tell me why the font locking changes are necessary

full-ack uses this regexp:

(defconst ack-font-lock-regexp-line
  (concat "\\(" ack-font-lock-regexp-color-fg-begin "?\\)"
          "\\([0-9]+\\)"
          "\\(" ack-font-lock-regexp-color-end "?\\)"
          "[:-]")
  "Matches the line output from ack (with or without color).
Color is used starting ack 1.94.")

to identify line numbers in the ack-grep output. The problem is that, if file names in ack-grep output also begin with numbers followed by a dash (-), e.g., if a file name is "1234-5/foo.cpp", using ack-font-lock-regexp-line regexp, it will be mistakenly identified as a line number and therefore be font-locked as a line number, making the search results extremely hard to read.

ack-grep produces the output, it knows which part is the file name, and which part is the line number, and has marked them with different color codes. Therefore, I think the most reliable approach would be to simply use the ack-grep color codes in the line and file name regexp. This will work as long as one uses an ack version 1.94 or newer. Do you have other reliable solution without using the ack-grep color codes?

and an example what ack-before-search-starts might be used for?

I use speck.el for spell check, but I noticed that if speck is doing spell checking in the background, full-ack could be slowed down significantly. I added these hooks so that I could stop spell check before starting ack search and then re-start it after ack search is done.

York

YorkZ avatar Oct 03 '15 15:10 YorkZ

I understand. Sounds good.

What happens if the user configures ack to use different colors? Shouldn't we add explicit --color-filename, --color-match and --color-lineno to ack-arguments-from-options to make sure they are what the regexp expects them to be?

nschum avatar Oct 03 '15 18:10 nschum

Shouldn't we add explicit --color-filename, --color-match and --color-lineno to ack-arguments-from-options to make sure they are what the regexp expects them to be

That would be better. I was not 100% sure if ack-grep provided users the means to customize colors. Also, I thought probably very little people would want change the default colors. Please feel free to add the feature if you want. Otherwise, I might add it when I get some time.

By the way, I'm currently playing with the silver searcher. It's really much faster than ack-grep. Have you used it already? What's your opinion? I really love it's lightening speed, but I don't like the output from ag.el. I'm thinking about making full-ack.el work with ag. Thoughts?

York

YorkZ avatar Oct 03 '15 19:10 YorkZ

I'm going to leave this PR open until you or I get the chance to add this. I don't want to merge in a change that might cause problems for existing users.

Yes, I have switched to ag recently. I'm not doing my coding in Emacs right now, so I haven't had a reason to work support it. Any contribution would be very welcome.

nschum avatar Oct 05 '15 11:10 nschum