emacs-devel
[Top][All Lists]
Advanced

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

Re: Extending define-derived-mode


From: Yuan Fu
Subject: Re: Extending define-derived-mode
Date: Wed, 31 May 2023 13:48:56 -0700

> 
>> 2. Inheritance:
>> 
>> 2.1 For xxx-mode and xxx-ts-mode, there should be shared hook. More
>>    generally, we want to be able to have a shared hook for similar
>>    modes (same language, similar language, etc).
>> 
>> 2.2 For xxx-mode and xxx-ts-mode, they should be able to share some
>>    setup, and diverge on some other.
>> 
>> 2.3 Right now we have a little inconsistency regarding hook
>>    inheritance. js-json-mode inherits from js-mode, json-ts-mode
>>    inherits from js-ts-mode. So there isn’t a shared hook that runs
>>    in both js-json-mode and json-ts-mode.
>> 
>>    More generally, if there is a language X and a derived language Y,
>>    and we have x-mode, x-ts-mode, y-mode, y-ts-mode, how should
>>    inheritance of code and hooks works among them? y-mode probably
>>    wants to inherit from x-mode, and y-ts-mode probably wants to
>>    inherit hook (but not necessarily code [1]) from x-ts-mode.
> 
> This is not simple in practice.  Ask yourself why don't the
> FOO-ts-mode's simply run the (existing) hooks of FOO-mode?  Look at
> the code, and you will understand: the stuff people put in these hooks
> usually customizes aspects that are very different in each of the
> modes: font-lock, indentation, syntax tables, supporting "electric"
> sub-modes, styles of comments and other things, etc.  The few places
> where the new TS modes tried to run the same hooks and share most of
> the initialization code (for example, bash-ts-mode and sh-mode,
> python-ts-mode and python-mode) introduced subtle bugs which were only
> recently fixed.  One problem with inheriting from the same base mode
> is that doing initialization there could be problematic because the
> mode stuff that gets automatically instantiated and initialized by
> define-derived-mode, such as the mode's map and variable, is not yet
> set up when the base mode's initialization runs, so you cannot do some
> of the things we are used to do there, like setting up the menu-bar
> menus.
> 
> So it would seem that, for efficient and convenient facilities of this
> kind, we need some way of defining stuff in the base mode, which will
> be actually run later, when the child mode is set up.

I don’t entirely understand the example. Say I have a xxx-base-mode, and I want 
to setup menu-bar menus in it to be shared by xxx-mode and xxx-ts-mode. What is 
the problem that I’m gonna run into? Couldn’t you just use the base-mode’s 
keymap?

Yuan


reply via email to

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