unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Yuan Fu <casouri@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,  emacs-devel <emacs-devel@gnu.org>,
	Mickey Petersen <mickey@masteringemacs.org>,
	 Theodor Thornhill <theo@thornhill.no>,
	 dgutov@yandex.ru
Subject: Re: Extending define-derived-mode
Date: Fri, 02 Jun 2023 12:46:07 -0400	[thread overview]
Message-ID: <jwvy1l1akto.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <EDB30821-2A92-4C79-B0D3-5592E85C45F8@gmail.com> (Yuan Fu's message of "Fri, 2 Jun 2023 00:44:15 -0700")

>>>> 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




  reply	other threads:[~2023-06-02 16:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  5:16 Extending define-derived-mode Yuan Fu
2023-05-30  5:51 ` Theodor Thornhill
2023-05-31 20:35   ` Yuan Fu
2023-06-01  5:43     ` Theodor Thornhill
2023-05-30 10:48 ` Eli Zaretskii
2023-05-30 14:16   ` Stefan Monnier
2023-05-31 21:31     ` Yuan Fu
2023-06-01  4:06       ` Stefan Monnier
2023-06-01  6:39         ` Eli Zaretskii
2023-06-02  7:50           ` Yuan Fu
2023-06-02 11:54             ` Eli Zaretskii
2023-06-05  7:31               ` Yuan Fu
2023-06-05 11:33                 ` Eli Zaretskii
2023-06-08  7:25                   ` Yuan Fu
2023-06-02  7:44         ` Yuan Fu
2023-06-02 16:46           ` Stefan Monnier [this message]
2023-06-05  7:39             ` Yuan Fu
2023-06-05 15:17               ` Stefan Monnier
2023-05-31 20:48   ` Yuan Fu
2023-06-01  5:47     ` Eli Zaretskii
2023-06-02  7:45       ` Yuan Fu
2023-06-02 11:51         ` Eli Zaretskii
2023-05-30 17:24 ` Juri Linkov
2023-06-05  8:30 ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvy1l1akto.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=casouri@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mickey@masteringemacs.org \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).