Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers

From: Matthias Meulien <[email-masked]>
Date: Mon, 14 Feb 2022 22:33:49 +0100

Matthias Meulien <[email-masked]> writes:

> My first impression is that setting `outline-level' to
> `diff--outline-level' inconditionnaly should work but since I don't
> understand why `diff-outline-regex' hasn't been defined in terms of
> `diff-file-header-re' and `diff-hunk-header-re' I guess I am missing
> some subtleties.
>
> (Note that there's another minor bug when `diff-buffer-type` isn't equal
> to 'git: `diff--font-lock-prettify` should be a no-op since the regexp
> written there match only Git generated diffs, confirmed by the FIXME
> string "This has only been tested with Git's diff output." written in
> the implementation).

Here's the corresponding patch:

>From 4cf31f61caa50ba97e67847b175d598387fabba4 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <[email-masked]>
Date: Mon, 14 Feb 2022 22:29:49 +0100
Subject: [PATCH] Fix computation of outline heading level for non-git diff

* lisp/vc/diff-mode.el (diff-setup-buffer-type): Compute outline heading level
using diff-hunk-header-re.
(diff--font-lock-prettify): Disable prettify in non-git diff.
---
 lisp/vc/diff-mode.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 0bf7899246..d0c05d3204 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -1596,8 +1596,8 @@ diff-setup-buffer-type
                   nil)))
   (when (eq diff-buffer-type 'git)
     (setq diff-outline-regexp
-          (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)"))
-    (setq-local outline-level #'diff--outline-level))
+          (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)")))
+  (setq-local outline-level #'diff--outline-level)
   (setq-local outline-regexp diff-outline-regexp))
 
 (defun diff-delete-if-empty ()
@@ -2599,7 +2599,8 @@ 'diff-fringe-nul
   nil nil 'center)
 
 (defun diff--font-lock-prettify (limit)
-  (when diff-font-lock-prettify
+  (when (and diff-font-lock-prettify
+             (eq diff-buffer-type 'git))
     (save-excursion
       ;; FIXME: Include the first space for context-style hunks!
       (while (re-search-forward "^[-+! ]" limit t)
-- 
2.30.2

Without this patch when I visit the reported woman.patch file I see the
following:

but with the patch I see:

-- 
Matthias