Subject: Re: bug#72343: [PATCH] Fix eglot-server-programs for TeX modes

From: Augusto Stoffel <[email-masked]>
Date: Wed, 07 Aug 2024 11:17:58 +0200

On Wed,  7 Aug 2024 at 09:47, João Távora wrote:

> On Wed, Aug 7, 2024 at 8:02 AM Augusto Stoffel <[email-masked]> wrote:
>
>> Sure, but how is that useful information for a language server?
>
> Fairly useful. If someone tells me this upfront about some stream of
> data they're about to send I know I can use a very simple parser.
> Or I can reject it altogether if I don't like "lisp" for some reason.
> If working on a language server multiplexer, for example
> that information is possibly enough to know where to redirect the
> didOpen.

(That's a tangent, but in practice your multiplexer will be required to
know what to do with more specific language ids such as "common-lisp" or
"scheme".  So I still see no advantage in sending less specific language
ids.)

>> > 3. Ignoring my advice and sending "plain-tex" from Eglot anyway
>> > (i.e. installing your patch without :language-id)
>>
>> You're clearly against this so it is not going to happen, but I hope I
>> managed to explain to you why I would have done it.
>
> Ultimately, I have to leave room for a pragmatic decision from
> domain experts,  even if it violates the spec.  I'm just trying to
> understand the angles and judge the probability of breakage
> later on.
>
>> > For the _other_ orthogonal problem, I suggest:
>> >      (racket-mode . ("racket" "-l" "racket-langserver"))
>> > -    ((tex-mode context-mode texinfo-mode bibtex-mode)
>> > +    ((latex-mode (plain-tex-mode :language-id "tex") tex-mode
>> > context-mode texinfo-mode bibtex-mode)
>>
>> Since you want to send "tex" language id for plain tex, the following
>> suffices:
>>
>>     ((latex-mode tex-mode context-mode texinfo-mode bibtex-mode)
>
> Again, I don't "want" to (see above for the reasons).  This patch
> is concerned with the orthogonal requirement of keeping tex-mode
> (and not removing it as you proposed)
>
> So:
>
> * please make up your mind, i.e. make a (possibly overriding) decision
>   whether sending off-spec "plain-tex" for tex-mode is really what is
>   needed.
>
> * whatever your decision, keep 'tex-mode' in the list.
>
> * help me test the patch below by checking that problem X is now
>   solved and now new problem Z has popped up.

So this is my final suggestion then:

>From 22b876a153e8bbede02804e374c5c234213181f2 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Tue, 6 Aug 2024 16:58:06 +0200
Subject: [PATCH] Fix eglot-server-programs for TeX modes

* lisp/progmodes/eglot.el (eglot-server-programs): Explicitly list modes
derived from tex-mode, so that the correct language id is guessed.
---
 lisp/progmodes/eglot.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 31948a12d69..67bd26f6f02 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -292,7 +292,7 @@ eglot-server-programs
     (scala-mode . ,(eglot-alternatives
                     '("metals" "metals-emacs")))
     (racket-mode . ("racket" "-l" "racket-langserver"))
-    ((tex-mode context-mode texinfo-mode bibtex-mode)
+    ((latex-mode plain-tex-mode context-mode texinfo-mode bibtex-mode tex-mode)
      . ,(eglot-alternatives '("digestif" "texlab")))
     (erlang-mode . ("erlang_ls" "--transport" "stdio"))
     ((yaml-ts-mode yaml-mode) . ("yaml-language-server" "--stdio"))
-- 
2.45.2

It solves problem X and my estimated breakage probability is
"infinitesimally small" since it works for LaTeX, BibTeX and ConTeXt and
all other dialects are very very fringe.