From: Dmitry Gutov <dmitry@gutov.dev>
To: Juri Linkov <juri@linkov.net>
Cc: 66113@debbugs.gnu.org
Subject: bug#66113: Apply the entire diff buffer
Date: Sun, 24 Sep 2023 04:34:33 +0300 [thread overview]
Message-ID: <095e4596-7c67-21e2-a69f-c0b7945773a3@gutov.dev> (raw)
In-Reply-To: <86lecwvjw4.fsf@mail.linkov.net>
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".
next prev parent reply other threads:[~2023-09-24 1:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 6:46 bug#66113: Apply the entire diff buffer Juri Linkov
2023-09-22 1:38 ` Dmitry Gutov
2023-09-22 6:45 ` Juri Linkov
2023-09-22 13:49 ` Dmitry Gutov
2023-09-22 15:48 ` Juri Linkov
2023-09-23 17:52 ` Juri Linkov
2023-09-24 1:34 ` Dmitry Gutov [this message]
2023-09-24 7:34 ` Juri Linkov
2023-09-24 10:58 ` Dmitry Gutov
2023-09-25 17:49 ` Juri Linkov
2023-09-25 23:07 ` Dmitry Gutov
2023-09-27 17:36 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=095e4596-7c67-21e2-a69f-c0b7945773a3@gutov.dev \
--to=dmitry@gutov.dev \
--cc=66113@debbugs.gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).