aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2000-03-11 03:37:37 +0000
committerStefan Monnier2000-03-11 03:37:37 +0000
commite4ad5f9e5f7b0b98399c7912ce41eb362fde5c11 (patch)
treec238d323ae2ef0ee5721518274bf5e422190d8d3 /lisp
parentd407456c9e369af38b26349303e5e2618ecb63de (diff)
downloademacs-e4ad5f9e5f7b0b98399c7912ce41eb362fde5c11.tar.gz
emacs-e4ad5f9e5f7b0b98399c7912ce41eb362fde5c11.zip
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
(easy-mmode-define-syntax): Fix CL typo. (easy-mmode-define-derived-mode): Improve the docstring generation.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emacs-lisp/easy-mmode.el105
1 files changed, 60 insertions, 45 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 98ee96bdac9..069430a7aa6 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -207,9 +207,11 @@ ARGS is a list of additional arguments."
207 207
208;;;###autoload 208;;;###autoload
209(defmacro easy-mmode-defmap (m bs doc &rest args) 209(defmacro easy-mmode-defmap (m bs doc &rest args)
210 `(defconst ,m 210 `(progn
211 (easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args)) 211 (autoload 'easy-mmode-define-keymap "easy-mmode")
212 ,doc)) 212 (defconst ,m
213 (easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args))
214 ,doc)))
213 215
214 216
215;;; 217;;;
@@ -222,13 +224,15 @@ ARGS is a list of additional arguments."
222 (let ((char (car cs)) 224 (let ((char (car cs))
223 (syntax (cdr cs))) 225 (syntax (cdr cs)))
224 (if (sequencep char) 226 (if (sequencep char)
225 (mapcar* (lambda (c) (modify-syntax-entry c syntax st)) char) 227 (mapcar (lambda (c) (modify-syntax-entry c syntax st)) char)
226 (modify-syntax-entry char syntax st)))) 228 (modify-syntax-entry char syntax st))))
227 st)) 229 st))
228 230
229;;;###autoload 231;;;###autoload
230(defmacro easy-mmode-defsyntax (st css doc &rest args) 232(defmacro easy-mmode-defsyntax (st css doc &rest args)
231 `(defconst ,st (custom-create-syntax ,css ,(cons 'list args)) doc)) 233 `(progn
234 (autoload 'easy-mmode-define-syntax "easy-mmode")
235 (defconst ,st (easy-mmode-define-syntax ,css ,(cons 'list args)) doc)))
232 236
233 237
234 238
@@ -265,67 +269,78 @@ the parent, and then sets the variable `case-fold-search' to nil:
265Note that if the documentation string had been left out, it would have 269Note that if the documentation string had been left out, it would have
266been generated automatically, with a reference to the keymap." 270been generated automatically, with a reference to the keymap."
267 271
268 ; Some trickiness, since what
269 ; appears to be the docstring
270 ; may really be the first
271 ; element of the body.
272 (if (and docstring (not (stringp docstring)))
273 (progn (setq body (cons docstring body))
274 (setq docstring nil)))
275 (let* ((child-name (symbol-name child)) 272 (let* ((child-name (symbol-name child))
276 (map (intern (concat child-name "-map"))) 273 (map (intern (concat child-name "-map")))
277 (syntax (intern (concat child-name "-syntax-table"))) 274 (syntax (intern (concat child-name "-syntax-table")))
278 (abbrev (intern (concat child-name "-abbrev-table"))) 275 (abbrev (intern (concat child-name "-abbrev-table")))
279 (hook (intern (concat child-name "-hook")))) 276 (hook (intern (concat child-name "-hook"))))
280 277
281 `(progn 278 (when (and docstring (not (stringp docstring)))
282 (defvar ,map (make-sparse-keymap)) 279 ;; DOCSTRING is really the first command and there's no docstring
283 (defvar ,syntax (make-char-table 'syntax-table nil)) 280 (push docstring body)
284 (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev)) 281 (setq docstring nil))
285 282
286 (defun ,child () 283 (unless (stringp docstring)
287 ,(or docstring 284 ;; Use a default docstring.
285 (setq docstring
288 (format "Major mode derived from `%s' by `define-derived-mode'. 286 (format "Major mode derived from `%s' by `define-derived-mode'.
289Inherits all of the parent's attributes, but has its own keymap, 287Inherits all of the parent's attributes, but has its own keymap,
290abbrev table and syntax table: 288abbrev table and syntax table:
291 289
292 `%s', `%s' and `%s' 290 `%s', `%s' and `%s'
293 291
294which more-or-less shadow %s's corresponding tables. 292which more-or-less shadow %s's corresponding tables."
295It also runs its own `%s' after its parent's. 293 parent map syntax abbrev parent)))
294
295 (unless (string-match (regexp-quote (symbol-name hook)) docstring)
296 ;; Make sure the docstring mentions the mode's hook
297 (setq docstring (format "%s
298This mode runs (additionally to any hooks his parent might have run)
299its own `%s' just before exiting."
300 docstring hook)))
296 301
297\\{%s}" parent map syntax abbrev parent hook map)) 302 (unless (string-match "\\\\[{[]" docstring)
298 (interactive) 303 ;; And don't forget to put the mode's keymap
304 (setq docstring (concat docstring "\n\\{" (symbol-name map) "}")))
305
306 `(progn
307 (defvar ,map (make-sparse-keymap))
308 (defvar ,syntax (make-char-table 'syntax-table nil))
309 (defvar ,abbrev (progn (define-abbrev-table ',abbrev nil) ,abbrev))
310
311 (defun ,child ()
312 ,docstring
313 (interactive)
299 ; Run the parent. 314 ; Run the parent.
300 (,parent) 315 (,parent)
301 ; Identify special modes. 316 ; Identify special modes.
302 (put ',child 'special (get ',parent 'special)) 317 (put ',child 'special (get ',parent 'special))
303 ; Identify the child mode. 318 ; Identify the child mode.
304 (setq major-mode ',child) 319 (setq major-mode ',child)
305 (setq mode-name ,name) 320 (setq mode-name ,name)
306 ; Set up maps and tables. 321 ; Set up maps and tables.
307 (unless (keymap-parent ,map) 322 (unless (keymap-parent ,map)
308 (set-keymap-parent ,map (current-local-map))) 323 (set-keymap-parent ,map (current-local-map)))
309 (let ((parent (char-table-parent ,syntax))) 324 (let ((parent (char-table-parent ,syntax)))
310 (unless (and parent (not (eq parent (standard-syntax-table)))) 325 (unless (and parent (not (eq parent (standard-syntax-table))))
311 (set-char-table-parent ,syntax (syntax-table)))) 326 (set-char-table-parent ,syntax (syntax-table))))
312 (when local-abbrev-table 327 (when local-abbrev-table
313 (mapatoms 328 (mapatoms
314 (lambda (symbol) 329 (lambda (symbol)
315 (or (intern-soft (symbol-name symbol) ,abbrev) 330 (or (intern-soft (symbol-name symbol) ,abbrev)
316 (define-abbrev ,abbrev (symbol-name symbol) 331 (define-abbrev ,abbrev (symbol-name symbol)
317 (symbol-value symbol) (symbol-function symbol)))) 332 (symbol-value symbol) (symbol-function symbol))))
318 local-abbrev-table)) 333 local-abbrev-table))
319 334
320 (use-local-map ,map) 335 (use-local-map ,map)
321 (set-syntax-table ,syntax) 336 (set-syntax-table ,syntax)
322 (setq local-abbrev-table ,abbrev) 337 (setq local-abbrev-table ,abbrev)
323 ; Splice in the body (if any). 338 ; Splice in the body (if any).
324 ,@body 339 ,@body
325 ; Run the hooks, if any. 340 ; Run the hooks, if any.
326 (run-hooks ',hook))))) 341 (run-hooks ',hook)))))
342
327 343
328
329(provide 'easy-mmode) 344(provide 'easy-mmode)
330 345
331;;; easy-mmode.el ends here 346;;; easy-mmode.el ends here