aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2001-10-05 09:22:09 +0000
committerGerd Moellmann2001-10-05 09:22:09 +0000
commit3848aeeb6f22a06a4f0bc3918472c33702263e54 (patch)
tree3ea3661b4354e259466e04239cdcdb6e5df26c73
parent6c0b26437e3703ebe7648b474fea190d84d126df (diff)
downloademacs-3848aeeb6f22a06a4f0bc3918472c33702263e54.tar.gz
emacs-3848aeeb6f22a06a4f0bc3918472c33702263e54.zip
(define-derived-mode, derived-mode-make-docstring): Allow `parent' to be nil.
-rw-r--r--lisp/derived.el50
1 files changed, 28 insertions, 22 deletions
diff --git a/lisp/derived.el b/lisp/derived.el
index 28b1a99bd27..9512bae492f 100644
--- a/lisp/derived.el
+++ b/lisp/derived.el
@@ -100,7 +100,8 @@
100The arguments to this command are as follow: 100The arguments to this command are as follow:
101 101
102CHILD: the name of the command for the derived mode. 102CHILD: the name of the command for the derived mode.
103PARENT: the name of the command for the parent mode (e.g. `text-mode'). 103PARENT: the name of the command for the parent mode (e.g. `text-mode')
104 or nil if there is no parent.
104NAME: a string which will appear in the status line (e.g. \"Hypertext\") 105NAME: a string which will appear in the status line (e.g. \"Hypertext\")
105DOCSTRING: an optional documentation string--if you do not supply one, 106DOCSTRING: an optional documentation string--if you do not supply one,
106 the function will attempt to invent something useful. 107 the function will attempt to invent something useful.
@@ -131,7 +132,7 @@ been generated automatically, with a reference to the keymap."
131 (push docstring body) 132 (push docstring body)
132 (setq docstring nil)) 133 (setq docstring nil))
133 134
134 (unless parent (setq parent 'fundamental-mode)) 135 (when (eq parent 'fundamental-mode) (setq parent nil))
135 136
136 (let ((map (derived-mode-map-name child)) 137 (let ((map (derived-mode-map-name child))
137 (syntax (derived-mode-syntax-table-name child)) 138 (syntax (derived-mode-syntax-table-name child))
@@ -141,7 +142,7 @@ been generated automatically, with a reference to the keymap."
141 142
142 `(progn 143 `(progn
143 (defvar ,map (make-sparse-keymap)) 144 (defvar ,map (make-sparse-keymap))
144 (defvar ,syntax (make-char-table 'syntax-table nil)) 145 (defvar ,syntax (make-syntax-table))
145 (defvar ,abbrev) 146 (defvar ,abbrev)
146 (define-abbrev-table ',abbrev nil) 147 (define-abbrev-table ',abbrev nil)
147 (put ',child 'derived-mode-parent ',parent) 148 (put ',child 'derived-mode-parent ',parent)
@@ -152,26 +153,28 @@ been generated automatically, with a reference to the keymap."
152 ; Run the parent. 153 ; Run the parent.
153 ;; (combine-run-hooks 154 ;; (combine-run-hooks
154 155
155 (,parent) 156 (,(or parent 'kill-all-local-variables))
156 ; Identify special modes.
157 (if (get (quote ,parent) 'special)
158 (put (quote ,child) 'special t))
159 ; Identify the child mode. 157 ; Identify the child mode.
160 (setq major-mode (quote ,child)) 158 (setq major-mode (quote ,child))
161 (setq mode-name ,name) 159 (setq mode-name ,name)
160 ; Identify special modes.
161 ,(when parent
162 `(progn
163 (if (get (quote ,parent) 'special)
164 (put (quote ,child) 'special t))
162 ; Set up maps and tables. 165 ; Set up maps and tables.
163 (unless (keymap-parent ,map) 166 (unless (keymap-parent ,map)
164 (set-keymap-parent ,map (current-local-map))) 167 (set-keymap-parent ,map (current-local-map)))
165 (let ((parent (char-table-parent ,syntax))) 168 (let ((parent (char-table-parent ,syntax)))
166 (unless (and parent (not (eq parent (standard-syntax-table)))) 169 (unless (and parent (not (eq parent (standard-syntax-table))))
167 (set-char-table-parent ,syntax (syntax-table)))) 170 (set-char-table-parent ,syntax (syntax-table))))
168 (when local-abbrev-table 171 (when local-abbrev-table
169 (mapatoms 172 (mapatoms
170 (lambda (symbol) 173 (lambda (symbol)
171 (or (intern-soft (symbol-name symbol) ,abbrev) 174 (or (intern-soft (symbol-name symbol) ,abbrev)
172 (define-abbrev ,abbrev (symbol-name symbol) 175 (define-abbrev ,abbrev (symbol-name symbol)
173 (symbol-value symbol) (symbol-function symbol)))) 176 (symbol-value symbol) (symbol-function symbol))))
174 local-abbrev-table)) 177 local-abbrev-table))))
175 178
176 (use-local-map ,map) 179 (use-local-map ,map)
177 (set-syntax-table ,syntax) 180 (set-syntax-table ,syntax)
@@ -234,20 +237,23 @@ this function is not very useful. Use `derived-mode-p' instead."
234 (unless (stringp docstring) 237 (unless (stringp docstring)
235 ;; Use a default docstring. 238 ;; Use a default docstring.
236 (setq docstring 239 (setq docstring
237 (format "Major mode derived from `%s' by `define-derived-mode'. 240 (if (null parent)
241 (format "Major-mode.
242Uses keymap `%s', abbrev table `%s' and syntax-table `%s'." map abbrev syntax)
243 (format "Major mode derived from `%s' by `define-derived-mode'.
238It inherits all of the parent's attributes, but has its own keymap, 244It inherits all of the parent's attributes, but has its own keymap,
239abbrev table and syntax table: 245abbrev table and syntax table:
240 246
241 `%s', `%s' and `%s' 247 `%s', `%s' and `%s'
242 248
243which more-or-less shadow %s's corresponding tables." 249which more-or-less shadow %s's corresponding tables."
244 parent map abbrev syntax parent))) 250 parent map abbrev syntax parent))))
245 251
246 (unless (string-match (regexp-quote (symbol-name hook)) docstring) 252 (unless (string-match (regexp-quote (symbol-name hook)) docstring)
247 ;; Make sure the docstring mentions the mode's hook 253 ;; Make sure the docstring mentions the mode's hook
248 (setq docstring 254 (setq docstring
249 (concat docstring 255 (concat docstring
250 (if (eq parent 'fundamental-mode) 256 (if (null parent)
251 "\n\nThis mode " 257 "\n\nThis mode "
252 (concat 258 (concat
253 "\n\nIn addition to any hooks its parent mode " 259 "\n\nIn addition to any hooks its parent mode "