unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Subject: Curse that hunk!
Date: Wed, 11 Aug 2021 19:53:46 +0000	[thread overview]
Message-ID: <YRQqyopRMKh1fGzy@ACM> (raw)

Hello, Emacs.

I found myself this evening trying to patch a file with a 1400 line hunk
which didn't (quite) match.  This happens to me quite often, though it's
never been as bad as a 1400 line mismatch before.

Finding the point where a patch hunk's old lines fail to match the file
being patched is tedious and error prone.  There surely ought to be a
Lisp program, perhaps in diff.el which would fine these differences.

This evening, I hacked together the following command which, though
ugly, did the job:

(defun crack-patch (p-buf s-buf)
  (interactive "b\nb")
  (let (str
        )
    (catch 'found
      (while (progn (set-buffer p-buf) (not (eobp)))
        (re-search-forward "^\\([ -]\\)\\(.*\\)$")
        (setq str (match-string-no-properties 2))
        (set-buffer s-buf)
        (message "point: %s" (point))
        (unless (looking-at (concat "^"
                                    (regexp-quote str) "$"))
          (throw 'found nil))
        (forward-line)))))

To use it, type in the p-buf, the name of the patch buffer, and s-buf,
the name of the source buffer you want to patch.  In p-buf, point should
be at the start of a context or - line, and in s-buf, point should be at
the corresponding point.  The command will run and stop at the first
discrepancy between the two.

As I say, very rough and ready, but I managed to get my 1400 line patch
hunk working with it.

Surely there ought to be some facility like this in Emacs?

-- 
Alan Mackenzie (Nuremberg, Germany).



             reply	other threads:[~2021-08-11 19:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 19:53 Alan Mackenzie [this message]
2021-08-11 21:24 ` Curse that hunk! Stefan Monnier
2021-08-12  7:49 ` 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=YRQqyopRMKh1fGzy@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /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).