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#68246: 30.0.50; Add non-TS mode as extra parent of TS modes Date: Mon, 15 Jan 2024 15:27:05 +0000 Message-ID: References: <838r53vlo5.fsf@gnu.org> <831qavvcbo.fsf@gnu.org> <83a5phskd5.fsf@gnu.org> <83h6joqz0t.fsf@gnu.org> <834jfoq86m.fsf@gnu.org> <831qarrbjx.fsf@gnu.org> <87a5p84nlh.fsf@gmail.com> <83edekfldq.fsf@gnu.org> 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="35589"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 68246@debbugs.gnu.org, Eli Zaretskii , casouri@gmail.com, Stefan Kangas , monnier@iro.umontreal.ca To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 15 16:28:26 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 1rPOsz-00094F-RL for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Jan 2024 16:28:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rPOse-0006hW-7P; Mon, 15 Jan 2024 10:28:04 -0500 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 1rPOsc-0006h7-4q for bug-gnu-emacs@gnu.org; Mon, 15 Jan 2024 10:28:02 -0500 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 1rPOsb-0004NI-Sn for bug-gnu-emacs@gnu.org; Mon, 15 Jan 2024 10:28:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rPOsb-00085h-MP for bug-gnu-emacs@gnu.org; Mon, 15 Jan 2024 10:28:01 -0500 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: Mon, 15 Jan 2024 15:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68246 X-GNU-PR-Package: emacs Original-Received: via spool by 68246-submit@debbugs.gnu.org id=B68246.170533244631055 (code B ref 68246); Mon, 15 Jan 2024 15:28:01 +0000 Original-Received: (at 68246) by debbugs.gnu.org; 15 Jan 2024 15:27:26 +0000 Original-Received: from localhost ([127.0.0.1]:46705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPOs2-00084p-CA for submit@debbugs.gnu.org; Mon, 15 Jan 2024 10:27:26 -0500 Original-Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]:43426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPOrz-00084b-Ub for 68246@debbugs.gnu.org; Mon, 15 Jan 2024 10:27:24 -0500 Original-Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2cd04078ebeso91042171fa.1 for <68246@debbugs.gnu.org>; Mon, 15 Jan 2024 07:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705332438; x=1705937238; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BWspocRlxCdFO7dR9ol+Y5pI3+NE87yAkOByuEsHtTc=; b=e4IMrxkNmUFRPHGGcKizCpvn0g62K3neOYwdEgPHYl/rCcxk41YG2BRTuk7mDYi8t4 rvy4ej3dr27MwzzZUxNMYRorhRFUz2fBlTuUbOmNCEY6OpMKbIt7l/WWzl7ju6Otvgdt 9yOA01wmFMJH81O07pEGxnLHac0eBmIT+kcgErK2b2UQ0Zw+6GrtPTaMMtmOzFm+wh/y 9jgRFIFumu/7S8dpfzNAeo3Ve+KRQr8HBOKLfaBo67cmj0bm0lNqoPNDzenepq6c3GTY YupMfESvHABIy74KEf9g7zt7hgORP1vl3U0DINiY2Ie8nCTcRXdZJO6nSzDNnAfC+cnU 0EYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705332438; x=1705937238; h=content-transfer-encoding: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=BWspocRlxCdFO7dR9ol+Y5pI3+NE87yAkOByuEsHtTc=; b=ciooEA2bsGxqYiHsYUVrPuVgtbFCTyxfVkAyNmf6VQlfB08Ag5e0ZbUAYa+0D70a1J 3fPDAT0R2QUV5XYuuJzOuTzlWQy9N+DaIa1bUw94DLc2vEyxpMeCtKX0fioQz/ugkx4v S4eZVqqjCheu0kE2F5ve4UdyhZynIv5eqZp5Qe+18QteLthKY938MYZF11j/pPHkO900 BhAm4P6qUYAikOCt2XMyt0qY/LKnyp/9UBl9AvdqiGngh1WZr9gNtZn9lrfGxhdFjaDx buqYYGCuX/Pjm76wXt2yOiL4c1FrjtJZLQatXZtHt1E+cU6CV9+QYG6QCZMExZjc00tn t2uw== X-Gm-Message-State: AOJu0YzuBk0ZbCwoXap+0XROu7r+o/lPrjoWTtXWHTJHooIE7QyYumQW hOnsNlV1m+344yfT8t94YayBYspwH/MiWOh8HaU= X-Google-Smtp-Source: AGHT+IHqwBXfTJYUADe3QURVT2wJFKbOI8icJ6HEbj/PPddzw9AY4SC3QVLprjQbrzKAYeLPkev2jCwzvi00ezmD7Q8= X-Received: by 2002:a2e:a54c:0:b0:2cd:8dda:e15c with SMTP id e12-20020a2ea54c000000b002cd8ddae15cmr4677030ljn.1.1705332437784; Mon, 15 Jan 2024 07:27:17 -0800 (PST) In-Reply-To: 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:278289 Archived-At: On Mon, Jan 15, 2024 at 2:10=E2=80=AFAM Dmitry Gutov wro= te: > > It's not like we don't have an existing solution for this: if there are > two different modes to configure, change the settings for both modes, or > alter two hooks. Less magical and more verbose, but being explicit can > be good. I don't think there's anything magical about a base mode. But I like your solution too. > Here's a draft patch of how a "language" could work. It doesn't alter > every entry, but it is backward compatible. I think something like this can work, yes. - (funcall (alist-get mode major-mode-remap-alist mode)) + ;; XXX: When there's no mapping for `:', we could also + ;; look for a function called `-mode'. + (funcall (alist-get mode major-mode-remap-alist (if (keywordp mode) + #'fundamental-mo= de + mode))) + (when (keywordp mode) ;Perhaps do that unconditionally. + (run-hooks (intern (format "%s-language-hook" (buffer-language))))= ) (unless (eq mode major-mode) Regarding the "XXX", this is basically the same questions in the two headings, I think, which is whether to consider the in existing -mode as language. I think we can do it yes. Eglot and other packages [*] have been doing it for quite some time. It will fail very rarely, only for major modes outside Emacs (like "tuareg-mode" for Ocaml) and we can probably fix that in-tree. The only thing that leaves me some doubts is the 'set-buffer-language' entry point. It's a new thing not strictly required. Normally the databases are edited (via whatever means) and then the buffer is reverted for a mode change. So I don't think we need to introduce this user convenience just yet (though, like the other user conveniences you have imagined, I'm not necessarily opposed to it). Also 'buffer-language' could be 'get-mode-language', so you don't have to have an actual buffer handy to get this association. The implementation would just be a reverse search in major-mode-remap-alist Other than that, I think the solution is workable. The other package [*] that does exactly the same thing as Eglot, and invented it independently is markdown-mode: (defun markdown-get-lang-mode (lang) "Return major mode that should be used for LANG. LANG is a string, and the returned major mode is a symbol." (cl-find-if #'markdown--lang-mode-predicate (nconc (list (cdr (assoc lang markdown-code-lang-modes)) (cdr (assoc (downcase lang) markdown-code-lang-modes))) (and (fboundp 'treesit-language-available-p) (list (and (treesit-language-available-p (intern lang)) (intern (concat lang "-ts-mode"))) (and (treesit-language-available-p (intern (downcase lang))) (intern (concat (downcase lang) "-ts-mode"))))) (list (intern (concat lang "-mode")) (intern (concat (downcase lang) "-mode")))))) It uses this to know what major-mode to use to fontify GitHub style markdown code blocks (which have a little language cookie after the three backticks). Like Eglot's similar code, I think it could be trivially rewritten if something like your patch were in place. Bug#68217 is also relevant here. Eglot calls into markdown-mode.el to fontify LSP documentation snippets and sometimes the mode picked by markdown-mode.el to do the fontification is not the same the user is using for the buffer. It most clearly should be. So get-language-for-mode and get-(preferred)-mode-for-language are two evidently needed helpers. Jo=C3=A3o