GNU bug report logs - #68246
30.0.50; Add non-TS mode as extra parent of TS modes

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Thu, 4 Jan 2024 22:12:01 UTC

Severity: wishlist

Found in version 30.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 68246 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>, casouri <at> gmail.com, João Távora <joaotavora <at> gmail.com>
Subject: bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes
Date: Wed, 10 Jan 2024 03:41:33 +0200
On 09/01/2024 05:55, Stefan Monnier wrote:
>> But for this to be useful to determine the language
>> of a major mode via reverse lookup,
> Define "the language".
> 
> The mapping from "language" to major mode can't be always reversible, so
> `major-mode-remap-alist` works to map "language" to "major-mode" but not
> the other way.

But that's the point: to be able to find 'javascript' from both 
'js-mode' and 'js2-mode'. Or 'ruby' from 'ruby-mode' and 'ruby-ts-mode'.

major-mode-remap-alist could have several entries for the same language: 
'assoc' will pick the highest priority (first) one, but 'rassoc' would 
be able to take advantage of every entry.

> The current bug-report*is*  about "finding the language" but the code
> that needs that info luckily doesn't need "the language" it just needs
> to know "does the current buffer contain language FOO", which is an
> easier problem, which I propose to solve with `derived-mode-p`, since
> that's what we've been using all these years.

TBF, I don't quite like the "subtleness" of this solution. The 
inheritance hierarchy of the modes is an implicit thing, and the fact 
that js-mode-hook would run in js-ts-mode in Emacs 30 but not in Emacs 
29 would likely trip over a lot of people. Especially those who read 
recipes on the Internet.

Also, "what language is this" does happen to be a meaningful question. 
Eglot's example aside, we can have other tools, databases, etc.

And what about the idea of TS modes becoming the "main" modes sometime, 
far in the future, if tree-sitter stays around long enough? At least for 
some languages, I mean. If the name of the "original" major mode stays 
synonymous with the file type, how do we migrate away from them? Create 
obsolete alias? Rename js-ts-mode to js-mode someday?

Finally, if we did have "languages" as an entity, we could have some UI 
for the user to choose the mode for a language - something like Debian's 
'update-alternatives'. And it would also serve to list the supported 
languages, I guess.




This bug report was last modified 1 year and 104 days ago.

Previous Next


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