From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#72343: [PATCH] Fix eglot-server-programs for TeX modes Date: Tue, 6 Aug 2024 19:08:45 +0100 Message-ID: References: <87sevtz8xg.fsf@gmail.com> <86msm1z8c4.fsf@gnu.org> <87ttg8k9l6.fsf@gmail.com> <86frrszbep.fsf@gnu.org> <87o765k7ze.fsf@gmail.com> <87ed71fvy8.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7400"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 72343@debbugs.gnu.org To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 06 20:10:59 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sbOeA-0001gk-KR for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 06 Aug 2024 20:10:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbOdr-0004S0-TY; Tue, 06 Aug 2024 14:10:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sbOdq-0004Rp-TX for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:10:38 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sbOdq-0003lP-K3 for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:10:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=n0IeHWRqWSZihnn7NsZ9IzjJcsRI5LTfbwBgGAL+xvk=; b=bKVaWDaYwE2Ny9adKFZeT539OCqwJF/Y+viO+PVDqK3lFNTV8D/gAqB2pjqwgNN3SmrZzVROpdIKp8XmcwTDKzLUD3knYAv+wKk8odUPhY0Mq/YgPwtS0ChSsDsjHP0ceAn4zNnWDSiHMYJF+wKXf89DLvsnmTyn0Xl97fXvAfsKR78U+21XCMu5K4tF9+MoQetekInl0WpvQ9wUn9CV0zPMduRDZxrFbFEUBHl8ywouzVdkt97WaGofddSg4E4Zg1HADu6RX5AOLO41oJZIyVvw7dx2EIiY8DBMIVSLRX0tMg2sVFyuw59E6T0SZG+QXFmyOgtRzi9cL32gxvWmqA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sbOeE-0005bE-FC for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 06 Aug 2024 18:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72343 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72343-submit@debbugs.gnu.org id=B72343.172296783021483 (code B ref 72343); Tue, 06 Aug 2024 18:11:02 +0000 Original-Received: (at 72343) by debbugs.gnu.org; 6 Aug 2024 18:10:30 +0000 Original-Received: from localhost ([127.0.0.1]:33015 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbOdh-0005aQ-Lt for submit@debbugs.gnu.org; Tue, 06 Aug 2024 14:10:30 -0400 Original-Received: from mail-oi1-f177.google.com ([209.85.167.177]:58720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbOde-0005a9-F4 for 72343@debbugs.gnu.org; Tue, 06 Aug 2024 14:10:28 -0400 Original-Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3db19caec60so530806b6e.1 for <72343@debbugs.gnu.org>; Tue, 06 Aug 2024 11:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722967736; x=1723572536; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=n0IeHWRqWSZihnn7NsZ9IzjJcsRI5LTfbwBgGAL+xvk=; b=RIKV+BBE1JOppxGAg8mKsoyG8InkZF2S0UHrs33fI7qC+V8fD+t2z3GrqS6vspyMT/ e2ZSFar40pAA2ABV4CBXszudMvCUWh+F9E1vmaLGOpShYviE8KUe30AKXSA1PyCldZTr NhK2YoEP+SWtwIf6Uwnc0igvP9ge521tr72yPYDfeZN/bwVRKQLsdbyGGh1Qr1MKt7rN 5weIAxO0OOjcs8YBCtvFojU2IaxwOB24JTDyp7sKTz3ZPQ4Jb7k8Pjvn/0ZQr/lnfhFT 1ohGBIJTLCiGsI3zqC99Xba6BIjV+cbAVnc0a/LD7XGQh7cu6Rb1tawOYV3WvdBsmHAh Kpjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722967736; x=1723572536; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=n0IeHWRqWSZihnn7NsZ9IzjJcsRI5LTfbwBgGAL+xvk=; b=bc236bcLB+9k0FcYN6SqM8eRxuPqSI9Ipxr9sYbFCQg7EIJUqB3bqsNZ8ikb5pLRtB T/+HEoMKM/nZuEiM9dTws7bS+afH24ls9U78/iNyUtUI62PoKk3IDNtjeMS01cce9UhB CdyFJlVDHZ++hQWa9in2xfTb9InIMrhNeRK1ntgjvkjs6oSCtNEkVHFcnoXd5i3P56An ks3wA/CAlKRsgXvoYZvCWWv+Wh7MxbBlDByoyrLRX0XmkrQeqYhvTHlVBKidvwuNt7TW /Y1LErZankhuf7w18NXC1SccUYoYTVZedgZAdciRPsEXaHURznAtaQcht/T3gVhQK9uC bqiA== X-Gm-Message-State: AOJu0Yx9mFrwHEPLpTGbGYVwqcDytju8bKgHtbUeuIUKg7fKxc8pfnVn KwCTkDSVAppNOy0/WEh47QbYN/0O4vF7y/BlM9rlDantqBwHl3dSk3Y+Syq4GAdBxJRNZ92S62N hSO9fXjSMhGUkDku+29TkwivvlhU= X-Google-Smtp-Source: AGHT+IGkPt8/4g4nuBd+GPrhpxwaiUIraEHSV8WaCifcuAyyeUMcPGOqzRLakjcBCJIEcgb2+i86aWRiZueSNbDg4Eg= X-Received: by 2002:a05:6871:62c1:b0:25a:eca3:6b59 with SMTP id 586e51a60fabf-26891e685e8mr19641695fac.40.1722967736473; Tue, 06 Aug 2024 11:08:56 -0700 (PDT) In-Reply-To: <87ed71fvy8.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289851 Archived-At: On Tue, Aug 6, 2024 at 5:38 PM Augusto Stoffel wrote: > > So there's no "single pick" in general. > You don't need to explain that to me ;-). It is you who alluded to a single pick, so I thought I had to. Also earlier you proposed multiple entries in eglot-server-programs, which would impede this multi-language-per-session feature. So I figured you wouldn't be familiar with it. > What I want to achieve (or, if I may, what Eglot should do) in case it > wasn't clear yet, is: file x.tex is sent language id "latex" and file > y.tex is sent language id "plain-tex". Indeed it wasn't clear, so I'm very glad I asked. I don't see "plain-tex" in the list over at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ I just see "tex" and "latex" and "bibtex". Now, if you want "latex" to be sent for x.tex (in latex-mode) and "tex" to be sent for x.tex (in plain-tex-mode), there is this possibility. diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 5845aff39b7..2695aa93ffe 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 tex-mode context-mode texinfo-mode bibtex-mode) . ,(eglot-alternatives '("digestif" "texlab"))) (erlang-mode . ("erlang_ls" "--transport" "stdio")) ((yaml-ts-mode yaml-mode) . ("yaml-language-server" "--stdio")) No need to mention plain-tex-mode at all. The "guess" logic will work (though I still recommend :language-id cookie). You might notice this will only work for a particular sequence of invocations (specifically starting the server with the latex-mode file open, then opening other files in plain-tex-mode). But it won't for many other cases. The fact that Emacs models latex-mode as a descendent of tex-mode is something Eglot can't do anything about. It means that Emacs thinks that that every LaTex program is a TeX program at least at some syntactic level (is this true? no idea). So as soon as you have the two files open, M-x eglot-reconnect will send "tex" for _both_. Which, according to Emacs's view of the world, isn't wrong. This has happened before with the js/json mode and has been fixed in the mode relations. I think bug#67463. The same idea thatfixed it there could be applied here. Anyway, if plain-tex-mode is an attempt to fix this, by making a core mode that is not directly related to latex-mode, then I think it should appear in the list, but then :language-id set to to "tex". But I see plain-tex-mode also inherits from tex-mode, so the fundamental problem remains. Unless you remove tex-mode from the list (which is what you did). But then outside descendents of tex-mode would be cut off, which is what I warned about. I do think that's the lesser of two evils though. So anyway this is my suggestion: @@ -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 :language-id "tex") context-mode texinfo-mode bibtex-mode) . ,(eglot-alternatives '("digestif" "texlab"))) (erlang-mode . ("erlang_ls" "--transport" "stdio")) ((yaml-ts-mode yaml-mode) . ("yaml-language-server" "--stdio")) In theory, this could also be fixed by keeping tex-mode in there, and then adjusting Eglot's heuristic, by ranking the potential ancestors and selecting the closest one, in 'eglot--languageId'. Could be tricky or could be easy, feel free to give it a shot. Yet another idea is to not reorder modes at all in 'eglot--lookup-mode' and use an explicit order to express this ranking. I admit I don't remember what the reordering idea (main-mode-sym is the local var name) is for. it couldprecede the multiple-language-ids feature. Or it could be essential for some other thing: testing would be needed. > This doesn't matter, as it's an Eglot issue. Any TeX server will do. This is not established, at least not yet. You are requesting for a "plain-tex" LSP languageId property to be sent and that is outside the spec as far as I can tell from reading the spec. Maybe your digestif server supports and likes it, though. But it might break "texlab" for all I know. Even the fact that "tex" is all that's being sent at the moment may or may not be a bug -- only LaTex/Tex specialists can say that. And certainly a capable enough language server, which is tasked with analysing a file syntactically, can do much the same as our own tex-mode.el and figure out the correct language from the contents. Might do it better than Emacs. That said, if you really want to send "plain-tex", then there are two options. You can change your user value of eglot-server-programs, obviously. Or you can confirm with "texlab" that they don't mind, in which case -- but only in that case -- your latest patch is acceptable.