rc diff: support absolute paths in diff-jump

Quick repro:

	diff /dev/null $PWD/README.asciidoc -u | kak -e 'set-option buffer filetype diff'

Fixes #4531
This commit is contained in:
Johannes Altmanninger 2022-02-07 14:10:27 +01:00
parent 49de2b91c4
commit eaaf562ed1

View File

@ -113,8 +113,10 @@ define-command diff-jump -params .. -docstring %{
# there should be no need to strip the directory. # there should be no need to strip the directory.
$strip = $have_diff_line ? 1 : 0; $strip = $have_diff_line ? 1 : 0;
} }
if ($file !~ m{^/}) {
$file =~ s,^([^/]+/+){$strip},, or fail "directory prefix underflow"; $file =~ s,^([^/]+/+){$strip},, or fail "directory prefix underflow";
$filepath = "$directory/$file"; $file = "$directory/$file";
}
if (defined $line) { if (defined $line) {
$column = $ENV{column} - 1; # Account for [ +-] diff prefix. $column = $ENV{column} - 1; # Account for [ +-] diff prefix.
@ -122,7 +124,7 @@ define-command diff-jump -params .. -docstring %{
if ($last_line =~ m{^(@@ -\d+(?:,\d+)? \+\d+(?:,\d+) @@ )([^\n]*)}) { if ($last_line =~ m{^(@@ -\d+(?:,\d+)? \+\d+(?:,\d+) @@ )([^\n]*)}) {
$hunk_header_prefix = $1; $hunk_header_prefix = $1;
$hunk_header_from_userdiff = $2; $hunk_header_from_userdiff = $2;
open FILE, "<", $filepath or fail "failed to open file: $!: $filepath"; open FILE, "<", $file or fail "failed to open file: $!: $file";
@lines = <FILE>; @lines = <FILE>;
for (my $i = $line - 1; $i >= 0 && $i < scalar @lines; $i--) { for (my $i = $line - 1; $i >= 0 && $i < scalar @lines; $i--) {
if ($lines[$i] !~ m{\Q$hunk_header_from_userdiff}) { if ($lines[$i] !~ m{\Q$hunk_header_from_userdiff}) {
@ -136,7 +138,7 @@ define-command diff-jump -params .. -docstring %{
} }
} }
printf "set-register c %s $line $column", quote($filepath); printf "set-register c %s $line $column", quote($file);
' -- "$@" ' -- "$@"
} }
evaluate-commands -client %val{client} %{ evaluate-commands -client %val{client} %{