bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Philip Kaludercic
Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer
Date: Wed, 13 Sep 2023 11:51:01 -0000

Daniel Martín <mardani29@yahoo.es> writes:

> Philip Kaludercic <philipk@posteo.net> writes:
>
>> +(defun diff-kill-ring-save (beg end)
>> +  "Save contents of the region between BEG and END akin to `kill-ring-save'.
>> +The contents of a region will not include diff indicators at the
>> +beginning of each line."
>> +  (interactive (list (region-beginning) (region-end)))
>> +  (let ((at-bol (save-excursion (goto-char beg) (bolp)))
>> +        lines)
>> +    (save-restriction
>> +      (narrow-to-region beg end)
>> +      (goto-char (point-min))
>> +      (while (not (eobp))
>> +        (let ((line (thing-at-point 'line t)))
>> +          ;; In case the user has selected a region that begins
>> +          ;; mid-line, we should not chomp off the first character.
>> +          (if (and (null lines) (not at-bol))
>> +              (push line lines)
>> +            (push (substring line 1) lines)))
>> +        (forward-line)))
>> +    (let ((region-extract-function
>> +           (lambda (_) (apply #'concat (nreverse lines)))))
>> +      (kill-ring-save beg end t))))
>>
>
> As an alternative implementation, to avoid creating lots of intermediate
> substrings, we could check if we're inside a hunk and, if so, perform a
> regular expression replace to remove the diff indicators.  If the region
> covers text outside of a hunk, then we could copy the text normally, as
> if the user pressed M-w.

What text would we want to copy outside of a hunk?  Something like a
patch commit message?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]