emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Curse that hunk!


From: Juri Linkov
Subject: Re: Curse that hunk!
Date: Thu, 12 Aug 2021 10:49:05 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]