diff options
| -rw-r--r-- | lisp/vc/diff-mode.el | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 8940c7e09a6..1d5a2cf69ab 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -2411,10 +2411,11 @@ and the position in MAX." | |||
| 2411 | (diff-syntax-fontify-hunk beg end t) | 2411 | (diff-syntax-fontify-hunk beg end t) |
| 2412 | (diff-syntax-fontify-hunk beg end nil))) | 2412 | (diff-syntax-fontify-hunk beg end nil))) |
| 2413 | 2413 | ||
| 2414 | (defvar diff-syntax-fontify-revisions (make-hash-table :test 'equal)) | ||
| 2415 | |||
| 2416 | (eval-when-compile (require 'subr-x)) ; for string-trim-right | 2414 | (eval-when-compile (require 'subr-x)) ; for string-trim-right |
| 2417 | 2415 | ||
| 2416 | (defvar-local diff--syntax-file-attributes nil) | ||
| 2417 | (put 'diff--syntax-file-attributes 'permanent-local t) | ||
| 2418 | |||
| 2418 | (defun diff-syntax-fontify-hunk (beg end old) | 2419 | (defun diff-syntax-fontify-hunk (beg end old) |
| 2419 | "Highlight source language syntax in diff hunk between BEG and END. | 2420 | "Highlight source language syntax in diff hunk between BEG and END. |
| 2420 | When OLD is non-nil, highlight the hunk from the old source." | 2421 | When OLD is non-nil, highlight the hunk from the old source." |
| @@ -2444,33 +2445,38 @@ When OLD is non-nil, highlight the hunk from the old source." | |||
| 2444 | (when file | 2445 | (when file |
| 2445 | (if (not revision) | 2446 | (if (not revision) |
| 2446 | ;; Get properties from the current working revision | 2447 | ;; Get properties from the current working revision |
| 2447 | (when (and (not old) (file-exists-p file) | 2448 | (when (and (not old) (file-readable-p file) |
| 2448 | (file-regular-p file)) | 2449 | (file-regular-p file)) |
| 2449 | (let ((buf (get-file-buffer (expand-file-name file)))) | 2450 | (let ((buf (get-file-buffer (expand-file-name file)))) |
| 2450 | ;; Try to reuse an existing buffer | 2451 | ;; Try to reuse an existing buffer |
| 2451 | (if buf | 2452 | (if buf |
| 2452 | (with-current-buffer buf | 2453 | (with-current-buffer buf |
| 2453 | (diff-syntax-fontify-props nil text line-nb)) | 2454 | (diff-syntax-fontify-props nil text line-nb)) |
| 2454 | ;; Get properties from the file | 2455 | ;; Get properties from the file. |
| 2455 | (with-temp-buffer | 2456 | (with-current-buffer (get-buffer-create |
| 2456 | (insert-file-contents file) | 2457 | " *diff-syntax-file*") |
| 2458 | (let ((attrs (file-attributes file))) | ||
| 2459 | (if (equal diff--syntax-file-attributes attrs) | ||
| 2460 | ;; Same file as last-time, unmodified. | ||
| 2461 | ;; Reuse buffer as-is. | ||
| 2462 | (setq file nil) | ||
| 2463 | (insert-file-contents file) | ||
| 2464 | (setq diff--syntax-file-attributes attrs))) | ||
| 2457 | (diff-syntax-fontify-props file text line-nb))))) | 2465 | (diff-syntax-fontify-props file text line-nb))))) |
| 2458 | ;; Get properties from a cached revision | 2466 | ;; Get properties from a cached revision |
| 2459 | (let* ((buffer-name (format " *diff-syntax:%s.~%s~*" | 2467 | (let* ((buffer-name (format " *diff-syntax:%s.~%s~*" |
| 2460 | (expand-file-name file) | 2468 | (expand-file-name file) |
| 2461 | revision)) | 2469 | revision)) |
| 2462 | (buffer (gethash buffer-name | 2470 | (buffer (get-buffer buffer-name))) |
| 2463 | diff-syntax-fontify-revisions))) | 2471 | (if buffer |
| 2464 | (unless (and buffer (buffer-live-p buffer)) | 2472 | ;; Don't re-initialize the buffer (which would throw |
| 2465 | (let* ((vc-buffer (ignore-errors | 2473 | ;; away the previous fontification work). |
| 2466 | (vc-find-revision-no-save | 2474 | (setq file nil) |
| 2467 | (expand-file-name file) revision | 2475 | (setq buffer (ignore-errors |
| 2468 | diff-vc-backend | 2476 | (vc-find-revision-no-save |
| 2469 | (get-buffer-create buffer-name))))) | 2477 | (expand-file-name file) revision |
| 2470 | (when vc-buffer | 2478 | diff-vc-backend |
| 2471 | (setq buffer vc-buffer) | 2479 | (get-buffer-create buffer-name))))) |
| 2472 | (puthash buffer-name buffer | ||
| 2473 | diff-syntax-fontify-revisions)))) | ||
| 2474 | (when buffer | 2480 | (when buffer |
| 2475 | (with-current-buffer buffer | 2481 | (with-current-buffer buffer |
| 2476 | (diff-syntax-fontify-props file text line-nb)))))))) | 2482 | (diff-syntax-fontify-props file text line-nb)))))))) |