unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60660: Support git-formatted patches in diff-mode
@ 2023-01-08 18:21 Juri Linkov
  2023-01-08 18:51 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2023-01-08 18:21 UTC (permalink / raw)
  To: 60660

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: diff-font-lock-changed.patch --]
[-- Type: text/x-diff, Size: 1339 bytes --]

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)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#60660: Support git-formatted patches in diff-mode
  2023-01-08 18:21 bug#60660: Support git-formatted patches in diff-mode Juri Linkov
@ 2023-01-08 18:51 ` Eli Zaretskii
  2023-01-09  7:54   ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-01-08 18:51 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60660

> From: Juri Linkov <juri@linkov.net>
> Date: Sun, 08 Jan 2023 20:21:23 +0200
> 
> 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.

OK for the emacs-29 branch (although I'm surprised that
diff-beginning-of-hunk can return a position that is not before
point).

Thanks.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#60660: Support git-formatted patches in diff-mode
  2023-01-08 18:51 ` Eli Zaretskii
@ 2023-01-09  7:54   ` Juri Linkov
  2023-09-05 23:30     ` Stefan Kangas
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2023-01-09  7:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 60660

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

Pushed to the emacs-29 branch.

> (although I'm surprised that diff-beginning-of-hunk can return
> a position that is not before point).

Indeed, strange to see this in 'diff-beginning-of-hunk':

      (cond ...
        ((re-search-backward regexp nil t)) ; In the middle of a hunk.
        ((re-search-forward regexp nil t) ; At first hunk header.
                    =======

Need to experiment more with this in master.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#60660: Support git-formatted patches in diff-mode
  2023-01-09  7:54   ` Juri Linkov
@ 2023-09-05 23:30     ` Stefan Kangas
  2024-01-10 22:37       ` Stefan Kangas
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Kangas @ 2023-09-05 23:30 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, 60660

Juri Linkov <juri@linkov.net> writes:

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

So is there more to do here, or should this bug be closed?  I'm not sure
if it's still needed to track the below.

>> (although I'm surprised that diff-beginning-of-hunk can return
>> a position that is not before point).
>
> Indeed, strange to see this in 'diff-beginning-of-hunk':
>
>       (cond ...
>         ((re-search-backward regexp nil t)) ; In the middle of a hunk.
>         ((re-search-forward regexp nil t) ; At first hunk header.
>                     =======
>
> Need to experiment more with this in master.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#60660: Support git-formatted patches in diff-mode
  2023-09-05 23:30     ` Stefan Kangas
@ 2024-01-10 22:37       ` Stefan Kangas
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Kangas @ 2024-01-10 22:37 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, 60660-done

Stefan Kangas <stefankangas@gmail.com> writes:

> Juri Linkov <juri@linkov.net> writes:
>
>>>> This patch for emacs-29 fixes this bug, and the rest of fontification
>>>> could be implemented in master.
>>>
>>> OK for the emacs-29 branch
>>
>> Pushed to the emacs-29 branch.
>
> So is there more to do here, or should this bug be closed?  I'm not sure
> if it's still needed to track the below.
>
>>> (although I'm surprised that diff-beginning-of-hunk can return
>>> a position that is not before point).
>>
>> Indeed, strange to see this in 'diff-beginning-of-hunk':
>>
>>       (cond ...
>>         ((re-search-backward regexp nil t)) ; In the middle of a hunk.
>>         ((re-search-forward regexp nil t) ; At first hunk header.
>>                     =======
>>
>> Need to experiment more with this in master.

No further comments, so I'm closing this now.  Please reopen if it's
needed to track the above.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-10 22:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08 18:21 bug#60660: Support git-formatted patches in diff-mode Juri Linkov
2023-01-08 18:51 ` Eli Zaretskii
2023-01-09  7:54   ` Juri Linkov
2023-09-05 23:30     ` Stefan Kangas
2024-01-10 22:37       ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).