From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 67008@debbugs.gnu.org
Cc: Ikumi Keita <ikumi@ikumi.que.jp>
Subject: bug#67008: 30.0.50; Multiple major mode parents
Date: Thu, 09 Nov 2023 00:38:22 -0500 [thread overview]
Message-ID: <jwvbkc3mqpd.fsf@iro.umontreal.ca> (raw)
Package: Emacs
Version: 30.0.50
While it seems difficult to add support for multiple inheritance to
`define-derived-mode`, it's fairly easy to allow a major mode to declare
itself the spiritual heir of various other major modes beside the one
from which it actually inherits.
We already have some very basic such cases in our own code:
- `locate-mode` inherits from `special-mode` but declares itself
as a child of `dired-mode`.
- CEDET declares that `c++-mode` is a child of `c-mode`.
I'd been toying with this idea for a while because it has seemed useful
a few times, tho until now there seemed to be good enough alternatives.
But in order to really support AUCTeX modes well, we do need such
a thing: we need `LaTeX-mode` to be able to declare itself as a child
of `latex-mode` (even tho it does not inherit from it) so that
directory-local variables are properly applied to it, which is
a fairly common use case.
I pushed to the branch `feature/derived-mode-add-parents` a bunch of
patches which add support for such limited form of `multiple
inheritance`.
The patch is fairly large because it goes through all the code that
uses the `derived-mode-parent` property and adjusts it to use
a few new functions:
- `derived-mode-set-parent` and `derived-mode-all-parents` cover
basically all previous uses of the `derived-mode-parent` property.
- `derived-mode-add-parents` to declare additional parents.
The patch also consolidates the code that linearizes the inheritance
hierarchy of CL classes, EIEIO classes, and major modes.
You can see below the corresponding commit log.
There are no doc (or etc/NEWS) changes yet.
Any comment/objection?
Stefan
commit 19445b6b7bb04e44e39ef2e39a620bd3eadb0acd
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Wed Nov 8 11:32:27 2023 -0500
subr.el: Provide a functional API around `derived-mode-parent`
The `derived-mode-parent` property should be an implementation detail,
so we can change it more easily. To that end, add functions to set and
query it.
* lisp/subr.el (derived-mode-all-parents): New function.
(provided-mode-derived-p): Use it.
(derived-mode-set-parent): New function.
commit 9c6b22bb3e2126a1ab355b81ae4268ac53c2b6fe
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Wed Nov 8 14:20:09 2023 -0500
(derived-mode-all-parents): Speed up with a cache
Most uses of the mode hierarchy don't really need to construct the
list, they just need to iterate over it. With single inheritance
we could do it just by jumping up from a mode to its parent,
but to support the upcoming multiple inheritance we'd need a more
complex and costly iterator.
Luckily, the inheritance graph is mostly static so we can cache
the list of all parents, making `derived-mode-all-parents` cheap
enough to be the basis of iteration and keeping the API very simple.
* lisp/subr.el (derived-mode-all-parents): Cache the result.
(derived-mode--flush): New function.
(derived-mode-set-parent): Use it.
commit 492920dd5b469e18596a49a62fbefd8ad2cc518b
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Wed Nov 8 22:53:39 2023 -0500
Use new `derived-mode-all/set-parents` functions.
Try and avoid using the `derived-mode-parent` property directly
and use the new API functions instead.
* lisp/emacs-lisp/derived.el (define-derived-mode):
Use `derived-mode-set-parent`.
* lisp/loadhist.el (unload--set-major-mode):
* lisp/info-look.el (info-lookup-select-mode):
* lisp/ibuf-ext.el (ibuffer-list-buffer-modes):
* lisp/files.el (dir-locals--get-sort-score):
* lisp/emacs-lisp/cl-generic.el (cl--generic-derived-specializers):
Use `derived-mode-all-parents`.
commit 5afa55a946a0271c624359e9de5d62bcaf39729b
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Mon Nov 6 16:57:05 2023 -0500
subr.el: Add multiple inheritance to `derived-mode-p`
Add the ability for a major mode to declare "extra parents" in
addition to the one from which it inherits.
* lisp/subr.el (derived-mode-add-parents): New function.
(derived-mode-all-parents): Adjust accordingly.
commit 8323394bc801e01dedd95e0ff8d573dd1f5e34ba
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Mon Nov 6 19:05:40 2023 -0500
Use `derived-mode-add-parents` in remaining uses of `derived-mode-parent`
Until now multiple inheritance wasn't really used, but some ad-hoc
code went a bit beyond the normal uses of the mode hierarchy.
Use the new multiple inheritance code to replace that ad-hoc code,
thereby eliminating basically all remaining direct uses of the
`derived-mode-parent` property.
CEDET had its own notion of mode hierrchy using `derived-mode-parent`
as well as its own `mode-local-parent` property set via
`define-child-mode`.
`derived-mode-add-parents` lets us reimplement `define-child-mode`
such that CEDET can now use the normal API functions.
* lisp/locate.el (locate-mode): Use `derived-mode-add-parents`.
* lisp/cedet/mode-local.el (get-mode-local-parent): Declare obsolete.
(mode-local-equivalent-mode-p, mode-local-use-bindings-p): Make them
obsolete aliases.
(mode-local--set-parent): Rewrite to use `derived-mode-add-parents`.
Declare as obsolete.
(mode-local-map-mode-buffers): Use `derived-mode-p`.
(mode-local-symbol, mode-local--activate-bindings)
(mode-local--deactivate-bindings, mode-local-describe-bindings-2):
Use `derived-mode-all-parents`.
* lisp/cedet/srecode/table.el (srecode-get-mode-table):
* lisp/cedet/srecode/find.el (srecode-table, srecode-load-tables-for-mode)
(srecode-all-template-hash): Use `derived-mode-all-parents`.
* lisp/cedet/srecode/map.el (srecode-map-entries-for-mode):
* lisp/cedet/semantic/db.el (semanticdb-equivalent-mode):
Use `provided-mode-derived-p` now that it obeys `define-child-mode`.
commit 0939433b63ab45d18fe1a2db706f66efe7307261
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Tue Nov 7 18:57:03 2023 -0500
Move EIEIO's C3 linearization code to `subr.el`
The code was used to linearize the EIEIO class hierarchy, since
it results in saner results than things like BFS or DFS.
By moving it to `subr.el` we get to benefit from that same
advantage both in `cl--class-allparents` and
in `derived-mode-all-parents`.
* lisp/subr.el (merge-ordered-lists): New function.
(derived-mode-all-parents): Use it to improve parent ordering.
* lisp/emacs-lisp/eieio-core.el (eieio--c3-candidate)
(eieio--c3-merge-lists): Delete functions, replaced by
`merge-ordered-lists`.
(eieio--class-precedence-c3): Use `merge-ordered-lists`.
* lisp/emacs-lisp/cl-preloaded.el (cl--class-allparents):
Use `merge-ordered-lists` to improve parent ordering.
* lisp/emacs-lisp/cl-macs.el (cl--struct-all-parents): Delete function.
(cl--pcase-mutually-exclusive-p): Use `cl--class-allparents` instead.
next reply other threads:[~2023-11-09 5:38 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 5:38 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-11-09 7:43 ` bug#67008: 30.0.50; Multiple major mode parents Yuan Fu
2023-11-12 22:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 15:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-11 0:01 ` Dmitry Gutov
2023-11-11 4:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-11 10:14 ` Mattias Engdegård
2023-11-11 16:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-11 18:12 ` Mattias Engdegård
2023-11-11 18:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-11 20:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 13:37 ` Mattias Engdegård
2023-11-12 16:41 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-13 12:45 ` Mattias Engdegård
2023-11-13 13:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-13 16:44 ` Mattias Engdegård
2023-11-13 17:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 11:07 ` Mattias Engdegård
2023-11-16 15:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 19:35 ` Mattias Engdegård
2023-11-16 21:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 14:04 ` Mattias Engdegård
2023-11-17 14:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 16:15 ` Mattias Engdegård
2023-11-11 12:21 ` Ikumi Keita
2023-11-11 16:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-12 9:50 ` Ikumi Keita
2023-11-12 16:04 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=jwvbkc3mqpd.fsf@iro.umontreal.ca \
--to=bug-gnu-emacs@gnu.org \
--cc=67008@debbugs.gnu.org \
--cc=ikumi@ikumi.que.jp \
--cc=monnier@iro.umontreal.ca \
/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).