Variable: diff-font-lock-syntax

diff-font-lock-syntax is a customizable variable defined in diff-mode.el.gz.

Value

t

Documentation

If non-nil, diff hunk font-lock includes source language syntax highlighting.

This highlighting is the same as added by font-lock-mode(var)/font-lock-mode(fun) when corresponding source files are visited normally. Syntax highlighting is added over diff-mode's own highlighted changes.

If t, the default, highlight syntax only in Diff buffers created by Diff commands that compare files or by VC commands that compare revisions. These provide all necessary context for reliable highlighting. This value requires support from a VC backend to find the files being compared. For diffs against the working-tree version of a file, the highlighting is based on the current file contents. File-based fontification tries to infer fontification from the compared files.

If hunk-only fontification is based on hunk alone, without full source. It tries to highlight hunks without enough context that sometimes might result in wrong fontification. This is the fastest option, but less reliable.

If hunk-also, use reliable file-based syntax highlighting when available and hunk-based syntax highlighting otherwise as a fallback.

This variable was added, or its default value changed, in Emacs 27.1.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defcustom diff-font-lock-syntax t
  "If non-nil, diff hunk font-lock includes source language syntax highlighting.
This highlighting is the same as added by `font-lock-mode'
when corresponding source files are visited normally.
Syntax highlighting is added over diff-mode's own highlighted changes.

If t, the default, highlight syntax only in Diff buffers created by Diff
commands that compare files or by VC commands that compare revisions.
These provide all necessary context for reliable highlighting.  This value
requires support from a VC backend to find the files being compared.
For diffs against the working-tree version of a file, the highlighting is
based on the current file contents.  File-based fontification tries to
infer fontification from the compared files.

If `hunk-only' fontification is based on hunk alone, without full source.
It tries to highlight hunks without enough context that sometimes might result
in wrong fontification.  This is the fastest option, but less reliable.

If `hunk-also', use reliable file-based syntax highlighting when available
and hunk-based syntax highlighting otherwise as a fallback."
  :version "27.1"
  :type '(choice (const :tag "Don't highlight syntax" nil)
                 (const :tag "Hunk-based only" hunk-only)
                 (const :tag "Highlight syntax" t)
                 (const :tag "Allow hunk-based fallback" hunk-also)))