GNU bug report logs -
#65380
[PATCH] Add command to copy contents in a diff-mode buffer
Previous Next
Reported by: Philip Kaludercic <philipk <at> posteo.net>
Date: Sat, 19 Aug 2023 09:55:01 UTC
Severity: normal
Tags: patch
Done: Philip Kaludercic <philipk <at> posteo.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Juri Linkov <juri <at> linkov.net> writes:
>> I'm attaching the newest version of the patch here:
>
> Thanks, I tried it out, and it works nicely for the single hunk case.
1+
>> +*** New command 'diff-kill-ring-save'
>> +This command copies out the modified contents out of a diff, without
>> +having to apply it first. If the selected range extends a hunk, the
>> +commands attempts to look up and copy the text between from the
>> +referenced file.
>
> I'm not sure about usefulness of the last part in multi-hunk case.
> Does someone really need to copy a huge part of the source file
> between hunks at the top and bottom? I expected that multi-hunk case
> would copy only concatenated text of hunks, not the source file.
> But I have no strong opinion about this.
The main scenario I had in mind was when someone modifies the beginning
and the end of a function, and I want to copy all of it at once. I
agree that there is usually not much of a use for copying huge parts of
a source file, but we get that for free when the beginning-to-end of a
function case is handled.
> My main use case will be
> to copy the text of the current hunk. Could you please support
> this case where typing 'w' would copy the current hunk when the
> region is not activated.
Done, see below.
>> @@ -630,6 +631,22 @@ diff-end-of-hunk
>> +(defun diff-beginning-of-hunk-position (&optional try-harder)
>> + "Call `diff-end-of-hunk' without moving.
>> +The optional argument TRY-HARDER is passed on to
>> +`diff-beginning-of-hunk'."
>> + (save-excursion
>> + (save-window-excursion
>> + (diff-beginning-of-hunk try-harder))))
>> +
>> +(defun diff-end-of-hunk-position (&optional style donttrustheader)
>> + "Call `diff-end-of-hunk' without moving.
>> +The optional arguments STYLE and DONTTRUSTHEADER are passed on to
>> +`diff-end-of-hunk'."
>> + (save-excursion
>> + (save-window-excursion
>> + (diff-end-of-hunk style donttrustheader))))
>
> I don't understand why separate functions with 'save-window-excursion'
> are needed here, since all other uses of 'diff-beginning-of-hunk'
> just wrap the calls with 'save-excursion'.
You are right, it isn't needed anymore, and I have removed it.
Here is the updated patch:
[0001-Add-command-to-copy-contents-in-a-diff-mode-buffer.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
--
Philip Kaludercic on peregrine
This bug report was last modified 273 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.