emacs-diffs
[Top][All Lists]
Advanced

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

master f0768d3: Fix 'diff-font-lock-prettify' breaking display of outlin


From: Lars Ingebrigtsen
Subject: master f0768d3: Fix 'diff-font-lock-prettify' breaking display of outline headers
Date: Thu, 4 Nov 2021 22:50:10 -0400 (EDT)

branch: master
commit f0768d31457bb9740957958d6b8abc281d5012d8
Author: Matthias Meulien <orontee@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Fix 'diff-font-lock-prettify' breaking display of outline headers
    
    * lisp/vc/diff-mode.el (diff-outline-level): Make hunk headers be
    at level 2.
    (diff-mode): Use prettified line as outline header.
    (diff--outline-level): New function (bug#51016).
    
    * lisp/vc/vc.el (vc-diff-internal): Fix diff mode being set before
    content inserted (bug#51016).
---
 lisp/vc/diff-mode.el | 25 +++++++++++++++++--------
 lisp/vc/vc.el        |  5 +++--
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index ae1a8b2..746f76b 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -893,6 +893,9 @@ data such as \"Index: ...\" and such."
       ;; 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
@@ -1493,7 +1496,6 @@ a diff with \\[diff-reverse-direction].
 
   (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
@@ -1542,7 +1544,12 @@ a diff with \\[diff-reverse-direction].
     (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
@@ -2602,13 +2609,15 @@ fixed, visit it in a buffer."
                            (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 927a241..df8990c 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1793,7 +1793,6 @@ Return t if the buffer had changes, nil otherwise."
         (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 @@ Return t if the buffer had changes, nil otherwise."
       ;; 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)))



reply via email to

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