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

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

bug#60660: Support git-formatted patches in diff-mode


From: Juri Linkov
Subject: bug#60660: Support git-formatted patches in diff-mode
Date: Sun, 08 Jan 2023 20:21:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

Currently, there is a lot of misfontification in diff-mode visiting a git patch.
Two dashes in the signature separator are highlighted with the diff-removed face
(the existing diff-prev-line-if-patch-separator is used for something else).
Three dashes in the git patch header that separate a list of affected files
are highlighted with the diff-hunk-header face, etc.

But the worst case that raises an error is when an exclamation mark is used
at the beginning of the line in the git patch message.

This patch for emacs-29 fixes this bug, and the rest of fontification
could be implemented in master.

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index acfd2c30f0c..eb01dede56e 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -485,17 +485,19 @@ diff-font-lock-keywords
          ;; if below, use `diff-added'.
          (save-match-data
            (let ((limit (save-excursion (diff-beginning-of-hunk))))
-             (if (save-excursion (re-search-backward 
diff-context-mid-hunk-header-re limit t))
-                 diff-indicator-added-face
-               diff-indicator-removed-face)))))
+              (when (< limit (point))
+                (if (save-excursion (re-search-backward 
diff-context-mid-hunk-header-re limit t))
+                   diff-indicator-added-face
+                 diff-indicator-removed-face))))))
      (2 (if diff-use-changed-face
            'diff-changed-unspecified
          ;; Otherwise, use the same method as above.
          (save-match-data
            (let ((limit (save-excursion (diff-beginning-of-hunk))))
-             (if (save-excursion (re-search-backward 
diff-context-mid-hunk-header-re limit t))
-                 'diff-added
-               'diff-removed))))))
+             (when (< limit (point))
+                (if (save-excursion (re-search-backward 
diff-context-mid-hunk-header-re limit t))
+                   'diff-added
+                 'diff-removed)))))))
     ("^\\(?:Index\\|revno\\): \\(.+\\).*\n"
      (0 'diff-header) (1 'diff-index prepend))
     ("^\\(?:index .*\\.\\.\\|diff \\).*\n" . 'diff-header)

reply via email to

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