From fb16313025dcbe2f010a79072536aeab000eaf80 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 19 Dec 2018 01:10:09 +0200 Subject: [PATCH] More font-lock improvements for diff-mode * lisp/vc/diff-mode.el (diff-font-lock-keywords): Use diff-header face for git index lines (like already used for bzr index lines). Use diff-file-header face for binary file headers. (diff-find-source-location): Use expand-file-name for vc-find-revision. (diff--font-lock-prettify): Use diff-indicator-* faces for left-fringe indicators. (diff-syntax-fontify-props): Optimize to not use text-property-not-all for font-lock-ensure. * lisp/replace.el (occur-engine-line): Simplify to use font-lock-ensure without text-property-not-all. --- lisp/replace.el | 6 ++---- lisp/vc/diff-mode.el | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lisp/replace.el b/lisp/replace.el index dcae12e9b76..b8f231eb55d 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1907,10 +1907,8 @@ See also `multi-occur'." global-matches))) (defun occur-engine-line (beg end &optional keep-props) - (if (and keep-props (if (boundp 'jit-lock-mode) jit-lock-mode) - (text-property-not-all beg end 'fontified t)) - (if (fboundp 'jit-lock-fontify-now) - (jit-lock-fontify-now beg end))) + (if (and keep-props font-lock-mode) + (font-lock-ensure beg end)) (if (and keep-props (not (eq occur-excluded-properties t))) (let ((str (buffer-substring beg end))) (remove-list-of-text-properties diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 549f49a8d13..043d22d14b3 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -255,7 +255,7 @@ in wrong fontification. This is the fastest option, but less reliable." "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.") (define-minor-mode diff-auto-refine-mode - "Toggle automatic diff hunk highlighting (Diff Auto Refine mode). + "Toggle automatic diff hunk finer highlighting (Diff Auto Refine mode). Diff Auto Refine mode is a buffer-local minor mode used with `diff-mode'. When enabled, Emacs automatically highlights @@ -435,7 +435,9 @@ and the face `diff-added' for added lines.") 'diff-removed)))))) ("^\\(?:Index\\|revno\\): \\(.+\\).*\n" (0 'diff-header) (1 'diff-index prepend)) + ("^\\(?:index .*\\.\\.\\|diff \\).*\n" . 'diff-header) ("^Only in .*\n" . 'diff-nonexistent) + ("^Binary files .* differ\n" . 'diff-file-header) ("^\\(#\\)\\(.*\\)" (1 font-lock-comment-delimiter-face) (2 font-lock-comment-face)) @@ -1785,7 +1787,7 @@ NOPROMPT, if non-nil, means not to prompt the user." (vc-working-revision file))))) (buf (if revision (let ((vc-find-revision-no-save t)) - (vc-find-revision file revision diff-vc-backend)) + (vc-find-revision (expand-file-name file) revision diff-vc-backend)) (find-file-noselect file)))) ;; Update the user preference if he so wished. (when (> (prefix-numeric-value other-file) 8) @@ -2321,9 +2323,9 @@ fixed, visit it in a buffer." ;; FIXME: Include the first space for context-style hunks! (while (re-search-forward "^[-+! ]" limit t) (let ((spec (alist-get (char-before) - '((?+ . (left-fringe diff-fringe-add diff-added)) - (?- . (left-fringe diff-fringe-del diff-removed)) - (?! . (left-fringe diff-fringe-rep diff-changed)) + '((?+ . (left-fringe diff-fringe-add diff-indicator-added)) + (?- . (left-fringe diff-fringe-del diff-indicator-removed)) + (?! . (left-fringe diff-fringe-rep diff-indicator-changed)) (?\s . (left-fringe diff-fringe-nul)))))) (put-text-property (match-beginning 0) (match-end 0) 'display spec)))) ;; Mimicks the output of Magit's diff. @@ -2523,14 +2525,14 @@ hunk text is not found in the source file." (when (and beg end) (goto-char beg) - (when (text-property-not-all beg end 'fontified t) - (if file - ;; In a temporary or cached buffer + (if file + ;; In a temporary or cached buffer + (when (text-property-not-all beg end 'fontified t) (save-excursion (font-lock-fontify-region beg end) - (put-text-property beg end 'fontified t)) - ;; In an existing buffer - (font-lock-ensure beg end))) + (put-text-property beg end 'fontified t))) + ;; In an existing buffer + (font-lock-ensure beg end)) (while (< (point) end) (let* ((bol (point)) -- 2.39.5