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

From: Juri Linkov <[email-masked]>
Date: Thu, 20 Feb 2020 02:58:20 +0200

>> I tested this with additional patch that replaces `conf-mode` calls with
>> `conf-guess-mode`, and see that syntax font-lock now is fixed in diff-mode
>> on some conf files (not tested on all possible conf submodes).
>
> This said.  Using delay-mode-hooks in the diff-syntax driver is an ugly
> hack and is the real source of the problem, so splitting conf-mode into
> two is basically a way to work around the breakage introduced by the hack.

Indeed, but it seems it's too late to redesign this in the release
branch.  So unfontified conf-mode files in diff hunks is a trade-off
for not breaking the release.

As for changes in master, I tried something like this to use in
diff-syntax-fontify-props instead of direct set-auto-mode call:

(let ((buffer (make-indirect-buffer
               (current-buffer)
               (generate-new-buffer-name (buffer-name)))))
  (funcall
   (unwind-protect
       (with-current-buffer buffer
         (let ((buffer-file-name "/tmp/foo.el"))
           (set-auto-mode)
           major-mode))
     (kill-buffer buffer))))

It calls set-auto-mode in a temporary buffer.

Do you think this is the right direction?