Subject: Re: bug#39190: 28.0.50; two buffers with same buffer-file-name (diff-syntax-fontify-props)

From: Felician Nemeth <[email-masked]>
Date: Sun, 02 Feb 2020 10:42:26 +0100

Juri Linkov <[email-masked]> writes:

>>> Could you please try to reproduce the issue using Eglot with the
>>> following minimal patch.  If it really fixes the bug then it
>>> should be committed to Emacs 27 immediately, and more changes
>>> could be added later.
>>
>> Unfortunately the minimal patch doesn't fix the issue.
>>
>> Case 1. When Eglot is started manually, then the recipe fails in an
>> after-change-major-mode-hook where the buffer-file-name is non-nil for
>> the temporary diff buffer.
>
> Strange, when I tested the minimal patch, there were no errors anymore.

Maybe I wasn't clear enough.  I got no errors, but flymake incorrectly
fontified the buffer.  Anyway, I tried to look into why this happened
even after applying your patch and it turned out that
vc-find-revision-no-save also calls set-auto-mode.  So, I don't know if
the following patch is correct, but together with your patch it does
solve the original issue.

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index f64b6c0631..c50ba132e7 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2098,7 +2098,7 @@ vc-find-revision-no-save
                     ;; For non-interactive, skip any questions
                     (let ((enable-local-variables :safe) ;; to find `mode:'
                           (buffer-file-name file))
-                      (ignore-errors (set-auto-mode)))
+                      (ignore-errors (delay-mode-hooks (set-auto-mode))))
                   (normal-mode))
 	        (set-buffer-modified-p nil)
                 (setq buffer-read-only t))