Subject: Re: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer

From: Juri Linkov <[email-masked]>
Date: Tue, 20 Aug 2024 09:44:22 +0300

> I'm attaching the newest version of the patch here:

Thanks, I tried it out, and it works nicely for the single hunk case.

> +*** 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.  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.

> @@ -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'.