aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-12-03 21:41:06 +0000
committerStefan Monnier2000-12-03 21:41:06 +0000
commit8b262a654924a43af89bf89bdbc478349085f213 (patch)
tree3b625aabf87caf1f5397bae9a69ee07226f97497
parent6ad501012b9a9ddc26dd8ce1cef8332ee16d87df (diff)
downloademacs-8b262a654924a43af89bf89bdbc478349085f213.tar.gz
emacs-8b262a654924a43af89bf89bdbc478349085f213.zip
(define-derived-mode,easy-mmode-derived-mode-p): Remove (moved to derived.el).
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/emacs-lisp/easy-mmode.el131
2 files changed, 10 insertions, 131 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 19105b69535..2828bb00ed0 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12000-12-03 Stefan Monnier <monnier@cs.yale.edu>
2
3 * emacs-lisp/easy-mmode.el (define-derived-mode)
4 (easy-mmode-derived-mode-p): Remove (moved to derived.el).
5
6 * derived.el (define-derived-mode): Revived, moved from easy-mmode.el.
7 (derived-mode-p): New function.
8 (derived-mode-make-docstring): Add `docstring' argument.
9 Use it if available and complete it if necessary.
10
12000-12-03 Andreas Schwab <schwab@suse.de> 112000-12-03 Andreas Schwab <schwab@suse.de>
2 12
3 * type-break.el (type-break): Don't make parent of itself. 13 * type-break.el (type-break): Don't make parent of itself.
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 2dde3559088..87ce0cc9c22 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -383,137 +383,6 @@ CSS contains a list of syntax specifications of the form (CHAR . SYNTAX).
383 383
384 384
385;;; 385;;;
386;;; A "macro-only" reimplementation of define-derived-mode.
387;;;
388
389;;;###autoload
390(defmacro define-derived-mode (child parent name &optional docstring &rest body)
391 "Create a new mode as a variant of an existing mode.
392
393The arguments to this command are as follow:
394
395CHILD: the name of the command for the derived mode.
396PARENT: the name of the command for the parent mode (e.g. `text-mode').
397NAME: a string which will appear in the status line (e.g. \"Hypertext\")
398DOCSTRING: an optional documentation string--if you do not supply one,
399 the function will attempt to invent something useful.
400BODY: forms to execute just before running the
401 hooks for the new mode.
402
403Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
404
405 (define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\")
406
407You could then make new key bindings for `LaTeX-thesis-mode-map'
408without changing regular LaTeX mode. In this example, BODY is empty,
409and DOCSTRING is generated by default.
410
411On a more complicated level, the following command uses `sgml-mode' as
412the parent, and then sets the variable `case-fold-search' to nil:
413
414 (define-derived-mode article-mode sgml-mode \"Article\"
415 \"Major mode for editing technical articles.\"
416 (setq case-fold-search nil))
417
418Note that if the documentation string had been left out, it would have
419been generated automatically, with a reference to the keymap."
420
421 (let* ((child-name (symbol-name child))
422 (map (intern (concat child-name "-map")))
423 (syntax (intern (concat child-name "-syntax-table")))
424 (abbrev (intern (concat child-name "-abbrev-table")))
425 (hook (intern (concat child-name "-hook"))))
426
427 (unless parent (setq parent 'fundamental-mode))
428
429 (when (and docstring (not (stringp docstring)))
430 ;; DOCSTRING is really the first command and there's no docstring
431 (push docstring body)
432 (setq docstring nil))
433
434 (unless (stringp docstring)
435 ;; Use a default docstring.
436 (setq docstring
437 (format "Major mode derived from `%s' by `define-derived-mode'.
438Inherits all of the parent's attributes, but has its own keymap,
439abbrev table and syntax table:
440
441 `%s', `%s' and `%s'
442
443which more-or-less shadow %s's corresponding tables."
444 parent map syntax abbrev parent)))
445
446 (unless (string-match (regexp-quote (symbol-name hook)) docstring)
447 ;; Make sure the docstring mentions the mode's hook
448 (setq docstring
449 (concat docstring
450 (if (eq parent 'fundamental-mode)
451 "\n\nThis mode "
452 (concat
453 "\n\nIn addition to any hooks its parent mode "
454 (if (string-match (regexp-quote (format "`%s'" parent))
455 docstring) nil
456 (format "`%s' " parent))
457 "might have run,\nthis mode "))
458 (format "runs the hook `%s'" hook)
459 ", as the final step\nduring initialization.")))
460
461 (unless (string-match "\\\\[{[]" docstring)
462 ;; And don't forget to put the mode's keymap
463 (setq docstring (concat docstring "\n\n\\{" (symbol-name map) "}")))
464
465 `(progn
466 (defvar ,map (make-sparse-keymap))
467 (defvar ,syntax (make-char-table 'syntax-table nil))
468 (defvar ,abbrev)
469 (define-abbrev-table ',abbrev nil)
470 (put ',child 'derived-mode-parent ',parent)
471
472 (defun ,child ()
473 ,docstring
474 (interactive)
475 ; Run the parent.
476 (combine-run-hooks
477
478 (,parent)
479 ; Identify special modes.
480 (put ',child 'special (get ',parent 'special))
481 ; Identify the child mode.
482 (setq major-mode ',child)
483 (setq mode-name ,name)
484 ; Set up maps and tables.
485 (unless (keymap-parent ,map)
486 (set-keymap-parent ,map (current-local-map)))
487 (let ((parent (char-table-parent ,syntax)))
488 (unless (and parent (not (eq parent (standard-syntax-table))))
489 (set-char-table-parent ,syntax (syntax-table))))
490 (when local-abbrev-table
491 (mapatoms
492 (lambda (symbol)
493 (or (intern-soft (symbol-name symbol) ,abbrev)
494 (define-abbrev ,abbrev (symbol-name symbol)
495 (symbol-value symbol) (symbol-function symbol))))
496 local-abbrev-table))
497
498 (use-local-map ,map)
499 (set-syntax-table ,syntax)
500 (setq local-abbrev-table ,abbrev)
501 ; Splice in the body (if any).
502 ,@body)
503 ; Run the hooks, if any.
504 (run-hooks ',hook)))))
505
506;; Inspired from derived-mode-class in derived.el
507(defun easy-mmode-derived-mode-p (mode)
508 "Non-nil if the current major mode is derived from MODE.
509Uses the `derived-mode-parent' property of the symbol to trace backwards."
510 (let ((parent major-mode))
511 (while (and (not (eq parent mode))
512 (setq parent (get parent 'derived-mode-parent))))
513 parent))
514
515
516;;;
517;;; easy-mmode-define-navigation 386;;; easy-mmode-define-navigation
518;;; 387;;;
519 388