dajva / rg.el

Emacs search tool based on ripgrep
https://rgel.readthedocs.io
GNU General Public License v3.0
471 stars 38 forks source link

Bug in rg-filter impacting font locking #99

Closed charignon closed 3 years ago

charignon commented 3 years ago

When performing searches that lead to a lot of results (thousands or more), I notice that on a few lines the column number remains event when I set (setq rg-show-columns nil). This impacts the font-locking and visual of the result buffer.

If I were to guess, this may have to do with the fact that we think we are dealing with whole line in rg-filter when we are not. I know we account for line ending in there but I think there is a subtle bug that shows with search that display a large volume of data. I haven't figured out more than that so far.

dajva commented 3 years ago

Thanks for the report. I have not seen that myself. Which version of emacs do you use? M-x emacs-version What rg settings do you use? Eval the following in scratch and copy the output in the report.

(defun rg-print-settings ()
  "Print all the active customization options for this package."
  (interactive)
  (let ((settings
         (thread-last (custom-group-members 'rg nil)
           (seq-filter (lambda (item)
                         (eq (cadr item) 'custom-variable)))
           (mapcar (lambda (member)
                     (cons (car member) (symbol-value (car member))))))))
    (message "--------- RG settings ---------\n%s\n------------- END -------------"
             (mapconcat
              (lambda (setting) (format "%S: %S" (car setting) (cdr setting)))
              settings "\n"))))
(rg-print-settings)
dajva commented 3 years ago

Can you also post a screen shot of the faulty rendering?

charignon commented 3 years ago
"--------- RG settings ---------                                                                                                      
rg-use-transient-menu: t                                                                                                              
rg-show-columns: nil                                                                                                                  
rg-group-result: t                                                                                                                    
rg-show-header: t                                                                                                                     
rg-hide-command: t                                                                                                                    
rg-align-position-numbers: t                                                                                                          
rg-align-line-number-field-length: 4                                                                                                  
rg-align-column-number-field-length: 3                                                                                                
rg-align-line-column-separator: \" \"                                                                                                 
rg-align-position-content-separator: \" \"                                                                                            
rg-custom-type-aliases: ((\"gyp\" . \"*.gyp *.gypi\"))                                                                                
rg-executable: \"/usr/bin/rg\"                                                                                                        
rg-command-line-flags: nil                                                                                                            
rg-ignore-case: case-fold-search                                                                                                      
rg-keymap-prefix: \"^Cs\"                                                                                                             
rg-default-alias-fallback: \"all\"                                                                                                    
rg-buffer-name: \"rg\"                                                                                                                
rg-ignore-ripgreprc: t                                                                                                                
------------- END -------------"

Screenshot from 2020-10-03 16-06-47

For example searching for "defun" in "fastai" Using emacs 27.1.50 on Manjaro with rg 12.1.1

dajva commented 3 years ago

Hmm, this seems like a tricky one. It's a bit hard to see in the screenshot but looks like the font changes on the line of the error and all the results after. Could you place cursor on such a faulty line, line and column number separately and run M-x describe-text-properties? And the same for correct line after that looks to have a modified fortification.

charignon commented 3 years ago

Another example with the information that you need: Screenshot from 2020-10-04 11-22-11 At the beginning of the green "faulty" line on "198": Screenshot from 2020-10-04 11-22-32 At the beginning of the line right before on "194": Screenshot from 2020-10-04 11-23-03

dajva commented 3 years ago

Thanks, this looks like an ansi-color issue. I thought ansi-color only integrated into comint mode which shouldn't be used by this package. Do you have some custom hook in compilation mode for ansi-color or similar?

Anyway. My guess would be (judging from the screen shots) that the output is first handled by rg in rg-filter which will filter out all SGR color codes except for an incomplete line at the end. After that the ansi-color somehow comes into play and apply color and removing color codes that were left out. When new output is inserted in the buffer rg-filter is called again but now the expected leading SGR codes at the start of the first line is missing and the line:column: is not matched.

GambolingPangolin commented 3 years ago

I'm running into the same problem

"--------- RG settings ---------
rg-use-transient-menu: t
rg-show-columns: t
rg-group-result: t
rg-show-header: t
rg-hide-command: t
rg-align-position-numbers: t
rg-align-line-number-field-length: 4
rg-align-column-number-field-length: 3
rg-align-line-column-separator: \" \"
rg-align-position-content-separator: \" \"
rg-custom-type-aliases: ((\"gyp\" . \"*.gyp *.gypi\"))
rg-executable: \"/usr/bin/rg\"
rg-command-line-flags: nil
rg-ignore-case: case-fold-search
rg-keymap-prefix: \"s\"
rg-default-alias-fallback: \"all\"
rg-buffer-name: \"rg\"
rg-ignore-ripgreprc: t
------------- END -------------"

Emacs 27.1 (doom) Arch Linux rg 12.1.1

dajva commented 3 years ago

For doom the problems lies here: https://github.com/hlissner/doom-emacs/blob/29b12de83e5f8ce76e9ff38549753c69bc507650/core/core-ui.el#L373 This should really be reported as a doom bug since this could break any compilation-mode downstream package. OTOH, this package, built-in grep.el and ag.el could be affected in different ways, unknown to what extent.

The config workaround for this would be something along these lines:

(defun rg-clear-doom-ansi-color-compilation-hook ()
  (make-local-variable 'compilation-filter-hook)
  (remove-hook 'compilation-filter-hook #'doom-apply-ansi-color-to-compilation-buffer-h))

(add-hook 'rg-mode-hook 'rg-clear-doom-ansi-color-compilation-hook)

I will make improvements to this package to make it less sensitive to such things but it's not possible to solve for real here.

@charignon Are your setup also doom based?

GambolingPangolin commented 3 years ago

Thanks for the tip! I'll see if I can get your workaround to work in my setup.

charignon commented 3 years ago

Yes, the workaround works for me, and it is not an issue with rg.el then. Thank you so much for your responsiveness and help on this @dajva 👍 🥇

GambolingPangolin commented 3 years ago

It works for me too. Thanks again!

dajva commented 3 years ago

I realised this could actually be fixed from this package so should work without the hook now.