From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Curse that hunk! Date: Wed, 11 Aug 2021 19:53:46 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38820"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Aug 11 21:54:45 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDuJJ-0009wg-59 for ged-emacs-devel@m.gmane-mx.org; Wed, 11 Aug 2021 21:54:45 +0200 Original-Received: from localhost ([::1]:44852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDuJH-0007cm-H6 for ged-emacs-devel@m.gmane-mx.org; Wed, 11 Aug 2021 15:54:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDuIb-0006yQ-3r for emacs-devel@gnu.org; Wed, 11 Aug 2021 15:54:01 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:61334 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1mDuIZ-0006Ai-2R for emacs-devel@gnu.org; Wed, 11 Aug 2021 15:54:00 -0400 Original-Received: (qmail 21421 invoked by uid 3782); 11 Aug 2021 19:53:46 -0000 Original-Received: from acm.muc.de (p4fe158ab.dip0.t-ipconnect.de [79.225.88.171]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 11 Aug 2021 21:53:46 +0200 Original-Received: (qmail 7631 invoked by uid 1000); 11 Aug 2021 19:53:46 -0000 Content-Disposition: inline X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:272333 Archived-At: 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).