Function: diff-mode
diff-mode is an autoloaded, interactive and byte-compiled function
defined in diff-mode.el.gz.
Signature
(diff-mode)
Documentation
Major mode for viewing/editing context diffs.
Supports unified and context diffs as well as, to a lesser extent, diffs
in the old "normal" format. (Unified diffs have become the standard,
most commonly encountered format.) If you edit the buffer manually,
diff-mode will try to update the hunk headers for you on-the-fly.
You can also switch between context diff and unified diff with M-x diff-context->unified (diff-context->unified),
or vice versa with M-x diff-unified->context (diff-unified->context) and you can also reverse the direction of
a diff with M-x diff-reverse-direction (diff-reverse-direction).
C-M-i diff-hunk-next
C-M-x u diff-undo
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
C-c C-f next-error-follow-minor-mode(var)/next-error-follow-minor-mode(fun)
C-c C-l diff-refresh-hunk
C-c C-n diff-restrict-view
C-c C-r diff-reverse-direction
C-c C-s diff-split-hunk
C-c C-t diff-test-hunk
C-c C-u diff-context->unified
C-c C-w diff-ignore-whitespace-hunk
C-c M-u diff-revert-and-kill-hunk
C-c RET a diff-apply-buffer
C-c RET n diff-delete-other-hunks
C-x 4 A diff-add-change-log-entries-other-window
ESC <backtab> diff-hunk-prev
ESC <mouse-2> diff-goto-source
M-A diff-ediff-patch
M-A nil
M-K diff-file-kill
M-N diff-file-next
M-P diff-file-prev
M-R diff-reverse-direction
M-R nil
M-RET diff-goto-source
M-W nil
M-W widen
M-k diff-hunk-kill
M-n diff-hunk-next
M-o diff-goto-source
M-p diff-hunk-prev
M-r diff-restrict-view
M-r nil
M-u diff-revert-and-kill-hunk
M-w diff-kill-ring-save
M-w nil
M-{ diff-file-prev
M-} diff-file-next
In read-only buffers the following bindings are also available:
- negative-argument
0 digit-argument
1 digit-argument
2 digit-argument
3 digit-argument
4 digit-argument
5 digit-argument
6 digit-argument
7 digit-argument
8 digit-argument
9 digit-argument
< beginning-of-buffer
<keymap> <backtab> diff-hunk-prev
<keymap> <mouse-2> diff-goto-source
<keymap> A diff-ediff-patch
<keymap> C-x u diff-undo
<keymap> K diff-file-kill
<keymap> N diff-file-next
<keymap> P diff-file-prev
<keymap> R diff-reverse-direction
<keymap> RET diff-goto-source
<keymap> TAB diff-hunk-next
<keymap> W widen
<keymap> k diff-hunk-kill
<keymap> n diff-hunk-next
<keymap> o diff-goto-source
<keymap> p diff-hunk-prev
<keymap> r diff-restrict-view
<keymap> w diff-kill-ring-save
<keymap> { diff-file-prev
<keymap> } diff-file-next
> end-of-buffer
? describe-mode
DEL scroll-down-command
S-SPC scroll-down-command
SPC scroll-up-command
SPC..~ undefined
g revert-buffer
h describe-mode
q quit-window
This mode runs the hook diff-mode-hook, as the final or penultimate
step during initialization.
Probably introduced at or before Emacs version 21.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
;;;###autoload
(define-derived-mode diff-mode fundamental-mode "Diff"
"Major mode for viewing/editing context diffs.
Supports unified and context diffs as well as, to a lesser extent, diffs
in the old \"normal\" format. (Unified diffs have become the standard,
most commonly encountered format.) If you edit the buffer manually,
`diff-mode' will try to update the hunk headers for you on-the-fly.
You can also switch between context diff and unified diff with \\[diff-context->unified],
or vice versa with \\[diff-unified->context] and you can also reverse the direction of
a diff with \\[diff-reverse-direction].
\\{diff-mode-map}
In read-only buffers the following bindings are also available:
\\{diff-read-only-map}"
(setq-local font-lock-defaults diff-font-lock-defaults)
(add-hook 'font-lock-mode-hook #'diff--font-lock-cleanup nil 'local)
(setq-local imenu-generic-expression
diff-imenu-generic-expression)
(setq-local project-find-matching-buffer-function
#'project-change-to-matching-directory)
;; These are not perfect. They would be better done separately for
;; context diffs and unidiffs.
;; (setq-local paragraph-start
;; (concat "@@ " ; unidiff hunk
;; "\\|\\*\\*\\* " ; context diff hunk or file start
;; "\\|--- [^\t]+\t")) ; context or unidiff file
;; ; start (first or second line)
;; (setq-local paragraph-separate paragraph-start)
;; (setq-local page-delimiter "--- [^\t]+\t")
;; compile support
(setq-local next-error-function #'diff-next-error)
(setq-local beginning-of-defun-function #'diff-beginning-of-file-and-junk)
(setq-local end-of-defun-function #'diff-end-of-file)
(diff-setup-whitespace)
;; read-only setup
(when diff-default-read-only
(setq buffer-read-only t))
(when buffer-read-only
(setq diff-mode-read-only t))
(add-hook 'read-only-mode-hook
(lambda ()
(setq diff-mode-read-only buffer-read-only))
nil t)
;; setup change hooks
(if (not diff-update-on-the-fly)
(add-hook 'write-contents-functions #'diff-write-contents-hooks nil t)
(setq diff--track-changes
(track-changes-register #'diff--track-changes-signal :nobefore t)))
;; add-log support
(setq-local add-log-current-defun-function #'diff-current-defun)
(setq-local add-log-buffer-file-name-function
(lambda () (diff-find-file-name nil 'noprompt)))
(add-function :filter-return (local 'filter-buffer-substring-function)
#'diff--filter-substring)
(unless buffer-file-name
(hack-dir-local-variables-non-file-buffer))
(diff-setup-buffer-type))