unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Curse that hunk!
@ 2021-08-11 19:53 Alan Mackenzie
  2021-08-11 21:24 ` Stefan Monnier
  2021-08-12  7:49 ` Juri Linkov
  0 siblings, 2 replies; 3+ messages in thread
From: Alan Mackenzie @ 2021-08-11 19:53 UTC (permalink / raw)
  To: emacs-devel

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).



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-12  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-11 19:53 Curse that hunk! Alan Mackenzie
2021-08-11 21:24 ` Stefan Monnier
2021-08-12  7:49 ` Juri Linkov

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).