Subject: Re: bug#59888: [PATCH] Add 'grep-use-headings'

From: Augusto Stoffel <[email-masked]>
Date: Tue, 28 Feb 2023 19:17:45 +0100

On Tue, 28 Feb 2023 at 19:24, Juri Linkov wrote:

>> +(defvar grep-heading-regexp
>> +  (rx bol
>> +      (or
>> +       (group-n 2
>> +         (group-n 1 (+ (not (any 0 ?\n))))
>> +         0)
>> +       (group-n 2
>> +        (group-n 1 (+? nonl))
>> +        (any ?: ?- ?=)))
>> +      (+ digit)
>> +      (any ?: ?- ?=))
>
> I wonder what is the reason for this regexp to be different
> from grep-regexp-alist?  Especially with such additional characters
> as ?- and ?=.  This mismatch causes wrong handling of files when
> file names contain these characters.

This is because of context lines:

--8<---------------cut here---------------start------------->8---
$ git grep -nC 1 grep-use-headings
etc/NEWS-99-
etc/NEWS:100:*** New user option 'grep-use-headings'.
etc/NEWS-101-When non-nil, the output of Grep is split into sections, one for each
--
lisp/progmodes/grep.el-459-
lisp/progmodes/grep.el:460:(defcustom grep-use-headings nil
lisp/progmodes/grep.el-461-  "If non-nil, subdivide grep output into sections, one per file."
--
lisp/progmodes/grep.el-465-(defface grep-heading `((t :inherit ,grep-hit-face))
lisp/progmodes/grep.el:466:  "Face of headings when `grep-use-headings' is non-nil."
lisp/progmodes/grep.el-467-  :version "30.1")
--
lisp/progmodes/grep.el-969-                  (string-replace "\0" ":" string)))
lisp/progmodes/grep.el:970:  (when grep-use-headings
lisp/progmodes/grep.el-971-    (add-hook 'compilation-filter-hook #'grep--heading-filter 80 t)
--8<---------------cut here---------------end--------------->8---

(I forget which program uses the =LINE= syntax)

At least when using grep --null, I think there is no confusion possible.  I
wrote a unit test that purports to prove that.