rc diff: skip email quotes in diff-jump

When reading and writing emails that contain patches (possibly
email-quoted), it can be convenient to the jump to the source file.
Allow this by making diff-jump (bound to <ret> in git-diff
buffers) ignore leading email quotes ("> "). A line that starts with
"> " should not occur in a unified diff, so this won't affect other
use cases.

Observe that diff-jump even works around interleaved replies; they
will not affect the computed line numbers because we ignore lines
that don't match ^(> )*[ +-].
This commit is contained in:
Johannes Altmanninger 2022-01-25 08:07:29 +01:00
parent bf239ba77a
commit 90b070034d

View File

@ -32,7 +32,7 @@ Switches:
set-register c %val{cursor_column} set-register c %val{cursor_column}
# If there is a "diff" line, we don't need to look further back. # If there is a "diff" line, we don't need to look further back.
try %{ try %{
execute-keys %{<a-l><semicolon><a-?>^diff\b<ret><a-x>} execute-keys %{<a-l><semicolon><a-?>^(?:> )*diff\b<ret><a-x>}
} catch %{ } catch %{
# A single file diff won't have a diff line. Start parsing from # A single file diff won't have a diff line. Start parsing from
# the buffer start, so we can tell if +++/--- lines are headers # the buffer start, so we can tell if +++/--- lines are headers
@ -73,6 +73,7 @@ Switches:
$have_diff_line = 0; $have_diff_line = 0;
$state = "header"; $state = "header";
while (<STDIN>) { while (<STDIN>) {
s/^(> )*//g;
$last_line = $_; $last_line = $_;
if (m{^diff\b}) { if (m{^diff\b}) {
$state = "header"; $state = "header";