From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: sadiq@sadiqpk.org, 60176@debbugs.gnu.org,
Stefan Monnier <monnier@iro.umontreal.ca>,
Juri Linkov <juri@linkov.net>
Subject: bug#60176: 29.0.60; Fallback file variable mode if treesitter is not usable
Date: Tue, 20 Dec 2022 20:35:32 -0800 [thread overview]
Message-ID: <2A48A6AE-F4C1-4AF6-9E14-8D032BC1D558@gmail.com> (raw)
In-Reply-To: <61db3ccacc2697d0b740315af495fca2@sadiqpk.org>
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Juri Linkov <juri@linkov.net>
>> Cc: sadiq@sadiqpk.org, monnier@iro.umontreal.ca, 60176@debbugs.gnu.org
>> Date: Mon, 19 Dec 2022 19:29:13 +0200
>>
>> >> 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.
>>
>> Then 'c-ts-mode' should fall back to 'c-mode' when treesit is not available?
>> Like this:
>>
>> ```
>> 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"
>>
>> (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’t want
c-mode-hook to run if we decide to fall back to c-ts-mode.
I don’t have a good way to cleanly implement such fallback without
changing auto mode, local variable, define-derived-mode, etc. I used
Stefan’s 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
prev parent reply other threads:[~2022-12-21 4:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-18 12:07 bug#60176: 29.0.60; Fallback file variable mode if treesitter is not usable Mohammed Sadiq
2022-12-19 7:39 ` Juri Linkov
2022-12-19 12:35 ` Eli Zaretskii
2022-12-19 13:12 ` Mohammed Sadiq
2022-12-19 16:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-09 17:30 ` Juri Linkov
2023-01-09 17:57 ` Eli Zaretskii
2023-01-09 23:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-10 12:55 ` Eli Zaretskii
2023-01-10 14:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-10 18:08 ` Juri Linkov
2023-01-10 18:21 ` Eli Zaretskii
2023-01-16 17:32 ` Juri Linkov
2023-01-16 18:21 ` Eli Zaretskii
2023-01-16 18:36 ` Juri Linkov
2023-01-16 19:26 ` Eli Zaretskii
2023-01-17 7:33 ` Juri Linkov
2023-01-17 12:07 ` Eli Zaretskii
2022-12-19 17:29 ` Juri Linkov
2022-12-19 17:47 ` Eli Zaretskii
2022-12-21 4:35 ` Yuan Fu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2A48A6AE-F4C1-4AF6-9E14-8D032BC1D558@gmail.com \
--to=casouri@gmail.com \
--cc=60176@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
--cc=monnier@iro.umontreal.ca \
--cc=sadiq@sadiqpk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).