Commit 6973b148 authored by Juri Linkov's avatar Juri Linkov

Syntactic fontification of diff hunks (bug#33567)

* lisp/vc/diff-mode.el (diff-font-lock-syntax): New defcustom.
(diff-default-directory): New buffer-local variable.
(diff-indicator-removed, diff-indicator-added)
(diff-indicator-changed): Set foreground to distinctive colors.
(diff-context): Remove colors to make room for syntax highlighting.
(diff-font-lock-keywords): Add diff--font-lock-syntax.
(diff--font-lock-cleanup): Remove diff-mode syntax overlays.
(diff--font-lock-syntax, diff--font-lock-syntax--refresh)
(diff-syntax-fontify-revisions, diff-syntax-fontify-hunk)
(diff-syntax-fontify-props): New functions.

* lisp/vc/diff.el (diff-no-select): Set diff-default-directory to

* doc/emacs/files.texi (Diff Mode): Document diff-font-lock-syntax.
parent c5e02f2b
Pipeline #312 failed with stage
in 2 seconds
......@@ -1617,6 +1617,10 @@ displayed in the echo area). With a prefix argument, it tries to
modify the original (``old'') source files rather than the patched
(``new'') source files.
@vindex diff-font-lock-syntax
If non-@code{nil}, fragments of source in hunks are highlighted
according to the appropriate major mode.
@node Copying and Naming
@section Copying, Naming and Renaming Files
......@@ -413,6 +413,12 @@ and compares their entire trees.
*** Hunks are now automatically refined by default.
To disable it, set the new defcustom 'diff-font-lock-refine' to nil.
*** Better syntax highlighting of Diff hunks.
Fragments of source in Diff hunks are now by default highlighted
according to the appropriate major mode. Customize the new option
'diff-font-lock-syntax' to nil to disable this.
*** File headers can be shortened, mimicking Magit's diff format.
To enable it, set the new defcustom 'diff-font-lock-prettify' to t.
This diff is collapsed.
......@@ -121,6 +121,8 @@ Possible values are:
nil -- no, it does not
check -- try to probe whether it does")
(defvar diff-default-directory)
(defun diff-no-select (old new &optional switches no-async buf)
;; Noninteractive helper for creating and reverting diff buffers
(unless (bufferp new) (setq new (expand-file-name new)))
......@@ -165,6 +167,7 @@ Possible values are:
(lambda (_ignore-auto _noconfirm)
(diff-no-select old new switches no-async (current-buffer))))
(setq default-directory thisdir)
(setq diff-default-directory default-directory)
(let ((inhibit-read-only t))
(insert command "\n"))
(if (and (not no-async) (fboundp 'make-process))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment