diff options
| author | Stefan Monnier | 2023-11-12 17:08:46 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2023-11-12 17:08:46 -0500 |
| commit | cf00f1526d04c0798a6a38c005b5704cf3b825f0 (patch) | |
| tree | 059d2d8671d3afa00dead6c09c4ca386b72c5c3a | |
| parent | b86dcea37c86a3b9cb9fc6c4656b481b2ad1c1e5 (diff) | |
| download | emacs-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.texi | 25 | ||||
| -rw-r--r-- | etc/NEWS | 12 | ||||
| -rw-r--r-- | test/lisp/subr-tests.el | 10 |
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 | |||
| 937 | derived from any of the major modes given by the symbols @var{modes}. | 937 | derived from any of the major modes given by the symbols @var{modes}. |
| 938 | @end defun | 938 | @end defun |
| 939 | 939 | ||
| 940 | The graph of major modes is accessed with the following lower-level | ||
| 941 | functions: | ||
| 942 | |||
| 943 | @defun derived-mode-set-parent mode parent | ||
| 944 | This function declares that @var{mode} inherits from @code{parent}. | ||
| 945 | This is the function that @code{define-derived-mode} calls after | ||
| 946 | defining @var{mode} to register the fact that @var{mode} was defined | ||
| 947 | by reusing @code{parent}. | ||
| 948 | @end defun | ||
| 949 | |||
| 950 | @defun derived-mode-add-parents mode extra-parents | ||
| 951 | This function makes it possible to register additional parents beside | ||
| 952 | the one that was used when defining @var{mode}. This can be used when | ||
| 953 | the similarity between @var{mode} and the modes in @var{extra-parents} | ||
| 954 | is such that it makes sense to treat it as a child of those | ||
| 955 | modes for purposes like applying directory-local variables. | ||
| 956 | @end defun | ||
| 957 | |||
| 958 | @defun derived-mode-all-parents mode | ||
| 959 | This 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 | ||
| 961 | starting 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 | ||
| @@ -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'. | ||
| 1185 | Mostly used internally to do a kind of topological sort of | ||
| 1186 | inheritance hierarchies. | ||
| 1187 | |||
| 1188 | ** New API to control the graph of major modes. | ||
| 1189 | While 'define-derived-mode' still only support single inheritance, | ||
| 1190 | modes can declare additional parents (for tests like 'derived-mode-p') | ||
| 1191 | with `derived-mode-add-parents`. | ||
| 1192 | Accessing the 'derived-mode-parent' property directly is now | ||
| 1193 | deprecated in favor of the new functions 'derived-mode-set-parent' | ||
| 1194 | and '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. |
| 1186 | It is now possible for drag-and-drop handler functions to respond to | 1198 | It 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 |