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: Dmitry Gutov
Subject: bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes
Date: Sat, 6 Jan 2024 05:36:09 +0200
User-agent: Mozilla Thunderbird

On 06/01/2024 05:19, Yuan Fu wrote:

The good thing about derived-mode-add-parents is that it doesn’t need major 
mode author’s cooperation. Even a normal user can do it themselves.

True.

Then there is the problem Eli pointed out, base-mode hooks runs before child 
major mode body does. It’s probably fine for most of the things, but if you 
want to change some buffer local variable that the major mode sets, base-mode 
hook can’t help. (Arguable a niche use-case, but my point is base-mode hooks 
have their limits.)

This is the same for all other case of mode inheritance (e.g. js2-mode inheriting from js-mode, or python-ts-mode inheriting from python-mode).

It would be odd if some inheriters would have this inconvenience, and others not.

Obviously derived-mode-add-parents can’t help with hooks. But adding the config 
to two hooks doesn’t seem to be too bad. Plus I haven’t come up with good 
solution. So I’m not too eager to solve that inconvenience.

I was thinking some "proper" language registry is the way to go. Like a custom structure tracking the correspondence between file names and languages, and a separate association list for lang->major-mode.

But it would require more changes indeed.

As for adding xxx-mode to xxx-ts-mode’s parent, I think it’s fine? Like others 
in the thread, I couldn’t think of a scenarios where this will be problematic. 
I thought about adding xxx-lang as the parent of both xxx-mode and xxx-ts-mode, 
but that’s probably not very helpful, since the goal is to make things work for 
ts-mode without needing to change the existing code, and using xxx-lang still 
requires modifying existing code.

OTOH, the required changes could be made fairly minimal (aside those in the user's config): add a new keyword to define-derived-mode which would add (run-hooks 'xyz-lang-hook) at the end.





reply via email to

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