From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#72343: [PATCH] Fix eglot-server-programs for TeX modes Date: Tue, 06 Aug 2024 20:48:00 +0200 Message-ID: <87frrhxzbz.fsf@gmail.com> 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 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13431"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 72343@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 06 20:50:05 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 1sbPG0-0003Ks-TM for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 06 Aug 2024 20:50:05 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sbPFh-0003mS-2n; Tue, 06 Aug 2024 14:49:45 -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 1sbPFb-0003l9-Av for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:49:39 -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 1sbPFa-0000j1-Id for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:49:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=9TjRZzbBop9SsNvUSX2VCeRWzrduAE82vmcccc08OM0=; b=Mng6iTNhy9rXEadjqUykFmSigj1RBCETTyHa+0dfWEEAKODeklq9u5ajPanm5XFDMgIHUNSW8cBLS6I9kemmKFAGxP5JEdPKpB/xe/pEk9AcZfiAPa4+NkYOwvmFWcXW7EfBn0zNz3+PKJi70/zKJBu440LwFHSrhN+KRcZlkwyvEhOh0EbcntkpuIh5Jh5kC2A7/tUFJRxvQr9FvbGMcwJpHkXlntDora/Codd9xQ/SjjYu8MbA1a0iv2AdYoG5pIdEZxZo9fAbKPtxKpiJVa5svLXh0GSepUS/9DhZH0GdAjRvemd05B6awRmyGgIokjkRS3J3HUOT1Bt+QZA3DA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sbPFy-0006ak-6B for bug-gnu-emacs@gnu.org; Tue, 06 Aug 2024 14:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 06 Aug 2024 18:50: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.172297017825294 (code B ref 72343); Tue, 06 Aug 2024 18:50:02 +0000 Original-Received: (at 72343) by debbugs.gnu.org; 6 Aug 2024 18:49:38 +0000 Original-Received: from localhost ([127.0.0.1]:33053 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbPFZ-0006Zt-Pv for submit@debbugs.gnu.org; Tue, 06 Aug 2024 14:49:38 -0400 Original-Received: from mail-ed1-f54.google.com ([209.85.208.54]:61537) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sbPFV-0006Zd-Ie for 72343@debbugs.gnu.org; Tue, 06 Aug 2024 14:49:36 -0400 Original-Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5b391c8abd7so1120402a12.2 for <72343@debbugs.gnu.org>; Tue, 06 Aug 2024 11:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722970083; x=1723574883; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9TjRZzbBop9SsNvUSX2VCeRWzrduAE82vmcccc08OM0=; b=H4JCYflDaWhxdocJBJNTtIXTAHRKCDg8Ac7toEHUPdyX2OaUDd9VKhIYEOw00CfX2W Byd2kLe1IxSPViukvjtef/9qJUPVKZWuHbTywP8yKiTBiPYoSjMI1WvdCSeJsYaiBcJp aFCZ7E7X4UydtsjasOTOHIyPB7QJ7G+9znW71w4lS0gqt3VAKaKg3BQImSB2f7hK3Vnj mDUIWQ433i1W8E3r2deXB+EC8LaIA3l1BMbaYjjfr9gdp+3qN/1V5pvloJvFHaTigJLt Zw2f2dKXlVq6dGHIkrxJvFL2F56fwI/I7MCcA54TzZe2VGt9geThZsHUsKHx93nBpW9/ zs0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722970083; x=1723574883; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9TjRZzbBop9SsNvUSX2VCeRWzrduAE82vmcccc08OM0=; b=agc2xcEHA7AUssabzoc/Z2HaCVo4GGYvm8E6FcNBeX11+ebU9A8SepSV7aIf3lfTzD +2JAnV5Pnqp+0fi5Id25RaHOlL/Xgbpw0lo/Qr8cEpz7uV/b1vHZ/nCqKNY5CfafZ72X DG8OUxceDES/lcmW0a8eAVGkrFe5wgbh5kg53kvK5rLXsWDEO5ILmfkh6hajGJhM8DU2 wW4wXlDhj9sVKiOcKyKt4StxpSpoD5rAar6cNGyNCjhkODsFnhv145u433cmMMTY/2L7 ozWmCdpON4I+yyAZbI/o1G+p/0xYjJ6aQttE+3Gai1wdj83RP/97gFORo7bLm7+Hzmr9 Qllw== X-Gm-Message-State: AOJu0YzdtsCpfQB7UHM9hQFRfS2whS9Q5Spuh9/Udrbqdc2Fq21562/p PbuV98MIcqQh30RsBY6ISKHKOZsOUGUmBSUOO3vPVWz2khUzj2pX X-Google-Smtp-Source: AGHT+IG+01I6wFX2eajClRMRPcMP5KmbLIMll3udgRSesJqQCx6ir5w0br+scji7jjM9YT9eNbVV1g== X-Received: by 2002:a05:6402:22d0:b0:5b9:3846:8bae with SMTP id 4fb4d7f45d1cf-5b93846941bmr8331575a12.15.1722970083064; Tue, 06 Aug 2024 11:48:03 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8a87:ff00::e354]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83960f2fdsm6219205a12.7.2024.08.06.11.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 11:48:02 -0700 (PDT) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Tue, 6 Aug 2024 19:08:45 +0100") 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:289856 Archived-At: On Tue, 6 Aug 2024 at 19:08, Jo=C3=A3o T=C3=A1vora wrote: > On Tue, Aug 6, 2024 at 5:38 PM Augusto Stoffel wrot= e: > >> > 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. Fair enough. >> 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". I know about the list, but unfortunately "tex" as a language id makes no sense. It's like saying a program is written in "lisp" without saying which Lisp dialect. > 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). Again, every TeX program belongs to a specific dialect: plain TeX, LaTeX and ConTeXt being the main ones. Accordingly, tex-mode is not a real major mode; it's just an "abstract base mode" from which the actual TeX modes derive (see the docstring for details). > 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")) So again, for the reason above, I wouldn't do what you suggest here. > 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. (The status quo is already way too complicated, and this doesn't sound like an improvement in that regard...) > 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. Note also that the LSP spec says nothing about ConTeXt or Texinfo. Moreover, texlab only supports latex and bibtex. > 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's true, and in fact it's true all languages. So a server could as well ignore the language id and deduce it on its own -- except for the caveat that ultimately the user might know better and it's useful to rely on the user's choice of major mode / language id. > 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. I didn't ask but I don't see what could go wrong, given that texlab is for latex and bibtex only.