unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Curse that hunk!
Date: Thu, 12 Aug 2021 10:49:05 +0300	[thread overview]
Message-ID: <875ywbcg4e.fsf@mail.linkov.net> (raw)
In-Reply-To: <YRQqyopRMKh1fGzy@ACM> (Alan Mackenzie's message of "Wed, 11 Aug 2021 19:53:46 +0000")

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

If you need only to find the point of mismatch, then what I do
is just remove the diff indicators from the diff buffers with
(replace-regexp "^[+-]" ""), and then compare two buffers
with the usual compare-windows or ediff-buffers.

Also sometimes there is a need to isearch a multi-line string
in the diff buffer.  For such cases I wrote an isearch mode that
ignores diff-mode hunk indicators such as '+' or '-' at the
beginning of the diff lines.  For example, put the deleted hunk
to the search string, then search it for the next match,
and it will find the hunk moved to another part of the file:

#+begin_src emacs-lisp
(isearch-define-mode-toggle diff-hunk "+" diff-hunk-to-regexp "\
Ignore diff-mode hunk indicators such as ‘+’ or ‘-’ at bol.")

(defun diff-hunk-to-regexp (string &optional _lax _from)
  (replace-regexp-in-string
   "[[:space:]]+" "[[:space:]]+"
   (replace-regexp-in-string
    "^\\(\\\\\\+\\|-\\)" "\\(^\\)[+-]"
    (regexp-quote string) nil t)))

(add-hook 'diff-mode-hook
          (lambda ()
            (setq-local search-default-mode 'diff-hunk-to-regexp)))
#+end_src



      parent reply	other threads:[~2021-08-12  7:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 19:53 Curse that hunk! Alan Mackenzie
2021-08-11 21:24 ` Stefan Monnier
2021-08-12  7:49 ` Juri Linkov [this message]

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=875ywbcg4e.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=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).