[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Curse that hunk!
From: |
Alan Mackenzie |
Subject: |
Curse that hunk! |
Date: |
Wed, 11 Aug 2021 19:53:46 +0000 |
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).
- Curse that hunk!,
Alan Mackenzie <=