Subject: bug#70036: a fix that

From: Theodor Thornhill <[email-masked]>
Date: Fri, 19 Apr 2024 13:51:12 +0200

Theodor Thornhill <[email-masked]> writes:

> João Távora <[email-masked]> writes:
>
>> On Fri, Apr 19, 2024 at 12:32 PM Theodor Thornhill <[email-masked]> wrote:
>>
>>> I wonder - why can't we use just buffer-file-truename?
>>>
>>> In the below function, wouldn't buffer-file-truename let us avoid the
>>> file-truename in eglot-path-to-uri?
>>
>> Never used, but try it out.  It seems it's already a built-in cache
>> of whatever the buffer's truename is (and the docstring says
>> it does call the slow `file-truename`).  But like in my patch, it's
>> a one-time thing.  So yeah, if it's available in old Emacsen as well,
>>  it could replace `eglot--cached-tdi`, but then the search in the
>> publishDiagnostics
>> handler would have to be adjusted accordingly to call uri-to-path again.
>
> What would you consider as a sufficiently old Emacs?
>

I guess this should be enough:

commit f6ed2e848d23035748b621a86be74956c093823f
Author: Richard M. Stallman <[email-masked]>
Date:   Tue Feb 14 16:33:19 1995 +0000

    (syms_of_buffer): Set up Lisp var buffer-file-truename.
    (init_buffer_once): Set up flag and default value for file_truename.
    (reset_buffer): Init file_truename slot.

diff --git a/src/buffer.c b/src/buffer.c
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -3011,0 +3014,5 @@
+  DEFVAR_PER_BUFFER ("buffer-file-truename", &current_buffer->file_truename,
+		     make_number (Lisp_String),
+    "Truename of file visited in current buffer, or nil if not visiting a file.\n\
+The truename of a file is calculated by `file-truename'.\n\
+Each buffer has its own value of this variable.");

Theo