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: Mon, 5 Jun 2023 00:39:41 -0700


> On Jun 2, 2023, at 9:46 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>>>>> I don't see this as a big problem, actually (there are already several
>>>>> mechanisms that can do that).  The question of how "user enables
>>>>> xxx-ts-mode" is probably harder.
>>>> Couldn’t they use major-mode-remap-alist?
>>> Yes, that's one way.  With its pros and cons.
>> What do you consider it’s cons? To me it’s more-or-less just a nicer
>> auto-mode-alist without needing to fiddle with regular expression.
> 
> It's "one mode at a time", whereas I'd expect some users might be
> looking for a more "global" setting such as one that causes TS modes to
> be used whenever possible (i.e. when there's a TS-using mode and
> the corresponding grammar is installed).
> 
>>>> How do you setup multiple keymap parents? I thought a keymap can only have 
>>>> one parent?
>>> The single parent can be a composite map (i.e. using 
>>> `make-composed-keymap`).
>> 
>> But IIUC that creates a new map instead of pointing to the parent maps, so
>> any change in the parent map are not reflected in the child map, which is
>> kind of the point of inheriting maps.
> 
> It creates a new map but it doesn't *copy* anything, it just keeps
> references to the maps included in the composite map, so changes to the
> parent maps *are* reflected.
> 
> IOW, we can implement XEmacs's multiple inheritance with
> 
>    (defun set-keymap-parents (keymap parents)
>      (set-keymap-parent keymap
>                         ;; Aka (cons 'keymap parents).
>                         (make-composed-map parents)))
> 
>    (defun keymap-parents (keymap)
>      (let ((parent (keymap-parent keymap)))
>        (if (and (eq 'keymap (car-safe parent))
>                 (proper-list-p parent)
>                 (seq-every-p #'keymapp (cdr parent)))
>            (cdr parent)
>          (if parent (list parent)))))

Oh great! I didn’t know that.

> 
>>>> Here’s another wild idea: we keep single-inheritance for
>>>> define-derived-mode; major modes for the same language inherits from
>>>> the same base mode; add a feature where xxx-base-mode is automatically
>>>> defined when someone defines a major mode with xxx-base-mode as
>>>> parent, so we don’t need to pre-define base-modes for every possible
>>>> language;
>>> Sounds hackish.  E.g. what would the `xxx-mode` docstring say about
>>> which hooks are run?
>> xxx-base-mode-hook,
> 
> But IIUC you're suggesting that this hook would only exist "when someone
> defines a major mode with xxx-base-mode as parent", so it's
> dynamic/conditional.

IIUC you can add functions to a hook regardless whether it’s defined or not, so 
it should be fine?


BTW, I want to clarify one thing: how are we feeling about base modes? Are they 
fine? Are they staying?

Yuan


reply via email to

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