If you C-cC-a (diff-apply-hunk) on a hunk which has already been applied, diff-mode will detect this and ask whether you wish to reverse that change.
You can also request this directly by passing a prefix argument to the command.
In cases where the context is insufficient to tell whether or not the patch has been applied, the latter method would be ...
Magit can do this by limiting the revert action to the region.
With the built-in diff-mode you can get the same kind of effect by splitting the hunk into portions using diff-split-hunk
which is bound to C-c C-s by default.
The grep parameters you are using should be adequate. Just do M-x grep-mode after opening your results file and you should get the links you desire.
You could also skip writing the grep results to a file and use a command like grep-find directly.
In grep mode, n/p are bound to next-error-no-select/previous-error-no-select respectively (open the file and ...
There are R in diff-mode.
R runs the command diff-reverse-direction
Reverse the direction of the diffs.
So first R and then C-c C-a to apply reversed diff.
It is possible to revert individual hunk without reversing whole diff by invoking diff-aply-hunk with prefix argument. So another solution is C-u C-c C-a.
The actual problem is the following form in the definition of diff-mode-hook. It removes all the refinement overlays that you created with your function my-diff-hunks-highlight-all immediately after starting up diff-mode and initializing font-lock-mode.
(declare-function 'diff-hunk-next "diff-mode")
(defun my-diff-refine-all ()
"Refine all diffs."
Sounds like a great addition, to diff-mode. It should be pretty easy to do that in the font-lock-keywords by adding some appropriate display text property which would both hide the "+" from the buffer and add it to the fringe. Contrary to @lawlist I wouldn't expect any serious performance issue.
EDIT: this has since been added to Emacs-27's development ...
You can always write a function to do all the repeated steps for you. This should get you started:
(interactive "sDiff command:")
(let ((buffer (generate-new-buffer "*diff-generic*")))
(with-current-buffer buffer (diff-mode))
(call-process-shell-command command nil buffer 0)
Move to the coloured text you're interested in, and type C-uC-x= to view details of the character at point, including any faces.
Select the face you're interested in, then select "customize this face", make the desired changes, and save.
The value of show-trailing-whitespace becomes buffer local when set so you can just set it in the relevant hook:
(add-hook 'diff-mode-hook (lambda () (setq show-trailing-whitespace nil)))
To check the documentation for show-trailing-whitespace: C-h v show-trailing-whitespace.
You can custom a face like this:
'(ediff-current-diff-A ((t (:foreground "White" :background "brown")))))
the ediff faces are:
C-h v magic-mode-alist says this:
magic-mode-alist is a variable defined in files.el.
Its value is nil
This variable can be risky when used as a file-local variable.
Alist of buffer beginnings vs. corresponding major mode functions.
Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION).
Here are 2 functions I came up with that open a fullscreen diff and close it when jumping to the line.
;; Override pop-up-windows
(defun diff-goto-source-and-close ()
"Go to the source and close the current diff buffer."
(let ((buf (current-buffer))
There are more faces involved than the ones mentioned in the link you pointed to. The answer is to use C-u C-x = to find out what faces are involved. Those are the ones you need to customize.
Use M-x customize-face to customize the faces you are interested in. If you don't know which faces they are, put the cursor on that highlighted text and use C-u C-x =...
The following works for me when I test on two small files (i.e., there are not many diffs).
(defun my-diff-hunks-highlight-all ()
"Highlight all hunks in diff-mode."
(run-at-time 0.1 nil
(while (not (eobp))
No, it is not possible. diff-mode is just for showing and editing diffs; VersionControl what gets committed, and works only with files or sets of files:
[some] version control systems [...] are file-based: each file has its own [...] history [...]. [...] changeset-based [systems' commits] may include changes to several files, and the entire set of changes ...
Adding own answer, since diff-apply-hunk didn't do exactly what I wanted.
This is a stripped down diff-apply-hunk with some modified behavior, to revert hunks without changing the context.
The buffer is saved after reverting.
The hunk is removed.
No new windows open.
It allows for quickly navigating over a diff and reverting hunks, without having to ...
I find that the built-in ediff serves great for diffing sexps. As soon as you ignore whitespace, the changes in sexps become very clear.
(setq ediff-diff-options "-w --text")
A nice command to start with is ediff-regions-wordwise, which can be used to narrow the bounds of the stuff you diff.
If you want to diff two sexps very quickly in terms of keys ...
Documenting my own crude solution for now, in case it helps anyone. I'll happily accept another answer with a better solution.
My solution took the form of two parts:
Wrapper shell script around BusyBox's diff, converting its unified output into traditional/"normal" output. (It's now in one of the directories in my PATH as bnudiff. I put it on GitHub it ...
There doesn't seem to be a function that does that.
You can get that functionality by using a macro. First, hit F3 C-c C-a F4 to define a macro that applies a hunk, and then type C-u 0 M-x kmacro-call-macro to repeatedly call that macro until an error occurs (probably at the end of the diff file).
One solution is to turn off Trailing whitespace mode in Diff mode, and instead define your own custom font lock rules for the trailing whitespace that you don't want to see.
'(("^[+-<>]\\(.*\\S \\)?\\(\\s +\\)$" (2 'trailing-whitespace t))))
(defun diff-mode-font-lock-add-trailing-whitespace ()