Subject: Re: bug#78269: diff-outline-regexp

From: Stefan Monnier <[email-masked]>
Date: Mon, 05 May 2025 18:42:07 -0400

> diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
> index a5f4169a7f3..76703526b63 100644
> --- a/lisp/vc/diff-mode.el
> +++ b/lisp/vc/diff-mode.el
> @@ -1719,7 +1719,7 @@ diff-setup-buffer-type
>                        'hg
>                      nil))))
>    (when (eq diff-buffer-type 'git)
> -    (setq diff-outline-regexp
> +    (setq-local diff-outline-regexp
>            (concat "\\(^diff --git.*\\|" diff-hunk-header-re "\\)")))
>    (setq-local outline-level #'diff--outline-level)
>    (setq-local outline-regexp diff-outline-regexp))

LGTM, thanks.

> Probably no one noticed this problem because its current default value
> is not useful to anyone:
>
>   (defvar diff-outline-regexp
>     "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")

I think the idea was to recognize file header and hunk headers, in the
case where the "diff" command itself is absent (as is the case in the
output of the (non-recursive) `diff` command).

> Maybe the default should be replaced with something like
>
>   (defvar diff-outline-regexp
>     (concat "\\(^diff -.*\\|" diff-hunk-header-re "\\)"))

LGTM (I'd even drop the `-` after `diff`).  AFAICT nowadays the "diff
..." command is absent only in cases where there's only one file in the
diff, so matching the file header is not very useful, indeed.

        Stefan