emacs-diffs
[Top][All Lists]
Advanced

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

master 910cdcf8c3: * lisp/vc/diff-mode.el (diff--font-lock-prettify): Fi


From: Stefan Monnier
Subject: master 910cdcf8c3: * lisp/vc/diff-mode.el (diff--font-lock-prettify): Fix mishaps
Date: Sat, 19 Feb 2022 13:45:12 -0500 (EST)

branch: master
commit 910cdcf8c3939b84f0eaeb178119dd32f867411d
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/vc/diff-mode.el (diff--font-lock-prettify): Fix mishaps
    
    This reverts the last change so it also applies to non-git diffs again.
    Instead, we're now more careful not to mis-recognize file headers as
    addition/removal lines.
    In addition to that, mark the file header such that it's
    re-font-locked all at once, and to still recognize it after
    `diff-reverse-direction`.
---
 lisp/vc/diff-mode.el | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index d0c05d3204..fb622bb6f9 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2599,22 +2599,23 @@ fixed, visit it in a buffer."
   nil nil 'center)
 
 (defun diff--font-lock-prettify (limit)
-  (when (and diff-font-lock-prettify
-             (eq diff-buffer-type 'git))
+  (when diff-font-lock-prettify
     (save-excursion
       ;; FIXME: Include the first space for context-style hunks!
       (while (re-search-forward "^[-+! ]" limit t)
-        (let ((spec (alist-get (char-before)
-                               '((?+ . (left-fringe diff-fringe-add 
diff-indicator-added))
-                                 (?- . (left-fringe diff-fringe-del 
diff-indicator-removed))
-                                 (?! . (left-fringe diff-fringe-rep 
diff-indicator-changed))
-                                 (?\s . (left-fringe diff-fringe-nul 
fringe))))))
-          (put-text-property (match-beginning 0) (match-end 0) 'display 
spec))))
+        (unless (eq (get-text-property (match-beginning 0) 'face) 'diff-header)
+          (let ((spec
+                 (alist-get
+                  (char-before)
+                  '((?+ . (left-fringe diff-fringe-add diff-indicator-added))
+                    (?- . (left-fringe diff-fringe-del diff-indicator-removed))
+                    (?! . (left-fringe diff-fringe-rep diff-indicator-changed))
+                    (?\s . (left-fringe diff-fringe-nul fringe))))))
+            (put-text-property (match-beginning 0) (match-end 0)
+                               'display spec)))))
     ;; Mimicks the output of Magit's diff.
     ;; FIXME: This has only been tested with Git's diff output.
     (while (re-search-forward "^diff " limit t)
-      ;; FIXME: Switching between context<->unified leads to messed up
-      ;; file headers by cutting the `display' property in chunks!
       (when (save-excursion
               (forward-line 0)
               (looking-at
@@ -2622,19 +2623,21 @@ fixed, visit it in a buffer."
                  (concat "diff.*\n"
                          "\\(?:\\(?:new file\\|deleted\\).*\n\\)?"
                          "\\(?:index.*\n\\)?"
-                         "--- \\(?:" null-device "\\|a/\\(.*\\)\\)\n"
-                         "\\+\\+\\+ \\(?:" null-device "\\|b/\\(.*\\)\\)\n"))))
-        (put-text-property (match-beginning 0) (1- (match-end 0))
-                           'display
-                           (propertize
-                            (cond
-                             ((null (match-string 1))
-                              (concat "new file  " (match-string 2)))
-                             ((null (match-string 2))
-                              (concat "deleted  " (match-string 1)))
-                             (t
-                              (concat "modified  " (match-string 1))))
-                            'face '(diff-file-header diff-header))))))
+                         "--- \\(?:" null-device "\\|[ab]/\\(.*\\)\\)\n"
+                         "\\+\\+\\+ \\(?:" null-device 
"\\|[ab]/\\(.*\\)\\)\n"))))
+        (add-text-properties
+         (match-beginning 0) (1- (match-end 0))
+         (list 'display
+               (propertize
+                (cond
+                 ((null (match-string 1))
+                  (concat "new file  " (match-string 2)))
+                 ((null (match-string 2))
+                  (concat "deleted  " (match-string 1)))
+                 (t
+                  (concat "modified  " (match-string 1))))
+                'face '(diff-file-header diff-header))
+               'font-lock-multiline t)))))
   nil)
 
 ;;; Syntax highlighting from font-lock



reply via email to

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