bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#51016: 28.0.50; 'diff-font-lock-prettify' breaks display of outline


From: Matthias Meulien
Subject: bug#51016: 28.0.50; 'diff-font-lock-prettify' breaks display of outline headers
Date: Wed, 13 Oct 2021 22:30:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

I updated the patch after a week using it. Outlines headers are now
updated for diff comming from Git even when diff-font-lock-prettify is
nil.

>From 67ef81b503b2529e28fcdca35912bf5c9ce54d8e Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Sat, 9 Oct 2021 00:36:11 +0200
Subject: [PATCH] Fix outline headers of diff buffers when using Git
 (bug#51016)

* lisp/vc/diff-mode.el (diff-outline-level): Make hunk headers be at level 2
(diff-mode): Use prettified line as outline header
* lisp/vc/vc.el (vc-diff-internal): Fix diff mode being set before content
inserted
---
 lisp/vc/diff-mode.el | 28 ++++++++++++++++++++--------
 lisp/vc/vc.el        |  5 +++--
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 057ffcd06e..f0a6cb7b15 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -894,6 +894,10 @@ diff-split-hunk
       ;; Fix the original hunk-header.
       (diff-fixup-modifs start pos))))
 
+(defun diff-outline-level ()
+  (if (string-match-p diff-hunk-header-re (match-string 0))
+      2 1))
+
 
 ;;;;
 ;;;; jump to other buffers
@@ -1494,7 +1498,6 @@ diff-mode
 
   (setq-local font-lock-defaults diff-font-lock-defaults)
   (add-hook 'font-lock-mode-hook #'diff--font-lock-cleanup nil 'local)
-  (setq-local outline-regexp diff-outline-regexp)
   (setq-local imenu-generic-expression
               diff-imenu-generic-expression)
   ;; These are not perfect.  They would be better done separately for
@@ -1543,7 +1546,17 @@ diff-mode
     (setq-local diff-buffer-type
                 (if (re-search-forward "^diff --git" nil t)
                     'git
-                  nil))))
+                  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))
+  (setq-local outline-regexp diff-outline-regexp))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
@@ -2603,13 +2616,12 @@ diff--font-lock-prettify
                            (or (match-beginning 2) (match-beginning 1))
                            'display (propertize
                                      (cond
-                                      ((null (match-beginning 1)) "new file  ")
-                                      ((null (match-beginning 2)) "deleted   ")
-                                      (t                          "modified  
"))
+                                      ((null (match-beginning 1)) (concat "new 
file  " (match-string 2)))
+                                      ((null (match-beginning 2)) (concat 
"deleted   " (match-string 1)))
+                                      (t                          (concat 
"modified  " (match-string 1))))
                                      'face '(diff-file-header diff-header)))
-        (unless (match-beginning 2)
-          (put-text-property (match-end 1) (1- (match-end 0))
-                             'display "")))))
+        (put-text-property (match-end 1) (1- (match-end 0))
+                           'display ""))))
   nil)
 
 ;;; Syntax highlighting from font-lock
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 5b259fcdb3..c82110274b 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1793,7 +1793,6 @@ vc-diff-internal
         (setq files (nreverse filtered))))
     (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async)
     (set-buffer buffer)
-    (diff-mode)
     (setq-local diff-vc-backend (car vc-fileset))
     (setq-local diff-vc-revisions (list rev1 rev2))
     (setq-local revert-buffer-function
@@ -1815,7 +1814,9 @@ vc-diff-internal
       ;; after `pop-to-buffer'; the former assumes the diff buffer is
       ;; shown in some window.
       (let ((buf (current-buffer)))
-        (vc-run-delayed (vc-diff-finish buf (when verbose messages))))
+        (vc-run-delayed (progn
+                          (vc-diff-finish buf (when verbose messages))
+                          (diff-mode))))
       ;; In the async case, we return t even if there are no differences
       ;; because we don't know that yet.
       t)))
-- 
2.30.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]