]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix 'diff-font-lock-prettify' breaking display of outline headers
authorMatthias Meulien <orontee@gmail.com>
Fri, 5 Nov 2021 02:50:01 +0000 (03:50 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 5 Nov 2021 02:50:01 +0000 (03:50 +0100)
* 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
lisp/vc/vc.el

index ae1a8b254ff2686e0275e5ff9ef4143ea6f5603a..746f76b46c3b96ddc02015e5fc9ac571540bee2c 100644 (file)
@@ -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
index 927a241a6068dba1a420e88a4e23522fe92cc4c4..df8990c118729c2d1c67965b66959ae9fecfe2f9 100644 (file)
@@ -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)))