Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function in elisp to apply a patch to a buffer?

I am working on an emacs mode for a review tool, and want to use ediff for viewing diffs... the problem is that the review tool only yields a diff, rather than old and new files. I'd like to put the old file in a buffer and apply a diff rather than copying the file, calling out to diff as a subprocess and loading it into a separate buffer.

Can this be done without writing it myself, does anyone know?

like image 352
HenryR Avatar asked Aug 19 '10 18:08

HenryR


3 Answers

ediff-patch-buffer can be used to patch a buffer in ediff-mode

like image 146
Jürgen Hötzel Avatar answered Nov 13 '22 22:11

Jürgen Hötzel


Depending on what your workflow is this may or may not apply.

Try

M-x diff-mode

From which you can do commands like:

C-c C-a         diff-apply-hunk
C-c C-b         diff-refine-hunk
C-c C-c         diff-goto-source
C-c C-d         diff-unified->context
C-c C-e         diff-ediff-patch

The most intuitive flow for me is the 'diff-ediff-patch.

When you're looking at a patch, run C-c C-e, enter the file name to patch (say file.to.patch). Emacs will then set you up with an ediff of two buffers file.to.patch.orig and file.to.patch containing the original file and the patched version. You then use ediff as you would regularly. At the end of the flow, you have the patched version in the filename you want.

Check out the documentation for diff-mode.

like image 7
Trey Jackson Avatar answered Nov 13 '22 21:11

Trey Jackson


There is also M-x epatch that asks for a buffer containing a patch (Gnus mail for example) and then asks for a file/directory to patch. Very handy.

like image 2
VitoshKa Avatar answered Nov 13 '22 23:11

VitoshKa