Subject: bug#42609: 28.0.50; Issue with highlight in long files

From: Juri Linkov <[email-masked]>
Date: Thu, 06 Aug 2020 02:43:50 +0300

>> If in line 3407 I do:
>>
>> M-s h r 0x20141e140
>> Only the first 6 occurrences are highlighted
>>
>> Else if I do instead
>> M-g g 73188
>> M-s h r 0x20141e140
>>
>> then only the occurences in lines [73184 -> 91916] are highlighted
>>
>> I don't attach the log because it is too big for an email.
>
> Please try to increase the value of hi-lock-highlight-range.
> Recently it was changed from 200_000 to 2_000_000 in bug#40224.
> Do you think it should be increased more?

My first thought was to add a new option 'nil' "No limit" to
hi-lock-highlight-range.  But actually it's easy to just set it
to a big value.  And this still doesn't solve the problem
when hi-lock gives an impression that it highlights everything.

So a better idea is to notify the user with a warning when hi-lock
highlights less occurrences than there are in the buffer:

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index a18310322a..33ca40f8de 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -812,7 +812,9 @@ hi-lock-set-pattern
               (setq hi-lock-interactive-patterns
                     (cdr hi-lock-interactive-patterns)
                     hi-lock-interactive-lighters
-                    (cdr hi-lock-interactive-lighters)))))))))
+                    (cdr hi-lock-interactive-lighters))))
+          (when (or (> search-start (point-min)) (< search-end (point-max)))
+            (message "Hi-lock added only in range %d-%d" search-start search-end)))))))
 
 (defun hi-lock-set-file-patterns (patterns)
   "Replace file patterns list with PATTERNS and refontify."