aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/vc/diff-mode.el35
2 files changed, 42 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 1a1e0d8b70e..c69bbe9d0f6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -212,6 +212,13 @@ navigation and editing of large files.
212 212
213* Changes in Specialized Modes and Packages in Emacs 27.1 213* Changes in Specialized Modes and Packages in Emacs 27.1
214 214
215** diff-mode
216*** Hunks are now automatically refined by default
217To disable it, set the new defcustom 'diff-font-lock-refine' to nil.
218
219*** File headers can be shortened, mimicking Magit's diff format
220To enable it, set the new defcustom 'diff-font-lock-prettify to t.
221
215** Browse-url 222** Browse-url
216 223
217*** The function 'browse-url-emacs' can now visit a URL in selected window. 224*** The function 'browse-url-emacs' can now visit a URL in selected window.
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index ffbd9e5479a..b91a2ba45a4 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -96,6 +96,11 @@ when editing big diffs)."
96 :version "27.1" 96 :version "27.1"
97 :type 'boolean) 97 :type 'boolean)
98 98
99(defcustom diff-font-lock-prettify nil
100 "If non-nil, font-lock will try and make the format prettier."
101 :version "27.1"
102 :type 'boolean)
103
99(defvar diff-vc-backend nil 104(defvar diff-vc-backend nil
100 "The VC backend that created the current Diff buffer, if any.") 105 "The VC backend that created the current Diff buffer, if any.")
101 106
@@ -396,6 +401,7 @@ and the face `diff-added' for added lines.")
396 (1 font-lock-comment-delimiter-face) 401 (1 font-lock-comment-delimiter-face)
397 (2 font-lock-comment-face)) 402 (2 font-lock-comment-face))
398 ("^[^-=+*!<>#].*\n" (0 'diff-context)) 403 ("^[^-=+*!<>#].*\n" (0 'diff-context))
404 (,#'diff--font-lock-prettify)
399 (,#'diff--font-lock-refined))) 405 (,#'diff--font-lock-refined)))
400 406
401(defconst diff-font-lock-defaults 407(defconst diff-font-lock-defaults
@@ -2195,6 +2201,35 @@ fixed, visit it in a buffer."
2195 modified-buffers ", ")) 2201 modified-buffers ", "))
2196 (message "No trailing whitespace to delete."))))) 2202 (message "No trailing whitespace to delete.")))))
2197 2203
2204
2205;;; Prettifying from font-lock
2206
2207(defun diff--font-lock-prettify (limit)
2208 ;; Mimicks the output of Magit's diff.
2209 ;; FIXME: This has only been tested with Git's diff output.
2210 (when diff-font-lock-prettify
2211 (while (re-search-forward "^diff " limit t)
2212 (when (save-excursion
2213 (forward-line 0)
2214 (looking-at (eval-when-compile
2215 (concat "diff.*\n"
2216 "\\(?:\\(?:new file\\|deleted\\).*\n\\)?"
2217 "\\(?:index.*\n\\)?"
2218 "--- \\(?:/dev/null\\|a/\\(.*\\)\\)\n"
2219 "\\+\\+\\+ \\(?:/dev/null\\|b/\\(.*\\)\\)\n"))))
2220 (put-text-property (match-beginning 0)
2221 (or (match-beginning 2) (match-beginning 1))
2222 'display (propertize
2223 (cond
2224 ((null (match-beginning 1)) "new file ")
2225 ((null (match-beginning 2)) "deleted ")
2226 (t "modified "))
2227 'face '(diff-file-header diff-header)))
2228 (unless (match-beginning 2)
2229 (put-text-property (match-end 1) (1- (match-end 0))
2230 'display "")))))
2231 nil)
2232
2198;;; Support for converting a diff to diff3 markers via `wiggle'. 2233;;; Support for converting a diff to diff3 markers via `wiggle'.
2199 2234
2200;; Wiggle can be found at http://neil.brown.name/wiggle/ or in your nearest 2235;; Wiggle can be found at http://neil.brown.name/wiggle/ or in your nearest