1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

* lisp/vc/diff-mode.el (diff-revert-and-kill-hunk): Fix killing.

This commit is contained in:
Sean Whitton 2025-12-04 15:40:11 +00:00
parent 21f9295aa9
commit d63ed68684

View file

@ -2307,20 +2307,18 @@ BEG and END."
(setq end (cadr (diff-bounds-of-hunk)))) (setq end (cadr (diff-bounds-of-hunk))))
(pcase-setq `(,beg ,end) (diff-bounds-of-hunk))) (pcase-setq `(,beg ,end) (diff-bounds-of-hunk)))
(when (null (diff-apply-buffer beg end t)) (when (null (diff-apply-buffer beg end t))
;; Use `diff-hunk-kill' because it properly handles file headers, ;; Use `diff-hunk-kill' because it properly handles file headers.
;; except if we are killing the last hunk we need not be concerned (goto-char end)
;; with that. If we are not deleting the very last hunk then (when-let* ((pos (diff--at-diff-header-p)))
;; exploit how `diff-hunk-kill' will always leave us at the (goto-char pos))
;; beginning of a hunk (except when killing the very last hunk!). (setq beg (copy-marker beg) end (point-marker))
(if (eql end (point-max))
(let ((inhibit-read-only t))
(kill-region beg end))
(setq end (copy-marker end))
(unwind-protect (unwind-protect
(cl-loop initially (goto-char beg) (cl-loop initially (goto-char beg)
do (diff-hunk-kill) do (diff-hunk-kill)
until (eql (point) (marker-position end))) until (or (< (point) (marker-position beg))
(set-marker end nil)))))) (eql (point) (marker-position end))))
(set-marker beg nil)
(set-marker end nil)))))
(defun diff-apply-buffer (&optional beg end reverse test-or-no-save) (defun diff-apply-buffer (&optional beg end reverse test-or-no-save)
"Apply the diff in the entire diff buffer. "Apply the diff in the entire diff buffer.