GNU bug report logs - #60176
29.0.60; Fallback file variable mode if treesitter is not usable

Previous Next

Package: emacs;

Reported by: Mohammed Sadiq <sadiq <at> sadiqpk.org>

Date: Sun, 18 Dec 2022 12:08:01 UTC

Severity: normal

Tags: notabug, wontfix

Merged with 60559, 60874

Found in version 29.0.60

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 60176 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: sadiq <at> sadiqpk.org, 60176 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#60176: 29.0.60; Fallback file variable mode if treesitter  is
 not usable
Date: Tue, 20 Dec 2022 20:35:32 -0800
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Juri Linkov <juri <at> linkov.net>
>> Cc: sadiq <at> sadiqpk.org,  monnier <at> iro.umontreal.ca,  60176 <at> 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




This bug report was last modified 2 years and 118 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.