GNU bug report logs - #66113
Apply the entire diff buffer

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 20 Sep 2023 06:51:01 UTC

Severity: normal

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


Message #23 received at 66113 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Juri Linkov <juri <at> linkov.net>
Cc: 66113 <at> debbugs.gnu.org
Subject: Re: bug#66113: Apply the entire diff buffer
Date: Sun, 24 Sep 2023 04:34:33 +0300
On 23/09/2023 20:52, Juri Linkov wrote:
> +(defun diff-apply-buffer ()
> +  "Apply the diff in the entire diff buffer.
> +When applying all hunks was successful, then save the changed buffers."
> +  (interactive)
> +  (let ((buffer-edits nil)
> +        (failures 0)
> +        (diff-refine nil))
> +    (save-excursion
> +      (goto-char (point-min))
> +      (diff-beginning-of-hunk t)
> +      (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched)
> +                          (diff-find-source-location nil nil)))
> +               (cond ((and line-offset (not switched))
> +                      (push (cons pos dst)
> +                            (alist-get buf buffer-edits)))
> +                     (t (setq failures (1+ failures))))
> +               (not (or (eq (prog1 (point) (diff-hunk-next)) (point))
> +                        (eobp))))))
> +    (cond ((zerop failures)
> +           (dolist (buf-edits (reverse buffer-edits))
> +             (with-current-buffer (car buf-edits)
> +               (dolist (edit (cdr buf-edits))
> +                 (let ((pos (car edit))
> +                       (dst (cdr edit))
> +                       (inhibit-read-only t))
> +                   (goto-char (car pos))
> +                   (delete-region (car pos) (cdr pos))
> +                   (insert (car dst))))
> +               (save-buffer)))
> +           (message "Saved %d buffers" (length buffer-edits)))
> +          (t
> +           (message "%d hunks failed; no buffers changed" failures)))))

Sorry, was there supposed to be a call to diff-test-hunk here? Or I'm 
just not following the implementation.

I tried testing it out too. There is a patch where the third hunk 
doesn't apply (errors with "can't find the text to patch" in regular 
usage). This command ends with cryptic "No next hunk".




This bug report was last modified 1 year and 234 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.