annotate lisp/derived.el @ 1601:442db3c3c43b

[xemacs-hg @ 2003-08-02 08:42:10 by michaels] 2003-07-31 Mike Sperber <mike@xemacs.org> * isearch-mode.el (isearch-mode-help): (isearch-update): (isearch-done): (isearch-edit-string): Change the way window configurations are handled: Formerly, the code would do `set-window-configuration' off `pre-command-hook' which isn't really allowed. (The old window-configuration code would quietly ignore this restriction.) Instead, save the window configuration only when someone asks for help, and restore afterwards, and otherwise leave it alone.
author michaels
date Sat, 02 Aug 2003 08:42:11 +0000
parents e2ddc2a2b794
children e6d43c299b9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; derived.el --- allow inheritance of major modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: David Megginson (dmeggins@aix1.uottawa.ca)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.34.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 428
diff changeset
32 ;; XEmacs is already, in a sense, object oriented -- each object
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; (buffer) belongs to a class (major mode), and that class defines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; the relationship between messages (input events) and methods
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; (commands) by means of a keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; The only thing missing is a good scheme of inheritance. It is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; possible to simulate a single level of inheritance with generous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; use of hooks and a bit of work -- sgml-mode, for example, also runs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; the hooks for text-mode, and keymaps can inherit from other keymaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; -- but generally, each major mode ends up reinventing the wheel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; Ideally, someone should redesign all of Emacs's major modes to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; follow a more conventional object-oriented system: when defining a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; new major mode, the user should need only to name the existing mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;; it is most similar to, then list the (few) differences.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;; In the mean time, this package offers most of the advantages of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;; full inheritance with the existing major modes. The macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;; `define-derived-mode' allows the user to make a variant of an existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;; major mode, with its own keymap. The new mode will inherit the key
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; bindings of its parent, and will, in fact, run its parent first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;; every time it is called. For example, the commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;; (define-derived-mode hypertext-mode text-mode "Hypertext"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;; "Major mode for hypertext.\n\n\\{hypertext-mode-map}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;; (setq case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;; (define-key hypertext-mode-map [down-mouse-3] 'do-hyper-link)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;; will create a function `hypertext-mode' with its own (sparse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;; keymap `hypertext-mode-map.' The command M-x hypertext-mode will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;; perform the following actions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;; - run the command (text-mode) to get its default setup
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;; - replace the current keymap with 'hypertext-mode-map,' which will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;; inherit from 'text-mode-map'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;; - replace the current syntax table with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;; 'hypertext-mode-syntax-table', which will borrow its defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;; from the current text-mode-syntax-table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;; - replace the current abbrev table with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;; 'hypertext-mode-abbrev-table', which will borrow its defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ;; from the current text-mode-abbrev table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;; - change the mode line to read "Hypertext"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;; - assign the value 'hypertext-mode' to the 'major-mode' variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ;; - run the body of commands provided in the macro -- in this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ;; set the local variable `case-fold-search' to nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 ;; - **run the command (hypertext-mode-setup), which is empty by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;; default, but may be redefined by the user to contain special
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;; commands (ie. setting local variables like 'outline-regexp')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ;; **NOTE: do not use this option -- it will soon be obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;; - run anything assigned to 'hypertext-mode-hooks' (obsolete, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ;; supported for the sake of compatibility).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;; The advantages of this system are threefold. First, text mode is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;; untouched -- if you had added the new keystroke to `text-mode-map,'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;; possibly using hooks, you would have added it to all text buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;; -- here, it appears only in hypertext buffers, where it makes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;; sense. Second, it is possible to build even further, and make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;; a derived mode from a derived mode. The commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;; (define-derived-mode html-mode hypertext-mode "HTML")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;; [various key definitions]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ;; will add a new major mode for HTML with very little fuss.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;; Note also the function `derived-mode-class,' which returns the non-derived
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ;; major mode which a derived mode is based on (ie. NOT necessarily the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;; immediate parent).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;; (derived-mode-class 'text-mode) ==> text-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;; (derived-mode-class 'hypertext-mode) ==> text-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;; (derived-mode-class 'html-mode) ==> text-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ;; PUBLIC: define a new major mode which inherits from an existing one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ;; XEmacs -- no autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (defmacro define-derived-mode (child parent name &optional docstring &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 "Create a new mode as a variant of an existing mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 The arguments to this command are as follow:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 CHILD: the name of the command for the derived mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 PARENT: the name of the command for the parent mode (ie. text-mode).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 NAME: a string which will appear in the status line (ie. \"Hypertext\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 DOCSTRING: an optional documentation string--if you do not supply one,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 the function will attempt to invent something useful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 BODY: forms to execute just before running the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 hooks for the new mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 You could then make new key bindings for `LaTeX-thesis-mode-map'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 without changing regular LaTeX mode. In this example, BODY is empty,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 and DOCSTRING is generated by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 On a more complicated level, the following command uses sgml-mode as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 the parent, and then sets the variable `case-fold-search' to nil:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (define-derived-mode article-mode sgml-mode \"Article\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 \"Major mode for editing technical articles.\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (setq case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 Note that if the documentation string had been left out, it would have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 been generated automatically, with a reference to the keymap."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ; Some trickiness, since what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ; appears to be the docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ; may really be the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 ; element of the body.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (if (and docstring (not (stringp docstring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (progn (setq body (cons docstring body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (setq docstring nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (setq docstring (or docstring (derived-mode-make-docstring parent child)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 `(progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (derived-mode-init-mode-variables (quote ,child))
906
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
151 (put (quote ,child) 'derived-mode-parent (quote ,parent))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (defun ,child ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ,docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ; Run the parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (,parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ; Identify special modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (if (get (quote ,parent) 'special)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (put (quote ,child) 'special t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;; XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (let ((mode-class (get (quote ,parent) 'mode-class)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (if mode-class
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (put (quote ,child) 'mode-class mode-class)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ; Identify the child mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (setq major-mode (quote ,child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (setq mode-name ,name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ; Set up maps and tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (derived-mode-set-keymap (quote ,child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (derived-mode-set-syntax-table (quote ,child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (derived-mode-set-abbrev-table (quote ,child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ; Splice in the body (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ,@body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 ;;; ; Run the setup function, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 ;;; ; any -- this will soon be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ;;; ; obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 ;;; (derived-mode-run-setup-function (quote ,child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ; Run the hooks, if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (derived-mode-run-hooks (quote ,child)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 ;; PUBLIC: find the ultimate class of a derived mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (defun derived-mode-class (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 "Find the class of a major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 A mode's class is the first ancestor which is NOT a derived mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 Use the `derived-mode-parent' property of the symbol to trace backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (while (get mode 'derived-mode-parent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (setq mode (get mode 'derived-mode-parent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
906
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
191 ;; PUBLIC: find if the current mode derives from another.
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
192 ;; from GNU Emacs 21 subr.el
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
193
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
194 (defun derived-mode-p (&rest modes)
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
195 "Non-nil if the current major mode is derived from one of MODES.
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
196 Uses the `derived-mode-parent' property of the symbol to trace backwards."
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
197 (let ((parent major-mode))
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
198 (while (and (not (memq parent modes))
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
199 (setq parent (get parent 'derived-mode-parent))))
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
200 parent))
7f5ac0d2a71f [xemacs-hg @ 2002-07-08 08:21:47 by youngs]
youngs
parents: 613
diff changeset
201
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;; Inline functions to construct various names from a mode name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (defsubst derived-mode-setup-function-name (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 "Construct a setup-function name based on a mode name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (intern (concat (symbol-name mode) "-setup")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (defsubst derived-mode-hooks-name (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 "Construct a hooks name based on a mode name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 ;; XEmacs change from -hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (intern (concat (symbol-name mode) "-hook")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (defsubst derived-mode-map-name (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 "Construct a map name based on a mode name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (intern (concat (symbol-name mode) "-map")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (defsubst derived-mode-syntax-table-name (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 "Construct a syntax-table name based on a mode name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (intern (concat (symbol-name mode) "-syntax-table")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (defsubst derived-mode-abbrev-table-name (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 "Construct an abbrev-table name based on a mode name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (intern (concat (symbol-name mode) "-abbrev-table")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; Utility functions for defining a derived mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ;; XEmacs -- don't autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (defun derived-mode-init-mode-variables (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 "Initialize variables for a new mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 Right now, if they don't already exist, set up a blank keymap, an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 empty syntax table, and an empty abbrev table -- these will be merged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 the first time the mode is used."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (if (boundp (derived-mode-map-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (eval `(defvar ,(derived-mode-map-name mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (make-sparse-keymap (derived-mode-map-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ,(format "Keymap for %s." mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (put (derived-mode-map-name mode) 'derived-mode-unmerged t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (if (boundp (derived-mode-syntax-table-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (eval `(defvar ,(derived-mode-syntax-table-name mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;; Make a syntax table which doesn't specify anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ;; for any char. Valid data will be merged in by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 ;; derived-mode-merge-syntax-tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 ;; (make-char-table 'syntax-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (make-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ,(format "Syntax table for %s." mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (put (derived-mode-syntax-table-name mode) 'derived-mode-unmerged t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (if (boundp (derived-mode-abbrev-table-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (eval `(defvar ,(derived-mode-abbrev-table-name mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (progn (define-abbrev-table (derived-mode-abbrev-table-name mode) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (make-abbrev-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 ,(format "Abbrev table for %s." mode)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (defun derived-mode-make-docstring (parent child)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 "Construct a docstring for a new mode if none is provided."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (format "This major mode is a variant of `%s', created by `define-derived-mode'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 It inherits all of the parent's attributes, but has its own keymap,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 abbrev table and syntax table:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 `%s-map' and `%s-syntax-table'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 which more-or-less shadow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 `%s-map' and `%s-syntax-table'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 \\{%s-map}" parent child child parent parent child))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 ;; Utility functions for running a derived mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (defun derived-mode-set-keymap (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 "Set the keymap of the new mode, maybe merging with the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (let* ((map-name (derived-mode-map-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (new-map (eval map-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (old-map (current-local-map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (and old-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (get map-name 'derived-mode-unmerged)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (derived-mode-merge-keymaps old-map new-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (put map-name 'derived-mode-unmerged nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (use-local-map new-map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (defun derived-mode-set-syntax-table (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 "Set the syntax table of the new mode, maybe merging with the parent."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (let* ((table-name (derived-mode-syntax-table-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (old-table (syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (new-table (eval table-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (if (get table-name 'derived-mode-unmerged)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (derived-mode-merge-syntax-tables old-table new-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (put table-name 'derived-mode-unmerged nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (set-syntax-table new-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (defun derived-mode-set-abbrev-table (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 "Set the abbrev table if it exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Always merge its parent into it, since the merge is non-destructive."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (let* ((table-name (derived-mode-abbrev-table-name mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (old-table local-abbrev-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (new-table (eval table-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (derived-mode-merge-abbrev-tables old-table new-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (setq local-abbrev-table new-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 ;;;(defun derived-mode-run-setup-function (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ;;; "Run the setup function if it exists."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 ;;; (let ((fname (derived-mode-setup-function-name mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ;;; (if (fboundp fname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 ;;; (funcall fname))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (defun derived-mode-run-hooks (mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 "Run the hooks if they exist."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (let ((hooks-name (derived-mode-hooks-name mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (if (boundp hooks-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (run-hooks hooks-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; Functions to merge maps and tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (defun derived-mode-merge-keymaps (old new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 "Merge an old keymap into a new one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 The old keymap is set to be the parent of the new one, so that there will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 be automatic inheritance."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ;; XEmacs change. FSF 19.30 & 19.34 has a whole bunch of weird crap here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 ;; for merging prefix keys and such. Hopefully none of this is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 ;; necessary in XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (set-keymap-parents new (list old)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (defun derived-mode-merge-syntax-tables (old new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 "Merge an old syntax table into a new one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 Where the new table already has an entry, nothing is copied from the old one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 ;; 20.x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (if (fboundp 'map-char-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ;; we use map-char-table not map-syntax-table so we can explicitly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 ;; check for inheritance.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (map-char-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 #'(lambda (key value)
1578
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
345 (let ((newval (get-range-char-table key new 'multi)))
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
346 (cond ((eq newval 'multi) ; OK, dive into the class hierarchy
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
347 (map-char-table
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
348 #'(lambda (key1 value1)
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
349 (when (eq ?@ (char-syntax-from-code
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
350 (get-range-char-table key new ?@)))
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
351 (put-char-table key1 value new))
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
352 nil)
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
353 new
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
354 key))
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
355 ((eq ?@ (char-syntax-from-code newval)) ;; class at once
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
356 (put-char-table key value new))))
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
357 nil)
e2ddc2a2b794 [xemacs-hg @ 2003-07-18 07:42:47 by stephent]
stephent
parents: 906
diff changeset
358 old)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ;; pre-20.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (let ((idx 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (end (min (length new) (length old))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (while (< idx end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (if (not (aref new idx))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (aset new idx (aref old idx)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (setq idx (1+ idx))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ;; Merge an old abbrev table into a new one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 ;; This function requires internal knowledge of how abbrev tables work,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ;; presuming that they are obarrays with the abbrev as the symbol, the expansion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 ;; as the value of the symbol, and the hook as the function definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (defun derived-mode-merge-abbrev-tables (old new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (if old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (mapatoms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (lambda (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (or (intern-soft (symbol-name symbol) new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (define-abbrev new (symbol-name symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (symbol-value symbol) (symbol-function symbol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 old)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (provide 'derived)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 ;;; derived.el ends here