Commit bd6a19cc authored by Stefan Monnier's avatar Stefan Monnier

* lisp/vc/diff-mode.el: Avoid re-initializing buffer in diff-syntax

(diff--syntax-file-attributes): New var.
(diff-syntax-fontify-hunk): Detect when we're reusing the same buffer as
last time, to avoid re-initializing it.  Skip the
diff-syntax-fontify-revisions hash-table, since buffer-alist plays the
same role.
(diff-syntax-fontify-revisions): Delete var.
parent 7ba7def5
Pipeline #1253 failed with stage
in 50 minutes and 4 seconds
......@@ -2411,10 +2411,11 @@ and the position in MAX."
(diff-syntax-fontify-hunk beg end t)
(diff-syntax-fontify-hunk beg end nil)))
(defvar diff-syntax-fontify-revisions (make-hash-table :test 'equal))
(eval-when-compile (require 'subr-x)) ; for string-trim-right
(defvar-local diff--syntax-file-attributes nil)
(put 'diff--syntax-file-attributes 'permanent-local t)
(defun diff-syntax-fontify-hunk (beg end old)
"Highlight source language syntax in diff hunk between BEG and END.
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."
(when file
(if (not revision)
;; Get properties from the current working revision
(when (and (not old) (file-exists-p file)
(when (and (not old) (file-readable-p file)
(file-regular-p file))
(let ((buf (get-file-buffer (expand-file-name file))))
;; Try to reuse an existing buffer
(if buf
(with-current-buffer buf
(diff-syntax-fontify-props nil text line-nb))
;; Get properties from the file
(insert-file-contents file)
;; Get properties from the file.
(with-current-buffer (get-buffer-create
" *diff-syntax-file*")
(let ((attrs (file-attributes file)))
(if (equal diff--syntax-file-attributes attrs)
;; Same file as last-time, unmodified.
;; Reuse buffer as-is.
(setq file nil)
(insert-file-contents file)
(setq diff--syntax-file-attributes attrs)))
(diff-syntax-fontify-props file text line-nb)))))
;; Get properties from a cached revision
(let* ((buffer-name (format " *diff-syntax:%s.~%s~*"
(expand-file-name file)
(buffer (gethash buffer-name
(unless (and buffer (buffer-live-p buffer))
(let* ((vc-buffer (ignore-errors
(expand-file-name file) revision
(get-buffer-create buffer-name)))))
(when vc-buffer
(setq buffer vc-buffer)
(puthash buffer-name buffer
(buffer (get-buffer buffer-name)))
(if buffer
;; Don't re-initialize the buffer (which would throw
;; away the previous fontification work).
(setq file nil)
(setq buffer (ignore-errors
(expand-file-name file) revision
(get-buffer-create buffer-name)))))
(when buffer
(with-current-buffer buffer
(diff-syntax-fontify-props file text line-nb))))))))
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