diff options
| author | Richard M. Stallman | 1994-02-04 01:04:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-02-04 01:04:15 +0000 |
| commit | b72226e37e48efc1ad2c3af40d9c8fd7dd27ebbd (patch) | |
| tree | 3f7ac0de6bfad795234bc2dd817cef51141eddbb /lisp | |
| parent | 76078cf0dd9c70ba218b75071b4ff9610c42afb9 (diff) | |
| download | emacs-b72226e37e48efc1ad2c3af40d9c8fd7dd27ebbd.tar.gz emacs-b72226e37e48efc1ad2c3af40d9c8fd7dd27ebbd.zip | |
(define-mode-clone): Renamed from mode-clone.
Swap args PARENT and CHILD.
Don't use clone-run-setup-function.
(clone-run-setup-function): Function deleted.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/derived.el | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/lisp/derived.el b/lisp/derived.el index bd1aef1f841..3a89407749f 100644 --- a/lisp/derived.el +++ b/lisp/derived.el | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | ;;; mode-clone.el (alpha version) -- allow inheritance of major modes. | 1 | ;;; mode-clone.el (alpha version) -- allow inheritance of major modes. |
| 2 | ;;; $Id: mode-clone.el,v 1.5 1993/12/25 14:02:33 david Exp $ | ||
| 3 | 2 | ||
| 4 | ;; Copyright (C) 1993 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1993 Free Software Foundation, Inc. |
| 5 | 4 | ||
| @@ -39,13 +38,13 @@ | |||
| 39 | ;; it is most similar to, then list the (few) differences. | 38 | ;; it is most similar to, then list the (few) differences. |
| 40 | ;; | 39 | ;; |
| 41 | ;; In the mean time, this package offers most of the advantages of | 40 | ;; In the mean time, this package offers most of the advantages of |
| 42 | ;; full inheritance with the existing major modes. The function | 41 | ;; full inheritance with the existing major modes. The macro |
| 43 | ;; `mode-clone' allows the user to make a clone of an existing | 42 | ;; `define-mode-clone' allows the user to make a clone of an existing |
| 44 | ;; major mode, with its own keymap. The new mode will inherit the key | 43 | ;; major mode, with its own keymap. The new mode will inherit the key |
| 45 | ;; bindings of its parent, and will, in fact, run its parent first | 44 | ;; bindings of its parent, and will, in fact, run its parent first |
| 46 | ;; every time it is called. For example, the commands | 45 | ;; every time it is called. For example, the commands |
| 47 | ;; | 46 | ;; |
| 48 | ;; (mode-clone text-mode hypertext-mode "Hypertext" | 47 | ;; (define-mode-clone hypertext-mode text-mode "Hypertext" |
| 49 | ;; "Major mode for hypertext.\n\n\\{hypertext-mode-map}" | 48 | ;; "Major mode for hypertext.\n\n\\{hypertext-mode-map}" |
| 50 | ;; (setq case-fold-search nil)) | 49 | ;; (setq case-fold-search nil)) |
| 51 | ;; | 50 | ;; |
| @@ -81,7 +80,7 @@ | |||
| 81 | ;; sense. Second, it is possible to build even further, and clone the | 80 | ;; sense. Second, it is possible to build even further, and clone the |
| 82 | ;; clone. The commands | 81 | ;; clone. The commands |
| 83 | ;; | 82 | ;; |
| 84 | ;; (mode-clone hypertext-mode html-mode "HTML") | 83 | ;; (define-mode-clone html-mode hypertext-mode "HTML") |
| 85 | ;; [various key definitions] | 84 | ;; [various key definitions] |
| 86 | ;; | 85 | ;; |
| 87 | ;; will add a new major mode for HTML with very little fuss. | 86 | ;; will add a new major mode for HTML with very little fuss. |
| @@ -99,35 +98,32 @@ | |||
| 99 | ;; PUBLIC: define a new major mode which inherits from an existing one. | 98 | ;; PUBLIC: define a new major mode which inherits from an existing one. |
| 100 | 99 | ||
| 101 | ;;;###autoload | 100 | ;;;###autoload |
| 102 | (defmacro mode-clone (parent child name &optional docstring &rest body) | 101 | (defmacro define-mode-clone (child parent name &optional docstring &rest body) |
| 103 | "Create a new mode which is similar to an old one. | 102 | "Create a new mode which is similar to an old one. |
| 104 | 103 | ||
| 105 | The arguments to this command are as follow: | 104 | The arguments to this command are as follow: |
| 106 | 105 | ||
| 107 | parent: the name of the command for the parent mode (ie. text-mode) | 106 | PARENT: the name of the command for the parent mode (ie. text-mode). |
| 108 | child: the name of the command for the clone | 107 | CHILD: the name of the command for the clone mode. |
| 109 | name: a string which will appear in the status line (ie. \"Hypertext\") | 108 | NAME: a string which will appear in the status line (ie. \"Hypertext\") |
| 110 | docstring: an optional documentation string -- if you do not supply one, | 109 | DOCSTRING: an optional documentation string--if you do not supply one, |
| 111 | the function will attempt to invent something useful. If this | 110 | the function will attempt to invent something useful. |
| 112 | argument is not a string, it will be added to body automatically. | 111 | BODY: forms to execute just before running the |
| 113 | body: a body of commands to execute just before running the | ||
| 114 | hooks for the new mode. | 112 | hooks for the new mode. |
| 115 | 113 | ||
| 116 | The following simple command would clone LaTeX-mode into | 114 | The following simple command would clone LaTeX mode into |
| 117 | LaTeX-thesis-mode: | 115 | LaTeX-Thesis mode: |
| 118 | 116 | ||
| 119 | (mode-clone LaTeX-mode LaTeX-thesis-mode \"LaTeX-Thesis\") | 117 | (define-mode-clone LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\") |
| 120 | 118 | ||
| 121 | It would then be possible to assign commands to keystrokes in | 119 | You could then make new key bindings for `LaTeX-thesis-mode-map' |
| 122 | `LaTeX-thesis-mode-map' without changing the interface in the regular | 120 | without changing regular LaTeX mode. In this example, BODY is empty, |
| 123 | LaTeX-mode. The function (LaTeX-thesis-mode-setup), if it exists, | 121 | and DOCSTRING is generated by default. |
| 124 | will contain commands which will run whenever (LaTeX-thesis-mode) is | ||
| 125 | run (just before 'LaTeX-thesis-mode-hooks). | ||
| 126 | 122 | ||
| 127 | On a more complicated level, the following command would clone | 123 | On a more complicated level, the following command would clone |
| 128 | sgml-mode and change the variable `case-fold-search' to nil: | 124 | sgml-mode and change the variable `case-fold-search' to nil: |
| 129 | 125 | ||
| 130 | (mode-clone sgml-mode article-mode \"Article\" | 126 | (define-mode-clone article-mode sgml-mode \"Article\" |
| 131 | \"Major mode for editing technical articles.\" | 127 | \"Major mode for editing technical articles.\" |
| 132 | (setq case-fold-search nil)) | 128 | (setq case-fold-search nil)) |
| 133 | 129 | ||
| @@ -162,10 +158,10 @@ been generated automatically, with a reference to the keymap." | |||
| 162 | (clone-set-abbrev-table (quote (, child))) | 158 | (clone-set-abbrev-table (quote (, child))) |
| 163 | ; Splice in the body (if any). | 159 | ; Splice in the body (if any). |
| 164 | (,@ body) | 160 | (,@ body) |
| 165 | ; Run the setup function, if | 161 | ;;; ; Run the setup function, if |
| 166 | ; any -- this will soon be | 162 | ;;; ; any -- this will soon be |
| 167 | ; obsolete. | 163 | ;;; ; obsolete. |
| 168 | (clone-run-setup-function (quote (, child))) | 164 | ;;; (clone-run-setup-function (quote (, child))) |
| 169 | ; Run the hooks, if any. | 165 | ; Run the hooks, if any. |
| 170 | (clone-run-hooks (quote (, child))))))) | 166 | (clone-run-hooks (quote (, child))))))) |
| 171 | 167 | ||
| @@ -228,15 +224,15 @@ Right now, just set up a blank keymap and an empty syntax table." | |||
| 228 | (defun clone-make-docstring (parent child) | 224 | (defun clone-make-docstring (parent child) |
| 229 | "Construct a docstring for a new mode if none is provided." | 225 | "Construct a docstring for a new mode if none is provided." |
| 230 | 226 | ||
| 231 | (format "This major mode is a clone of (%s), created by (mode-clone). | 227 | (format "This major mode is a clone of `%s', created by `define-mode-clone'. |
| 232 | It inherits all of the parent's attributes, but has its own keymap | 228 | It inherits all of the parent's attributes, but has its own keymap, |
| 233 | and syntax table: | 229 | abbrev table and syntax table: |
| 234 | 230 | ||
| 235 | '%s-map' and '%s-syntax-table' | 231 | `%s-map' and `%s-syntax-table' |
| 236 | 232 | ||
| 237 | which more-or-less shadow | 233 | which more-or-less shadow |
| 238 | 234 | ||
| 239 | '%s-map' and '%s-syntax-table' | 235 | `%s-map' and `%s-syntax-table' |
| 240 | 236 | ||
| 241 | \\{%s-map}" parent child child parent parent child)) | 237 | \\{%s-map}" parent child child parent parent child)) |
| 242 | 238 | ||
| @@ -271,12 +267,12 @@ which more-or-less shadow | |||
| 271 | (if table | 267 | (if table |
| 272 | (setq local-abbrev-table table)))) | 268 | (setq local-abbrev-table table)))) |
| 273 | 269 | ||
| 274 | (defun clone-run-setup-function (mode) | 270 | ;;;(defun clone-run-setup-function (mode) |
| 275 | "Run the setup function if it exists." | 271 | ;;; "Run the setup function if it exists." |
| 276 | 272 | ||
| 277 | (let ((fname (clone-setup-function-name mode))) | 273 | ;;; (let ((fname (clone-setup-function-name mode))) |
| 278 | (if (fboundp fname) | 274 | ;;; (if (fboundp fname) |
| 279 | (funcall fname)))) | 275 | ;;; (funcall fname)))) |
| 280 | 276 | ||
| 281 | (defun clone-run-hooks (mode) | 277 | (defun clone-run-hooks (mode) |
| 282 | "Run the hooks if they exist." | 278 | "Run the hooks if they exist." |