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

From: Stefan Monnier <[email-masked]>
Date: Tue, 28 Jan 2020 08:58:32 -0500

> I wasn't following this thread closely, so I don't have a clear idea
> what problems does this change try to solve.  Could you humor me with
> a summary, please?  Why isn't buffer-file-name enough?

Some packages set `buffer-file-name` in temp-buffers in order to
activate the major mode of the corresponding file.  As you can see in
the patch it's used in various circumstances.

Most of the time this is harmless because it's transient, but it is
fundamentally a lie (it more or less claims that this temp buffer holds
the content of that file, even though it's not the case (not only
because the content doesn't match, but the buffer is usually not fully
set up as a proper file buffer, it can lead to get-file-buffer returning
the wrong buffer, ...) and even though it's transient it can cause
problems because hooks are run during this time (e.g. major mode hooks)
which may take action under the mistaken assumption that this buffer
really correspond to the file.

In the original bug report the problem was that the major mode activated
`eglot-mode` in this temp buffer.  There are many ways for this to
create problems.  The immediate error can be avoided in eglot of course,
but I think the problem goes deeper and we should fix it by making it
possible to set the major mode without having to lie about
`buffer-file-name`.

        Stefan