From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#60176: 29.0.60; Fallback file variable mode if treesitter is not usable Date: Tue, 20 Dec 2022 20:35:32 -0800 Message-ID: <2A48A6AE-F4C1-4AF6-9E14-8D032BC1D558@gmail.com> References: <61db3ccacc2697d0b740315af495fca2@sadiqpk.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="4595"; mail-complaints-to="usenet@ciao.gmane.io" Cc: sadiq@sadiqpk.org, 60176@debbugs.gnu.org, Stefan Monnier , Juri Linkov To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 21 05:36:16 2022 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 1p7qpz-00012Q-Nd for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Dec 2022 05:36:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7qpn-00057N-My; Tue, 20 Dec 2022 23:36:03 -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 1p7qpm-00055j-Pt for bug-gnu-emacs@gnu.org; Tue, 20 Dec 2022 23:36:02 -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 1p7qpm-0007ga-Cy for bug-gnu-emacs@gnu.org; Tue, 20 Dec 2022 23:36:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p7qpl-00016u-RR for bug-gnu-emacs@gnu.org; Tue, 20 Dec 2022 23:36:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <61db3ccacc2697d0b740315af495fca2@sadiqpk.org> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Dec 2022 04:36:01 +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.16715973434261 (code B ref 60176); Wed, 21 Dec 2022 04:36:01 +0000 Original-Received: (at 60176) by debbugs.gnu.org; 21 Dec 2022 04:35:43 +0000 Original-Received: from localhost ([127.0.0.1]:49224 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7qpT-00016f-Do for submit@debbugs.gnu.org; Tue, 20 Dec 2022 23:35:43 -0500 Original-Received: from mail-pj1-f50.google.com ([209.85.216.50]:46917) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p7qpR-00016X-1f for 60176@debbugs.gnu.org; Tue, 20 Dec 2022 23:35:41 -0500 Original-Received: by mail-pj1-f50.google.com with SMTP id u4-20020a17090a518400b00223f7eba2c4so910078pjh.5 for <60176@debbugs.gnu.org>; Tue, 20 Dec 2022 20:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=08tr56+9lu35K67xAt3jx07f+u/xO46YhhzfRKeSBCQ=; b=Cs49nZ5YzfBXgCNYEd8thjl5DSM2IKmAGf5mCtrUmrjsiAcp5qcG1x06oCA5LMfB36 0jmZs3+ksEk/7hgEfrJ88oORCNtMCdIUlsptqMGq64nrd5l53AIFjo5uGV63E61HHVbX 1OTa0gbbzgunaOUltI2PzWeVuL2VSZ2JmqjHaVNhyxKh7Ub9lR6ub8bgy0QyTqJxUiRu PZYKFyG4vpnfLyUzaCDkQqStQeEZyeeRBx6PCsp3X4Si7wi6o/IUYeM4/K8tfbfMJmio /r7QG4PwwU4l/Lf6Y7bqDtY78fk7yDUe6DdA+dhMyMhBPf3H9y1nCbxs7Hyj9DFQTy6G nCtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=08tr56+9lu35K67xAt3jx07f+u/xO46YhhzfRKeSBCQ=; b=4ht7p1dEDqrq1FUgzkt5mp98pB0aKwZ/F6G17asG2+p/uD1HJIervqp0xgbc5lKpKD k0WzV94Wxi7JZYIWX2yFvKpnmyiS7Dfgy/EwRJY/IIl5ITeR62A09jUavnSh/7GPVO/l WQB0E5idzmwE2vK/tyoqONZm4WtMqQKgQy1qSbcssa7RIUXxeS3VTEf/7W5Na5fX3b6W WEz8tLn6SvU5+mAQZQ5Str6Jl0r6mZH9lWlKa9lkpPP3Vj5RQ/g/Xd0MOclRFVGAedUX XF6YELKkeUdoA2vl3oo5zMe+E/xnVPVwJMk2vIyrr2PYViizniXcQXsAZnCPdlvHjZ3K B4VA== X-Gm-Message-State: AFqh2krr7anTir2cE0l6ciAMpJrO5tWIaHTZjYwpstTUVlJgCWZOOAhQ k9VUQB+WZPozr+LXjzSE3ng= X-Google-Smtp-Source: AMrXdXu1rXUgNlwFs7O4G+i9KYPVHXDp4WBqRhALDTHfkEVO+c5qz2rRENi3o6ygIsrE4y4Amt2c0A== X-Received: by 2002:a17:902:b947:b0:185:441e:2d78 with SMTP id h7-20020a170902b94700b00185441e2d78mr640142pls.15.1671597334874; Tue, 20 Dec 2022 20:35:34 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b00186b6a04636sm10214718plk.255.2022.12.20.20.35.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2022 20:35:34 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:251560 Archived-At: Eli Zaretskii writes: >> From: Juri Linkov >> Cc: sadiq@sadiqpk.org, monnier@iro.umontreal.ca, = 60176@debbugs.gnu.org >> Date: Mon, 19 Dec 2022 19:29:13 +0200 >>=20 >> >> 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))) >> > >> > I think the idea is that this should happen by default, not as a >> > (not-so-trivial) customization by the users. >>=20 >> Then 'c-ts-mode' should fall back to 'c-mode' when treesit is not = available? >> Like this: >>=20 >> ``` >> diff --git a/lisp/progmodes/c-ts-mode.el = b/lisp/progmodes/c-ts-mode.el >> index cf941236f82..5004b9a5e1d 100644 >> --- a/lisp/progmodes/c-ts-mode.el >> +++ b/lisp/progmodes/c-ts-mode.el >> @@ -616,7 +616,7 @@ c-ts-mode >> (define-derived-mode c-ts-mode c-ts-base-mode "C" >> =20 >> (unless (treesit-ready-p 'c) >> - (error "Tree-sitter for C isn't available")) >> + (c-mode)) > > Yes. But not literally like that, because, for example, we don't want > that to happen when c-ts-mode is invoked interactively by the user -- > in that case we do want to signal an error. > > The automatic fallback should IMO happen only in situations like mode > specifications in 'mode' cookies or file-local variables, where it is > better to visit in a similar mode than completely fail visiting a > file. Also (mentioned by Stefan in another thread), we probably don=E2=80=99t = want c-mode-hook to run if we decide to fall back to c-ts-mode. I don=E2=80=99t have a good way to cleanly implement such fallback = without changing auto mode, local variable, define-derived-mode, etc. I used Stefan=E2=80=99s advice hack on bash-ts-mode, only because bash-ts-mode = only supports bash and it has to fallback to sh-mode for other shell scripts, otherwise it would be a pain to use. Yuan