-been generated automatically, with a reference to the keymap."
-
- ; Some trickiness, since what
- ; appears to be the docstring
- ; may really be the first
- ; element of the body.
- (if (and docstring (not (stringp docstring)))
- (progn (setq body (cons docstring body))
- (setq docstring nil)))
- (setq docstring (or docstring (derived-mode-make-docstring parent child)))
-
- (` (progn
- (derived-mode-init-mode-variables (quote (, child)))
- (defun (, child) ()
- (, docstring)
+been generated automatically, with a reference to the keymap.
+
+The new mode runs the hook constructed by the function
+`derived-mode-hook-name'."
+ (declare (debug (&define name symbolp sexp [&optional stringp]
+ [&rest keywordp sexp] def-body)))
+
+ (when (and docstring (not (stringp docstring)))
+ ;; Some trickiness, since what appears to be the docstring may really be
+ ;; the first element of the body.
+ (push docstring body)
+ (setq docstring nil))
+
+ (when (eq parent 'fundamental-mode) (setq parent nil))
+
+ (let ((map (derived-mode-map-name child))
+ (syntax (derived-mode-syntax-table-name child))
+ (abbrev (derived-mode-abbrev-table-name child))
+ (declare-abbrev t)
+ (declare-syntax t)
+ (hook (derived-mode-hook-name child))
+ (group nil))
+
+ ;; Process the keyword args.
+ (while (keywordp (car body))
+ (case (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))
+ (t (pop body))))
+
+ (setq docstring (derived-mode-make-docstring
+ parent child docstring syntax abbrev))
+
+ `(progn
+ (defvar ,hook nil ,(format "Hook run when entering %s mode." name))
+ (defvar ,map (make-sparse-keymap))
+ ,(if declare-syntax
+ `(defvar ,syntax (make-syntax-table)))
+ ,(if declare-abbrev
+ `(defvar ,abbrev
+ (progn (define-abbrev-table ',abbrev nil) ,abbrev)))
+ (put ',child 'derived-mode-parent ',parent)
+ ,(if group `(put ',child 'custom-mode-group ,group))
+
+ (defun ,child ()
+ ,docstring