From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#60176: 29.0.60; Fallback file variable mode if treesitter is not usable Date: Mon, 09 Jan 2023 19:30:20 +0200 Organization: LINKOV.NET Message-ID: <865ydf3dnf.fsf@mail.linkov.net> References: <61db3ccacc2697d0b740315af495fca2@sadiqpk.org> <86359bhmfx.fsf@mail.linkov.net> <83o7rzeflc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25383"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: Eli Zaretskii , sadiq@sadiqpk.org, 60176@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 09 18:39:55 2023 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 1pEw7l-0006SZ-PO for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Jan 2023 18:39:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEw49-0007xk-Mp; Mon, 09 Jan 2023 12:36:09 -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 1pEw47-0007rd-3g for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 12:36:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEw43-0005Zx-JJ for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 12:36:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pEw43-0004F1-Ev for bug-gnu-emacs@gnu.org; Mon, 09 Jan 2023 12:36:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Jan 2023 17:36:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60176 X-GNU-PR-Package: emacs Original-Received: via spool by 60176-submit@debbugs.gnu.org id=B60176.167328572616217 (code B ref 60176); Mon, 09 Jan 2023 17:36:03 +0000 Original-Received: (at 60176) by debbugs.gnu.org; 9 Jan 2023 17:35:26 +0000 Original-Received: from localhost ([127.0.0.1]:38094 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEw3R-0004DU-Nn for submit@debbugs.gnu.org; Mon, 09 Jan 2023 12:35:25 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:60275) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pEw3P-0004D5-NX for 60176@debbugs.gnu.org; Mon, 09 Jan 2023 12:35:24 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id B49A5FF807; Mon, 9 Jan 2023 17:35:14 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Mon, 19 Dec 2022 11:43:46 -0500") 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:253033 Archived-At: >> 'major-mode-remap-alist' should be able to handle this requirement >> since its design is similar to MIME.TYPES and MAILCAP. But actually >> MAILCAP supports an additional predicate TEST that is a command >> executed to determine whether or not the mailcap line applies. >> >> So to completely cover all needs, 'major-mode-remap-alist' should >> support a predicate as well. For example, >> >> (setq major-mode-remap-alist '((c-mode #'treesit-available-p c-ts-mode))) > > The current syntax is rather > > (setq major-mode-remap-alist '((c-mode . treesit-available-p c-ts-mode))) Is it possible at least to make this forward-compatible to support such a predicate in future? To enable ts-modes only in some buffers currently requires first to enable non-ts-mode, then conditionally ts-mode: (add-hook 'find-file-hook (lambda () (when (and (eq major-mode 'c-mode) ;; Unless in internal buffers: (not (string-prefix-p " " (buffer-name)))) (c-ts-mode)))) With a predicate in major-mode-remap-alist it would immediately enable the required mode: (setq major-mode-remap-alist '((c-mode . (lambda () (not (string-prefix-p " " (buffer-name)))) c-ts-mode))) Such a predicate would be useful in many other cases. For example, by default ".pl" is assigned to perl-mode, but this would help to reassign it to prolog-mode using some heuristics: (setq major-mode-remap-alist '((perl-mode . (lambda () (string-match-p "src/prolog" buffer-file-name)) prolog-mode)))