250
|
1 /* Manipulation of keymaps
|
20708
|
2 Copyright (C) 1985, 86,87,88,93,94,95,98 Free Software Foundation, Inc.
|
250
|
3
|
|
4 This file is part of GNU Emacs.
|
|
5
|
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
647
|
8 the Free Software Foundation; either version 2, or (at your option)
|
250
|
9 any later version.
|
|
10
|
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
14186
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
250
|
20
|
|
21
|
4696
|
22 #include <config.h>
|
250
|
23 #include <stdio.h>
|
21514
|
24 #ifdef STDC_HEADERS
|
|
25 #include <stdlib.h>
|
|
26 #endif
|
250
|
27 #undef NULL
|
|
28 #include "lisp.h"
|
|
29 #include "commands.h"
|
|
30 #include "buffer.h"
|
17036
|
31 #include "charset.h"
|
517
|
32 #include "keyboard.h"
|
2059
|
33 #include "termhooks.h"
|
2439
|
34 #include "blockinput.h"
|
13771
|
35 #include "puresize.h"
|
250
|
36
|
|
37 #define min(a, b) ((a) < (b) ? (a) : (b))
|
|
38
|
1209
|
39 /* The number of elements in keymap vectors. */
|
250
|
40 #define DENSE_TABLE_SIZE (0200)
|
|
41
|
|
42 /* Actually allocate storage for these variables */
|
|
43
|
|
44 Lisp_Object current_global_map; /* Current global keymap */
|
|
45
|
|
46 Lisp_Object global_map; /* default global key bindings */
|
|
47
|
|
48 Lisp_Object meta_map; /* The keymap used for globally bound
|
|
49 ESC-prefixed default commands */
|
|
50
|
|
51 Lisp_Object control_x_map; /* The keymap used for globally bound
|
|
52 C-x-prefixed default commands */
|
|
53
|
|
54 /* was MinibufLocalMap */
|
|
55 Lisp_Object Vminibuffer_local_map;
|
|
56 /* The keymap used by the minibuf for local
|
|
57 bindings when spaces are allowed in the
|
|
58 minibuf */
|
|
59
|
|
60 /* was MinibufLocalNSMap */
|
|
61 Lisp_Object Vminibuffer_local_ns_map;
|
|
62 /* The keymap used by the minibuf for local
|
|
63 bindings when spaces are not encouraged
|
|
64 in the minibuf */
|
|
65
|
|
66 /* keymap used for minibuffers when doing completion */
|
|
67 /* was MinibufLocalCompletionMap */
|
|
68 Lisp_Object Vminibuffer_local_completion_map;
|
|
69
|
|
70 /* keymap used for minibuffers when doing completion and require a match */
|
|
71 /* was MinibufLocalMustMatchMap */
|
|
72 Lisp_Object Vminibuffer_local_must_match_map;
|
|
73
|
465
|
74 /* Alist of minor mode variables and keymaps. */
|
|
75 Lisp_Object Vminor_mode_map_alist;
|
|
76
|
20517
|
77 /* Alist of major-mode-specific overrides for
|
|
78 minor mode variables and keymaps. */
|
|
79 Lisp_Object Vminor_mode_overriding_map_alist;
|
|
80
|
517
|
81 /* Keymap mapping ASCII function key sequences onto their preferred forms.
|
|
82 Initialized by the terminal-specific lisp files. See DEFVAR for more
|
|
83 documentation. */
|
|
84 Lisp_Object Vfunction_key_map;
|
|
85
|
12710
|
86 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
|
|
87 Lisp_Object Vkey_translation_map;
|
|
88
|
12297
|
89 /* A list of all commands given new bindings since a certain time
|
|
90 when nil was stored here.
|
|
91 This is used to speed up recomputation of menu key equivalents
|
|
92 when Emacs starts up. t means don't record anything here. */
|
|
93 Lisp_Object Vdefine_key_rebound_commands;
|
|
94
|
21241
|
95 Lisp_Object Qkeymapp, Qkeymap, Qnon_ascii, Qmenu_item;
|
250
|
96
|
2886
|
97 /* A char with the CHAR_META bit set in a vector or the 0200 bit set
|
|
98 in a string key sequence is equivalent to prefixing with this
|
|
99 character. */
|
250
|
100 extern Lisp_Object meta_prefix_char;
|
|
101
|
5613
|
102 extern Lisp_Object Voverriding_local_map;
|
|
103
|
3735
|
104 static Lisp_Object define_as_prefix ();
|
250
|
105 static Lisp_Object describe_buffer_bindings ();
|
12710
|
106 static void describe_command (), describe_translation ();
|
250
|
107 static void describe_map ();
|
|
108
|
465
|
109 /* Keymap object support - constructors and predicates. */
|
|
110
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
111 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0,
|
23758
|
112 "Construct and return a new keymap, of the form (keymap CHARTABLE . ALIST).\n\
|
|
113 CHARTABLE is a char-table that holds the bindings for the ASCII\n\
|
250
|
114 characters. ALIST is an assoc-list which holds bindings for function keys,\n\
|
|
115 mouse events, and any other things that appear in the input stream.\n\
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
116 All entries in it are initially nil, meaning \"command undefined\".\n\n\
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
117 The optional arg STRING supplies a menu name for the keymap\n\
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
118 in case you use it as a menu with `x-popup-menu'.")
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
119 (string)
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
120 Lisp_Object string;
|
250
|
121 {
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
122 Lisp_Object tail;
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
123 if (!NILP (string))
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
124 tail = Fcons (string, Qnil);
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
125 else
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
126 tail = Qnil;
|
250
|
127 return Fcons (Qkeymap,
|
17788
|
128 Fcons (Fmake_char_table (Qkeymap, Qnil), tail));
|
250
|
129 }
|
|
130
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
131 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, Smake_sparse_keymap, 0, 1, 0,
|
250
|
132 "Construct and return a new sparse-keymap list.\n\
|
|
133 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\
|
|
134 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\
|
|
135 which binds the function key or mouse event SYMBOL to DEFINITION.\n\
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
136 Initially the alist is nil.\n\n\
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
137 The optional arg STRING supplies a menu name for the keymap\n\
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
138 in case you use it as a menu with `x-popup-menu'.")
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
139 (string)
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
140 Lisp_Object string;
|
250
|
141 {
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
142 if (!NILP (string))
|
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
143 return Fcons (Qkeymap, Fcons (string, Qnil));
|
250
|
144 return Fcons (Qkeymap, Qnil);
|
|
145 }
|
|
146
|
|
147 /* This function is used for installing the standard key bindings
|
|
148 at initialization time.
|
|
149
|
|
150 For example:
|
|
151
|
1388
|
152 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */
|
250
|
153
|
|
154 void
|
|
155 initial_define_key (keymap, key, defname)
|
|
156 Lisp_Object keymap;
|
|
157 int key;
|
|
158 char *defname;
|
|
159 {
|
|
160 store_in_keymap (keymap, make_number (key), intern (defname));
|
|
161 }
|
|
162
|
1388
|
163 void
|
|
164 initial_define_lispy_key (keymap, keyname, defname)
|
|
165 Lisp_Object keymap;
|
|
166 char *keyname;
|
|
167 char *defname;
|
|
168 {
|
|
169 store_in_keymap (keymap, intern (keyname), intern (defname));
|
|
170 }
|
|
171
|
250
|
172 /* Define character fromchar in map frommap as an alias for character
|
|
173 tochar in map tomap. Subsequent redefinitions of the latter WILL
|
|
174 affect the former. */
|
|
175
|
|
176 #if 0
|
|
177 void
|
|
178 synkey (frommap, fromchar, tomap, tochar)
|
|
179 struct Lisp_Vector *frommap, *tomap;
|
|
180 int fromchar, tochar;
|
|
181 {
|
|
182 Lisp_Object v, c;
|
9273
129621997564
(synkey, Fdescribe_bindings, describe_command): Use new accessor macros
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
183 XSETVECTOR (v, tomap);
|
9312
|
184 XSETFASTINT (c, tochar);
|
250
|
185 frommap->contents[fromchar] = Fcons (v, c);
|
|
186 }
|
|
187 #endif /* 0 */
|
|
188
|
|
189 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0,
|
14080
|
190 "Return t if OBJECT is a keymap.\n\
|
362
|
191 \n\
|
2790
|
192 A keymap is a list (keymap . ALIST),\n\
|
6457
|
193 or a symbol whose function definition is itself a keymap.\n\
|
362
|
194 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\
|
2790
|
195 a vector of densely packed bindings for small character codes\n\
|
|
196 is also allowed as an element.")
|
250
|
197 (object)
|
|
198 Lisp_Object object;
|
|
199 {
|
1517
|
200 return (NILP (get_keymap_1 (object, 0, 0)) ? Qnil : Qt);
|
250
|
201 }
|
|
202
|
|
203 /* Check that OBJECT is a keymap (after dereferencing through any
|
1517
|
204 symbols). If it is, return it.
|
|
205
|
|
206 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
|
|
207 is an autoload form, do the autoload and try again.
|
7998
|
208 If AUTOLOAD is nonzero, callers must assume GC is possible.
|
1517
|
209
|
|
210 ERROR controls how we respond if OBJECT isn't a keymap.
|
|
211 If ERROR is non-zero, signal an error; otherwise, just return Qnil.
|
|
212
|
|
213 Note that most of the time, we don't want to pursue autoloads.
|
|
214 Functions like Faccessible_keymaps which scan entire keymap trees
|
|
215 shouldn't load every autoloaded keymap. I'm not sure about this,
|
|
216 but it seems to me that only read_key_sequence, Flookup_key, and
|
|
217 Fdefine_key should cause keymaps to be autoloaded. */
|
|
218
|
250
|
219 Lisp_Object
|
1517
|
220 get_keymap_1 (object, error, autoload)
|
250
|
221 Lisp_Object object;
|
1517
|
222 int error, autoload;
|
250
|
223 {
|
1517
|
224 Lisp_Object tem;
|
250
|
225
|
1517
|
226 autoload_retry:
|
25128
|
227 if (NILP (object))
|
|
228 goto end;
|
|
229 if (CONSP (object) && EQ (XCAR (object), Qkeymap))
|
|
230 return object;
|
|
231 else
|
|
232 {
|
|
233 tem = indirect_function (object);
|
|
234 if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap))
|
|
235 return tem;
|
|
236 }
|
1209
|
237
|
1566
|
238 /* Should we do an autoload? Autoload forms for keymaps have
|
|
239 Qkeymap as their fifth element. */
|
1517
|
240 if (autoload
|
8866
|
241 && SYMBOLP (object)
|
1517
|
242 && CONSP (tem)
|
|
243 && EQ (XCONS (tem)->car, Qautoload))
|
|
244 {
|
1566
|
245 Lisp_Object tail;
|
|
246
|
|
247 tail = Fnth (make_number (4), tem);
|
|
248 if (EQ (tail, Qkeymap))
|
|
249 {
|
|
250 struct gcpro gcpro1, gcpro2;
|
1517
|
251
|
3691
|
252 GCPRO2 (tem, object);
|
|
253 do_autoload (tem, object);
|
1566
|
254 UNGCPRO;
|
1517
|
255
|
1566
|
256 goto autoload_retry;
|
|
257 }
|
1517
|
258 }
|
|
259
|
25128
|
260 end:
|
250
|
261 if (error)
|
|
262 wrong_type_argument (Qkeymapp, object);
|
465
|
263 else
|
|
264 return Qnil;
|
250
|
265 }
|
|
266
|
1517
|
267
|
|
268 /* Follow any symbol chaining, and return the keymap denoted by OBJECT.
|
|
269 If OBJECT doesn't denote a keymap at all, signal an error. */
|
250
|
270 Lisp_Object
|
|
271 get_keymap (object)
|
|
272 Lisp_Object object;
|
|
273 {
|
6774
|
274 return get_keymap_1 (object, 1, 0);
|
250
|
275 }
|
15344
|
276
|
|
277 /* Return the parent map of the keymap MAP, or nil if it has none.
|
|
278 We assume that MAP is a valid keymap. */
|
|
279
|
|
280 DEFUN ("keymap-parent", Fkeymap_parent, Skeymap_parent, 1, 1, 0,
|
|
281 "Return the parent keymap of KEYMAP.")
|
|
282 (keymap)
|
|
283 Lisp_Object keymap;
|
|
284 {
|
|
285 Lisp_Object list;
|
|
286
|
|
287 keymap = get_keymap_1 (keymap, 1, 1);
|
|
288
|
|
289 /* Skip past the initial element `keymap'. */
|
|
290 list = XCONS (keymap)->cdr;
|
|
291 for (; CONSP (list); list = XCONS (list)->cdr)
|
|
292 {
|
|
293 /* See if there is another `keymap'. */
|
|
294 if (EQ (Qkeymap, XCONS (list)->car))
|
|
295 return list;
|
|
296 }
|
|
297
|
|
298 return Qnil;
|
|
299 }
|
|
300
|
|
301 /* Set the parent keymap of MAP to PARENT. */
|
|
302
|
|
303 DEFUN ("set-keymap-parent", Fset_keymap_parent, Sset_keymap_parent, 2, 2, 0,
|
|
304 "Modify KEYMAP to set its parent map to PARENT.\n\
|
|
305 PARENT should be nil or another keymap.")
|
|
306 (keymap, parent)
|
|
307 Lisp_Object keymap, parent;
|
|
308 {
|
|
309 Lisp_Object list, prev;
|
|
310 int i;
|
|
311
|
|
312 keymap = get_keymap_1 (keymap, 1, 1);
|
|
313 if (!NILP (parent))
|
|
314 parent = get_keymap_1 (parent, 1, 1);
|
|
315
|
|
316 /* Skip past the initial element `keymap'. */
|
|
317 prev = keymap;
|
|
318 while (1)
|
|
319 {
|
|
320 list = XCONS (prev)->cdr;
|
|
321 /* If there is a parent keymap here, replace it.
|
|
322 If we came to the end, add the parent in PREV. */
|
|
323 if (! CONSP (list) || EQ (Qkeymap, XCONS (list)->car))
|
|
324 {
|
15422
dd639432a55a
(Fset_keymap_parent): Return early if KEYMAP already has the proper parent.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
325 /* If we already have the right parent, return now
|
dd639432a55a
(Fset_keymap_parent): Return early if KEYMAP already has the proper parent.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
326 so that we avoid the loops below. */
|
dd639432a55a
(Fset_keymap_parent): Return early if KEYMAP already has the proper parent.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
327 if (EQ (XCONS (prev)->cdr, parent))
|
dd639432a55a
(Fset_keymap_parent): Return early if KEYMAP already has the proper parent.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
328 return parent;
|
dd639432a55a
(Fset_keymap_parent): Return early if KEYMAP already has the proper parent.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
329
|
15344
|
330 XCONS (prev)->cdr = parent;
|
|
331 break;
|
|
332 }
|
|
333 prev = list;
|
|
334 }
|
|
335
|
|
336 /* Scan through for submaps, and set their parents too. */
|
|
337
|
|
338 for (list = XCONS (keymap)->cdr; CONSP (list); list = XCONS (list)->cdr)
|
|
339 {
|
|
340 /* Stop the scan when we come to the parent. */
|
|
341 if (EQ (XCONS (list)->car, Qkeymap))
|
|
342 break;
|
|
343
|
|
344 /* If this element holds a prefix map, deal with it. */
|
|
345 if (CONSP (XCONS (list)->car)
|
|
346 && CONSP (XCONS (XCONS (list)->car)->cdr))
|
|
347 fix_submap_inheritance (keymap, XCONS (XCONS (list)->car)->car,
|
|
348 XCONS (XCONS (list)->car)->cdr);
|
|
349
|
|
350 if (VECTORP (XCONS (list)->car))
|
|
351 for (i = 0; i < XVECTOR (XCONS (list)->car)->size; i++)
|
|
352 if (CONSP (XVECTOR (XCONS (list)->car)->contents[i]))
|
|
353 fix_submap_inheritance (keymap, make_number (i),
|
|
354 XVECTOR (XCONS (list)->car)->contents[i]);
|
17788
|
355
|
|
356 if (CHAR_TABLE_P (XCONS (list)->car))
|
|
357 {
|
20076
|
358 Lisp_Object indices[3];
|
17788
|
359
|
|
360 map_char_table (fix_submap_inheritance, Qnil, XCONS (list)->car,
|
|
361 keymap, 0, indices);
|
|
362 }
|
15344
|
363 }
|
|
364
|
|
365 return parent;
|
|
366 }
|
|
367
|
|
368 /* EVENT is defined in MAP as a prefix, and SUBMAP is its definition.
|
|
369 if EVENT is also a prefix in MAP's parent,
|
|
370 make sure that SUBMAP inherits that definition as its own parent. */
|
|
371
|
20374
|
372 void
|
15344
|
373 fix_submap_inheritance (map, event, submap)
|
|
374 Lisp_Object map, event, submap;
|
|
375 {
|
|
376 Lisp_Object map_parent, parent_entry;
|
|
377
|
|
378 /* SUBMAP is a cons that we found as a key binding.
|
|
379 Discard the other things found in a menu key binding. */
|
|
380
|
21429
|
381 if (CONSP (submap))
|
15344
|
382 {
|
21241
|
383 /* May be an old format menu item */
|
21429
|
384 if (STRINGP (XCONS (submap)->car))
|
15344
|
385 {
|
21241
|
386 submap = XCONS (submap)->cdr;
|
|
387 /* Also remove a menu help string, if any,
|
|
388 following the menu item name. */
|
|
389 if (CONSP (submap) && STRINGP (XCONS (submap)->car))
|
15344
|
390 submap = XCONS (submap)->cdr;
|
21241
|
391 /* Also remove the sublist that caches key equivalences, if any. */
|
|
392 if (CONSP (submap)
|
|
393 && CONSP (XCONS (submap)->car))
|
|
394 {
|
|
395 Lisp_Object carcar;
|
|
396 carcar = XCONS (XCONS (submap)->car)->car;
|
|
397 if (NILP (carcar) || VECTORP (carcar))
|
|
398 submap = XCONS (submap)->cdr;
|
|
399 }
|
|
400 }
|
|
401
|
|
402 /* Or a new format menu item */
|
|
403 else if (EQ (XCONS (submap)->car, Qmenu_item)
|
|
404 && CONSP (XCONS (submap)->cdr))
|
|
405 {
|
|
406 submap = XCONS (XCONS (submap)->cdr)->cdr;
|
|
407 if (CONSP (submap))
|
|
408 submap = XCONS (submap)->car;
|
15344
|
409 }
|
|
410 }
|
|
411
|
|
412 /* If it isn't a keymap now, there's no work to do. */
|
|
413 if (! CONSP (submap)
|
|
414 || ! EQ (XCONS (submap)->car, Qkeymap))
|
|
415 return;
|
|
416
|
|
417 map_parent = Fkeymap_parent (map);
|
|
418 if (! NILP (map_parent))
|
|
419 parent_entry = access_keymap (map_parent, event, 0, 0);
|
|
420 else
|
|
421 parent_entry = Qnil;
|
|
422
|
15378
ecfc288350ab
(fix_submap_inheritance): If parent_entry is not a keymap, use nil instead.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
423 /* If MAP's parent has something other than a keymap,
|
ecfc288350ab
(fix_submap_inheritance): If parent_entry is not a keymap, use nil instead.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
424 our own submap shadows it completely, so use nil as SUBMAP's parent. */
|
ecfc288350ab
(fix_submap_inheritance): If parent_entry is not a keymap, use nil instead.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
425 if (! (CONSP (parent_entry) && EQ (XCONS (parent_entry)->car, Qkeymap)))
|
ecfc288350ab
(fix_submap_inheritance): If parent_entry is not a keymap, use nil instead.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
426 parent_entry = Qnil;
|
ecfc288350ab
(fix_submap_inheritance): If parent_entry is not a keymap, use nil instead.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
427
|
15344
|
428 if (! EQ (parent_entry, submap))
|
|
429 Fset_keymap_parent (submap, parent_entry);
|
|
430 }
|
|
431
|
1209
|
432 /* Look up IDX in MAP. IDX may be any sort of event.
|
|
433 Note that this does only one level of lookup; IDX must be a single
|
1388
|
434 event, not a sequence.
|
|
435
|
|
436 If T_OK is non-zero, bindings for Qt are treated as default
|
|
437 bindings; any key left unmentioned by other tables and bindings is
|
|
438 given the binding of Qt.
|
|
439
|
3735
|
440 If T_OK is zero, bindings for Qt are not treated specially.
|
|
441
|
|
442 If NOINHERIT, don't accept a subkeymap found in an inherited keymap. */
|
250
|
443
|
|
444 Lisp_Object
|
3735
|
445 access_keymap (map, idx, t_ok, noinherit)
|
250
|
446 Lisp_Object map;
|
|
447 Lisp_Object idx;
|
1388
|
448 int t_ok;
|
3735
|
449 int noinherit;
|
250
|
450 {
|
3735
|
451 int noprefix = 0;
|
|
452 Lisp_Object val;
|
|
453
|
250
|
454 /* If idx is a list (some sort of mouse click, perhaps?),
|
|
455 the index we want to use is the car of the list, which
|
|
456 ought to be a symbol. */
|
1315
|
457 idx = EVENT_HEAD (idx);
|
250
|
458
|
1209
|
459 /* If idx is a symbol, it might have modifiers, which need to
|
|
460 be put in the canonical order. */
|
8866
|
461 if (SYMBOLP (idx))
|
1209
|
462 idx = reorder_modifiers (idx);
|
3515
|
463 else if (INTEGERP (idx))
|
|
464 /* Clobber the high bits that can be present on a machine
|
|
465 with more than 24 bits of integer. */
|
9312
|
466 XSETFASTINT (idx, XINT (idx) & (CHAR_META | (CHAR_META - 1)));
|
250
|
467
|
|
468 {
|
1209
|
469 Lisp_Object tail;
|
6502
|
470 Lisp_Object t_binding;
|
250
|
471
|
6502
|
472 t_binding = Qnil;
|
1209
|
473 for (tail = map; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
474 {
|
6502
|
475 Lisp_Object binding;
|
250
|
476
|
6502
|
477 binding = XCONS (tail)->car;
|
9973
|
478 if (SYMBOLP (binding))
|
1209
|
479 {
|
3735
|
480 /* If NOINHERIT, stop finding prefix definitions
|
|
481 after we pass a second occurrence of the `keymap' symbol. */
|
|
482 if (noinherit && EQ (binding, Qkeymap) && ! EQ (tail, map))
|
|
483 noprefix = 1;
|
9973
|
484 }
|
|
485 else if (CONSP (binding))
|
|
486 {
|
1209
|
487 if (EQ (XCONS (binding)->car, idx))
|
3735
|
488 {
|
|
489 val = XCONS (binding)->cdr;
|
|
490 if (noprefix && CONSP (val) && EQ (XCONS (val)->car, Qkeymap))
|
|
491 return Qnil;
|
15344
|
492 if (CONSP (val))
|
|
493 fix_submap_inheritance (map, idx, val);
|
3735
|
494 return val;
|
|
495 }
|
1388
|
496 if (t_ok && EQ (XCONS (binding)->car, Qt))
|
|
497 t_binding = XCONS (binding)->cdr;
|
9973
|
498 }
|
|
499 else if (VECTORP (binding))
|
|
500 {
|
9957
940847846909
(access_keymap, store_in_keymap): Use NATNUMP instead of its expansion.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
501 if (NATNUMP (idx) && XFASTINT (idx) < XVECTOR (binding)->size)
|
3735
|
502 {
|
9973
|
503 val = XVECTOR (binding)->contents[XFASTINT (idx)];
|
3735
|
504 if (noprefix && CONSP (val) && EQ (XCONS (val)->car, Qkeymap))
|
|
505 return Qnil;
|
15344
|
506 if (CONSP (val))
|
|
507 fix_submap_inheritance (map, idx, val);
|
3735
|
508 return val;
|
|
509 }
|
1209
|
510 }
|
17788
|
511 else if (CHAR_TABLE_P (binding))
|
|
512 {
|
17932
|
513 /* Character codes with modifiers
|
|
514 are not included in a char-table.
|
|
515 All character codes without modifiers are included. */
|
|
516 if (NATNUMP (idx)
|
|
517 && ! (XFASTINT (idx)
|
|
518 & (CHAR_ALT | CHAR_SUPER | CHAR_HYPER
|
|
519 | CHAR_SHIFT | CHAR_CTL | CHAR_META)))
|
17788
|
520 {
|
|
521 val = Faref (binding, idx);
|
|
522 if (noprefix && CONSP (val) && EQ (XCONS (val)->car, Qkeymap))
|
|
523 return Qnil;
|
|
524 if (CONSP (val))
|
|
525 fix_submap_inheritance (map, idx, val);
|
|
526 return val;
|
|
527 }
|
|
528 }
|
1264
|
529
|
|
530 QUIT;
|
250
|
531 }
|
1388
|
532
|
|
533 return t_binding;
|
1236
|
534 }
|
250
|
535 }
|
|
536
|
|
537 /* Given OBJECT which was found in a slot in a keymap,
|
|
538 trace indirect definitions to get the actual definition of that slot.
|
|
539 An indirect definition is a list of the form
|
|
540 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one
|
|
541 and INDEX is the object to look up in KEYMAP to yield the definition.
|
|
542
|
|
543 Also if OBJECT has a menu string as the first element,
|
6774
|
544 remove that. Also remove a menu help string as second element.
|
|
545
|
|
546 If AUTOLOAD is nonzero, load autoloadable keymaps
|
|
547 that are referred to with indirection. */
|
250
|
548
|
|
549 Lisp_Object
|
6774
|
550 get_keyelt (object, autoload)
|
250
|
551 register Lisp_Object object;
|
6774
|
552 int autoload;
|
250
|
553 {
|
|
554 while (1)
|
|
555 {
|
25128
|
556 if (!(CONSP (object)))
|
21241
|
557 /* This is really the value. */
|
|
558 return object;
|
|
559
|
25128
|
560 /* If the keymap contents looks like (keymap ...) or (lambda ...)
|
|
561 then use itself. */
|
|
562 else if (EQ (XCAR (object), Qkeymap) || EQ (XCAR (object), Qlambda))
|
|
563 return object;
|
250
|
564
|
21241
|
565 /* If the keymap contents looks like (menu-item name . DEFN)
|
|
566 or (menu-item name DEFN ...) then use DEFN.
|
|
567 This is a new format menu item.
|
|
568 */
|
25128
|
569 else if (EQ (XCAR (object), Qmenu_item))
|
|
570 {
|
|
571 if (CONSP (XCDR (object)))
|
|
572 {
|
|
573 object = XCDR (XCDR (object));
|
|
574 if (CONSP (object))
|
|
575 object = XCAR (object);
|
|
576 }
|
|
577 else
|
|
578 /* Invalid keymap */
|
|
579 return object;
|
|
580 }
|
|
581
|
|
582 /* If the keymap contents looks like (STRING . DEFN), use DEFN.
|
|
583 Keymap alist elements like (CHAR MENUSTRING . DEFN)
|
|
584 will be used by HierarKey menus. */
|
|
585 else if (STRINGP (XCAR (object)))
|
21241
|
586 {
|
25128
|
587 object = XCDR (object);
|
|
588 /* Also remove a menu help string, if any,
|
|
589 following the menu item name. */
|
|
590 if (CONSP (object) && STRINGP (XCAR (object)))
|
|
591 object = XCDR (object);
|
|
592 /* Also remove the sublist that caches key equivalences, if any. */
|
|
593 if (CONSP (object) && CONSP (XCAR (object)))
|
|
594 {
|
|
595 Lisp_Object carcar;
|
|
596 carcar = XCAR (XCAR (object));
|
|
597 if (NILP (carcar) || VECTORP (carcar))
|
|
598 object = XCDR (object);
|
|
599 }
|
21241
|
600 }
|
|
601
|
25128
|
602 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
|
250
|
603 else
|
25128
|
604 {
|
|
605 register Lisp_Object map;
|
|
606 map = get_keymap_1 (Fcar_safe (object), 0, autoload);
|
|
607 if (NILP (map))
|
|
608 /* Invalid keymap */
|
|
609 return object;
|
|
610 else
|
|
611 {
|
|
612 Lisp_Object key;
|
|
613 key = Fcdr (object);
|
|
614 if (INTEGERP (key) && (XINT (key) & meta_modifier))
|
|
615 {
|
|
616 object = access_keymap (map, meta_prefix_char, 0, 0);
|
|
617 map = get_keymap_1 (object, 0, autoload);
|
|
618 object = access_keymap (map, make_number (XINT (key)
|
|
619 & ~meta_modifier),
|
|
620 0, 0);
|
|
621 }
|
|
622 else
|
|
623 object = access_keymap (map, key, 0, 0);
|
|
624 }
|
|
625 }
|
250
|
626 }
|
|
627 }
|
|
628
|
|
629 Lisp_Object
|
|
630 store_in_keymap (keymap, idx, def)
|
|
631 Lisp_Object keymap;
|
|
632 register Lisp_Object idx;
|
|
633 register Lisp_Object def;
|
|
634 {
|
10367
|
635 /* If we are preparing to dump, and DEF is a menu element
|
21241
|
636 with a menu item indicator, copy it to ensure it is not pure. */
|
|
637 if (CONSP (def) && PURE_P (def)
|
|
638 && (EQ (XCONS (def)->car, Qmenu_item) || STRINGP (XCONS (def)->car)))
|
10305
|
639 def = Fcons (XCONS (def)->car, XCONS (def)->cdr);
|
|
640
|
9123
|
641 if (!CONSP (keymap) || ! EQ (XCONS (keymap)->car, Qkeymap))
|
1209
|
642 error ("attempt to define a key in a non-keymap");
|
|
643
|
250
|
644 /* If idx is a list (some sort of mouse click, perhaps?),
|
|
645 the index we want to use is the car of the list, which
|
|
646 ought to be a symbol. */
|
1315
|
647 idx = EVENT_HEAD (idx);
|
250
|
648
|
1209
|
649 /* If idx is a symbol, it might have modifiers, which need to
|
|
650 be put in the canonical order. */
|
9123
|
651 if (SYMBOLP (idx))
|
1209
|
652 idx = reorder_modifiers (idx);
|
3515
|
653 else if (INTEGERP (idx))
|
|
654 /* Clobber the high bits that can be present on a machine
|
|
655 with more than 24 bits of integer. */
|
9312
|
656 XSETFASTINT (idx, XINT (idx) & (CHAR_META | (CHAR_META - 1)));
|
250
|
657
|
1209
|
658 /* Scan the keymap for a binding of idx. */
|
|
659 {
|
|
660 Lisp_Object tail;
|
250
|
661
|
1209
|
662 /* The cons after which we should insert new bindings. If the
|
|
663 keymap has a table element, we record its position here, so new
|
|
664 bindings will go after it; this way, the table will stay
|
|
665 towards the front of the alist and character lookups in dense
|
|
666 keymaps will remain fast. Otherwise, this just points at the
|
|
667 front of the keymap. */
|
6502
|
668 Lisp_Object insertion_point;
|
1209
|
669
|
6502
|
670 insertion_point = keymap;
|
1209
|
671 for (tail = XCONS (keymap)->cdr; CONSP (tail); tail = XCONS (tail)->cdr)
|
250
|
672 {
|
6502
|
673 Lisp_Object elt;
|
1209
|
674
|
6502
|
675 elt = XCONS (tail)->car;
|
9973
|
676 if (VECTORP (elt))
|
1209
|
677 {
|
9957
940847846909
(access_keymap, store_in_keymap): Use NATNUMP instead of its expansion.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
678 if (NATNUMP (idx) && XFASTINT (idx) < XVECTOR (elt)->size)
|
1209
|
679 {
|
|
680 XVECTOR (elt)->contents[XFASTINT (idx)] = def;
|
|
681 return def;
|
|
682 }
|
|
683 insertion_point = tail;
|
9973
|
684 }
|
17788
|
685 else if (CHAR_TABLE_P (elt))
|
|
686 {
|
17932
|
687 /* Character codes with modifiers
|
|
688 are not included in a char-table.
|
|
689 All character codes without modifiers are included. */
|
|
690 if (NATNUMP (idx)
|
|
691 && ! (XFASTINT (idx)
|
|
692 & (CHAR_ALT | CHAR_SUPER | CHAR_HYPER
|
|
693 | CHAR_SHIFT | CHAR_CTL | CHAR_META)))
|
17788
|
694 {
|
|
695 Faset (elt, idx, def);
|
|
696 return def;
|
|
697 }
|
|
698 insertion_point = tail;
|
|
699 }
|
9973
|
700 else if (CONSP (elt))
|
|
701 {
|
1209
|
702 if (EQ (idx, XCONS (elt)->car))
|
|
703 {
|
|
704 XCONS (elt)->cdr = def;
|
|
705 return def;
|
|
706 }
|
9973
|
707 }
|
|
708 else if (SYMBOLP (elt))
|
|
709 {
|
1209
|
710 /* If we find a 'keymap' symbol in the spine of KEYMAP,
|
|
711 then we must have found the start of a second keymap
|
|
712 being used as the tail of KEYMAP, and a binding for IDX
|
|
713 should be inserted before it. */
|
|
714 if (EQ (elt, Qkeymap))
|
|
715 goto keymap_end;
|
|
716 }
|
1441
|
717
|
|
718 QUIT;
|
250
|
719 }
|
1209
|
720
|
|
721 keymap_end:
|
|
722 /* We have scanned the entire keymap, and not found a binding for
|
|
723 IDX. Let's add one. */
|
10305
|
724 XCONS (insertion_point)->cdr
|
|
725 = Fcons (Fcons (idx, def), XCONS (insertion_point)->cdr);
|
250
|
726 }
|
1209
|
727
|
250
|
728 return def;
|
|
729 }
|
|
730
|
20319
|
731 void
|
17788
|
732 copy_keymap_1 (chartable, idx, elt)
|
|
733 Lisp_Object chartable, idx, elt;
|
|
734 {
|
17861
|
735 if (!SYMBOLP (elt) && ! NILP (Fkeymapp (elt)))
|
|
736 Faset (chartable, idx, Fcopy_keymap (elt));
|
17788
|
737 }
|
1209
|
738
|
250
|
739 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0,
|
|
740 "Return a copy of the keymap KEYMAP.\n\
|
|
741 The copy starts out with the same definitions of KEYMAP,\n\
|
|
742 but changing either the copy or KEYMAP does not affect the other.\n\
|
362
|
743 Any key definitions that are subkeymaps are recursively copied.\n\
|
|
744 However, a key definition which is a symbol whose definition is a keymap\n\
|
|
745 is not copied.")
|
250
|
746 (keymap)
|
|
747 Lisp_Object keymap;
|
|
748 {
|
|
749 register Lisp_Object copy, tail;
|
|
750
|
|
751 copy = Fcopy_alist (get_keymap (keymap));
|
|
752
|
1209
|
753 for (tail = copy; CONSP (tail); tail = XCONS (tail)->cdr)
|
250
|
754 {
|
6502
|
755 Lisp_Object elt;
|
250
|
756
|
6502
|
757 elt = XCONS (tail)->car;
|
17788
|
758 if (CHAR_TABLE_P (elt))
|
|
759 {
|
20076
|
760 Lisp_Object indices[3];
|
17788
|
761
|
|
762 elt = Fcopy_sequence (elt);
|
18142
c9bd973ca168
(Fcopy_keymap): After copying a sub-char-table, do store the copy.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
763 XCONS (tail)->car = elt;
|
c9bd973ca168
(Fcopy_keymap): After copying a sub-char-table, do store the copy.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
764
|
17788
|
765 map_char_table (copy_keymap_1, Qnil, elt, elt, 0, indices);
|
|
766 }
|
|
767 else if (VECTORP (elt))
|
250
|
768 {
|
1209
|
769 int i;
|
250
|
770
|
1209
|
771 elt = Fcopy_sequence (elt);
|
|
772 XCONS (tail)->car = elt;
|
250
|
773
|
2790
|
774 for (i = 0; i < XVECTOR (elt)->size; i++)
|
9123
|
775 if (!SYMBOLP (XVECTOR (elt)->contents[i])
|
3674
|
776 && ! NILP (Fkeymapp (XVECTOR (elt)->contents[i])))
|
17788
|
777 XVECTOR (elt)->contents[i]
|
|
778 = Fcopy_keymap (XVECTOR (elt)->contents[i]);
|
250
|
779 }
|
21241
|
780 else if (CONSP (elt) && CONSP (XCONS (elt)->cdr))
|
6456
|
781 {
|
21241
|
782 Lisp_Object tem;
|
|
783 tem = XCONS (elt)->cdr;
|
|
784
|
|
785 /* Is this a new format menu item. */
|
|
786 if (EQ (XCONS (tem)->car,Qmenu_item))
|
6456
|
787 {
|
21241
|
788 /* Copy cell with menu-item marker. */
|
|
789 XCONS (elt)->cdr
|
|
790 = Fcons (XCONS (tem)->car, XCONS (tem)->cdr);
|
6456
|
791 elt = XCONS (elt)->cdr;
|
21241
|
792 tem = XCONS (elt)->cdr;
|
|
793 if (CONSP (tem))
|
|
794 {
|
|
795 /* Copy cell with menu-item name. */
|
|
796 XCONS (elt)->cdr
|
|
797 = Fcons (XCONS (tem)->car, XCONS (tem)->cdr);
|
|
798 elt = XCONS (elt)->cdr;
|
|
799 tem = XCONS (elt)->cdr;
|
|
800 };
|
|
801 if (CONSP (tem))
|
6456
|
802 {
|
21241
|
803 /* Copy cell with binding and if the binding is a keymap,
|
|
804 copy that. */
|
|
805 XCONS (elt)->cdr
|
|
806 = Fcons (XCONS (tem)->car, XCONS (tem)->cdr);
|
6456
|
807 elt = XCONS (elt)->cdr;
|
21241
|
808 tem = XCONS (elt)->car;
|
|
809 if (!(SYMBOLP (tem) || NILP (Fkeymapp (tem))))
|
|
810 XCONS (elt)->car = Fcopy_keymap (tem);
|
|
811 tem = XCONS (elt)->cdr;
|
|
812 if (CONSP (tem) && CONSP (XCONS (tem)->car))
|
|
813 /* Delete cache for key equivalences. */
|
|
814 XCONS (elt)->cdr = XCONS (tem)->cdr;
|
6456
|
815 }
|
|
816 }
|
21241
|
817 else
|
|
818 {
|
|
819 /* It may be an old fomat menu item.
|
|
820 Skip the optional menu string.
|
|
821 */
|
|
822 if (STRINGP (XCONS (tem)->car))
|
|
823 {
|
|
824 /* Copy the cell, since copy-alist didn't go this deep. */
|
|
825 XCONS (elt)->cdr
|
|
826 = Fcons (XCONS (tem)->car, XCONS (tem)->cdr);
|
|
827 elt = XCONS (elt)->cdr;
|
|
828 tem = XCONS (elt)->cdr;
|
|
829 /* Also skip the optional menu help string. */
|
|
830 if (CONSP (tem) && STRINGP (XCONS (tem)->car))
|
|
831 {
|
|
832 XCONS (elt)->cdr
|
|
833 = Fcons (XCONS (tem)->car, XCONS (tem)->cdr);
|
|
834 elt = XCONS (elt)->cdr;
|
|
835 tem = XCONS (elt)->cdr;
|
|
836 }
|
|
837 /* There may also be a list that caches key equivalences.
|
|
838 Just delete it for the new keymap. */
|
|
839 if (CONSP (tem)
|
|
840 && CONSP (XCONS (tem)->car)
|
|
841 && (NILP (XCONS (XCONS (tem)->car)->car)
|
|
842 || VECTORP (XCONS (XCONS (tem)->car)->car)))
|
|
843 XCONS (elt)->cdr = XCONS (tem)->cdr;
|
|
844 }
|
|
845 if (CONSP (elt)
|
|
846 && ! SYMBOLP (XCONS (elt)->cdr)
|
|
847 && ! NILP (Fkeymapp (XCONS (elt)->cdr)))
|
|
848 XCONS (elt)->cdr = Fcopy_keymap (XCONS (elt)->cdr);
|
|
849 }
|
|
850
|
6456
|
851 }
|
250
|
852 }
|
21241
|
853
|
250
|
854 return copy;
|
|
855 }
|
|
856
|
465
|
857 /* Simple Keymap mutators and accessors. */
|
|
858
|
7998
|
859 /* GC is possible in this function if it autoloads a keymap. */
|
|
860
|
250
|
861 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0,
|
|
862 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\
|
|
863 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\
|
|
864 meaning a sequence of keystrokes and events.\n\
|
5100
|
865 Non-ASCII characters with codes above 127 (such as ISO Latin-1)\n\
|
|
866 can be included if you use a vector.\n\
|
250
|
867 DEF is anything that can be a key's definition:\n\
|
|
868 nil (means key is undefined in this keymap),\n\
|
|
869 a command (a Lisp function suitable for interactive calling)\n\
|
|
870 a string (treated as a keyboard macro),\n\
|
|
871 a keymap (to define a prefix key),\n\
|
|
872 a symbol. When the key is looked up, the symbol will stand for its\n\
|
|
873 function definition, which should at that time be one of the above,\n\
|
|
874 or another symbol whose function definition is used, etc.\n\
|
|
875 a cons (STRING . DEFN), meaning that DEFN is the definition\n\
|
|
876 (DEFN should be a valid definition in its own right),\n\
|
368
|
877 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\
|
|
878 \n\
|
|
879 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\
|
|
880 the front of KEYMAP.")
|
250
|
881 (keymap, key, def)
|
1517
|
882 Lisp_Object keymap;
|
250
|
883 Lisp_Object key;
|
|
884 Lisp_Object def;
|
|
885 {
|
|
886 register int idx;
|
|
887 register Lisp_Object c;
|
|
888 register Lisp_Object tem;
|
|
889 register Lisp_Object cmd;
|
|
890 int metized = 0;
|
2059
|
891 int meta_bit;
|
250
|
892 int length;
|
1517
|
893 struct gcpro gcpro1, gcpro2, gcpro3;
|
250
|
894
|
6774
|
895 keymap = get_keymap_1 (keymap, 1, 1);
|
250
|
896
|
9123
|
897 if (!VECTORP (key) && !STRINGP (key))
|
250
|
898 key = wrong_type_argument (Qarrayp, key);
|
|
899
|
1517
|
900 length = XFASTINT (Flength (key));
|
250
|
901 if (length == 0)
|
|
902 return Qnil;
|
|
903
|
12297
|
904 if (SYMBOLP (def) && !EQ (Vdefine_key_rebound_commands, Qt))
|
|
905 Vdefine_key_rebound_commands = Fcons (def, Vdefine_key_rebound_commands);
|
|
906
|
1517
|
907 GCPRO3 (keymap, key, def);
|
|
908
|
9123
|
909 if (VECTORP (key))
|
2059
|
910 meta_bit = meta_modifier;
|
|
911 else
|
|
912 meta_bit = 0x80;
|
|
913
|
250
|
914 idx = 0;
|
|
915 while (1)
|
|
916 {
|
|
917 c = Faref (key, make_number (idx));
|
|
918
|
10840
|
919 if (CONSP (c) && lucid_event_type_list_p (c))
|
12151
|
920 c = Fevent_convert_list (c);
|
10840
|
921
|
9123
|
922 if (INTEGERP (c)
|
2059
|
923 && (XINT (c) & meta_bit)
|
250
|
924 && !metized)
|
|
925 {
|
|
926 c = meta_prefix_char;
|
|
927 metized = 1;
|
|
928 }
|
|
929 else
|
|
930 {
|
9123
|
931 if (INTEGERP (c))
|
2093
|
932 XSETINT (c, XINT (c) & ~meta_bit);
|
250
|
933
|
|
934 metized = 0;
|
|
935 idx++;
|
|
936 }
|
|
937
|
6473
|
938 if (! INTEGERP (c) && ! SYMBOLP (c) && ! CONSP (c))
|
8517
|
939 error ("Key sequence contains invalid events");
|
6473
|
940
|
250
|
941 if (idx == length)
|
1517
|
942 RETURN_UNGCPRO (store_in_keymap (keymap, c, def));
|
250
|
943
|
6774
|
944 cmd = get_keyelt (access_keymap (keymap, c, 0, 1), 1);
|
250
|
945
|
3735
|
946 /* If this key is undefined, make it a prefix. */
|
485
|
947 if (NILP (cmd))
|
3735
|
948 cmd = define_as_prefix (keymap, c);
|
250
|
949
|
1517
|
950 keymap = get_keymap_1 (cmd, 0, 1);
|
|
951 if (NILP (keymap))
|
6502
|
952 /* We must use Fkey_description rather than just passing key to
|
|
953 error; key might be a vector, not a string. */
|
|
954 error ("Key sequence %s uses invalid prefix characters",
|
|
955 XSTRING (Fkey_description (key))->data);
|
250
|
956 }
|
|
957 }
|
|
958
|
|
959 /* Value is number if KEY is too long; NIL if valid but has no definition. */
|
7998
|
960 /* GC is possible in this function if it autoloads a keymap. */
|
250
|
961
|
1871
|
962 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0,
|
250
|
963 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
|
|
964 nil means undefined. See doc of `define-key' for kinds of definitions.\n\
|
1871
|
965 \n\
|
250
|
966 A number as value means KEY is \"too long\";\n\
|
|
967 that is, characters or symbols in it except for the last one\n\
|
|
968 fail to be a valid sequence of prefix characters in KEYMAP.\n\
|
|
969 The number is how many characters at the front of KEY\n\
|
1871
|
970 it takes to reach a non-prefix command.\n\
|
|
971 \n\
|
|
972 Normally, `lookup-key' ignores bindings for t, which act as default\n\
|
|
973 bindings, used when nothing else in the keymap applies; this makes it\n\
|
13947
|
974 usable as a general function for probing keymaps. However, if the\n\
|
1871
|
975 third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will\n\
|
|
976 recognize the default bindings, just as `read-key-sequence' does.")
|
|
977 (keymap, key, accept_default)
|
250
|
978 register Lisp_Object keymap;
|
|
979 Lisp_Object key;
|
1871
|
980 Lisp_Object accept_default;
|
250
|
981 {
|
|
982 register int idx;
|
|
983 register Lisp_Object tem;
|
|
984 register Lisp_Object cmd;
|
|
985 register Lisp_Object c;
|
|
986 int metized = 0;
|
|
987 int length;
|
1871
|
988 int t_ok = ! NILP (accept_default);
|
2059
|
989 int meta_bit;
|
7998
|
990 struct gcpro gcpro1;
|
250
|
991
|
6774
|
992 keymap = get_keymap_1 (keymap, 1, 1);
|
250
|
993
|
9123
|
994 if (!VECTORP (key) && !STRINGP (key))
|
250
|
995 key = wrong_type_argument (Qarrayp, key);
|
|
996
|
1517
|
997 length = XFASTINT (Flength (key));
|
250
|
998 if (length == 0)
|
|
999 return keymap;
|
|
1000
|
9123
|
1001 if (VECTORP (key))
|
2059
|
1002 meta_bit = meta_modifier;
|
|
1003 else
|
|
1004 meta_bit = 0x80;
|
|
1005
|
7998
|
1006 GCPRO1 (key);
|
|
1007
|
250
|
1008 idx = 0;
|
|
1009 while (1)
|
|
1010 {
|
|
1011 c = Faref (key, make_number (idx));
|
|
1012
|
10840
|
1013 if (CONSP (c) && lucid_event_type_list_p (c))
|
12151
|
1014 c = Fevent_convert_list (c);
|
10840
|
1015
|
9123
|
1016 if (INTEGERP (c)
|
2059
|
1017 && (XINT (c) & meta_bit)
|
250
|
1018 && !metized)
|
|
1019 {
|
|
1020 c = meta_prefix_char;
|
|
1021 metized = 1;
|
|
1022 }
|
|
1023 else
|
|
1024 {
|
9123
|
1025 if (INTEGERP (c))
|
2059
|
1026 XSETINT (c, XINT (c) & ~meta_bit);
|
250
|
1027
|
|
1028 metized = 0;
|
|
1029 idx++;
|
|
1030 }
|
|
1031
|
6774
|
1032 cmd = get_keyelt (access_keymap (keymap, c, t_ok, 0), 1);
|
250
|
1033 if (idx == length)
|
7998
|
1034 RETURN_UNGCPRO (cmd);
|
250
|
1035
|
6774
|
1036 keymap = get_keymap_1 (cmd, 0, 1);
|
1517
|
1037 if (NILP (keymap))
|
7998
|
1038 RETURN_UNGCPRO (make_number (idx));
|
250
|
1039
|
|
1040 QUIT;
|
|
1041 }
|
|
1042 }
|
|
1043
|
3735
|
1044 /* Make KEYMAP define event C as a keymap (i.e., as a prefix).
|
|
1045 Assume that currently it does not define C at all.
|
|
1046 Return the keymap. */
|
|
1047
|
|
1048 static Lisp_Object
|
|
1049 define_as_prefix (keymap, c)
|
|
1050 Lisp_Object keymap, c;
|
|
1051 {
|
|
1052 Lisp_Object inherit, cmd;
|
|
1053
|
|
1054 cmd = Fmake_sparse_keymap (Qnil);
|
|
1055 /* If this key is defined as a prefix in an inherited keymap,
|
|
1056 make it a prefix in this map, and make its definition
|
|
1057 inherit the other prefix definition. */
|
|
1058 inherit = access_keymap (keymap, c, 0, 0);
|
15344
|
1059 #if 0
|
|
1060 /* This code is needed to do the right thing in the following case:
|
|
1061 keymap A inherits from B,
|
|
1062 you define KEY as a prefix in A,
|
|
1063 then later you define KEY as a prefix in B.
|
|
1064 We want the old prefix definition in A to inherit from that in B.
|
|
1065 It is hard to do that retroactively, so this code
|
|
1066 creates the prefix in B right away.
|
|
1067
|
|
1068 But it turns out that this code causes problems immediately
|
|
1069 when the prefix in A is defined: it causes B to define KEY
|
|
1070 as a prefix with no subcommands.
|
|
1071
|
|
1072 So I took out this code. */
|
3735
|
1073 if (NILP (inherit))
|
|
1074 {
|
|
1075 /* If there's an inherited keymap
|
|
1076 and it doesn't define this key,
|
|
1077 make it define this key. */
|
|
1078 Lisp_Object tail;
|
|
1079
|
|
1080 for (tail = Fcdr (keymap); CONSP (tail); tail = XCONS (tail)->cdr)
|
|
1081 if (EQ (XCONS (tail)->car, Qkeymap))
|
|
1082 break;
|
|
1083
|
|
1084 if (!NILP (tail))
|
|
1085 inherit = define_as_prefix (tail, c);
|
|
1086 }
|
15344
|
1087 #endif
|
3735
|
1088
|
|
1089 cmd = nconc2 (cmd, inherit);
|
|
1090 store_in_keymap (keymap, c, cmd);
|
|
1091
|
|
1092 return cmd;
|
|
1093 }
|
|
1094
|
2093
|
1095 /* Append a key to the end of a key sequence. We always make a vector. */
|
|
1096
|
250
|
1097 Lisp_Object
|
|
1098 append_key (key_sequence, key)
|
|
1099 Lisp_Object key_sequence, key;
|
|
1100 {
|
|
1101 Lisp_Object args[2];
|
|
1102
|
|
1103 args[0] = key_sequence;
|
|
1104
|
2093
|
1105 args[1] = Fcons (key, Qnil);
|
|
1106 return Fvconcat (2, args);
|
250
|
1107 }
|
|
1108
|
|
1109
|
465
|
1110 /* Global, local, and minor mode keymap stuff. */
|
|
1111
|
485
|
1112 /* We can't put these variables inside current_minor_maps, since under
|
517
|
1113 some systems, static gets macro-defined to be the empty string.
|
|
1114 Ickypoo. */
|
485
|
1115 static Lisp_Object *cmm_modes, *cmm_maps;
|
|
1116 static int cmm_size;
|
|
1117
|
12542
|
1118 /* Error handler used in current_minor_maps. */
|
|
1119 static Lisp_Object
|
|
1120 current_minor_maps_error ()
|
|
1121 {
|
|
1122 return Qnil;
|
|
1123 }
|
|
1124
|
465
|
1125 /* Store a pointer to an array of the keymaps of the currently active
|
|
1126 minor modes in *buf, and return the number of maps it contains.
|
|
1127
|
|
1128 This function always returns a pointer to the same buffer, and may
|
|
1129 free or reallocate it, so if you want to keep it for a long time or
|
|
1130 hand it out to lisp code, copy it. This procedure will be called
|
|
1131 for every key sequence read, so the nice lispy approach (return a
|
|
1132 new assoclist, list, what have you) for each invocation would
|
|
1133 result in a lot of consing over time.
|
|
1134
|
|
1135 If we used xrealloc/xmalloc and ran out of memory, they would throw
|
|
1136 back to the command loop, which would try to read a key sequence,
|
|
1137 which would call this function again, resulting in an infinite
|
|
1138 loop. Instead, we'll use realloc/malloc and silently truncate the
|
|
1139 list, let the key sequence be read, and hope some other piece of
|
|
1140 code signals the error. */
|
|
1141 int
|
|
1142 current_minor_maps (modeptr, mapptr)
|
|
1143 Lisp_Object **modeptr, **mapptr;
|
|
1144 {
|
|
1145 int i = 0;
|
20517
|
1146 int list_number = 0;
|
517
|
1147 Lisp_Object alist, assoc, var, val;
|
20517
|
1148 Lisp_Object lists[2];
|
|
1149
|
|
1150 lists[0] = Vminor_mode_overriding_map_alist;
|
|
1151 lists[1] = Vminor_mode_map_alist;
|
|
1152
|
|
1153 for (list_number = 0; list_number < 2; list_number++)
|
|
1154 for (alist = lists[list_number];
|
|
1155 CONSP (alist);
|
|
1156 alist = XCONS (alist)->cdr)
|
|
1157 if ((assoc = XCONS (alist)->car, CONSP (assoc))
|
|
1158 && (var = XCONS (assoc)->car, SYMBOLP (var))
|
|
1159 && (val = find_symbol_value (var), ! EQ (val, Qunbound))
|
|
1160 && ! NILP (val))
|
|
1161 {
|
|
1162 Lisp_Object temp;
|
|
1163
|
20576
|
1164 /* If a variable has an entry in Vminor_mode_overriding_map_alist,
|
|
1165 and also an entry in Vminor_mode_map_alist,
|
|
1166 ignore the latter. */
|
|
1167 if (list_number == 1)
|
|
1168 {
|
|
1169 val = assq_no_quit (var, lists[0]);
|
|
1170 if (!NILP (val))
|
|
1171 break;
|
|
1172 }
|
|
1173
|
20517
|
1174 if (i >= cmm_size)
|
|
1175 {
|
|
1176 Lisp_Object *newmodes, *newmaps;
|
|
1177
|
|
1178 if (cmm_maps)
|
|
1179 {
|
|
1180 BLOCK_INPUT;
|
|
1181 cmm_size *= 2;
|
|
1182 newmodes
|
|
1183 = (Lisp_Object *) realloc (cmm_modes,
|
|
1184 cmm_size * sizeof (Lisp_Object));
|
|
1185 newmaps
|
|
1186 = (Lisp_Object *) realloc (cmm_maps,
|
|
1187 cmm_size * sizeof (Lisp_Object));
|
|
1188 UNBLOCK_INPUT;
|
|
1189 }
|
|
1190 else
|
|
1191 {
|
|
1192 BLOCK_INPUT;
|
|
1193 cmm_size = 30;
|
|
1194 newmodes
|
|
1195 = (Lisp_Object *) malloc (cmm_size * sizeof (Lisp_Object));
|
|
1196 newmaps
|
|
1197 = (Lisp_Object *) malloc (cmm_size * sizeof (Lisp_Object));
|
|
1198 UNBLOCK_INPUT;
|
|
1199 }
|
|
1200
|
|
1201 if (newmaps && newmodes)
|
|
1202 {
|
|
1203 cmm_modes = newmodes;
|
|
1204 cmm_maps = newmaps;
|
|
1205 }
|
|
1206 else
|
|
1207 break;
|
|
1208 }
|
|
1209
|
|
1210 /* Get the keymap definition--or nil if it is not defined. */
|
|
1211 temp = internal_condition_case_1 (Findirect_function,
|
|
1212 XCONS (assoc)->cdr,
|
|
1213 Qerror, current_minor_maps_error);
|
|
1214 if (!NILP (temp))
|
|
1215 {
|
|
1216 cmm_modes[i] = var;
|
|
1217 cmm_maps [i] = temp;
|
|
1218 i++;
|
|
1219 }
|
|
1220 }
|
465
|
1221
|
485
|
1222 if (modeptr) *modeptr = cmm_modes;
|
|
1223 if (mapptr) *mapptr = cmm_maps;
|
465
|
1224 return i;
|
|
1225 }
|
|
1226
|
7998
|
1227 /* GC is possible in this function if it autoloads a keymap. */
|
|
1228
|
1871
|
1229 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0,
|
250
|
1230 "Return the binding for command KEY in current keymaps.\n\
|
1871
|
1231 KEY is a string or vector, a sequence of keystrokes.\n\
|
|
1232 The binding is probably a symbol with a function definition.\n\
|
|
1233 \n\
|
|
1234 Normally, `key-binding' ignores bindings for t, which act as default\n\
|
|
1235 bindings, used when nothing else in the keymap applies; this makes it\n\
|
5055
|
1236 usable as a general function for probing keymaps. However, if the\n\
|
|
1237 optional second argument ACCEPT-DEFAULT is non-nil, `key-binding' does\n\
|
1871
|
1238 recognize the default bindings, just as `read-key-sequence' does.")
|
|
1239 (key, accept_default)
|
6834
|
1240 Lisp_Object key, accept_default;
|
250
|
1241 {
|
465
|
1242 Lisp_Object *maps, value;
|
|
1243 int nmaps, i;
|
7998
|
1244 struct gcpro gcpro1;
|
|
1245
|
|
1246 GCPRO1 (key);
|
465
|
1247
|
12262
|
1248 if (!NILP (current_kboard->Voverriding_terminal_local_map))
|
|
1249 {
|
|
1250 value = Flookup_key (current_kboard->Voverriding_terminal_local_map,
|
|
1251 key, accept_default);
|
|
1252 if (! NILP (value) && !INTEGERP (value))
|
|
1253 RETURN_UNGCPRO (value);
|
|
1254 }
|
|
1255 else if (!NILP (Voverriding_local_map))
|
250
|
1256 {
|
5613
|
1257 value = Flookup_key (Voverriding_local_map, key, accept_default);
|
9123
|
1258 if (! NILP (value) && !INTEGERP (value))
|
7998
|
1259 RETURN_UNGCPRO (value);
|
250
|
1260 }
|
5613
|
1261 else
|
|
1262 {
|
13771
|
1263 Lisp_Object local;
|
|
1264
|
5613
|
1265 nmaps = current_minor_maps (0, &maps);
|
7998
|
1266 /* Note that all these maps are GCPRO'd
|
|
1267 in the places where we found them. */
|
|
1268
|
5613
|
1269 for (i = 0; i < nmaps; i++)
|
|
1270 if (! NILP (maps[i]))
|
|
1271 {
|
|
1272 value = Flookup_key (maps[i], key, accept_default);
|
9123
|
1273 if (! NILP (value) && !INTEGERP (value))
|
7998
|
1274 RETURN_UNGCPRO (value);
|
5613
|
1275 }
|
|
1276
|
13771
|
1277 local = get_local_map (PT, current_buffer);
|
|
1278
|
|
1279 if (! NILP (local))
|
5613
|
1280 {
|
13771
|
1281 value = Flookup_key (local, key, accept_default);
|
9123
|
1282 if (! NILP (value) && !INTEGERP (value))
|
7998
|
1283 RETURN_UNGCPRO (value);
|
5613
|
1284 }
|
|
1285 }
|
465
|
1286
|
1871
|
1287 value = Flookup_key (current_global_map, key, accept_default);
|
7998
|
1288 UNGCPRO;
|
9123
|
1289 if (! NILP (value) && !INTEGERP (value))
|
465
|
1290 return value;
|
|
1291
|
|
1292 return Qnil;
|
250
|
1293 }
|
|
1294
|
7998
|
1295 /* GC is possible in this function if it autoloads a keymap. */
|
|
1296
|
1871
|
1297 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0,
|
250
|
1298 "Return the binding for command KEYS in current local keymap only.\n\
|
|
1299 KEYS is a string, a sequence of keystrokes.\n\
|
1871
|
1300 The binding is probably a symbol with a function definition.\n\
|
|
1301 \n\
|
|
1302 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
|
|
1303 bindings; see the description of `lookup-key' for more details about this.")
|
|
1304 (keys, accept_default)
|
|
1305 Lisp_Object keys, accept_default;
|
250
|
1306 {
|
|
1307 register Lisp_Object map;
|
|
1308 map = current_buffer->keymap;
|
485
|
1309 if (NILP (map))
|
250
|
1310 return Qnil;
|
1871
|
1311 return Flookup_key (map, keys, accept_default);
|
250
|
1312 }
|
|
1313
|
7998
|
1314 /* GC is possible in this function if it autoloads a keymap. */
|
|
1315
|
1871
|
1316 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0,
|
250
|
1317 "Return the binding for command KEYS in current global keymap only.\n\
|
|
1318 KEYS is a string, a sequence of keystrokes.\n\
|
517
|
1319 The binding is probably a symbol with a function definition.\n\
|
|
1320 This function's return values are the same as those of lookup-key\n\
|
7998
|
1321 \(which see).\n\
|
1871
|
1322 \n\
|
|
1323 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
|
|
1324 bindings; see the description of `lookup-key' for more details about this.")
|
|
1325 (keys, accept_default)
|
|
1326 Lisp_Object keys, accept_default;
|
250
|
1327 {
|
1871
|
1328 return Flookup_key (current_global_map, keys, accept_default);
|
250
|
1329 }
|
|
1330
|
7998
|
1331 /* GC is possible in this function if it autoloads a keymap. */
|
|
1332
|
1871
|
1333 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0,
|
465
|
1334 "Find the visible minor mode bindings of KEY.\n\
|
|
1335 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\
|
|
1336 the symbol which names the minor mode binding KEY, and BINDING is\n\
|
|
1337 KEY's definition in that mode. In particular, if KEY has no\n\
|
|
1338 minor-mode bindings, return nil. If the first binding is a\n\
|
|
1339 non-prefix, all subsequent bindings will be omitted, since they would\n\
|
|
1340 be ignored. Similarly, the list doesn't include non-prefix bindings\n\
|
1871
|
1341 that come after prefix bindings.\n\
|
|
1342 \n\
|
|
1343 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\
|
|
1344 bindings; see the description of `lookup-key' for more details about this.")
|
|
1345 (key, accept_default)
|
|
1346 Lisp_Object key, accept_default;
|
465
|
1347 {
|
|
1348 Lisp_Object *modes, *maps;
|
|
1349 int nmaps;
|
|
1350 Lisp_Object binding;
|
|
1351 int i, j;
|
7998
|
1352 struct gcpro gcpro1, gcpro2;
|
465
|
1353
|
|
1354 nmaps = current_minor_maps (&modes, &maps);
|
7998
|
1355 /* Note that all these maps are GCPRO'd
|
|
1356 in the places where we found them. */
|
|
1357
|
|
1358 binding = Qnil;
|
|
1359 GCPRO2 (key, binding);
|
465
|
1360
|
|
1361 for (i = j = 0; i < nmaps; i++)
|
485
|
1362 if (! NILP (maps[i])
|
1871
|
1363 && ! NILP (binding = Flookup_key (maps[i], key, accept_default))
|
9123
|
1364 && !INTEGERP (binding))
|
465
|
1365 {
|
1517
|
1366 if (! NILP (get_keymap (binding)))
|
465
|
1367 maps[j++] = Fcons (modes[i], binding);
|
|
1368 else if (j == 0)
|
7998
|
1369 RETURN_UNGCPRO (Fcons (Fcons (modes[i], binding), Qnil));
|
465
|
1370 }
|
|
1371
|
7998
|
1372 UNGCPRO;
|
465
|
1373 return Flist (j, maps);
|
|
1374 }
|
|
1375
|
23968
|
1376 DEFUN ("define-prefix-command", Fdefine_prefix_command, Sdefine_prefix_command, 1, 3, 0,
|
2652
|
1377 "Define COMMAND as a prefix command. COMMAND should be a symbol.\n\
|
250
|
1378 A new sparse keymap is stored as COMMAND's function definition and its value.\n\
|
362
|
1379 If a second optional argument MAPVAR is given, the map is stored as\n\
|
|
1380 its value instead of as COMMAND's value; but COMMAND is still defined\n\
|
23968
|
1381 as a function.\n\
|
|
1382 The third optional argument NAME, if given, supplies a menu name\n\
|
|
1383 string for the map. This is required to use the keymap as a menu.")
|
|
1384 (command, mapvar, name)
|
|
1385 Lisp_Object command, mapvar, name;
|
250
|
1386 {
|
|
1387 Lisp_Object map;
|
23968
|
1388 map = Fmake_sparse_keymap (name);
|
14080
|
1389 Ffset (command, map);
|
485
|
1390 if (!NILP (mapvar))
|
250
|
1391 Fset (mapvar, map);
|
|
1392 else
|
14080
|
1393 Fset (command, map);
|
|
1394 return command;
|
250
|
1395 }
|
|
1396
|
|
1397 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0,
|
|
1398 "Select KEYMAP as the global keymap.")
|
|
1399 (keymap)
|
|
1400 Lisp_Object keymap;
|
|
1401 {
|
|
1402 keymap = get_keymap (keymap);
|
|
1403 current_global_map = keymap;
|
8464
edbb014c600a
(Fuse_global_map, Fuse_local_map): Call record_asynch_buffer_change.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1404
|
250
|
1405 return Qnil;
|
|
1406 }
|
|
1407
|
|
1408 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 1, 0,
|
|
1409 "Select KEYMAP as the local keymap.\n\
|
|
1410 If KEYMAP is nil, that means no local keymap.")
|
|
1411 (keymap)
|
|
1412 Lisp_Object keymap;
|
|
1413 {
|
485
|
1414 if (!NILP (keymap))
|
250
|
1415 keymap = get_keymap (keymap);
|
|
1416
|
|
1417 current_buffer->keymap = keymap;
|
|
1418
|
|
1419 return Qnil;
|
|
1420 }
|
|
1421
|
|
1422 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 0, 0,
|
|
1423 "Return current buffer's local keymap, or nil if it has none.")
|
|
1424 ()
|
|
1425 {
|
|
1426 return current_buffer->keymap;
|
|
1427 }
|
|
1428
|
|
1429 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0,
|
|
1430 "Return the current global keymap.")
|
|
1431 ()
|
|
1432 {
|
|
1433 return current_global_map;
|
|
1434 }
|
465
|
1435
|
|
1436 DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps, Scurrent_minor_mode_maps, 0, 0, 0,
|
|
1437 "Return a list of keymaps for the minor modes of the current buffer.")
|
|
1438 ()
|
|
1439 {
|
|
1440 Lisp_Object *maps;
|
|
1441 int nmaps = current_minor_maps (0, &maps);
|
|
1442
|
|
1443 return Flist (nmaps, maps);
|
|
1444 }
|
250
|
1445
|
465
|
1446 /* Help functions for describing and documenting keymaps. */
|
|
1447
|
20319
|
1448 static void accessible_keymaps_char_table ();
|
17788
|
1449
|
7998
|
1450 /* This function cannot GC. */
|
|
1451
|
250
|
1452 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps,
|
3952
|
1453 1, 2, 0,
|
250
|
1454 "Find all keymaps accessible via prefix characters from KEYMAP.\n\
|
|
1455 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\
|
|
1456 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\
|
14304
|
1457 so that the KEYS increase in length. The first element is ([] . KEYMAP).\n\
|
3962
|
1458 An optional argument PREFIX, if non-nil, should be a key sequence;\n\
|
|
1459 then the value includes only maps for prefixes that start with PREFIX.")
|
14080
|
1460 (keymap, prefix)
|
|
1461 Lisp_Object keymap, prefix;
|
250
|
1462 {
|
3952
|
1463 Lisp_Object maps, good_maps, tail;
|
|
1464 int prefixlen = 0;
|
|
1465
|
7998
|
1466 /* no need for gcpro because we don't autoload any keymaps. */
|
|
1467
|
3952
|
1468 if (!NILP (prefix))
|
|
1469 prefixlen = XINT (Flength (prefix));
|
250
|
1470
|
8431
|
1471 if (!NILP (prefix))
|
|
1472 {
|
|
1473 /* If a prefix was specified, start with the keymap (if any) for
|
|
1474 that prefix, so we don't waste time considering other prefixes. */
|
|
1475 Lisp_Object tem;
|
14080
|
1476 tem = Flookup_key (keymap, prefix, Qt);
|
8473
|
1477 /* Flookup_key may give us nil, or a number,
|
|
1478 if the prefix is not defined in this particular map.
|
|
1479 It might even give us a list that isn't a keymap. */
|
|
1480 tem = get_keymap_1 (tem, 0, 0);
|
8431
|
1481 if (!NILP (tem))
|
17510
|
1482 {
|
|
1483 /* Convert PREFIX to a vector now, so that later on
|
|
1484 we don't have to deal with the possibility of a string. */
|
|
1485 if (STRINGP (prefix))
|
|
1486 {
|
20624
|
1487 int i, i_byte, c;
|
17510
|
1488 Lisp_Object copy;
|
|
1489
|
|
1490 copy = Fmake_vector (make_number (XSTRING (prefix)->size), Qnil);
|
24572
|
1491 for (i = 0, i_byte = 0; i < XSTRING (prefix)->size;)
|
17510
|
1492 {
|
20624
|
1493 int i_before = i;
|
|
1494 if (STRING_MULTIBYTE (prefix))
|
|
1495 FETCH_STRING_CHAR_ADVANCE (c, prefix, i, i_byte);
|
|
1496 else
|
24572
|
1497 {
|
|
1498 c = XSTRING (prefix)->data[i++];
|
|
1499 if (c & 0200)
|
|
1500 c ^= 0200 | meta_modifier;
|
|
1501 }
|
20624
|
1502 XVECTOR (copy)->contents[i_before] = make_number (c);
|
17510
|
1503 }
|
|
1504 prefix = copy;
|
|
1505 }
|
|
1506 maps = Fcons (Fcons (prefix, tem), Qnil);
|
|
1507 }
|
8431
|
1508 else
|
|
1509 return Qnil;
|
|
1510 }
|
|
1511 else
|
|
1512 maps = Fcons (Fcons (Fmake_vector (make_number (0), Qnil),
|
14080
|
1513 get_keymap (keymap)),
|
8431
|
1514 Qnil);
|
250
|
1515
|
|
1516 /* For each map in the list maps,
|
|
1517 look at any other maps it points to,
|
|
1518 and stick them at the end if they are not already in the list.
|
|
1519
|
|
1520 This is a breadth-first traversal, where tail is the queue of
|
|
1521 nodes, and maps accumulates a list of all nodes visited. */
|
|
1522
|
1209
|
1523 for (tail = maps; CONSP (tail); tail = XCONS (tail)->cdr)
|
250
|
1524 {
|
6502
|
1525 register Lisp_Object thisseq, thismap;
|
|
1526 Lisp_Object last;
|
|
1527 /* Does the current sequence end in the meta-prefix-char? */
|
|
1528 int is_metized;
|
250
|
1529
|
6502
|
1530 thisseq = Fcar (Fcar (tail));
|
|
1531 thismap = Fcdr (Fcar (tail));
|
|
1532 last = make_number (XINT (Flength (thisseq)) - 1);
|
|
1533 is_metized = (XINT (last) >= 0
|
17264
|
1534 /* Don't metize the last char of PREFIX. */
|
|
1535 && XINT (last) >= prefixlen
|
6502
|
1536 && EQ (Faref (thisseq, last), meta_prefix_char));
|
250
|
1537
|
1209
|
1538 for (; CONSP (thismap); thismap = XCONS (thismap)->cdr)
|
|
1539 {
|
6502
|
1540 Lisp_Object elt;
|
|
1541
|
|
1542 elt = XCONS (thismap)->car;
|
250
|
1543
|
1209
|
1544 QUIT;
|
250
|
1545
|
17788
|
1546 if (CHAR_TABLE_P (elt))
|
|
1547 {
|
20076
|
1548 Lisp_Object indices[3];
|
17788
|
1549
|
|
1550 map_char_table (accessible_keymaps_char_table, Qnil,
|
|
1551 elt, Fcons (maps, Fcons (tail, thisseq)),
|
|
1552 0, indices);
|
|
1553 }
|
|
1554 else if (VECTORP (elt))
|
250
|
1555 {
|
|
1556 register int i;
|
|
1557
|
|
1558 /* Vector keymap. Scan all the elements. */
|
2752
|
1559 for (i = 0; i < XVECTOR (elt)->size; i++)
|
250
|
1560 {
|
|
1561 register Lisp_Object tem;
|
|
1562 register Lisp_Object cmd;
|
|
1563
|
6774
|
1564 cmd = get_keyelt (XVECTOR (elt)->contents[i], 0);
|
485
|
1565 if (NILP (cmd)) continue;
|
250
|
1566 tem = Fkeymapp (cmd);
|
485
|
1567 if (!NILP (tem))
|
250
|
1568 {
|
|
1569 cmd = get_keymap (cmd);
|
|
1570 /* Ignore keymaps that are already added to maps. */
|
|
1571 tem = Frassq (cmd, maps);
|
485
|
1572 if (NILP (tem))
|
250
|
1573 {
|
|
1574 /* If the last key in thisseq is meta-prefix-char,
|
|
1575 turn it into a meta-ized keystroke. We know
|
|
1576 that the event we're about to append is an
|
1209
|
1577 ascii keystroke since we're processing a
|
|
1578 keymap table. */
|
250
|
1579 if (is_metized)
|
|
1580 {
|
2093
|
1581 int meta_bit = meta_modifier;
|
250
|
1582 tem = Fcopy_sequence (thisseq);
|
2093
|
1583
|
|
1584 Faset (tem, last, make_number (i | meta_bit));
|
250
|
1585
|
|
1586 /* This new sequence is the same length as
|
|
1587 thisseq, so stick it in the list right
|
|
1588 after this one. */
|
2093
|
1589 XCONS (tail)->cdr
|
|
1590 = Fcons (Fcons (tem, cmd), XCONS (tail)->cdr);
|
250
|
1591 }
|
|
1592 else
|
|
1593 {
|
|
1594 tem = append_key (thisseq, make_number (i));
|
|
1595 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil));
|
|
1596 }
|
|
1597 }
|
|
1598 }
|
|
1599 }
|
17788
|
1600 }
|
1209
|
1601 else if (CONSP (elt))
|
250
|
1602 {
|
6502
|
1603 register Lisp_Object cmd, tem, filter;
|
250
|
1604
|
6774
|
1605 cmd = get_keyelt (XCONS (elt)->cdr, 0);
|
250
|
1606 /* Ignore definitions that aren't keymaps themselves. */
|
|
1607 tem = Fkeymapp (cmd);
|
485
|
1608 if (!NILP (tem))
|
250
|
1609 {
|
|
1610 /* Ignore keymaps that have been seen already. */
|
|
1611 cmd = get_keymap (cmd);
|
|
1612 tem = Frassq (cmd, maps);
|
485
|
1613 if (NILP (tem))
|
250
|
1614 {
|
3952
|
1615 /* Let elt be the event defined by this map entry. */
|
250
|
1616 elt = XCONS (elt)->car;
|
|
1617
|
|
1618 /* If the last key in thisseq is meta-prefix-char, and
|
|
1619 this entry is a binding for an ascii keystroke,
|
|
1620 turn it into a meta-ized keystroke. */
|
9123
|
1621 if (is_metized && INTEGERP (elt))
|
250
|
1622 {
|
17264
|
1623 Lisp_Object element;
|
|
1624
|
|
1625 element = thisseq;
|
|
1626 tem = Fvconcat (1, &element);
|
18613
|
1627 XSETFASTINT (XVECTOR (tem)->contents[XINT (last)],
|
|
1628 XINT (elt) | meta_modifier);
|
250
|
1629
|
|
1630 /* This new sequence is the same length as
|
|
1631 thisseq, so stick it in the list right
|
|
1632 after this one. */
|
3952
|
1633 XCONS (tail)->cdr
|
|
1634 = Fcons (Fcons (tem, cmd), XCONS (tail)->cdr);
|
250
|
1635 }
|
|
1636 else
|
|
1637 nconc2 (tail,
|
|
1638 Fcons (Fcons (append_key (thisseq, elt), cmd),
|
|
1639 Qnil));
|
|
1640 }
|
|
1641 }
|
|
1642 }
|
|
1643 }
|
|
1644 }
|
|
1645
|
3952
|
1646 if (NILP (prefix))
|
|
1647 return maps;
|
|
1648
|
|
1649 /* Now find just the maps whose access prefixes start with PREFIX. */
|
|
1650
|
|
1651 good_maps = Qnil;
|
|
1652 for (; CONSP (maps); maps = XCONS (maps)->cdr)
|
|
1653 {
|
|
1654 Lisp_Object elt, thisseq;
|
|
1655 elt = XCONS (maps)->car;
|
|
1656 thisseq = XCONS (elt)->car;
|
|
1657 /* The access prefix must be at least as long as PREFIX,
|
|
1658 and the first elements must match those of PREFIX. */
|
|
1659 if (XINT (Flength (thisseq)) >= prefixlen)
|
|
1660 {
|
|
1661 int i;
|
|
1662 for (i = 0; i < prefixlen; i++)
|
|
1663 {
|
|
1664 Lisp_Object i1;
|
9312
|
1665 XSETFASTINT (i1, i);
|
3952
|
1666 if (!EQ (Faref (thisseq, i1), Faref (prefix, i1)))
|
|
1667 break;
|
|
1668 }
|
|
1669 if (i == prefixlen)
|
|
1670 good_maps = Fcons (elt, good_maps);
|
|
1671 }
|
|
1672 }
|
|
1673
|
|
1674 return Fnreverse (good_maps);
|
250
|
1675 }
|
|
1676
|
20319
|
1677 static void
|
17788
|
1678 accessible_keymaps_char_table (args, index, cmd)
|
|
1679 Lisp_Object args, index, cmd;
|
|
1680 {
|
|
1681 Lisp_Object tem;
|
|
1682 Lisp_Object maps, tail, thisseq;
|
|
1683
|
|
1684 if (NILP (cmd))
|
20319
|
1685 return;
|
17788
|
1686
|
|
1687 maps = XCONS (args)->car;
|
|
1688 tail = XCONS (XCONS (args)->cdr)->car;
|
|
1689 thisseq = XCONS (XCONS (args)->cdr)->cdr;
|
|
1690
|
|
1691 tem = Fkeymapp (cmd);
|
|
1692 if (!NILP (tem))
|
|
1693 {
|
|
1694 cmd = get_keymap (cmd);
|
|
1695 /* Ignore keymaps that are already added to maps. */
|
|
1696 tem = Frassq (cmd, maps);
|
|
1697 if (NILP (tem))
|
|
1698 {
|
|
1699 tem = append_key (thisseq, index);
|
|
1700 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil));
|
|
1701 }
|
|
1702 }
|
|
1703 }
|
|
1704
|
250
|
1705 Lisp_Object Qsingle_key_description, Qkey_description;
|
|
1706
|
7998
|
1707 /* This function cannot GC. */
|
|
1708
|
250
|
1709 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0,
|
|
1710 "Return a pretty description of key-sequence KEYS.\n\
|
|
1711 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\
|
|
1712 spaces are put between sequence elements, etc.")
|
|
1713 (keys)
|
|
1714 Lisp_Object keys;
|
|
1715 {
|
7809
|
1716 int len;
|
20624
|
1717 int i, i_byte;
|
7809
|
1718 Lisp_Object sep;
|
|
1719 Lisp_Object *args;
|
|
1720
|
8866
|
1721 if (STRINGP (keys))
|
2059
|
1722 {
|
|
1723 Lisp_Object vector;
|
|
1724 vector = Fmake_vector (Flength (keys), Qnil);
|
24572
|
1725 for (i = 0, i_byte = 0; i < XSTRING (keys)->size; )
|
2059
|
1726 {
|
20624
|
1727 int c;
|
20641
a48d24f8726c
(push_key_description): If C >= 128, always use octal representation.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1728 int i_before = i;
|
20624
|
1729
|
|
1730 if (STRING_MULTIBYTE (keys))
|
|
1731 FETCH_STRING_CHAR_ADVANCE (c, keys, i, i_byte);
|
|
1732 else
|
24572
|
1733 {
|
|
1734 c = XSTRING (keys)->data[i++];
|
|
1735 if (c & 0200)
|
|
1736 c ^= 0200 | meta_modifier;
|
|
1737 }
|
|
1738
|
|
1739 XSETFASTINT (XVECTOR (vector)->contents[i_before], c);
|
2059
|
1740 }
|
|
1741 keys = vector;
|
|
1742 }
|
23953
|
1743
|
|
1744 if (VECTORP (keys))
|
|
1745 {
|
|
1746 /* In effect, this computes
|
|
1747 (mapconcat 'single-key-description keys " ")
|
|
1748 but we shouldn't use mapconcat because it can do GC. */
|
|
1749
|
|
1750 len = XVECTOR (keys)->size;
|
|
1751 sep = build_string (" ");
|
|
1752 /* This has one extra element at the end that we don't pass to Fconcat. */
|
|
1753 args = (Lisp_Object *) alloca (len * 2 * sizeof (Lisp_Object));
|
|
1754
|
|
1755 for (i = 0; i < len; i++)
|
|
1756 {
|
|
1757 args[i * 2] = Fsingle_key_description (XVECTOR (keys)->contents[i]);
|
|
1758 args[i * 2 + 1] = sep;
|
|
1759 }
|
|
1760 }
|
|
1761 else if (CONSP (keys))
|
|
1762 {
|
|
1763 /* In effect, this computes
|
|
1764 (mapconcat 'single-key-description keys " ")
|
|
1765 but we shouldn't use mapconcat because it can do GC. */
|
|
1766
|
|
1767 len = XFASTINT (Flength (keys));
|
|
1768 sep = build_string (" ");
|
|
1769 /* This has one extra element at the end that we don't pass to Fconcat. */
|
|
1770 args = (Lisp_Object *) alloca (len * 2 * sizeof (Lisp_Object));
|
|
1771
|
|
1772 for (i = 0; i < len; i++)
|
|
1773 {
|
|
1774 args[i * 2] = Fsingle_key_description (XCONS (keys)->car);
|
|
1775 args[i * 2 + 1] = sep;
|
|
1776 keys = XCONS (keys)->cdr;
|
|
1777 }
|
|
1778 }
|
|
1779 else
|
8866
|
1780 keys = wrong_type_argument (Qarrayp, keys);
|
7809
|
1781
|
|
1782 return Fconcat (len * 2 - 1, args);
|
250
|
1783 }
|
|
1784
|
|
1785 char *
|
|
1786 push_key_description (c, p)
|
|
1787 register unsigned int c;
|
|
1788 register char *p;
|
|
1789 {
|
2343
|
1790 /* Clear all the meaningless bits above the meta bit. */
|
|
1791 c &= meta_modifier | ~ - meta_modifier;
|
|
1792
|
2059
|
1793 if (c & alt_modifier)
|
|
1794 {
|
|
1795 *p++ = 'A';
|
|
1796 *p++ = '-';
|
|
1797 c -= alt_modifier;
|
|
1798 }
|
|
1799 if (c & ctrl_modifier)
|
|
1800 {
|
|
1801 *p++ = 'C';
|
|
1802 *p++ = '-';
|
|
1803 c -= ctrl_modifier;
|
|
1804 }
|
|
1805 if (c & hyper_modifier)
|
|
1806 {
|
|
1807 *p++ = 'H';
|
|
1808 *p++ = '-';
|
|
1809 c -= hyper_modifier;
|
|
1810 }
|
|
1811 if (c & meta_modifier)
|
250
|
1812 {
|
|
1813 *p++ = 'M';
|
|
1814 *p++ = '-';
|
2059
|
1815 c -= meta_modifier;
|
|
1816 }
|
|
1817 if (c & shift_modifier)
|
|
1818 {
|
|
1819 *p++ = 'S';
|
|
1820 *p++ = '-';
|
|
1821 c -= shift_modifier;
|
|
1822 }
|
|
1823 if (c & super_modifier)
|
|
1824 {
|
|
1825 *p++ = 's';
|
|
1826 *p++ = '-';
|
|
1827 c -= super_modifier;
|
250
|
1828 }
|
|
1829 if (c < 040)
|
|
1830 {
|
|
1831 if (c == 033)
|
|
1832 {
|
|
1833 *p++ = 'E';
|
|
1834 *p++ = 'S';
|
|
1835 *p++ = 'C';
|
|
1836 }
|
2059
|
1837 else if (c == '\t')
|
250
|
1838 {
|
|
1839 *p++ = 'T';
|
|
1840 *p++ = 'A';
|
|
1841 *p++ = 'B';
|
|
1842 }
|
16875
|
1843 else if (c == Ctl ('M'))
|
250
|
1844 {
|
|
1845 *p++ = 'R';
|
|
1846 *p++ = 'E';
|
|
1847 *p++ = 'T';
|
|
1848 }
|
|
1849 else
|
|
1850 {
|
|
1851 *p++ = 'C';
|
|
1852 *p++ = '-';
|
|
1853 if (c > 0 && c <= Ctl ('Z'))
|
|
1854 *p++ = c + 0140;
|
|
1855 else
|
|
1856 *p++ = c + 0100;
|
|
1857 }
|
|
1858 }
|
|
1859 else if (c == 0177)
|
|
1860 {
|
|
1861 *p++ = 'D';
|
|
1862 *p++ = 'E';
|
|
1863 *p++ = 'L';
|
|
1864 }
|
|
1865 else if (c == ' ')
|
24394
|
1866 {
|
250
|
1867 *p++ = 'S';
|
|
1868 *p++ = 'P';
|
|
1869 *p++ = 'C';
|
|
1870 }
|
24396
|
1871 else if (c < 128
|
|
1872 || (NILP (current_buffer->enable_multibyte_characters)
|
|
1873 && SINGLE_BYTE_CHAR_P (c)))
|
17189
7c008ec99e97
(describe_vector): Adjusted for the change of CHAR_TABLE_ORDINARY_SLOTS.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1874 *p++ = c;
|
250
|
1875 else
|
2059
|
1876 {
|
24394
|
1877 if (! NILP (current_buffer->enable_multibyte_characters))
|
|
1878 c = unibyte_char_to_multibyte (c);
|
|
1879
|
|
1880 if (NILP (current_buffer->enable_multibyte_characters)
|
|
1881 || SINGLE_BYTE_CHAR_P (c)
|
|
1882 || ! char_valid_p (c, 0))
|
|
1883 {
|
|
1884 int bit_offset;
|
|
1885 *p++ = '\\';
|
|
1886 /* The biggest character code uses 19 bits. */
|
|
1887 for (bit_offset = 18; bit_offset >= 0; bit_offset -= 3)
|
|
1888 {
|
|
1889 if (c >= (1 << bit_offset))
|
|
1890 *p++ = ((c & (7 << bit_offset)) >> bit_offset) + '0';
|
|
1891 }
|
|
1892 }
|
|
1893 else
|
|
1894 {
|
|
1895 unsigned char work[4], *str;
|
|
1896 int i = CHAR_STRING (c, work, str);
|
|
1897 bcopy (str, p, i);
|
|
1898 p += i;
|
|
1899 }
|
2059
|
1900 }
|
250
|
1901
|
|
1902 return p;
|
|
1903 }
|
|
1904
|
7998
|
1905 /* This function cannot GC. */
|
|
1906
|
250
|
1907 DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0,
|
|
1908 "Return a pretty description of command character KEY.\n\
|
|
1909 Control characters turn into C-whatever, etc.")
|
|
1910 (key)
|
|
1911 Lisp_Object key;
|
|
1912 {
|
23953
|
1913 if (CONSP (key) && lucid_event_type_list_p (key))
|
|
1914 key = Fevent_convert_list (key);
|
|
1915
|
1315
|
1916 key = EVENT_HEAD (key);
|
517
|
1917
|
10008
|
1918 if (INTEGERP (key)) /* Normal character */
|
250
|
1919 {
|
23734
|
1920 unsigned int charset, c1, c2;
|
23776
|
1921 int without_bits = XINT (key) & ~((-1) << CHARACTERBITS);
|
|
1922
|
|
1923 if (SINGLE_BYTE_CHAR_P (without_bits))
|
23734
|
1924 charset = 0;
|
|
1925 else
|
23776
|
1926 SPLIT_NON_ASCII_CHAR (without_bits, charset, c1, c2);
|
23734
|
1927
|
|
1928 if (charset
|
24394
|
1929 && CHARSET_DEFINED_P (charset)
|
23734
|
1930 && ((c1 >= 0 && c1 < 32)
|
|
1931 || (c2 >= 0 && c2 < 32)))
|
|
1932 {
|
|
1933 /* Handle a generic character. */
|
|
1934 Lisp_Object name;
|
|
1935 name = CHARSET_TABLE_INFO (charset, CHARSET_LONG_NAME_IDX);
|
|
1936 CHECK_STRING (name, 0);
|
|
1937 return concat2 (build_string ("Character set "), name);
|
|
1938 }
|
|
1939 else
|
|
1940 {
|
|
1941 char tem[20];
|
|
1942
|
|
1943 *push_key_description (XUINT (key), tem) = 0;
|
|
1944 return build_string (tem);
|
|
1945 }
|
250
|
1946 }
|
10008
|
1947 else if (SYMBOLP (key)) /* Function key or event-symbol */
|
|
1948 return Fsymbol_name (key);
|
|
1949 else if (STRINGP (key)) /* Buffer names in the menubar. */
|
|
1950 return Fcopy_sequence (key);
|
|
1951 else
|
|
1952 error ("KEY must be an integer, cons, symbol, or string");
|
250
|
1953 }
|
|
1954
|
|
1955 char *
|
|
1956 push_text_char_description (c, p)
|
|
1957 register unsigned int c;
|
|
1958 register char *p;
|
|
1959 {
|
|
1960 if (c >= 0200)
|
|
1961 {
|
|
1962 *p++ = 'M';
|
|
1963 *p++ = '-';
|
|
1964 c -= 0200;
|
|
1965 }
|
|
1966 if (c < 040)
|
|
1967 {
|
|
1968 *p++ = '^';
|
|
1969 *p++ = c + 64; /* 'A' - 1 */
|
|
1970 }
|
|
1971 else if (c == 0177)
|
|
1972 {
|
|
1973 *p++ = '^';
|
|
1974 *p++ = '?';
|
|
1975 }
|
|
1976 else
|
|
1977 *p++ = c;
|
|
1978 return p;
|
|
1979 }
|
|
1980
|
7998
|
1981 /* This function cannot GC. */
|
|
1982
|
250
|
1983 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0,
|
14080
|
1984 "Return a pretty description of file-character CHARACTER.\n\
|
250
|
1985 Control characters turn into \"^char\", etc.")
|
14080
|
1986 (character)
|
|
1987 Lisp_Object character;
|
250
|
1988 {
|
|
1989 char tem[6];
|
|
1990
|
14080
|
1991 CHECK_NUMBER (character, 0);
|
|
1992
|
17036
|
1993 if (!SINGLE_BYTE_CHAR_P (XFASTINT (character)))
|
|
1994 {
|
20319
|
1995 unsigned char *str;
|
17036
|
1996 int len = non_ascii_char_to_string (XFASTINT (character), tem, &str);
|
|
1997
|
20624
|
1998 return make_multibyte_string (str, 1, len);
|
17036
|
1999 }
|
|
2000
|
14080
|
2001 *push_text_char_description (XINT (character) & 0377, tem) = 0;
|
250
|
2002
|
|
2003 return build_string (tem);
|
|
2004 }
|
2727
|
2005
|
|
2006 /* Return non-zero if SEQ contains only ASCII characters, perhaps with
|
|
2007 a meta bit. */
|
|
2008 static int
|
|
2009 ascii_sequence_p (seq)
|
|
2010 Lisp_Object seq;
|
|
2011 {
|
9312
|
2012 int i;
|
2727
|
2013 int len = XINT (Flength (seq));
|
6008
|
2014
|
9312
|
2015 for (i = 0; i < len; i++)
|
2727
|
2016 {
|
9312
|
2017 Lisp_Object ii, elt;
|
6008
|
2018
|
9312
|
2019 XSETFASTINT (ii, i);
|
|
2020 elt = Faref (seq, ii);
|
2727
|
2021
|
9123
|
2022 if (!INTEGERP (elt)
|
2727
|
2023 || (XUINT (elt) & ~CHAR_META) >= 0x80)
|
|
2024 return 0;
|
|
2025 }
|
|
2026
|
|
2027 return 1;
|
|
2028 }
|
|
2029
|
250
|
2030
|
465
|
2031 /* where-is - finding a command in a set of keymaps. */
|
|
2032
|
17788
|
2033 static Lisp_Object where_is_internal_1 ();
|
20319
|
2034 static void where_is_internal_2 ();
|
17788
|
2035
|
7998
|
2036 /* This function can GC if Flookup_key autoloads any keymaps. */
|
|
2037
|
5785
|
2038 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 4, 0,
|
|
2039 "Return list of keys that invoke DEFINITION.\n\
|
|
2040 If KEYMAP is non-nil, search only KEYMAP and the global keymap.\n\
|
|
2041 If KEYMAP is nil, search all the currently active keymaps.\n\
|
250
|
2042 \n\
|
5785
|
2043 If optional 3rd arg FIRSTONLY is non-nil, return the first key sequence found,\n\
|
5246
|
2044 rather than a list of all possible key sequences.\n\
|
10810
|
2045 If FIRSTONLY is the symbol `non-ascii', return the first binding found,\n\
|
|
2046 no matter what it is.\n\
|
11089
|
2047 If FIRSTONLY has another non-nil value, prefer sequences of ASCII characters,\n\
|
10810
|
2048 and entirely reject menu bindings.\n\
|
250
|
2049 \n\
|
5785
|
2050 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections\n\
|
250
|
2051 to other keymaps or slots. This makes it possible to search for an\n\
|
|
2052 indirect definition itself.")
|
5785
|
2053 (definition, keymap, firstonly, noindirect)
|
|
2054 Lisp_Object definition, keymap;
|
250
|
2055 Lisp_Object firstonly, noindirect;
|
|
2056 {
|
7998
|
2057 Lisp_Object maps;
|
17788
|
2058 Lisp_Object found, sequences;
|
20070
|
2059 Lisp_Object keymap1;
|
5785
|
2060 int keymap_specified = !NILP (keymap);
|
7998
|
2061 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
10810
|
2062 /* 1 means ignore all menu bindings entirely. */
|
|
2063 int nomenus = !NILP (firstonly) && !EQ (firstonly, Qnon_ascii);
|
250
|
2064
|
20070
|
2065 /* Find keymaps accessible from `keymap' or the current
|
|
2066 context. But don't muck with the value of `keymap',
|
|
2067 because `where_is_internal_1' uses it to check for
|
|
2068 shadowed bindings. */
|
|
2069 keymap1 = keymap;
|
5785
|
2070 if (! keymap_specified)
|
|
2071 {
|
|
2072 #ifdef USE_TEXT_PROPERTIES
|
20070
|
2073 keymap1 = get_local_map (PT, current_buffer);
|
5785
|
2074 #else
|
20070
|
2075 keymap1 = current_buffer->keymap;
|
5785
|
2076 #endif
|
|
2077 }
|
20070
|
2078
|
|
2079 if (!NILP (keymap1))
|
|
2080 maps = nconc2 (Faccessible_keymaps (get_keymap (keymap1), Qnil),
|
5785
|
2081 Faccessible_keymaps (get_keymap (current_global_map),
|
|
2082 Qnil));
|
250
|
2083 else
|
5785
|
2084 maps = Faccessible_keymaps (get_keymap (current_global_map), Qnil);
|
|
2085
|
|
2086 /* Put the minor mode keymaps on the front. */
|
|
2087 if (! keymap_specified)
|
|
2088 {
|
|
2089 Lisp_Object minors;
|
|
2090 minors = Fnreverse (Fcurrent_minor_mode_maps ());
|
|
2091 while (!NILP (minors))
|
|
2092 {
|
|
2093 maps = nconc2 (Faccessible_keymaps (get_keymap (XCONS (minors)->car),
|
|
2094 Qnil),
|
|
2095 maps);
|
|
2096 minors = XCONS (minors)->cdr;
|
|
2097 }
|
|
2098 }
|
250
|
2099
|
17788
|
2100 GCPRO5 (definition, keymap, maps, found, sequences);
|
250
|
2101 found = Qnil;
|
17788
|
2102 sequences = Qnil;
|
250
|
2103
|
485
|
2104 for (; !NILP (maps); maps = Fcdr (maps))
|
250
|
2105 {
|
6502
|
2106 /* Key sequence to reach map, and the map that it reaches */
|
|
2107 register Lisp_Object this, map;
|
1209
|
2108
|
250
|
2109 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into
|
|
2110 [M-CHAR] sequences, check if last character of the sequence
|
|
2111 is the meta-prefix char. */
|
6502
|
2112 Lisp_Object last;
|
|
2113 int last_is_meta;
|
|
2114
|
|
2115 this = Fcar (Fcar (maps));
|
|
2116 map = Fcdr (Fcar (maps));
|
|
2117 last = make_number (XINT (Flength (this)) - 1);
|
|
2118 last_is_meta = (XINT (last) >= 0
|
|
2119 && EQ (Faref (this, last), meta_prefix_char));
|
250
|
2120
|
1236
|
2121 QUIT;
|
|
2122
|
1209
|
2123 while (CONSP (map))
|
|
2124 {
|
|
2125 /* Because the code we want to run on each binding is rather
|
|
2126 large, we don't want to have two separate loop bodies for
|
|
2127 sparse keymap bindings and tables; we want to iterate one
|
|
2128 loop body over both keymap and vector bindings.
|
250
|
2129
|
1209
|
2130 For this reason, if Fcar (map) is a vector, we don't
|
|
2131 advance map to the next element until i indicates that we
|
|
2132 have finished off the vector. */
|
7998
|
2133 Lisp_Object elt, key, binding;
|
6502
|
2134 elt = XCONS (map)->car;
|
17788
|
2135 map = XCONS (map)->cdr;
|
|
2136
|
|
2137 sequences = Qnil;
|
250
|
2138
|
1236
|
2139 QUIT;
|
|
2140
|
1209
|
2141 /* Set key and binding to the current key and binding, and
|
|
2142 advance map and i to the next binding. */
|
9123
|
2143 if (VECTORP (elt))
|
250
|
2144 {
|
17788
|
2145 Lisp_Object sequence;
|
|
2146 int i;
|
250
|
2147 /* In a vector, look at each element. */
|
17788
|
2148 for (i = 0; i < XVECTOR (elt)->size; i++)
|
1209
|
2149 {
|
17788
|
2150 binding = XVECTOR (elt)->contents[i];
|
|
2151 XSETFASTINT (key, i);
|
|
2152 sequence = where_is_internal_1 (binding, key, definition,
|
|
2153 noindirect, keymap, this,
|
|
2154 last, nomenus, last_is_meta);
|
|
2155 if (!NILP (sequence))
|
|
2156 sequences = Fcons (sequence, sequences);
|
1209
|
2157 }
|
250
|
2158 }
|
17788
|
2159 else if (CHAR_TABLE_P (elt))
|
|
2160 {
|
20076
|
2161 Lisp_Object indices[3];
|
17788
|
2162 Lisp_Object args;
|
20076
|
2163
|
17788
|
2164 args = Fcons (Fcons (Fcons (definition, noindirect),
|
|
2165 Fcons (keymap, Qnil)),
|
|
2166 Fcons (Fcons (this, last),
|
|
2167 Fcons (make_number (nomenus),
|
|
2168 make_number (last_is_meta))));
|
|
2169
|
|
2170 map_char_table (where_is_internal_2, Qnil, elt, args,
|
|
2171 0, indices);
|
|
2172 sequences = XCONS (XCONS (XCONS (args)->car)->cdr)->cdr;
|
|
2173 }
|
1209
|
2174 else if (CONSP (elt))
|
250
|
2175 {
|
17788
|
2176 Lisp_Object sequence;
|
|
2177
|
|
2178 key = XCONS (elt)->car;
|
|
2179 binding = XCONS (elt)->cdr;
|
|
2180
|
|
2181 sequence = where_is_internal_1 (binding, key, definition,
|
|
2182 noindirect, keymap, this,
|
|
2183 last, nomenus, last_is_meta);
|
|
2184 if (!NILP (sequence))
|
|
2185 sequences = Fcons (sequence, sequences);
|
250
|
2186 }
|
17788
|
2187
|
|
2188
|
|
2189 for (; ! NILP (sequences); sequences = XCONS (sequences)->cdr)
|
250
|
2190 {
|
17788
|
2191 Lisp_Object sequence;
|
|
2192
|
|
2193 sequence = XCONS (sequences)->car;
|
|
2194
|
|
2195 /* It is a true unshadowed match. Record it, unless it's already
|
|
2196 been seen (as could happen when inheriting keymaps). */
|
|
2197 if (NILP (Fmember (sequence, found)))
|
|
2198 found = Fcons (sequence, found);
|
|
2199
|
|
2200 /* If firstonly is Qnon_ascii, then we can return the first
|
|
2201 binding we find. If firstonly is not Qnon_ascii but not
|
|
2202 nil, then we should return the first ascii-only binding
|
|
2203 we find. */
|
|
2204 if (EQ (firstonly, Qnon_ascii))
|
|
2205 RETURN_UNGCPRO (sequence);
|
|
2206 else if (! NILP (firstonly) && ascii_sequence_p (sequence))
|
|
2207 RETURN_UNGCPRO (sequence);
|
250
|
2208 }
|
|
2209 }
|
|
2210 }
|
2727
|
2211
|
7998
|
2212 UNGCPRO;
|
|
2213
|
2727
|
2214 found = Fnreverse (found);
|
|
2215
|
|
2216 /* firstonly may have been t, but we may have gone all the way through
|
|
2217 the keymaps without finding an all-ASCII key sequence. So just
|
|
2218 return the best we could find. */
|
|
2219 if (! NILP (firstonly))
|
|
2220 return Fcar (found);
|
|
2221
|
|
2222 return found;
|
250
|
2223 }
|
17788
|
2224
|
|
2225 /* This is the function that Fwhere_is_internal calls using map_char_table.
|
|
2226 ARGS has the form
|
|
2227 (((DEFINITION . NOINDIRECT) . (KEYMAP . RESULT))
|
|
2228 .
|
|
2229 ((THIS . LAST) . (NOMENUS . LAST_IS_META)))
|
|
2230 Since map_char_table doesn't really use the return value from this function,
|
|
2231 we the result append to RESULT, the slot in ARGS. */
|
|
2232
|
20319
|
2233 static void
|
17788
|
2234 where_is_internal_2 (args, key, binding)
|
|
2235 Lisp_Object args, key, binding;
|
|
2236 {
|
|
2237 Lisp_Object definition, noindirect, keymap, this, last;
|
|
2238 Lisp_Object result, sequence;
|
|
2239 int nomenus, last_is_meta;
|
|
2240
|
|
2241 result = XCONS (XCONS (XCONS (args)->car)->cdr)->cdr;
|
|
2242 definition = XCONS (XCONS (XCONS (args)->car)->car)->car;
|
|
2243 noindirect = XCONS (XCONS (XCONS (args)->car)->car)->cdr;
|
|
2244 keymap = XCONS (XCONS (XCONS (args)->car)->cdr)->car;
|
|
2245 this = XCONS (XCONS (XCONS (args)->cdr)->car)->car;
|
|
2246 last = XCONS (XCONS (XCONS (args)->cdr)->car)->cdr;
|
|
2247 nomenus = XFASTINT (XCONS (XCONS (XCONS (args)->cdr)->cdr)->car);
|
|
2248 last_is_meta = XFASTINT (XCONS (XCONS (XCONS (args)->cdr)->cdr)->cdr);
|
|
2249
|
|
2250 sequence = where_is_internal_1 (binding, key, definition, noindirect, keymap,
|
|
2251 this, last, nomenus, last_is_meta);
|
|
2252
|
|
2253 if (!NILP (sequence))
|
|
2254 XCONS (XCONS (XCONS (args)->car)->cdr)->cdr
|
|
2255 = Fcons (sequence, result);
|
|
2256 }
|
|
2257
|
|
2258 static Lisp_Object
|
|
2259 where_is_internal_1 (binding, key, definition, noindirect, keymap, this, last,
|
|
2260 nomenus, last_is_meta)
|
|
2261 Lisp_Object binding, key, definition, noindirect, keymap, this, last;
|
|
2262 int nomenus, last_is_meta;
|
|
2263 {
|
|
2264 Lisp_Object sequence;
|
|
2265 int keymap_specified = !NILP (keymap);
|
|
2266
|
|
2267 /* Search through indirections unless that's not wanted. */
|
|
2268 if (NILP (noindirect))
|
|
2269 {
|
|
2270 if (nomenus)
|
|
2271 {
|
|
2272 while (1)
|
|
2273 {
|
|
2274 Lisp_Object map, tem;
|
|
2275 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
|
|
2276 map = get_keymap_1 (Fcar_safe (definition), 0, 0);
|
|
2277 tem = Fkeymapp (map);
|
|
2278 if (!NILP (tem))
|
|
2279 definition = access_keymap (map, Fcdr (definition), 0, 0);
|
|
2280 else
|
|
2281 break;
|
|
2282 }
|
21241
|
2283 /* If the contents are (menu-item ...) or (STRING ...), reject. */
|
17788
|
2284 if (CONSP (definition)
|
21241
|
2285 && (EQ (XCONS (definition)->car,Qmenu_item)
|
|
2286 || STRINGP (XCONS (definition)->car)))
|
17788
|
2287 return Qnil;
|
|
2288 }
|
|
2289 else
|
|
2290 binding = get_keyelt (binding, 0);
|
|
2291 }
|
|
2292
|
|
2293 /* End this iteration if this element does not match
|
|
2294 the target. */
|
|
2295
|
|
2296 if (CONSP (definition))
|
|
2297 {
|
|
2298 Lisp_Object tem;
|
|
2299 tem = Fequal (binding, definition);
|
|
2300 if (NILP (tem))
|
|
2301 return Qnil;
|
|
2302 }
|
|
2303 else
|
|
2304 if (!EQ (binding, definition))
|
|
2305 return Qnil;
|
|
2306
|
|
2307 /* We have found a match.
|
|
2308 Construct the key sequence where we found it. */
|
|
2309 if (INTEGERP (key) && last_is_meta)
|
|
2310 {
|
|
2311 sequence = Fcopy_sequence (this);
|
|
2312 Faset (sequence, last, make_number (XINT (key) | meta_modifier));
|
|
2313 }
|
|
2314 else
|
|
2315 sequence = append_key (this, key);
|
|
2316
|
|
2317 /* Verify that this key binding is not shadowed by another
|
|
2318 binding for the same key, before we say it exists.
|
|
2319
|
|
2320 Mechanism: look for local definition of this key and if
|
|
2321 it is defined and does not match what we found then
|
|
2322 ignore this key.
|
|
2323
|
|
2324 Either nil or number as value from Flookup_key
|
|
2325 means undefined. */
|
|
2326 if (keymap_specified)
|
|
2327 {
|
|
2328 binding = Flookup_key (keymap, sequence, Qnil);
|
|
2329 if (!NILP (binding) && !INTEGERP (binding))
|
|
2330 {
|
|
2331 if (CONSP (definition))
|
|
2332 {
|
|
2333 Lisp_Object tem;
|
|
2334 tem = Fequal (binding, definition);
|
|
2335 if (NILP (tem))
|
|
2336 return Qnil;
|
|
2337 }
|
|
2338 else
|
|
2339 if (!EQ (binding, definition))
|
|
2340 return Qnil;
|
|
2341 }
|
|
2342 }
|
|
2343 else
|
|
2344 {
|
|
2345 binding = Fkey_binding (sequence, Qnil);
|
|
2346 if (!EQ (binding, definition))
|
|
2347 return Qnil;
|
|
2348 }
|
|
2349
|
|
2350 return sequence;
|
|
2351 }
|
250
|
2352
|
465
|
2353 /* describe-bindings - summarizing all the bindings in a set of keymaps. */
|
|
2354
|
20850
|
2355 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, Sdescribe_bindings_internal, 0, 2, "",
|
250
|
2356 "Show a list of all defined keys, and their definitions.\n\
|
20850
|
2357 We put that list in a buffer, and display the buffer.\n\
|
|
2358 \n\
|
|
2359 The optional argument MENUS, if non-nil, says to mention menu bindings.\n\
|
|
2360 \(Ordinarily these are omitted from the output.)\n\
|
|
2361 The optional argument PREFIX, if non-nil, should be a key sequence;\n\
|
3952
|
2362 then we display only bindings that start with that prefix.")
|
20850
|
2363 (menus, prefix)
|
|
2364 Lisp_Object menus, prefix;
|
250
|
2365 {
|
|
2366 register Lisp_Object thisbuf;
|
9273
129621997564
(synkey, Fdescribe_bindings, describe_command): Use new accessor macros
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2367 XSETBUFFER (thisbuf, current_buffer);
|
250
|
2368 internal_with_output_to_temp_buffer ("*Help*",
|
|
2369 describe_buffer_bindings,
|
20850
|
2370 list3 (thisbuf, prefix, menus));
|
250
|
2371 return Qnil;
|
|
2372 }
|
|
2373
|
20850
|
2374 /* ARG is (BUFFER PREFIX MENU-FLAG). */
|
3952
|
2375
|
250
|
2376 static Lisp_Object
|
3952
|
2377 describe_buffer_bindings (arg)
|
|
2378 Lisp_Object arg;
|
250
|
2379 {
|
3952
|
2380 Lisp_Object descbuf, prefix, shadow;
|
20850
|
2381 int nomenu;
|
7186
|
2382 register Lisp_Object start1;
|
|
2383 struct gcpro gcpro1;
|
250
|
2384
|
1120
|
2385 char *alternate_heading
|
|
2386 = "\
|
20850
|
2387 Keyboard translations:\n\n\
|
|
2388 You type Translation\n\
|
|
2389 -------- -----------\n";
|
250
|
2390
|
3952
|
2391 descbuf = XCONS (arg)->car;
|
20850
|
2392 arg = XCONS (arg)->cdr;
|
|
2393 prefix = XCONS (arg)->car;
|
|
2394 arg = XCONS (arg)->cdr;
|
|
2395 nomenu = NILP (XCONS (arg)->car);
|
|
2396
|
4575
|
2397 shadow = Qnil;
|
7186
|
2398 GCPRO1 (shadow);
|
3952
|
2399
|
250
|
2400 Fset_buffer (Vstandard_output);
|
|
2401
|
1120
|
2402 /* Report on alternates for keys. */
|
12710
|
2403 if (STRINGP (Vkeyboard_translate_table) && !NILP (prefix))
|
1120
|
2404 {
|
|
2405 int c;
|
|
2406 unsigned char *translate = XSTRING (Vkeyboard_translate_table)->data;
|
|
2407 int translate_len = XSTRING (Vkeyboard_translate_table)->size;
|
|
2408
|
|
2409 for (c = 0; c < translate_len; c++)
|
|
2410 if (translate[c] != c)
|
|
2411 {
|
|
2412 char buf[20];
|
|
2413 char *bufend;
|
|
2414
|
|
2415 if (alternate_heading)
|
|
2416 {
|
|
2417 insert_string (alternate_heading);
|
|
2418 alternate_heading = 0;
|
|
2419 }
|
|
2420
|
|
2421 bufend = push_key_description (translate[c], buf);
|
|
2422 insert (buf, bufend - buf);
|
|
2423 Findent_to (make_number (16), make_number (1));
|
|
2424 bufend = push_key_description (c, buf);
|
|
2425 insert (buf, bufend - buf);
|
|
2426
|
|
2427 insert ("\n", 1);
|
|
2428 }
|
|
2429
|
|
2430 insert ("\n", 1);
|
|
2431 }
|
|
2432
|
12710
|
2433 if (!NILP (Vkey_translation_map))
|
|
2434 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix,
|
20850
|
2435 "Key translations", nomenu, 1, 0);
|
12710
|
2436
|
465
|
2437 {
|
|
2438 int i, nmaps;
|
|
2439 Lisp_Object *modes, *maps;
|
|
2440
|
1120
|
2441 /* Temporarily switch to descbuf, so that we can get that buffer's
|
|
2442 minor modes correctly. */
|
|
2443 Fset_buffer (descbuf);
|
12710
|
2444
|
12262
|
2445 if (!NILP (current_kboard->Voverriding_terminal_local_map)
|
|
2446 || !NILP (Voverriding_local_map))
|
5613
|
2447 nmaps = 0;
|
|
2448 else
|
|
2449 nmaps = current_minor_maps (&modes, &maps);
|
1120
|
2450 Fset_buffer (Vstandard_output);
|
|
2451
|
3952
|
2452 /* Print the minor mode maps. */
|
465
|
2453 for (i = 0; i < nmaps; i++)
|
|
2454 {
|
6695
|
2455 /* The title for a minor mode keymap
|
4023
|
2456 is constructed at run time.
|
|
2457 We let describe_map_tree do the actual insertion
|
|
2458 because it takes care of other features when doing so. */
|
6695
|
2459 char *title, *p;
|
4023
|
2460
|
9123
|
2461 if (!SYMBOLP (modes[i]))
|
7186
|
2462 abort();
|
|
2463
|
|
2464 p = title = (char *) alloca (40 + XSYMBOL (modes[i])->name->size);
|
|
2465 *p++ = '`';
|
|
2466 bcopy (XSYMBOL (modes[i])->name->data, p,
|
|
2467 XSYMBOL (modes[i])->name->size);
|
|
2468 p += XSYMBOL (modes[i])->name->size;
|
|
2469 *p++ = '\'';
|
6695
|
2470 bcopy (" Minor Mode Bindings", p, sizeof (" Minor Mode Bindings") - 1);
|
|
2471 p += sizeof (" Minor Mode Bindings") - 1;
|
4023
|
2472 *p = 0;
|
|
2473
|
20850
|
2474 describe_map_tree (maps[i], 1, shadow, prefix, title, nomenu, 0, 0);
|
3952
|
2475 shadow = Fcons (maps[i], shadow);
|
465
|
2476 }
|
|
2477 }
|
|
2478
|
3952
|
2479 /* Print the (major mode) local map. */
|
12262
|
2480 if (!NILP (current_kboard->Voverriding_terminal_local_map))
|
|
2481 start1 = current_kboard->Voverriding_terminal_local_map;
|
|
2482 else if (!NILP (Voverriding_local_map))
|
5613
|
2483 start1 = Voverriding_local_map;
|
|
2484 else
|
|
2485 start1 = XBUFFER (descbuf)->keymap;
|
|
2486
|
485
|
2487 if (!NILP (start1))
|
250
|
2488 {
|
16465
|
2489 describe_map_tree (start1, 1, shadow, prefix,
|
20850
|
2490 "Major Mode Bindings", nomenu, 0, 0);
|
3952
|
2491 shadow = Fcons (start1, shadow);
|
250
|
2492 }
|
|
2493
|
16465
|
2494 describe_map_tree (current_global_map, 1, shadow, prefix,
|
20850
|
2495 "Global Bindings", nomenu, 0, 1);
|
12710
|
2496
|
|
2497 /* Print the function-key-map translations under this prefix. */
|
|
2498 if (!NILP (Vfunction_key_map))
|
|
2499 describe_map_tree (Vfunction_key_map, 0, Qnil, prefix,
|
20850
|
2500 "Function key map translations", nomenu, 1, 0);
|
250
|
2501
|
9862
|
2502 call0 (intern ("help-mode"));
|
250
|
2503 Fset_buffer (descbuf);
|
7186
|
2504 UNGCPRO;
|
250
|
2505 return Qnil;
|
|
2506 }
|
|
2507
|
13947
|
2508 /* Insert a description of the key bindings in STARTMAP,
|
250
|
2509 followed by those of all maps reachable through STARTMAP.
|
|
2510 If PARTIAL is nonzero, omit certain "uninteresting" commands
|
|
2511 (such as `undefined').
|
3952
|
2512 If SHADOW is non-nil, it is a list of maps;
|
|
2513 don't mention keys which would be shadowed by any of them.
|
|
2514 PREFIX, if non-nil, says mention only keys that start with PREFIX.
|
4023
|
2515 TITLE, if not 0, is a string to insert at the beginning.
|
5551
|
2516 TITLE should not end with a colon or a newline; we supply that.
|
12710
|
2517 If NOMENU is not 0, then omit menu-bar commands.
|
|
2518
|
|
2519 If TRANSL is nonzero, the definitions are actually key translations
|
13245
|
2520 so print strings and vectors differently.
|
|
2521
|
|
2522 If ALWAYS_TITLE is nonzero, print the title even if there are no maps
|
|
2523 to look through. */
|
250
|
2524
|
|
2525 void
|
13245
|
2526 describe_map_tree (startmap, partial, shadow, prefix, title, nomenu, transl,
|
|
2527 always_title)
|
3952
|
2528 Lisp_Object startmap, shadow, prefix;
|
250
|
2529 int partial;
|
3952
|
2530 char *title;
|
5551
|
2531 int nomenu;
|
12710
|
2532 int transl;
|
13245
|
2533 int always_title;
|
250
|
2534 {
|
20883
|
2535 Lisp_Object maps, orig_maps, seen, sub_shadows;
|
7184
|
2536 struct gcpro gcpro1, gcpro2, gcpro3;
|
4023
|
2537 int something = 0;
|
3952
|
2538 char *key_heading
|
|
2539 = "\
|
|
2540 key binding\n\
|
|
2541 --- -------\n";
|
250
|
2542
|
20883
|
2543 orig_maps = maps = Faccessible_keymaps (startmap, prefix);
|
6976
|
2544 seen = Qnil;
|
7184
|
2545 sub_shadows = Qnil;
|
|
2546 GCPRO3 (maps, seen, sub_shadows);
|
250
|
2547
|
5551
|
2548 if (nomenu)
|
|
2549 {
|
|
2550 Lisp_Object list;
|
|
2551
|
|
2552 /* Delete from MAPS each element that is for the menu bar. */
|
|
2553 for (list = maps; !NILP (list); list = XCONS (list)->cdr)
|
|
2554 {
|
|
2555 Lisp_Object elt, prefix, tem;
|
|
2556
|
|
2557 elt = Fcar (list);
|
|
2558 prefix = Fcar (elt);
|
|
2559 if (XVECTOR (prefix)->size >= 1)
|
|
2560 {
|
|
2561 tem = Faref (prefix, make_number (0));
|
|
2562 if (EQ (tem, Qmenu_bar))
|
|
2563 maps = Fdelq (elt, maps);
|
|
2564 }
|
|
2565 }
|
|
2566 }
|
|
2567
|
13245
|
2568 if (!NILP (maps) || always_title)
|
3952
|
2569 {
|
|
2570 if (title)
|
4023
|
2571 {
|
|
2572 insert_string (title);
|
|
2573 if (!NILP (prefix))
|
|
2574 {
|
|
2575 insert_string (" Starting With ");
|
|
2576 insert1 (Fkey_description (prefix));
|
|
2577 }
|
|
2578 insert_string (":\n");
|
|
2579 }
|
3952
|
2580 insert_string (key_heading);
|
4023
|
2581 something = 1;
|
3952
|
2582 }
|
|
2583
|
485
|
2584 for (; !NILP (maps); maps = Fcdr (maps))
|
250
|
2585 {
|
7184
|
2586 register Lisp_Object elt, prefix, tail;
|
3952
|
2587
|
250
|
2588 elt = Fcar (maps);
|
3952
|
2589 prefix = Fcar (elt);
|
250
|
2590
|
3952
|
2591 sub_shadows = Qnil;
|
|
2592
|
|
2593 for (tail = shadow; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
2594 {
|
|
2595 Lisp_Object shmap;
|
|
2596
|
|
2597 shmap = XCONS (tail)->car;
|
250
|
2598
|
3952
|
2599 /* If the sequence by which we reach this keymap is zero-length,
|
|
2600 then the shadow map for this keymap is just SHADOW. */
|
9123
|
2601 if ((STRINGP (prefix) && XSTRING (prefix)->size == 0)
|
|
2602 || (VECTORP (prefix) && XVECTOR (prefix)->size == 0))
|
3952
|
2603 ;
|
|
2604 /* If the sequence by which we reach this keymap actually has
|
|
2605 some elements, then the sequence's definition in SHADOW is
|
|
2606 what we should use. */
|
|
2607 else
|
|
2608 {
|
6859
|
2609 shmap = Flookup_key (shmap, Fcar (elt), Qt);
|
9123
|
2610 if (INTEGERP (shmap))
|
3952
|
2611 shmap = Qnil;
|
|
2612 }
|
250
|
2613
|
3952
|
2614 /* If shmap is not nil and not a keymap,
|
|
2615 it completely shadows this map, so don't
|
|
2616 describe this map at all. */
|
|
2617 if (!NILP (shmap) && NILP (Fkeymapp (shmap)))
|
|
2618 goto skip;
|
|
2619
|
|
2620 if (!NILP (shmap))
|
|
2621 sub_shadows = Fcons (shmap, sub_shadows);
|
250
|
2622 }
|
|
2623
|
20883
|
2624 /* Maps we have already listed in this loop shadow this map. */
|
|
2625 for (tail = orig_maps; ! EQ (tail, maps); tail = XCDR (tail))
|
|
2626 {
|
|
2627 Lisp_Object tem;
|
|
2628 tem = Fequal (Fcar (XCAR (tail)), prefix);
|
|
2629 if (! NILP (tem))
|
|
2630 sub_shadows = Fcons (XCDR (XCAR (tail)), sub_shadows);
|
|
2631 }
|
|
2632
|
|
2633 describe_map (Fcdr (elt), prefix,
|
12710
|
2634 transl ? describe_translation : describe_command,
|
14129
|
2635 partial, sub_shadows, &seen, nomenu);
|
3952
|
2636
|
|
2637 skip: ;
|
250
|
2638 }
|
|
2639
|
4023
|
2640 if (something)
|
|
2641 insert_string ("\n");
|
|
2642
|
250
|
2643 UNGCPRO;
|
|
2644 }
|
|
2645
|
14304
|
2646 static int previous_description_column;
|
|
2647
|
250
|
2648 static void
|
|
2649 describe_command (definition)
|
|
2650 Lisp_Object definition;
|
|
2651 {
|
|
2652 register Lisp_Object tem1;
|
14304
|
2653 int column = current_column ();
|
|
2654 int description_column;
|
|
2655
|
|
2656 /* If column 16 is no good, go to col 32;
|
|
2657 but don't push beyond that--go to next line instead. */
|
|
2658 if (column > 30)
|
|
2659 {
|
|
2660 insert_char ('\n');
|
|
2661 description_column = 32;
|
|
2662 }
|
|
2663 else if (column > 14 || (column > 10 && previous_description_column == 32))
|
|
2664 description_column = 32;
|
|
2665 else
|
|
2666 description_column = 16;
|
|
2667
|
|
2668 Findent_to (make_number (description_column), make_number (1));
|
|
2669 previous_description_column = description_column;
|
250
|
2670
|
9123
|
2671 if (SYMBOLP (definition))
|
250
|
2672 {
|
9273
129621997564
(synkey, Fdescribe_bindings, describe_command): Use new accessor macros
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2673 XSETSTRING (tem1, XSYMBOL (definition)->name);
|
250
|
2674 insert1 (tem1);
|
21539
|
2675 insert_string ("\n");
|
250
|
2676 }
|
12710
|
2677 else if (STRINGP (definition) || VECTORP (definition))
|
5367
|
2678 insert_string ("Keyboard Macro\n");
|
250
|
2679 else
|
|
2680 {
|
|
2681 tem1 = Fkeymapp (definition);
|
485
|
2682 if (!NILP (tem1))
|
250
|
2683 insert_string ("Prefix Command\n");
|
|
2684 else
|
|
2685 insert_string ("??\n");
|
|
2686 }
|
|
2687 }
|
|
2688
|
12710
|
2689 static void
|
|
2690 describe_translation (definition)
|
|
2691 Lisp_Object definition;
|
|
2692 {
|
|
2693 register Lisp_Object tem1;
|
|
2694
|
|
2695 Findent_to (make_number (16), make_number (1));
|
|
2696
|
|
2697 if (SYMBOLP (definition))
|
|
2698 {
|
|
2699 XSETSTRING (tem1, XSYMBOL (definition)->name);
|
|
2700 insert1 (tem1);
|
|
2701 insert_string ("\n");
|
|
2702 }
|
|
2703 else if (STRINGP (definition) || VECTORP (definition))
|
13343
|
2704 {
|
|
2705 insert1 (Fkey_description (definition));
|
|
2706 insert_string ("\n");
|
|
2707 }
|
12710
|
2708 else
|
|
2709 {
|
|
2710 tem1 = Fkeymapp (definition);
|
|
2711 if (!NILP (tem1))
|
|
2712 insert_string ("Prefix Command\n");
|
|
2713 else
|
|
2714 insert_string ("??\n");
|
|
2715 }
|
|
2716 }
|
|
2717
|
3952
|
2718 /* Like Flookup_key, but uses a list of keymaps SHADOW instead of a single map.
|
|
2719 Returns the first non-nil binding found in any of those maps. */
|
|
2720
|
|
2721 static Lisp_Object
|
|
2722 shadow_lookup (shadow, key, flag)
|
|
2723 Lisp_Object shadow, key, flag;
|
|
2724 {
|
|
2725 Lisp_Object tail, value;
|
|
2726
|
|
2727 for (tail = shadow; CONSP (tail); tail = XCONS (tail)->cdr)
|
|
2728 {
|
|
2729 value = Flookup_key (XCONS (tail)->car, key, flag);
|
|
2730 if (!NILP (value))
|
|
2731 return value;
|
|
2732 }
|
|
2733 return Qnil;
|
|
2734 }
|
|
2735
|
6974
|
2736 /* Describe the contents of map MAP, assuming that this map itself is
|
|
2737 reached by the sequence of prefix keys KEYS (a string or vector).
|
14129
|
2738 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */
|
250
|
2739
|
|
2740 static void
|
14129
|
2741 describe_map (map, keys, elt_describer, partial, shadow, seen, nomenu)
|
6974
|
2742 register Lisp_Object map;
|
|
2743 Lisp_Object keys;
|
20381
|
2744 void (*elt_describer) P_ ((Lisp_Object));
|
250
|
2745 int partial;
|
|
2746 Lisp_Object shadow;
|
6976
|
2747 Lisp_Object *seen;
|
14129
|
2748 int nomenu;
|
250
|
2749 {
|
6974
|
2750 Lisp_Object elt_prefix;
|
3952
|
2751 Lisp_Object tail, definition, event;
|
3908
|
2752 Lisp_Object tem;
|
250
|
2753 Lisp_Object suppress;
|
|
2754 Lisp_Object kludge;
|
|
2755 int first = 1;
|
|
2756 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2757
|
6974
|
2758 if (!NILP (keys) && XFASTINT (Flength (keys)) > 0)
|
|
2759 {
|
|
2760 /* Call Fkey_description first, to avoid GC bug for the other string. */
|
|
2761 tem = Fkey_description (keys);
|
|
2762 elt_prefix = concat2 (tem, build_string (" "));
|
|
2763 }
|
|
2764 else
|
|
2765 elt_prefix = Qnil;
|
|
2766
|
250
|
2767 if (partial)
|
|
2768 suppress = intern ("suppress-keymap");
|
|
2769
|
|
2770 /* This vector gets used to present single keys to Flookup_key. Since
|
1209
|
2771 that is done once per keymap element, we don't want to cons up a
|
250
|
2772 fresh vector every time. */
|
|
2773 kludge = Fmake_vector (make_number (1), Qnil);
|
3908
|
2774 definition = Qnil;
|
250
|
2775
|
3908
|
2776 GCPRO3 (elt_prefix, definition, kludge);
|
250
|
2777
|
6976
|
2778 for (tail = map; CONSP (tail); tail = XCONS (tail)->cdr)
|
250
|
2779 {
|
|
2780 QUIT;
|
|
2781
|
17788
|
2782 if (VECTORP (XCONS (tail)->car)
|
|
2783 || CHAR_TABLE_P (XCONS (tail)->car))
|
3952
|
2784 describe_vector (XCONS (tail)->car,
|
17788
|
2785 elt_prefix, elt_describer, partial, shadow, map,
|
|
2786 (int *)0, 0);
|
6976
|
2787 else if (CONSP (XCONS (tail)->car))
|
250
|
2788 {
|
6976
|
2789 event = XCONS (XCONS (tail)->car)->car;
|
7341
516dd16e2017
(describe_map): Ignore bindings for all except symbols and integers.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2790
|
516dd16e2017
(describe_map): Ignore bindings for all except symbols and integers.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2791 /* Ignore bindings whose "keys" are not really valid events.
|
516dd16e2017
(describe_map): Ignore bindings for all except symbols and integers.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2792 (We get these in the frames and buffers menu.) */
|
516dd16e2017
(describe_map): Ignore bindings for all except symbols and integers.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2793 if (! (SYMBOLP (event) || INTEGERP (event)))
|
7191
|
2794 continue;
|
7341
516dd16e2017
(describe_map): Ignore bindings for all except symbols and integers.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2795
|
14129
|
2796 if (nomenu && EQ (event, Qmenu_bar))
|
|
2797 continue;
|
|
2798
|
6976
|
2799 definition = get_keyelt (XCONS (XCONS (tail)->car)->cdr, 0);
|
250
|
2800
|
1209
|
2801 /* Don't show undefined commands or suppressed commands. */
|
3908
|
2802 if (NILP (definition)) continue;
|
9123
|
2803 if (SYMBOLP (definition) && partial)
|
1209
|
2804 {
|
3908
|
2805 tem = Fget (definition, suppress);
|
|
2806 if (!NILP (tem))
|
1209
|
2807 continue;
|
|
2808 }
|
250
|
2809
|
1209
|
2810 /* Don't show a command that isn't really visible
|
|
2811 because a local definition of the same key shadows it. */
|
250
|
2812
|
3908
|
2813 XVECTOR (kludge)->contents[0] = event;
|
1209
|
2814 if (!NILP (shadow))
|
|
2815 {
|
3952
|
2816 tem = shadow_lookup (shadow, kludge, Qt);
|
1209
|
2817 if (!NILP (tem)) continue;
|
|
2818 }
|
250
|
2819
|
6974
|
2820 tem = Flookup_key (map, kludge, Qt);
|
3908
|
2821 if (! EQ (tem, definition)) continue;
|
|
2822
|
1209
|
2823 if (first)
|
|
2824 {
|
14304
|
2825 previous_description_column = 0;
|
1209
|
2826 insert ("\n", 1);
|
|
2827 first = 0;
|
|
2828 }
|
|
2829
|
|
2830 if (!NILP (elt_prefix))
|
|
2831 insert1 (elt_prefix);
|
250
|
2832
|
3908
|
2833 /* THIS gets the string to describe the character EVENT. */
|
|
2834 insert1 (Fsingle_key_description (event));
|
250
|
2835
|
1209
|
2836 /* Print a description of the definition of this character.
|
|
2837 elt_describer will take care of spacing out far enough
|
|
2838 for alignment purposes. */
|
3908
|
2839 (*elt_describer) (definition);
|
1209
|
2840 }
|
6976
|
2841 else if (EQ (XCONS (tail)->car, Qkeymap))
|
|
2842 {
|
|
2843 /* The same keymap might be in the structure twice, if we're
|
|
2844 using an inherited keymap. So skip anything we've already
|
|
2845 encountered. */
|
|
2846 tem = Fassq (tail, *seen);
|
7669
|
2847 if (CONSP (tem) && !NILP (Fequal (XCONS (tem)->car, keys)))
|
6976
|
2848 break;
|
|
2849 *seen = Fcons (Fcons (tail, keys), *seen);
|
|
2850 }
|
250
|
2851 }
|
|
2852
|
|
2853 UNGCPRO;
|
|
2854 }
|
|
2855
|
20319
|
2856 static void
|
250
|
2857 describe_vector_princ (elt)
|
|
2858 Lisp_Object elt;
|
|
2859 {
|
3691
|
2860 Findent_to (make_number (16), make_number (1));
|
250
|
2861 Fprinc (elt, Qnil);
|
3632
|
2862 Fterpri (Qnil);
|
250
|
2863 }
|
|
2864
|
|
2865 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 1, 0,
|
3632
|
2866 "Insert a description of contents of VECTOR.\n\
|
250
|
2867 This is text showing the elements of vector matched against indices.")
|
|
2868 (vector)
|
|
2869 Lisp_Object vector;
|
|
2870 {
|
3632
|
2871 int count = specpdl_ptr - specpdl;
|
|
2872
|
|
2873 specbind (Qstandard_output, Fcurrent_buffer ());
|
13201
|
2874 CHECK_VECTOR_OR_CHAR_TABLE (vector, 0);
|
17788
|
2875 describe_vector (vector, Qnil, describe_vector_princ, 0,
|
|
2876 Qnil, Qnil, (int *)0, 0);
|
3632
|
2877
|
|
2878 return unbind_to (count, Qnil);
|
250
|
2879 }
|
|
2880
|
13201
|
2881 /* Insert in the current buffer a description of the contents of VECTOR.
|
|
2882 We call ELT_DESCRIBER to insert the description of one value found
|
|
2883 in VECTOR.
|
|
2884
|
|
2885 ELT_PREFIX describes what "comes before" the keys or indices defined
|
17788
|
2886 by this vector. This is a human-readable string whose size
|
|
2887 is not necessarily related to the situation.
|
13201
|
2888
|
|
2889 If the vector is in a keymap, ELT_PREFIX is a prefix key which
|
|
2890 leads to this keymap.
|
|
2891
|
|
2892 If the vector is a chartable, ELT_PREFIX is the vector
|
|
2893 of bytes that lead to the character set or portion of a character
|
|
2894 set described by this chartable.
|
|
2895
|
|
2896 If PARTIAL is nonzero, it means do not mention suppressed commands
|
|
2897 (that assumes the vector is in a keymap).
|
|
2898
|
|
2899 SHADOW is a list of keymaps that shadow this map.
|
|
2900 If it is non-nil, then we look up the key in those maps
|
|
2901 and we don't mention it now if it is defined by any of them.
|
|
2902
|
|
2903 ENTIRE_MAP is the keymap in which this vector appears.
|
|
2904 If the definition in effect in the whole map does not match
|
17788
|
2905 the one in this vector, we ignore this one.
|
|
2906
|
|
2907 When describing a sub-char-table, INDICES is a list of
|
|
2908 indices at higher levels in this char-table,
|
|
2909 and CHAR_TABLE_DEPTH says how many levels down we have gone. */
|
13201
|
2910
|
20374
|
2911 void
|
11973
|
2912 describe_vector (vector, elt_prefix, elt_describer,
|
17788
|
2913 partial, shadow, entire_map,
|
|
2914 indices, char_table_depth)
|
250
|
2915 register Lisp_Object vector;
|
|
2916 Lisp_Object elt_prefix;
|
20319
|
2917 void (*elt_describer) P_ ((Lisp_Object));
|
250
|
2918 int partial;
|
|
2919 Lisp_Object shadow;
|
11973
|
2920 Lisp_Object entire_map;
|
17788
|
2921 int *indices;
|
|
2922 int char_table_depth;
|
250
|
2923 {
|
11973
|
2924 Lisp_Object definition;
|
|
2925 Lisp_Object tem2;
|
250
|
2926 register int i;
|
|
2927 Lisp_Object suppress;
|
|
2928 Lisp_Object kludge;
|
|
2929 int first = 1;
|
13201
|
2930 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
17036
|
2931 /* Range of elements to be handled. */
|
|
2932 int from, to;
|
|
2933 /* A flag to tell if a leaf in this level of char-table is not a
|
|
2934 generic character (i.e. a complete multibyte character). */
|
|
2935 int complete_char;
|
17788
|
2936 int character;
|
|
2937 int starting_i;
|
|
2938
|
|
2939 if (indices == 0)
|
18613
|
2940 indices = (int *) alloca (3 * sizeof (int));
|
250
|
2941
|
11973
|
2942 definition = Qnil;
|
250
|
2943
|
|
2944 /* This vector gets used to present single keys to Flookup_key. Since
|
|
2945 that is done once per vector element, we don't want to cons up a
|
|
2946 fresh vector every time. */
|
|
2947 kludge = Fmake_vector (make_number (1), Qnil);
|
17788
|
2948 GCPRO3 (elt_prefix, definition, kludge);
|
250
|
2949
|
|
2950 if (partial)
|
|
2951 suppress = intern ("suppress-keymap");
|
|
2952
|
17036
|
2953 if (CHAR_TABLE_P (vector))
|
|
2954 {
|
17788
|
2955 if (char_table_depth == 0)
|
17036
|
2956 {
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2957 /* VECTOR is a top level char-table. */
|
17788
|
2958 complete_char = 1;
|
17036
|
2959 from = 0;
|
|
2960 to = CHAR_TABLE_ORDINARY_SLOTS;
|
|
2961 }
|
|
2962 else
|
|
2963 {
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2964 /* VECTOR is a sub char-table. */
|
17788
|
2965 if (char_table_depth >= 3)
|
|
2966 /* A char-table is never that deep. */
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2967 error ("Too deep char table");
|
17036
|
2968
|
|
2969 complete_char
|
17788
|
2970 = (CHARSET_VALID_P (indices[0])
|
|
2971 && ((CHARSET_DIMENSION (indices[0]) == 1
|
|
2972 && char_table_depth == 1)
|
|
2973 || char_table_depth == 2));
|
17036
|
2974
|
|
2975 /* Meaningful elements are from 32th to 127th. */
|
|
2976 from = 32;
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2977 to = SUB_CHAR_TABLE_ORDINARY_SLOTS;
|
17036
|
2978 }
|
|
2979 }
|
|
2980 else
|
|
2981 {
|
17788
|
2982 /* This does the right thing for ordinary vectors. */
|
|
2983
|
|
2984 complete_char = 1;
|
17036
|
2985 from = 0;
|
17788
|
2986 to = XVECTOR (vector)->size;
|
17036
|
2987 }
|
|
2988
|
|
2989 for (i = from; i < to; i++)
|
250
|
2990 {
|
|
2991 QUIT;
|
17189
7c008ec99e97
(describe_vector): Adjusted for the change of CHAR_TABLE_ORDINARY_SLOTS.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2992
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2993 if (CHAR_TABLE_P (vector))
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2994 {
|
17788
|
2995 if (char_table_depth == 0 && i >= CHAR_TABLE_SINGLE_BYTE_SLOTS)
|
|
2996 complete_char = 0;
|
|
2997
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2998 if (i >= CHAR_TABLE_SINGLE_BYTE_SLOTS
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
2999 && !CHARSET_DEFINED_P (i - 128))
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3000 continue;
|
17788
|
3001
|
|
3002 definition
|
|
3003 = get_keyelt (XCHAR_TABLE (vector)->contents[i], 0);
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3004 }
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3005 else
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3006 definition = get_keyelt (XVECTOR (vector)->contents[i], 0);
|
250
|
3007
|
17511
|
3008 if (NILP (definition)) continue;
|
|
3009
|
250
|
3010 /* Don't mention suppressed commands. */
|
11973
|
3011 if (SYMBOLP (definition) && partial)
|
250
|
3012 {
|
17036
|
3013 Lisp_Object tem;
|
|
3014
|
|
3015 tem = Fget (definition, suppress);
|
|
3016
|
|
3017 if (!NILP (tem)) continue;
|
250
|
3018 }
|
|
3019
|
17788
|
3020 /* Set CHARACTER to the character this entry describes, if any.
|
|
3021 Also update *INDICES. */
|
|
3022 if (CHAR_TABLE_P (vector))
|
|
3023 {
|
|
3024 indices[char_table_depth] = i;
|
|
3025
|
|
3026 if (char_table_depth == 0)
|
|
3027 {
|
|
3028 character = i;
|
|
3029 indices[0] = i - 128;
|
|
3030 }
|
|
3031 else if (complete_char)
|
|
3032 {
|
|
3033 character
|
|
3034 = MAKE_NON_ASCII_CHAR (indices[0], indices[1], indices[2]);
|
|
3035 }
|
|
3036 else
|
|
3037 character = 0;
|
|
3038 }
|
|
3039 else
|
|
3040 character = i;
|
|
3041
|
11973
|
3042 /* If this binding is shadowed by some other map, ignore it. */
|
17788
|
3043 if (!NILP (shadow) && complete_char)
|
250
|
3044 {
|
|
3045 Lisp_Object tem;
|
|
3046
|
17788
|
3047 XVECTOR (kludge)->contents[0] = make_number (character);
|
3952
|
3048 tem = shadow_lookup (shadow, kludge, Qt);
|
250
|
3049
|
485
|
3050 if (!NILP (tem)) continue;
|
250
|
3051 }
|
|
3052
|
11973
|
3053 /* Ignore this definition if it is shadowed by an earlier
|
|
3054 one in the same keymap. */
|
17788
|
3055 if (!NILP (entire_map) && complete_char)
|
11973
|
3056 {
|
|
3057 Lisp_Object tem;
|
|
3058
|
17788
|
3059 XVECTOR (kludge)->contents[0] = make_number (character);
|
11973
|
3060 tem = Flookup_key (entire_map, kludge, Qt);
|
|
3061
|
|
3062 if (! EQ (tem, definition))
|
|
3063 continue;
|
|
3064 }
|
|
3065
|
250
|
3066 if (first)
|
|
3067 {
|
17788
|
3068 if (char_table_depth == 0)
|
17036
|
3069 insert ("\n", 1);
|
250
|
3070 first = 0;
|
|
3071 }
|
|
3072
|
17788
|
3073 /* For a sub char-table, show the depth by indentation.
|
|
3074 CHAR_TABLE_DEPTH can be greater than 0 only for a char-table. */
|
|
3075 if (char_table_depth > 0)
|
|
3076 insert (" ", char_table_depth * 2); /* depth is 1 or 2. */
|
|
3077
|
|
3078 /* Output the prefix that applies to every entry in this map. */
|
|
3079 if (!NILP (elt_prefix))
|
|
3080 insert1 (elt_prefix);
|
|
3081
|
|
3082 /* Insert or describe the character this slot is for,
|
|
3083 or a description of what it is for. */
|
|
3084 if (SUB_CHAR_TABLE_P (vector))
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3085 {
|
17788
|
3086 if (complete_char)
|
|
3087 insert_char (character);
|
|
3088 else
|
|
3089 {
|
|
3090 /* We need an octal representation for this block of
|
|
3091 characters. */
|
17795
|
3092 char work[16];
|
|
3093 sprintf (work, "(row %d)", i);
|
|
3094 insert (work, strlen (work));
|
17788
|
3095 }
|
|
3096 }
|
|
3097 else if (CHAR_TABLE_P (vector))
|
|
3098 {
|
|
3099 if (complete_char)
|
|
3100 insert1 (Fsingle_key_description (make_number (character)));
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3101 else
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3102 {
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3103 /* Print the information for this character set. */
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3104 insert_string ("<");
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3105 tem2 = CHARSET_TABLE_INFO (i - 128, CHARSET_SHORT_NAME_IDX);
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3106 if (STRINGP (tem2))
|
20624
|
3107 insert_from_string (tem2, 0, 0, XSTRING (tem2)->size,
|
21244
|
3108 STRING_BYTES (XSTRING (tem2)), 0);
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3109 else
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3110 insert ("?", 1);
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3111 insert (">", 1);
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3112 }
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3113 }
|
13201
|
3114 else
|
|
3115 {
|
17788
|
3116 insert1 (Fsingle_key_description (make_number (character)));
|
17036
|
3117 }
|
|
3118
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3119 /* If we find a sub char-table within a char-table,
|
17036
|
3120 scan it recursively; it defines the details for
|
|
3121 a character set or a portion of a character set. */
|
20624
|
3122 if (CHAR_TABLE_P (vector) && SUB_CHAR_TABLE_P (definition))
|
17036
|
3123 {
|
|
3124 insert ("\n", 1);
|
17788
|
3125 describe_vector (definition, elt_prefix, elt_describer,
|
|
3126 partial, shadow, entire_map,
|
|
3127 indices, char_table_depth + 1);
|
17036
|
3128 continue;
|
13201
|
3129 }
|
250
|
3130
|
17788
|
3131 starting_i = i;
|
|
3132
|
17795
|
3133 /* Find all consecutive characters or rows that have the same
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3134 definition. But, for elements of a top level char table, if
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3135 they are for charsets, we had better describe one by one even
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3136 if they have the same definition. */
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3137 if (CHAR_TABLE_P (vector))
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3138 {
|
17788
|
3139 int limit = to;
|
|
3140
|
|
3141 if (char_table_depth == 0)
|
|
3142 limit = CHAR_TABLE_SINGLE_BYTE_SLOTS;
|
|
3143
|
|
3144 while (i + 1 < limit
|
|
3145 && (tem2 = get_keyelt (XCHAR_TABLE (vector)->contents[i + 1], 0),
|
|
3146 !NILP (tem2))
|
|
3147 && !NILP (Fequal (tem2, definition)))
|
|
3148 i++;
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3149 }
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3150 else
|
17788
|
3151 while (i + 1 < to
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3152 && (tem2 = get_keyelt (XVECTOR (vector)->contents[i + 1], 0),
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3153 !NILP (tem2))
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3154 && !NILP (Fequal (tem2, definition)))
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3155 i++;
|
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3156
|
250
|
3157
|
|
3158 /* If we have a range of more than one character,
|
|
3159 print where the range reaches to. */
|
|
3160
|
17788
|
3161 if (i != starting_i)
|
250
|
3162 {
|
|
3163 insert (" .. ", 4);
|
17788
|
3164
|
|
3165 if (!NILP (elt_prefix))
|
|
3166 insert1 (elt_prefix);
|
|
3167
|
13201
|
3168 if (CHAR_TABLE_P (vector))
|
|
3169 {
|
17788
|
3170 if (char_table_depth == 0)
|
|
3171 {
|
|
3172 insert1 (Fsingle_key_description (make_number (i)));
|
|
3173 }
|
|
3174 else if (complete_char)
|
13201
|
3175 {
|
17788
|
3176 indices[char_table_depth] = i;
|
|
3177 character
|
|
3178 = MAKE_NON_ASCII_CHAR (indices[0], indices[1], indices[2]);
|
|
3179 insert_char (character);
|
17036
|
3180 }
|
17788
|
3181 else
|
17036
|
3182 {
|
17795
|
3183 /* We need an octal representation for this block of
|
|
3184 characters. */
|
|
3185 char work[16];
|
|
3186 sprintf (work, "(row %d)", i);
|
|
3187 insert (work, strlen (work));
|
13201
|
3188 }
|
|
3189 }
|
|
3190 else
|
|
3191 {
|
17788
|
3192 insert1 (Fsingle_key_description (make_number (i)));
|
13201
|
3193 }
|
250
|
3194 }
|
|
3195
|
|
3196 /* Print a description of the definition of this character.
|
|
3197 elt_describer will take care of spacing out far enough
|
|
3198 for alignment purposes. */
|
11973
|
3199 (*elt_describer) (definition);
|
250
|
3200 }
|
|
3201
|
17327
0cb065f8702e
(describe_vector): Adjusted for the new structure of Lisp_Char_Table.
Kenichi Handa <handa@m17n.org>
diff
changeset
|
3202 /* For (sub) char-table, print `defalt' slot at last. */
|
17036
|
3203 if (CHAR_TABLE_P (vector) && !NILP (XCHAR_TABLE (vector)->defalt))
|
|
3204 {
|
17788
|
3205 insert (" ", char_table_depth * 2);
|
17036
|
3206 insert_string ("<<default>>");
|
|
3207 (*elt_describer) (XCHAR_TABLE (vector)->defalt);
|
|
3208 }
|
|
3209
|
250
|
3210 UNGCPRO;
|
|
3211 }
|
|
3212
|
465
|
3213 /* Apropos - finding all symbols whose names match a regexp. */
|
250
|
3214 Lisp_Object apropos_predicate;
|
|
3215 Lisp_Object apropos_accumulate;
|
|
3216
|
|
3217 static void
|
|
3218 apropos_accum (symbol, string)
|
|
3219 Lisp_Object symbol, string;
|
|
3220 {
|
|
3221 register Lisp_Object tem;
|
|
3222
|
|
3223 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil);
|
485
|
3224 if (!NILP (tem) && !NILP (apropos_predicate))
|
250
|
3225 tem = call1 (apropos_predicate, symbol);
|
485
|
3226 if (!NILP (tem))
|
250
|
3227 apropos_accumulate = Fcons (symbol, apropos_accumulate);
|
|
3228 }
|
|
3229
|
|
3230 DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0,
|
|
3231 "Show all symbols whose names contain match for REGEXP.\n\
|
14080
|
3232 If optional 2nd arg PREDICATE is non-nil, (funcall PREDICATE SYMBOL) is done\n\
|
250
|
3233 for each symbol and a symbol is mentioned only if that returns non-nil.\n\
|
|
3234 Return list of symbols found.")
|
14080
|
3235 (regexp, predicate)
|
|
3236 Lisp_Object regexp, predicate;
|
250
|
3237 {
|
|
3238 struct gcpro gcpro1, gcpro2;
|
14099
|
3239 CHECK_STRING (regexp, 0);
|
14080
|
3240 apropos_predicate = predicate;
|
250
|
3241 GCPRO2 (apropos_predicate, apropos_accumulate);
|
|
3242 apropos_accumulate = Qnil;
|
14080
|
3243 map_obarray (Vobarray, apropos_accum, regexp);
|
250
|
3244 apropos_accumulate = Fsort (apropos_accumulate, Qstring_lessp);
|
|
3245 UNGCPRO;
|
|
3246 return apropos_accumulate;
|
|
3247 }
|
|
3248
|
21514
|
3249 void
|
250
|
3250 syms_of_keymap ()
|
|
3251 {
|
|
3252 Lisp_Object tem;
|
|
3253
|
|
3254 Qkeymap = intern ("keymap");
|
|
3255 staticpro (&Qkeymap);
|
|
3256
|
17788
|
3257 /* Now we are ready to set up this property, so we can
|
|
3258 create char tables. */
|
|
3259 Fput (Qkeymap, Qchar_table_extra_slots, make_number (0));
|
|
3260
|
|
3261 /* Initialize the keymaps standardly used.
|
|
3262 Each one is the value of a Lisp variable, and is also
|
|
3263 pointed to by a C variable */
|
|
3264
|
|
3265 global_map = Fmake_keymap (Qnil);
|
250
|
3266 Fset (intern ("global-map"), global_map);
|
|
3267
|
16125
|
3268 current_global_map = global_map;
|
16227
|
3269 staticpro (&global_map);
|
16125
|
3270 staticpro (¤t_global_map);
|
|
3271
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3272 meta_map = Fmake_keymap (Qnil);
|
250
|
3273 Fset (intern ("esc-map"), meta_map);
|
|
3274 Ffset (intern ("ESC-prefix"), meta_map);
|
|
3275
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3276 control_x_map = Fmake_keymap (Qnil);
|
250
|
3277 Fset (intern ("ctl-x-map"), control_x_map);
|
|
3278 Ffset (intern ("Control-X-prefix"), control_x_map);
|
|
3279
|
12297
|
3280 DEFVAR_LISP ("define-key-rebound-commands", &Vdefine_key_rebound_commands,
|
|
3281 "List of commands given new key bindings recently.\n\
|
|
3282 This is used for internal purposes during Emacs startup;\n\
|
|
3283 don't alter it yourself.");
|
|
3284 Vdefine_key_rebound_commands = Qt;
|
|
3285
|
250
|
3286 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map,
|
|
3287 "Default keymap to use when reading from the minibuffer.");
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3288 Vminibuffer_local_map = Fmake_sparse_keymap (Qnil);
|
250
|
3289
|
|
3290 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map,
|
|
3291 "Local keymap for the minibuffer when spaces are not allowed.");
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3292 Vminibuffer_local_ns_map = Fmake_sparse_keymap (Qnil);
|
250
|
3293
|
|
3294 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map,
|
|
3295 "Local keymap for minibuffer input with completion.");
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3296 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil);
|
250
|
3297
|
|
3298 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map,
|
|
3299 "Local keymap for minibuffer input with completion, for exact match.");
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3300 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil);
|
250
|
3301
|
465
|
3302 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist,
|
|
3303 "Alist of keymaps to use for minor modes.\n\
|
|
3304 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\
|
|
3305 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\
|
|
3306 If two active keymaps bind the same key, the keymap appearing earlier\n\
|
|
3307 in the list takes precedence.");
|
|
3308 Vminor_mode_map_alist = Qnil;
|
|
3309
|
20517
|
3310 DEFVAR_LISP ("minor-mode-overriding-map-alist", &Vminor_mode_overriding_map_alist,
|
|
3311 "Alist of keymaps to use for minor modes, in current major mode.\n\
|
|
3312 This variable is a alist just like `minor-mode-map-alist', and it is\n\
|
|
3313 used the same way (and before `minor-mode-map-alist'); however,\n\
|
|
3314 it is provided for major modes to bind locally.");
|
|
3315 Vminor_mode_overriding_map_alist = Qnil;
|
|
3316
|
517
|
3317 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
|
|
3318 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\
|
|
3319 This allows Emacs to recognize function keys sent from ASCII\n\
|
|
3320 terminals at any point in a key sequence.\n\
|
|
3321 \n\
|
8731
|
3322 The `read-key-sequence' function replaces any subsequence bound by\n\
|
|
3323 `function-key-map' with its binding. More precisely, when the active\n\
|
517
|
3324 keymaps have no binding for the current key sequence but\n\
|
8731
|
3325 `function-key-map' binds a suffix of the sequence to a vector or string,\n\
|
|
3326 `read-key-sequence' replaces the matching suffix with its binding, and\n\
|
517
|
3327 continues with the new sequence.\n\
|
|
3328 \n\
|
8731
|
3329 The events that come from bindings in `function-key-map' are not\n\
|
|
3330 themselves looked up in `function-key-map'.\n\
|
|
3331 \n\
|
|
3332 For example, suppose `function-key-map' binds `ESC O P' to [f1].\n\
|
|
3333 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing\n\
|
4138
|
3334 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix\n\
|
|
3335 key, typing `ESC O P x' would return [f1 x].");
|
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
3336 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
|
517
|
3337
|
12710
|
3338 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
|
|
3339 "Keymap of key translations that can override keymaps.\n\
|
|
3340 This keymap works like `function-key-map', but comes after that,\n\
|
|
3341 and applies even for keys that have ordinary bindings.");
|
|
3342 Vkey_translation_map = Qnil;
|
|
3343
|
250
|
3344 Qsingle_key_description = intern ("single-key-description");
|
|
3345 staticpro (&Qsingle_key_description);
|
|
3346
|
|
3347 Qkey_description = intern ("key-description");
|
|
3348 staticpro (&Qkey_description);
|
|
3349
|
|
3350 Qkeymapp = intern ("keymapp");
|
|
3351 staticpro (&Qkeymapp);
|
|
3352
|
2727
|
3353 Qnon_ascii = intern ("non-ascii");
|
|
3354 staticpro (&Qnon_ascii);
|
|
3355
|
21241
|
3356 Qmenu_item = intern ("menu-item");
|
|
3357 staticpro (&Qmenu_item);
|
|
3358
|
250
|
3359 defsubr (&Skeymapp);
|
15344
|
3360 defsubr (&Skeymap_parent);
|
|
3361 defsubr (&Sset_keymap_parent);
|
250
|
3362 defsubr (&Smake_keymap);
|
|
3363 defsubr (&Smake_sparse_keymap);
|
|
3364 defsubr (&Scopy_keymap);
|
|
3365 defsubr (&Skey_binding);
|
|
3366 defsubr (&Slocal_key_binding);
|
|
3367 defsubr (&Sglobal_key_binding);
|
465
|
3368 defsubr (&Sminor_mode_key_binding);
|
250
|
3369 defsubr (&Sdefine_key);
|
|
3370 defsubr (&Slookup_key);
|
|
3371 defsubr (&Sdefine_prefix_command);
|
|
3372 defsubr (&Suse_global_map);
|
|
3373 defsubr (&Suse_local_map);
|
|
3374 defsubr (&Scurrent_local_map);
|
|
3375 defsubr (&Scurrent_global_map);
|
465
|
3376 defsubr (&Scurrent_minor_mode_maps);
|
250
|
3377 defsubr (&Saccessible_keymaps);
|
|
3378 defsubr (&Skey_description);
|
|
3379 defsubr (&Sdescribe_vector);
|
|
3380 defsubr (&Ssingle_key_description);
|
|
3381 defsubr (&Stext_char_description);
|
|
3382 defsubr (&Swhere_is_internal);
|
20850
|
3383 defsubr (&Sdescribe_bindings_internal);
|
250
|
3384 defsubr (&Sapropos_internal);
|
|
3385 }
|
|
3386
|
21514
|
3387 void
|
250
|
3388 keys_of_keymap ()
|
|
3389 {
|
|
3390 Lisp_Object tem;
|
|
3391
|
|
3392 initial_define_key (global_map, 033, "ESC-prefix");
|
|
3393 initial_define_key (global_map, Ctl('X'), "Control-X-prefix");
|
|
3394 }
|