diff options
Diffstat (limited to 'lisp/emacs-lisp/derived.el')
-rw-r--r-- | lisp/emacs-lisp/derived.el | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el index c6c4430efd3..a6578e33086 100644 --- a/lisp/emacs-lisp/derived.el +++ b/lisp/emacs-lisp/derived.el @@ -113,9 +113,9 @@ ;;;###autoload (defmacro define-derived-mode (child parent name &optional docstring &rest body) - "Create a new mode as a variant of an existing mode. + "Create a new mode CHILD which is a variant of an existing mode PARENT. -The arguments to this command are as follow: +The arguments are as follows: CHILD: the name of the command for the derived mode. PARENT: the name of the command for the parent mode (e.g. `text-mode') @@ -123,24 +123,28 @@ PARENT: the name of the command for the parent mode (e.g. `text-mode') NAME: a string which will appear in the status line (e.g. \"Hypertext\") DOCSTRING: an optional documentation string--if you do not supply one, the function will attempt to invent something useful. +KEYWORD-ARGS: + optional arguments in the form of pairs of keyword and value. + The following keyword arguments are currently supported: + + :group GROUP + Declare the customization group that corresponds + to this mode. The command `customize-mode' uses this. + :syntax-table TABLE + Use TABLE instead of the default (CHILD-syntax-table). + A nil value means to simply use the same syntax-table + as the parent. + :abbrev-table TABLE + Use TABLE instead of the default (CHILD-abbrev-table). + A nil value means to simply use the same abbrev-table + as the parent. + :after-hook FORM + A single lisp form which is evaluated after the mode + hooks have been run. It should not be quoted. + BODY: forms to execute just before running the hooks for the new mode. Do not use `interactive' here. -BODY can start with a bunch of keyword arguments. The following keyword - arguments are currently understood: -:group GROUP - Declare the customization group that corresponds to this mode. - The command `customize-mode' uses this. -:syntax-table TABLE - Use TABLE instead of the default (CHILD-syntax-table). - A nil value means to simply use the same syntax-table as the parent. -:abbrev-table TABLE - Use TABLE instead of the default (CHILD-abbrev-table). - A nil value means to simply use the same abbrev-table as the parent. -:after-hook FORM - A single lisp form which is evaluated after the mode hooks have been - run. It should not be quoted. - Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode: (define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\") @@ -149,7 +153,7 @@ You could then make new key bindings for `LaTeX-thesis-mode-map' without changing regular LaTeX mode. In this example, BODY is empty, and DOCSTRING is generated by default. -On a more complicated level, the following command uses `sgml-mode' as +As a more complex example, the following command uses `sgml-mode' as the parent, and then sets the variable `case-fold-search' to nil: (define-derived-mode article-mode sgml-mode \"Article\" @@ -162,7 +166,9 @@ been generated automatically, with a reference to the keymap. The new mode runs the hook constructed by the function `derived-mode-hook-name'. -See Info node `(elisp)Derived Modes' for more details." +See Info node `(elisp)Derived Modes' for more details. + +\(fn CHILD PARENT NAME [DOCSTRING] [KEYWORD-ARGS...] &rest BODY)" (declare (debug (&define name symbolp sexp [&optional stringp] [&rest keywordp sexp] def-body)) (doc-string 4) @@ -193,10 +199,10 @@ See Info node `(elisp)Derived Modes' for more details." ;; Process the keyword args. (while (keywordp (car body)) (pcase (pop body) - (`:group (setq group (pop body))) - (`:abbrev-table (setq abbrev (pop body)) (setq declare-abbrev nil)) - (`:syntax-table (setq syntax (pop body)) (setq declare-syntax nil)) - (`:after-hook (setq after-hook (pop body))) + (:group (setq group (pop body))) + (:abbrev-table (setq abbrev (pop body)) (setq declare-abbrev nil)) + (:syntax-table (setq syntax (pop body)) (setq declare-syntax nil)) + (:after-hook (setq after-hook (pop body))) (_ (pop body)))) (setq docstring (derived-mode-make-docstring @@ -281,25 +287,10 @@ No problems result if this variable is not bound. ; Splice in the body (if any). ,@body ) - ;; Run the hooks, if any. - (run-mode-hooks ',hook) - ,@(when after-hook - `((if delay-mode-hooks - (push (lambda () ,after-hook) delayed-after-hook-functions) - ,after-hook))))))) - -;; PUBLIC: find the ultimate class of a derived mode. - -(defun derived-mode-class (mode) - "Find the class of a major MODE. -A mode's class is the first ancestor which is NOT a derived mode. -Use the `derived-mode-parent' property of the symbol to trace backwards. -Since major-modes might all derive from `fundamental-mode', this function -is not very useful." - (declare (obsolete derived-mode-p "22.1")) - (while (get mode 'derived-mode-parent) - (setq mode (get mode 'derived-mode-parent))) - mode) + ,@(when after-hook + `((push (lambda () ,after-hook) delayed-after-hook-functions))) + ;; Run the hooks (and delayed-after-hook-functions), if any. + (run-mode-hooks ',hook))))) ;;; PRIVATE |