rc diff: pass diff to diff-jump via stdin instead of env

Passing large diff buffers via the environment can quickly result in
the error "execve failed: Argument list too long". Use a pipe like
in format.kak

When running | (or <a-|>), Kakoune does not use %arg{@} to populate
"$@" (missing feature?). Work around this by moving %arg{@} to a
temporary register. Apparently $kak_quoted_reg_a will never be an
empty list, so work around that too.

When diff parsing fails, we take care to run "fail" in the calling
client, unlike :format (probably a bug in format.kak).

(This patch is best viewed while ignoring whitespace changes (diff -w))
This commit is contained in:
Johannes Altmanninger 2022-02-12 16:12:29 +01:00
parent eaaf562ed1
commit 13948ecb94

View File

@ -27,7 +27,7 @@ define-command diff-jump -params .. -docstring %{
- jump to the old file instead of the new file - jump to the old file instead of the new file
-<num> strip <num> leading directory components, like -p<num> in patch(1). Defaults to 1 if there is a 'diff' line (as printed by 'diff -r'), or 0 otherwise. -<num> strip <num> leading directory components, like -p<num> in patch(1). Defaults to 1 if there is a 'diff' line (as printed by 'diff -r'), or 0 otherwise.
} %{ } %{
evaluate-commands -draft -save-regs c %{ evaluate-commands -draft -save-regs ac| %{
# Save the column because we will move the cursor. # Save the column because we will move the cursor.
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.
@ -39,9 +39,10 @@ define-command diff-jump -params .. -docstring %{
# or content. # or content.
execute-keys Gk execute-keys Gk
} }
evaluate-commands %sh{ set-register a %arg{@}
printf %s "$kak_selection" | set-register | %{
column=$kak_reg_c perl -we ' [ -n "$kak_reg_a" ] && eval set -- $kak_quoted_reg_a
cmd=$(column=$kak_reg_c perl -we '
sub quote { sub quote {
$SQ = "'\''"; $SQ = "'\''";
$token = shift; $token = shift;
@ -51,7 +52,7 @@ define-command diff-jump -params .. -docstring %{
sub fail { sub fail {
$reason = shift; $reason = shift;
print "fail " . quote("diff-jump: $reason"); print "fail " . quote("diff-jump: $reason");
exit 1; exit;
} }
$version = "+", $other_version = "-"; $version = "+", $other_version = "-";
$strip = undef; $strip = undef;
@ -138,12 +139,14 @@ define-command diff-jump -params .. -docstring %{
} }
} }
printf "set-register c %s $line $column", quote($file); printf "edit -existing -- %s $line $column", quote($file);
' -- "$@" ' -- "$@")
echo "set-register c $cmd" >"$kak_command_fifo"
} }
execute-keys <a-|><ret>
evaluate-commands -client %val{client} %{ evaluate-commands -client %val{client} %{
evaluate-commands -try-client %opt{jumpclient} %{ evaluate-commands -try-client %opt{jumpclient} %{
edit -existing -- %reg{c} %reg{c}
} }
} }
} }