[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extending define-derived-mode
From: |
Stefan Monnier |
Subject: |
Re: Extending define-derived-mode |
Date: |
Fri, 02 Jun 2023 12:46:07 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>>>> 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)))))
>>> 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.
Stefan
Re: Extending define-derived-mode, Yuan Fu, 2023/06/02
- Re: Extending define-derived-mode,
Stefan Monnier <=