Juri Linkov 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: