bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes


From: João Távora
Subject: bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes
Date: Tue, 16 Jan 2024 22:00:35 +0000

On Tue, Jan 16, 2024, 17:45 Dmitry Gutov <dmitry@gutov.dev> wrote:
>
> On 16/01/2024 12:34, João Távora wrote:
> > I see no real categorization or classification.  I just see
> > a many-to-one mapping of major modes to languages.
>
> It might even be many-to-many, at least in some cases.
>
> E.g. js-ts-mode being good for both :js and :jsx.

>
> Not sure how useful this -to-many relation is going to be in the above
> cases, but it's probably a good illustration of the possibility.

According to https://react.dev, jsx is a "JavaScript syntax
extension".  So it would seem JSX is a superset of JS.  If
js-ts-mode parses it perfectly, it could be called
jsx-ts-mode instead.

But does it? I see Emacs modes specific for jsx out there, I
suppose people use them for a reason.  There's also tsx-ts-mode
and typescript-ts-mode.

At the end of the day, a language is not so easy to define,
but it's not that problematic either, especially in the editor
(in the compiler, it's much more important).

The best sources are a standard, when it exists, but each iteration,
sometimes  each compiler is also its own language.  There's "GNU C",
"ANSI C", C17, C23.  All handled by the C modes we have and the best
way we have to designate this is just "C".  c++-mode also handles
this code by the way, probably flawlessly, and yet we don't say
c++-mode is for C and C++.

But if you want, I don't think there's any big problem
in making get-language-for-mode return a list, with
the most important likely language at the top.

I predict it'll be pretty rare, but I guess you could
have this (excuse the ugly CamelCase for demo purposes)

(setq auto-mode-alist '(("\\.js$" . :JavaScript)
                        ("\\.jsx$" . :JavaScriptReact)))

(setq m-m-remap-alist '((:JavaScript . js-ts-mode)
                        (:JavaScriptReact . js-ts-mode)))

And 'buffer-language' becomes more like:

(or buffer-overriding-language-keyword
    (with-current-buffer buffer (get-language-for-mode major-mode))
    (let (kw)
       (and buffer-file-name
            (keywordp
              (setq kw
                    ;; yes I know this needs regexps
                    (alist-get buffer-file-name auto-mode-alist)))
            kw))
    (consult-oracles)
    (error "Don't know what language this is, sorry"))

João





reply via email to

[Prev in Thread] Current Thread [Next in Thread]