aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2023-11-12 17:08:46 -0500
committerStefan Monnier2023-11-12 17:08:46 -0500
commitcf00f1526d04c0798a6a38c005b5704cf3b825f0 (patch)
tree059d2d8671d3afa00dead6c09c4ca386b72c5c3a
parentb86dcea37c86a3b9cb9fc6c4656b481b2ad1c1e5 (diff)
downloademacs-scratch/derived-mode-add-parents.tar.gz
emacs-scratch/derived-mode-add-parents.zip
Subject: (derived-mode-add-parents): Add documentation and one more testscratch/derived-mode-add-parents
* doc/lispref/modes.texi (Derived Modes): Document new derived-modes API. * test/lisp/subr-tests.el (subt-tests--merge-ordered-lists): New test.
-rw-r--r--doc/lispref/modes.texi25
-rw-r--r--etc/NEWS12
-rw-r--r--test/lisp/subr-tests.el10
3 files changed, 47 insertions, 0 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index f365d88fade..22ff07f9641 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -937,6 +937,31 @@ This function returns non-@code{nil} if the current major mode is
937derived from any of the major modes given by the symbols @var{modes}. 937derived from any of the major modes given by the symbols @var{modes}.
938@end defun 938@end defun
939 939
940The graph of major modes is accessed with the following lower-level
941functions:
942
943@defun derived-mode-set-parent mode parent
944This function declares that @var{mode} inherits from @code{parent}.
945This is the function that @code{define-derived-mode} calls after
946defining @var{mode} to register the fact that @var{mode} was defined
947by reusing @code{parent}.
948@end defun
949
950@defun derived-mode-add-parents mode extra-parents
951This function makes it possible to register additional parents beside
952the one that was used when defining @var{mode}. This can be used when
953the similarity between @var{mode} and the modes in @var{extra-parents}
954is such that it makes sense to treat it as a child of those
955modes for purposes like applying directory-local variables.
956@end defun
957
958@defun derived-mode-all-parents mode
959This function returns the list of all the modes in the ancestry of
960@var{mode}, ordered from the most specific to the least specific, and
961starting with @var{mode} itself.
962@end defun
963
964
940@node Basic Major Modes 965@node Basic Major Modes
941@subsection Basic Major Modes 966@subsection Basic Major Modes
942 967
diff --git a/etc/NEWS b/etc/NEWS
index 767e4c27b43..1db22c4f2f5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1181,6 +1181,18 @@ values.
1181 1181
1182* Lisp Changes in Emacs 30.1 1182* Lisp Changes in Emacs 30.1
1183 1183
1184** New function 'merge-ordered-lists'.
1185Mostly used internally to do a kind of topological sort of
1186inheritance hierarchies.
1187
1188** New API to control the graph of major modes.
1189While 'define-derived-mode' still only support single inheritance,
1190modes can declare additional parents (for tests like 'derived-mode-p')
1191with `derived-mode-add-parents`.
1192Accessing the 'derived-mode-parent' property directly is now
1193deprecated in favor of the new functions 'derived-mode-set-parent'
1194and 'derived-mode-all-parents'.
1195
1184+++ 1196+++
1185** Drag-and-drop functions can now be called once for compound drops. 1197** Drag-and-drop functions can now be called once for compound drops.
1186It is now possible for drag-and-drop handler functions to respond to 1198It is now possible for drag-and-drop handler functions to respond to
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 03eb0d5bf8c..f67ac70046a 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -381,6 +381,16 @@
381 '(subr-tests--mode-A subr-tests--mode-B prog-mode 381 '(subr-tests--mode-A subr-tests--mode-B prog-mode
382 subr-tests--mode-C subr-tests--derived-mode-1)))))) 382 subr-tests--mode-C subr-tests--derived-mode-1))))))
383 383
384(ert-deftest subt-tests--merge-ordered-lists ()
385 (should (equal (merge-ordered-lists
386 '((B A) (C A) (D B) (E D C)))
387 '(E D B C A)))
388 (should (equal (merge-ordered-lists
389 '((E D C) (B A) (C A) (D B)))
390 '(E D C B A)))
391 (should-error (merge-ordered-lists
392 '((E C D) (B A) (A C) (D B))
393 (lambda (_) (error "cycle")))))
384 394
385(ert-deftest number-sequence-test () 395(ert-deftest number-sequence-test ()
386 (should (= (length 396 (should (= (length