|
From: | Dmitry Gutov |
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 |
User-agent: | Mozilla Thunderbird |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |