Mercurial > emacs
annotate src/keymap.c @ 2387:cb44857cab89
moby rlogin-filter fixes
author | Noah Friedman <friedman@splode.com> |
---|---|
date | Sat, 27 Mar 1993 08:21:02 +0000 |
parents | e99cada8fb8f |
children | b6c62e4abf59 |
rev | line source |
---|---|
250 | 1 /* Manipulation of keymaps |
647 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1992 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 | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include "config.h" | |
22 #include <stdio.h> | |
23 #undef NULL | |
24 #include "lisp.h" | |
25 #include "commands.h" | |
26 #include "buffer.h" | |
517 | 27 #include "keyboard.h" |
2059 | 28 #include "termhooks.h" |
250 | 29 |
30 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
31 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
32 /* The number of elements in keymap vectors. */ |
250 | 33 #define DENSE_TABLE_SIZE (0200) |
34 | |
35 /* Actually allocate storage for these variables */ | |
36 | |
37 Lisp_Object current_global_map; /* Current global keymap */ | |
38 | |
39 Lisp_Object global_map; /* default global key bindings */ | |
40 | |
41 Lisp_Object meta_map; /* The keymap used for globally bound | |
42 ESC-prefixed default commands */ | |
43 | |
44 Lisp_Object control_x_map; /* The keymap used for globally bound | |
45 C-x-prefixed default commands */ | |
46 | |
47 /* was MinibufLocalMap */ | |
48 Lisp_Object Vminibuffer_local_map; | |
49 /* The keymap used by the minibuf for local | |
50 bindings when spaces are allowed in the | |
51 minibuf */ | |
52 | |
53 /* was MinibufLocalNSMap */ | |
54 Lisp_Object Vminibuffer_local_ns_map; | |
55 /* The keymap used by the minibuf for local | |
56 bindings when spaces are not encouraged | |
57 in the minibuf */ | |
58 | |
59 /* keymap used for minibuffers when doing completion */ | |
60 /* was MinibufLocalCompletionMap */ | |
61 Lisp_Object Vminibuffer_local_completion_map; | |
62 | |
63 /* keymap used for minibuffers when doing completion and require a match */ | |
64 /* was MinibufLocalMustMatchMap */ | |
65 Lisp_Object Vminibuffer_local_must_match_map; | |
66 | |
465 | 67 /* Alist of minor mode variables and keymaps. */ |
68 Lisp_Object Vminor_mode_map_alist; | |
69 | |
517 | 70 /* Keymap mapping ASCII function key sequences onto their preferred forms. |
71 Initialized by the terminal-specific lisp files. See DEFVAR for more | |
72 documentation. */ | |
73 Lisp_Object Vfunction_key_map; | |
74 | |
250 | 75 Lisp_Object Qkeymapp, Qkeymap; |
76 | |
77 /* A char over 0200 in a key sequence | |
78 is equivalent to prefixing with this character. */ | |
79 | |
80 extern Lisp_Object meta_prefix_char; | |
81 | |
82 void describe_map_tree (); | |
83 static Lisp_Object describe_buffer_bindings (); | |
84 static void describe_command (); | |
85 static void describe_map (); | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
86 static void describe_map_2 (); |
250 | 87 |
465 | 88 /* Keymap object support - constructors and predicates. */ |
89 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
90 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0, |
250 | 91 "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\ |
92 VECTOR is a 128-element vector which holds the bindings for the ASCII\n\ | |
93 characters. ALIST is an assoc-list which holds bindings for function keys,\n\ | |
94 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>
parents:
647
diff
changeset
|
95 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>
parents:
647
diff
changeset
|
96 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>
parents:
647
diff
changeset
|
97 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>
parents:
647
diff
changeset
|
98 (string) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
99 Lisp_Object string; |
250 | 100 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
101 Lisp_Object tail; |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
102 if (!NILP (string)) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
103 tail = Fcons (string, Qnil); |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
104 else |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
105 tail = Qnil; |
250 | 106 return Fcons (Qkeymap, |
107 Fcons (Fmake_vector (make_number (DENSE_TABLE_SIZE), Qnil), | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
108 tail)); |
250 | 109 } |
110 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
111 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, Smake_sparse_keymap, 0, 1, 0, |
250 | 112 "Construct and return a new sparse-keymap list.\n\ |
113 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\ | |
114 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\ | |
115 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>
parents:
647
diff
changeset
|
116 Initially the alist is nil.\n\n\ |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
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>
parents:
647
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>
parents:
647
diff
changeset
|
119 (string) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
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>
parents:
647
diff
changeset
|
122 if (!NILP (string)) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
123 return Fcons (Qkeymap, Fcons (string, Qnil)); |
250 | 124 return Fcons (Qkeymap, Qnil); |
125 } | |
126 | |
127 /* This function is used for installing the standard key bindings | |
128 at initialization time. | |
129 | |
130 For example: | |
131 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
132 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */ |
250 | 133 |
134 void | |
135 initial_define_key (keymap, key, defname) | |
136 Lisp_Object keymap; | |
137 int key; | |
138 char *defname; | |
139 { | |
140 store_in_keymap (keymap, make_number (key), intern (defname)); | |
141 } | |
142 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
143 void |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
144 initial_define_lispy_key (keymap, keyname, defname) |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
145 Lisp_Object keymap; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
146 char *keyname; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
147 char *defname; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
148 { |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
149 store_in_keymap (keymap, intern (keyname), intern (defname)); |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
150 } |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
151 |
250 | 152 /* Define character fromchar in map frommap as an alias for character |
153 tochar in map tomap. Subsequent redefinitions of the latter WILL | |
154 affect the former. */ | |
155 | |
156 #if 0 | |
157 void | |
158 synkey (frommap, fromchar, tomap, tochar) | |
159 struct Lisp_Vector *frommap, *tomap; | |
160 int fromchar, tochar; | |
161 { | |
162 Lisp_Object v, c; | |
163 XSET (v, Lisp_Vector, tomap); | |
164 XFASTINT (c) = tochar; | |
165 frommap->contents[fromchar] = Fcons (v, c); | |
166 } | |
167 #endif /* 0 */ | |
168 | |
169 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0, | |
170 "Return t if ARG is a keymap.\n\ | |
362 | 171 \n\ |
2358
e99cada8fb8f
* keymap.c (Fkeymapp): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
2343
diff
changeset
|
172 A keymap is a list (keymap . ALIST), a list (keymap VECTOR . ALIST),\n\ |
362 | 173 or a symbol whose function definition is a keymap is itself a keymap.\n\ |
174 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\ | |
175 VECTOR is a 128-element vector of bindings for ASCII characters.") | |
250 | 176 (object) |
177 Lisp_Object object; | |
178 { | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
179 return (NILP (get_keymap_1 (object, 0, 0)) ? Qnil : Qt); |
250 | 180 } |
181 | |
182 /* Check that OBJECT is a keymap (after dereferencing through any | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
183 symbols). If it is, return it. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
184 |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
185 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
186 is an autoload form, do the autoload and try again. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
187 |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
188 ERROR controls how we respond if OBJECT isn't a keymap. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
189 If ERROR is non-zero, signal an error; otherwise, just return Qnil. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
190 |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
191 Note that most of the time, we don't want to pursue autoloads. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
192 Functions like Faccessible_keymaps which scan entire keymap trees |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
193 shouldn't load every autoloaded keymap. I'm not sure about this, |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
194 but it seems to me that only read_key_sequence, Flookup_key, and |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
195 Fdefine_key should cause keymaps to be autoloaded. */ |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
196 |
250 | 197 Lisp_Object |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
198 get_keymap_1 (object, error, autoload) |
250 | 199 Lisp_Object object; |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
200 int error, autoload; |
250 | 201 { |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
202 Lisp_Object tem; |
250 | 203 |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
204 autoload_retry: |
647 | 205 tem = indirect_function (object); |
250 | 206 if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap)) |
207 return tem; | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
208 |
1566
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
209 /* Should we do an autoload? Autoload forms for keymaps have |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
210 Qkeymap as their fifth element. */ |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
211 if (autoload |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
212 && XTYPE (object) == Lisp_Symbol |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
213 && CONSP (tem) |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
214 && EQ (XCONS (tem)->car, Qautoload)) |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
215 { |
1566
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
216 Lisp_Object tail; |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
217 |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
218 tail = Fnth (make_number (4), tem); |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
219 if (EQ (tail, Qkeymap)) |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
220 { |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
221 struct gcpro gcpro1, gcpro2; |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
222 |
1566
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
223 GCPRO2 (tem, object) |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
224 do_autoload (tem, object); |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
225 UNGCPRO; |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
226 |
1566
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
227 goto autoload_retry; |
892c9f61217a
* keymap.c (get_keymap_1): Don't try to autoload OBJECT's function
Jim Blandy <jimb@redhat.com>
parents:
1517
diff
changeset
|
228 } |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
229 } |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
230 |
250 | 231 if (error) |
232 wrong_type_argument (Qkeymapp, object); | |
465 | 233 else |
234 return Qnil; | |
250 | 235 } |
236 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
237 |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
238 /* Follow any symbol chaining, and return the keymap denoted by OBJECT. |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
239 If OBJECT doesn't denote a keymap at all, signal an error. */ |
250 | 240 Lisp_Object |
241 get_keymap (object) | |
242 Lisp_Object object; | |
243 { | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
244 return get_keymap_1 (object, 0, 0); |
250 | 245 } |
246 | |
247 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
248 /* Look up IDX in MAP. IDX may be any sort of event. |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
249 Note that this does only one level of lookup; IDX must be a single |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
250 event, not a sequence. |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
251 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
252 If T_OK is non-zero, bindings for Qt are treated as default |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
253 bindings; any key left unmentioned by other tables and bindings is |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
254 given the binding of Qt. |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
255 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
256 If T_OK is zero, bindings for Qt are not treated specially. */ |
250 | 257 |
258 Lisp_Object | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
259 access_keymap (map, idx, t_ok) |
250 | 260 Lisp_Object map; |
261 Lisp_Object idx; | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
262 int t_ok; |
250 | 263 { |
264 /* If idx is a list (some sort of mouse click, perhaps?), | |
265 the index we want to use is the car of the list, which | |
266 ought to be a symbol. */ | |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
267 idx = EVENT_HEAD (idx); |
250 | 268 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
269 /* If idx is a symbol, it might have modifiers, which need to |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
270 be put in the canonical order. */ |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
271 if (XTYPE (idx) == Lisp_Symbol) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
272 idx = reorder_modifiers (idx); |
250 | 273 |
274 { | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
275 Lisp_Object tail; |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
276 Lisp_Object t_binding = Qnil; |
250 | 277 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
278 for (tail = map; CONSP (tail); tail = XCONS (tail)->cdr) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
279 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
280 Lisp_Object binding = XCONS (tail)->car; |
250 | 281 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
282 switch (XTYPE (binding)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
283 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
284 case Lisp_Cons: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
285 if (EQ (XCONS (binding)->car, idx)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
286 return XCONS (binding)->cdr; |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
287 if (t_ok && EQ (XCONS (binding)->car, Qt)) |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
288 t_binding = XCONS (binding)->cdr; |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
289 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
290 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
291 case Lisp_Vector: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
292 if (XVECTOR (binding)->size == DENSE_TABLE_SIZE |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
293 && XTYPE (idx) == Lisp_Int |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
294 && XINT (idx) >= 0 |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
295 && XINT (idx) < DENSE_TABLE_SIZE) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
296 return XVECTOR (binding)->contents[XINT (idx)]; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
297 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
298 } |
1264
6ba9d5aaace6
* keymap.c (access_keymap): Don't forget to QUIT while scanning
Jim Blandy <jimb@redhat.com>
parents:
1236
diff
changeset
|
299 |
6ba9d5aaace6
* keymap.c (access_keymap): Don't forget to QUIT while scanning
Jim Blandy <jimb@redhat.com>
parents:
1236
diff
changeset
|
300 QUIT; |
250 | 301 } |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
302 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
303 return t_binding; |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
304 } |
250 | 305 } |
306 | |
307 /* Given OBJECT which was found in a slot in a keymap, | |
308 trace indirect definitions to get the actual definition of that slot. | |
309 An indirect definition is a list of the form | |
310 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one | |
311 and INDEX is the object to look up in KEYMAP to yield the definition. | |
312 | |
313 Also if OBJECT has a menu string as the first element, | |
1160
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
314 remove that. Also remove a menu help string as second element. */ |
250 | 315 |
316 Lisp_Object | |
317 get_keyelt (object) | |
318 register Lisp_Object object; | |
319 { | |
320 while (1) | |
321 { | |
322 register Lisp_Object map, tem; | |
323 | |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
324 /* If the contents are (KEYMAP . ELEMENT), go indirect. */ |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
325 map = get_keymap_1 (Fcar_safe (object), 0, 0); |
250 | 326 tem = Fkeymapp (map); |
485 | 327 if (!NILP (tem)) |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
328 object = access_keymap (map, Fcdr (object), 0); |
250 | 329 |
330 /* If the keymap contents looks like (STRING . DEFN), | |
331 use DEFN. | |
332 Keymap alist elements like (CHAR MENUSTRING . DEFN) | |
333 will be used by HierarKey menus. */ | |
334 else if (XTYPE (object) == Lisp_Cons | |
335 && XTYPE (XCONS (object)->car) == Lisp_String) | |
1160
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
336 { |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
337 object = XCONS (object)->cdr; |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
338 /* Also remove a menu help string, if any, |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
339 following the menu item name. */ |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
340 if (XTYPE (object) == Lisp_Cons |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
341 && XTYPE (XCONS (object)->car) == Lisp_String) |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
342 object = XCONS (object)->cdr; |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
343 } |
250 | 344 |
345 else | |
346 /* Anything else is really the value. */ | |
347 return object; | |
348 } | |
349 } | |
350 | |
351 Lisp_Object | |
352 store_in_keymap (keymap, idx, def) | |
353 Lisp_Object keymap; | |
354 register Lisp_Object idx; | |
355 register Lisp_Object def; | |
356 { | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
357 if (XTYPE (keymap) != Lisp_Cons |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
358 || ! EQ (XCONS (keymap)->car, Qkeymap)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
359 error ("attempt to define a key in a non-keymap"); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
360 |
250 | 361 /* If idx is a list (some sort of mouse click, perhaps?), |
362 the index we want to use is the car of the list, which | |
363 ought to be a symbol. */ | |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
364 idx = EVENT_HEAD (idx); |
250 | 365 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
366 /* If idx is a symbol, it might have modifiers, which need to |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
367 be put in the canonical order. */ |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
368 if (XTYPE (idx) == Lisp_Symbol) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
369 idx = reorder_modifiers (idx); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
370 |
250 | 371 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
372 /* Scan the keymap for a binding of idx. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
373 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
374 Lisp_Object tail; |
250 | 375 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
376 /* The cons after which we should insert new bindings. If the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
377 keymap has a table element, we record its position here, so new |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
378 bindings will go after it; this way, the table will stay |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
379 towards the front of the alist and character lookups in dense |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
380 keymaps will remain fast. Otherwise, this just points at the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
381 front of the keymap. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
382 Lisp_Object insertion_point = keymap; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
383 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
384 for (tail = XCONS (keymap)->cdr; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 385 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
386 Lisp_Object elt = XCONS (tail)->car; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
387 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
388 switch (XTYPE (elt)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
389 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
390 case Lisp_Vector: |
1441
929409595312
* keymap.c (store_in_keymap): Don't forget to QUIT in the
Jim Blandy <jimb@redhat.com>
parents:
1388
diff
changeset
|
391 if (XVECTOR (elt)->size != DENSE_TABLE_SIZE) |
929409595312
* keymap.c (store_in_keymap): Don't forget to QUIT in the
Jim Blandy <jimb@redhat.com>
parents:
1388
diff
changeset
|
392 break; |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
393 if (XTYPE (idx) == Lisp_Int |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
394 && XINT (idx) >= 0 && XINT (idx) < DENSE_TABLE_SIZE) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
395 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
396 XVECTOR (elt)->contents[XFASTINT (idx)] = def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
397 return def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
398 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
399 insertion_point = tail; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
400 break; |
250 | 401 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
402 case Lisp_Cons: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
403 if (EQ (idx, XCONS (elt)->car)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
404 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
405 XCONS (elt)->cdr = def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
406 return def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
407 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
408 break; |
250 | 409 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
410 case Lisp_Symbol: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
411 /* If we find a 'keymap' symbol in the spine of KEYMAP, |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
412 then we must have found the start of a second keymap |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
413 being used as the tail of KEYMAP, and a binding for IDX |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
414 should be inserted before it. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
415 if (EQ (elt, Qkeymap)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
416 goto keymap_end; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
417 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
418 } |
1441
929409595312
* keymap.c (store_in_keymap): Don't forget to QUIT in the
Jim Blandy <jimb@redhat.com>
parents:
1388
diff
changeset
|
419 |
929409595312
* keymap.c (store_in_keymap): Don't forget to QUIT in the
Jim Blandy <jimb@redhat.com>
parents:
1388
diff
changeset
|
420 QUIT; |
250 | 421 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
422 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
423 keymap_end: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
424 /* We have scanned the entire keymap, and not found a binding for |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
425 IDX. Let's add one. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
426 XCONS (insertion_point)->cdr = |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
427 Fcons (Fcons (idx, def), XCONS (insertion_point)->cdr); |
250 | 428 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
429 |
250 | 430 return def; |
431 } | |
432 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
433 |
250 | 434 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, |
435 "Return a copy of the keymap KEYMAP.\n\ | |
436 The copy starts out with the same definitions of KEYMAP,\n\ | |
437 but changing either the copy or KEYMAP does not affect the other.\n\ | |
362 | 438 Any key definitions that are subkeymaps are recursively copied.\n\ |
439 However, a key definition which is a symbol whose definition is a keymap\n\ | |
440 is not copied.") | |
250 | 441 (keymap) |
442 Lisp_Object keymap; | |
443 { | |
444 register Lisp_Object copy, tail; | |
445 | |
446 copy = Fcopy_alist (get_keymap (keymap)); | |
447 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
448 for (tail = copy; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 449 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
450 Lisp_Object elt = XCONS (tail)->car; |
250 | 451 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
452 if (XTYPE (elt) == Lisp_Vector |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
453 && XVECTOR (elt)->size == DENSE_TABLE_SIZE) |
250 | 454 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
455 int i; |
250 | 456 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
457 elt = Fcopy_sequence (elt); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
458 XCONS (tail)->car = elt; |
250 | 459 |
460 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
461 if (XTYPE (XVECTOR (elt)->contents[i]) != Lisp_Symbol |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
462 && Fkeymapp (XVECTOR (elt)->contents[i])) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
463 XVECTOR (elt)->contents[i] = |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
464 Fcopy_keymap (XVECTOR (elt)->contents[i]); |
250 | 465 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
466 else if (CONSP (elt) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
467 && XTYPE (XCONS (elt)->cdr) != Lisp_Symbol |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
468 && ! NILP (Fkeymapp (XCONS (elt)->cdr))) |
250 | 469 XCONS (elt)->cdr = Fcopy_keymap (XCONS (elt)->cdr); |
470 } | |
471 | |
472 return copy; | |
473 } | |
474 | |
465 | 475 /* Simple Keymap mutators and accessors. */ |
476 | |
250 | 477 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, |
478 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\ | |
479 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\ | |
480 meaning a sequence of keystrokes and events.\n\ | |
481 DEF is anything that can be a key's definition:\n\ | |
482 nil (means key is undefined in this keymap),\n\ | |
483 a command (a Lisp function suitable for interactive calling)\n\ | |
484 a string (treated as a keyboard macro),\n\ | |
485 a keymap (to define a prefix key),\n\ | |
486 a symbol. When the key is looked up, the symbol will stand for its\n\ | |
487 function definition, which should at that time be one of the above,\n\ | |
488 or another symbol whose function definition is used, etc.\n\ | |
489 a cons (STRING . DEFN), meaning that DEFN is the definition\n\ | |
490 (DEFN should be a valid definition in its own right),\n\ | |
368 | 491 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\ |
492 \n\ | |
493 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\ | |
494 the front of KEYMAP.") | |
250 | 495 (keymap, key, def) |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
496 Lisp_Object keymap; |
250 | 497 Lisp_Object key; |
498 Lisp_Object def; | |
499 { | |
500 register int idx; | |
501 register Lisp_Object c; | |
502 register Lisp_Object tem; | |
503 register Lisp_Object cmd; | |
504 int metized = 0; | |
2059 | 505 int meta_bit; |
250 | 506 int length; |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
507 struct gcpro gcpro1, gcpro2, gcpro3; |
250 | 508 |
509 keymap = get_keymap (keymap); | |
510 | |
511 if (XTYPE (key) != Lisp_Vector | |
512 && XTYPE (key) != Lisp_String) | |
513 key = wrong_type_argument (Qarrayp, key); | |
514 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
515 length = XFASTINT (Flength (key)); |
250 | 516 if (length == 0) |
517 return Qnil; | |
518 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
519 GCPRO3 (keymap, key, def); |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
520 |
2059 | 521 if (XTYPE (key) == Lisp_Vector) |
522 meta_bit = meta_modifier; | |
523 else | |
524 meta_bit = 0x80; | |
525 | |
250 | 526 idx = 0; |
527 while (1) | |
528 { | |
529 c = Faref (key, make_number (idx)); | |
530 | |
531 if (XTYPE (c) == Lisp_Int | |
2059 | 532 && (XINT (c) & meta_bit) |
250 | 533 && !metized) |
534 { | |
535 c = meta_prefix_char; | |
536 metized = 1; | |
537 } | |
538 else | |
539 { | |
540 if (XTYPE (c) == Lisp_Int) | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
541 XSETINT (c, XINT (c) & ~meta_bit); |
250 | 542 |
543 metized = 0; | |
544 idx++; | |
545 } | |
546 | |
547 if (idx == length) | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
548 RETURN_UNGCPRO (store_in_keymap (keymap, c, def)); |
250 | 549 |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
550 cmd = get_keyelt (access_keymap (keymap, c, 0)); |
250 | 551 |
485 | 552 if (NILP (cmd)) |
250 | 553 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
554 cmd = Fmake_sparse_keymap (Qnil); |
250 | 555 store_in_keymap (keymap, c, cmd); |
556 } | |
557 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
558 keymap = get_keymap_1 (cmd, 0, 1); |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
559 if (NILP (keymap)) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
560 { |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
561 /* We must use Fkey_description rather than just passing key to |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
562 error; key might be a vector, not a string. */ |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
563 Lisp_Object description = Fkey_description (key); |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
564 |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
565 error ("Key sequence %s uses invalid prefix characters", |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
566 XSTRING (description)->data); |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1566
diff
changeset
|
567 } |
250 | 568 } |
569 } | |
570 | |
571 /* Value is number if KEY is too long; NIL if valid but has no definition. */ | |
572 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
573 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, |
250 | 574 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\ |
575 nil means undefined. See doc of `define-key' for kinds of definitions.\n\ | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
576 \n\ |
250 | 577 A number as value means KEY is \"too long\";\n\ |
578 that is, characters or symbols in it except for the last one\n\ | |
579 fail to be a valid sequence of prefix characters in KEYMAP.\n\ | |
580 The number is how many characters at the front of KEY\n\ | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
581 it takes to reach a non-prefix command.\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
582 \n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
583 Normally, `lookup-key' ignores bindings for t, which act as default\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
584 bindings, used when nothing else in the keymap applies; this makes it\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
585 useable as a general function for probing keymaps. However, if the\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
586 third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
587 recognize the default bindings, just as `read-key-sequence' does.") |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
588 (keymap, key, accept_default) |
250 | 589 register Lisp_Object keymap; |
590 Lisp_Object key; | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
591 Lisp_Object accept_default; |
250 | 592 { |
593 register int idx; | |
594 register Lisp_Object tem; | |
595 register Lisp_Object cmd; | |
596 register Lisp_Object c; | |
597 int metized = 0; | |
598 int length; | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
599 int t_ok = ! NILP (accept_default); |
2059 | 600 int meta_bit; |
250 | 601 |
602 keymap = get_keymap (keymap); | |
603 | |
604 if (XTYPE (key) != Lisp_Vector | |
605 && XTYPE (key) != Lisp_String) | |
606 key = wrong_type_argument (Qarrayp, key); | |
607 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
608 length = XFASTINT (Flength (key)); |
250 | 609 if (length == 0) |
610 return keymap; | |
611 | |
2059 | 612 if (XTYPE (key) == Lisp_Vector) |
613 meta_bit = meta_modifier; | |
614 else | |
615 meta_bit = 0x80; | |
616 | |
250 | 617 idx = 0; |
618 while (1) | |
619 { | |
620 c = Faref (key, make_number (idx)); | |
621 | |
622 if (XTYPE (c) == Lisp_Int | |
2059 | 623 && (XINT (c) & meta_bit) |
250 | 624 && !metized) |
625 { | |
626 c = meta_prefix_char; | |
627 metized = 1; | |
628 } | |
629 else | |
630 { | |
631 if (XTYPE (c) == Lisp_Int) | |
2059 | 632 XSETINT (c, XINT (c) & ~meta_bit); |
250 | 633 |
634 metized = 0; | |
635 idx++; | |
636 } | |
637 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
638 cmd = get_keyelt (access_keymap (keymap, c, t_ok)); |
250 | 639 if (idx == length) |
640 return cmd; | |
641 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
642 keymap = get_keymap_1 (cmd, 0, 0); |
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
643 if (NILP (keymap)) |
250 | 644 return make_number (idx); |
645 | |
646 QUIT; | |
647 } | |
648 } | |
649 | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
650 /* Append a key to the end of a key sequence. We always make a vector. */ |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
651 |
250 | 652 Lisp_Object |
653 append_key (key_sequence, key) | |
654 Lisp_Object key_sequence, key; | |
655 { | |
656 Lisp_Object args[2]; | |
657 | |
658 args[0] = key_sequence; | |
659 | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
660 args[1] = Fcons (key, Qnil); |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
661 return Fvconcat (2, args); |
250 | 662 } |
663 | |
664 | |
465 | 665 /* Global, local, and minor mode keymap stuff. */ |
666 | |
485 | 667 /* We can't put these variables inside current_minor_maps, since under |
517 | 668 some systems, static gets macro-defined to be the empty string. |
669 Ickypoo. */ | |
485 | 670 static Lisp_Object *cmm_modes, *cmm_maps; |
671 static int cmm_size; | |
672 | |
465 | 673 /* Store a pointer to an array of the keymaps of the currently active |
674 minor modes in *buf, and return the number of maps it contains. | |
675 | |
676 This function always returns a pointer to the same buffer, and may | |
677 free or reallocate it, so if you want to keep it for a long time or | |
678 hand it out to lisp code, copy it. This procedure will be called | |
679 for every key sequence read, so the nice lispy approach (return a | |
680 new assoclist, list, what have you) for each invocation would | |
681 result in a lot of consing over time. | |
682 | |
683 If we used xrealloc/xmalloc and ran out of memory, they would throw | |
684 back to the command loop, which would try to read a key sequence, | |
685 which would call this function again, resulting in an infinite | |
686 loop. Instead, we'll use realloc/malloc and silently truncate the | |
687 list, let the key sequence be read, and hope some other piece of | |
688 code signals the error. */ | |
689 int | |
690 current_minor_maps (modeptr, mapptr) | |
691 Lisp_Object **modeptr, **mapptr; | |
692 { | |
693 int i = 0; | |
517 | 694 Lisp_Object alist, assoc, var, val; |
465 | 695 |
696 for (alist = Vminor_mode_map_alist; | |
697 CONSP (alist); | |
698 alist = XCONS (alist)->cdr) | |
699 if (CONSP (assoc = XCONS (alist)->car) | |
700 && XTYPE (var = XCONS (assoc)->car) == Lisp_Symbol | |
517 | 701 && ! EQ ((val = find_symbol_value (var)), Qunbound) |
702 && ! NILP (val)) | |
465 | 703 { |
485 | 704 if (i >= cmm_size) |
465 | 705 { |
706 Lisp_Object *newmodes, *newmaps; | |
707 | |
485 | 708 if (cmm_maps) |
465 | 709 { |
485 | 710 newmodes = (Lisp_Object *) realloc (cmm_modes, cmm_size *= 2); |
711 newmaps = (Lisp_Object *) realloc (cmm_maps, cmm_size); | |
465 | 712 } |
713 else | |
714 { | |
485 | 715 newmodes = (Lisp_Object *) malloc (cmm_size = 30); |
716 newmaps = (Lisp_Object *) malloc (cmm_size); | |
465 | 717 } |
718 | |
719 if (newmaps && newmodes) | |
720 { | |
485 | 721 cmm_modes = newmodes; |
722 cmm_maps = newmaps; | |
465 | 723 } |
724 else | |
725 break; | |
726 } | |
485 | 727 cmm_modes[i] = var; |
728 cmm_maps [i] = XCONS (assoc)->cdr; | |
465 | 729 i++; |
730 } | |
731 | |
485 | 732 if (modeptr) *modeptr = cmm_modes; |
733 if (mapptr) *mapptr = cmm_maps; | |
465 | 734 return i; |
735 } | |
736 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
737 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0, |
250 | 738 "Return the binding for command KEY in current keymaps.\n\ |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
739 KEY is a string or vector, a sequence of keystrokes.\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
740 The binding is probably a symbol with a function definition.\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
741 \n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
742 Normally, `key-binding' ignores bindings for t, which act as default\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
743 bindings, used when nothing else in the keymap applies; this makes it\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
744 useable as a general function for probing keymaps. However, if the\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
745 third optional argument ACCEPT-DEFAULT is non-nil, `key-binding' will\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
746 recognize the default bindings, just as `read-key-sequence' does.") |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
747 (key, accept_default) |
250 | 748 Lisp_Object key; |
749 { | |
465 | 750 Lisp_Object *maps, value; |
751 int nmaps, i; | |
752 | |
753 nmaps = current_minor_maps (0, &maps); | |
754 for (i = 0; i < nmaps; i++) | |
485 | 755 if (! NILP (maps[i])) |
465 | 756 { |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
757 value = Flookup_key (maps[i], key, accept_default); |
485 | 758 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
465 | 759 return value; |
760 } | |
761 | |
485 | 762 if (! NILP (current_buffer->keymap)) |
250 | 763 { |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
764 value = Flookup_key (current_buffer->keymap, key, accept_default); |
485 | 765 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
250 | 766 return value; |
767 } | |
465 | 768 |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
769 value = Flookup_key (current_global_map, key, accept_default); |
485 | 770 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
465 | 771 return value; |
772 | |
773 return Qnil; | |
250 | 774 } |
775 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
776 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 2, 0, |
250 | 777 "Return the binding for command KEYS in current local keymap only.\n\ |
778 KEYS is a string, a sequence of keystrokes.\n\ | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
779 The binding is probably a symbol with a function definition.\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
780 \n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
781 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
782 bindings; see the description of `lookup-key' for more details about this.") |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
783 (keys, accept_default) |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
784 Lisp_Object keys, accept_default; |
250 | 785 { |
786 register Lisp_Object map; | |
787 map = current_buffer->keymap; | |
485 | 788 if (NILP (map)) |
250 | 789 return Qnil; |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
790 return Flookup_key (map, keys, accept_default); |
250 | 791 } |
792 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
793 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 2, 0, |
250 | 794 "Return the binding for command KEYS in current global keymap only.\n\ |
795 KEYS is a string, a sequence of keystrokes.\n\ | |
517 | 796 The binding is probably a symbol with a function definition.\n\ |
797 This function's return values are the same as those of lookup-key\n\ | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
798 (which see).\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
799 \n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
800 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
801 bindings; see the description of `lookup-key' for more details about this.") |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
802 (keys, accept_default) |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
803 Lisp_Object keys, accept_default; |
250 | 804 { |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
805 return Flookup_key (current_global_map, keys, accept_default); |
250 | 806 } |
807 | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
808 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 2, 0, |
465 | 809 "Find the visible minor mode bindings of KEY.\n\ |
810 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\ | |
811 the symbol which names the minor mode binding KEY, and BINDING is\n\ | |
812 KEY's definition in that mode. In particular, if KEY has no\n\ | |
813 minor-mode bindings, return nil. If the first binding is a\n\ | |
814 non-prefix, all subsequent bindings will be omitted, since they would\n\ | |
815 be ignored. Similarly, the list doesn't include non-prefix bindings\n\ | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
816 that come after prefix bindings.\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
817 \n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
818 If optional argument ACCEPT-DEFAULT is non-nil, recognize default\n\ |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
819 bindings; see the description of `lookup-key' for more details about this.") |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
820 (key, accept_default) |
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
821 Lisp_Object key, accept_default; |
465 | 822 { |
823 Lisp_Object *modes, *maps; | |
824 int nmaps; | |
825 Lisp_Object binding; | |
826 int i, j; | |
827 | |
828 nmaps = current_minor_maps (&modes, &maps); | |
829 | |
830 for (i = j = 0; i < nmaps; i++) | |
485 | 831 if (! NILP (maps[i]) |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
832 && ! NILP (binding = Flookup_key (maps[i], key, accept_default)) |
465 | 833 && XTYPE (binding) != Lisp_Int) |
834 { | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
835 if (! NILP (get_keymap (binding))) |
465 | 836 maps[j++] = Fcons (modes[i], binding); |
837 else if (j == 0) | |
838 return Fcons (Fcons (modes[i], binding), Qnil); | |
839 } | |
840 | |
841 return Flist (j, maps); | |
842 } | |
843 | |
250 | 844 DEFUN ("global-set-key", Fglobal_set_key, Sglobal_set_key, 2, 2, |
845 "kSet key globally: \nCSet key %s to command: ", | |
846 "Give KEY a global binding as COMMAND.\n\ | |
847 COMMAND is a symbol naming an interactively-callable function.\n\ | |
848 KEY is a string representing a sequence of keystrokes.\n\ | |
849 Note that if KEY has a local binding in the current buffer\n\ | |
850 that local binding will continue to shadow any global binding.") | |
851 (keys, function) | |
852 Lisp_Object keys, function; | |
853 { | |
854 if (XTYPE (keys) != Lisp_Vector | |
855 && XTYPE (keys) != Lisp_String) | |
856 keys = wrong_type_argument (Qarrayp, keys); | |
857 | |
858 Fdefine_key (current_global_map, keys, function); | |
859 return Qnil; | |
860 } | |
861 | |
862 DEFUN ("local-set-key", Flocal_set_key, Slocal_set_key, 2, 2, | |
863 "kSet key locally: \nCSet key %s locally to command: ", | |
864 "Give KEY a local binding as COMMAND.\n\ | |
865 COMMAND is a symbol naming an interactively-callable function.\n\ | |
866 KEY is a string representing a sequence of keystrokes.\n\ | |
867 The binding goes in the current buffer's local map,\n\ | |
868 which is shared with other buffers in the same major mode.") | |
869 (keys, function) | |
870 Lisp_Object keys, function; | |
871 { | |
872 register Lisp_Object map; | |
873 map = current_buffer->keymap; | |
485 | 874 if (NILP (map)) |
250 | 875 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
876 map = Fmake_sparse_keymap (Qnil); |
250 | 877 current_buffer->keymap = map; |
878 } | |
879 | |
880 if (XTYPE (keys) != Lisp_Vector | |
881 && XTYPE (keys) != Lisp_String) | |
882 keys = wrong_type_argument (Qarrayp, keys); | |
883 | |
884 Fdefine_key (map, keys, function); | |
885 return Qnil; | |
886 } | |
887 | |
888 DEFUN ("global-unset-key", Fglobal_unset_key, Sglobal_unset_key, | |
889 1, 1, "kUnset key globally: ", | |
890 "Remove global binding of KEY.\n\ | |
891 KEY is a string representing a sequence of keystrokes.") | |
892 (keys) | |
893 Lisp_Object keys; | |
894 { | |
895 return Fglobal_set_key (keys, Qnil); | |
896 } | |
897 | |
898 DEFUN ("local-unset-key", Flocal_unset_key, Slocal_unset_key, 1, 1, | |
899 "kUnset key locally: ", | |
900 "Remove local binding of KEY.\n\ | |
901 KEY is a string representing a sequence of keystrokes.") | |
902 (keys) | |
903 Lisp_Object keys; | |
904 { | |
485 | 905 if (!NILP (current_buffer->keymap)) |
250 | 906 Flocal_set_key (keys, Qnil); |
907 return Qnil; | |
908 } | |
909 | |
910 DEFUN ("define-prefix-command", Fdefine_prefix_command, Sdefine_prefix_command, 1, 2, 0, | |
911 "Define COMMAND as a prefix command.\n\ | |
912 A new sparse keymap is stored as COMMAND's function definition and its value.\n\ | |
362 | 913 If a second optional argument MAPVAR is given, the map is stored as\n\ |
914 its value instead of as COMMAND's value; but COMMAND is still defined\n\ | |
915 as a function.") | |
250 | 916 (name, mapvar) |
917 Lisp_Object name, mapvar; | |
918 { | |
919 Lisp_Object map; | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
920 map = Fmake_sparse_keymap (Qnil); |
250 | 921 Ffset (name, map); |
485 | 922 if (!NILP (mapvar)) |
250 | 923 Fset (mapvar, map); |
924 else | |
925 Fset (name, map); | |
926 return name; | |
927 } | |
928 | |
929 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0, | |
930 "Select KEYMAP as the global keymap.") | |
931 (keymap) | |
932 Lisp_Object keymap; | |
933 { | |
934 keymap = get_keymap (keymap); | |
935 current_global_map = keymap; | |
936 return Qnil; | |
937 } | |
938 | |
939 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 1, 0, | |
940 "Select KEYMAP as the local keymap.\n\ | |
941 If KEYMAP is nil, that means no local keymap.") | |
942 (keymap) | |
943 Lisp_Object keymap; | |
944 { | |
485 | 945 if (!NILP (keymap)) |
250 | 946 keymap = get_keymap (keymap); |
947 | |
948 current_buffer->keymap = keymap; | |
949 | |
950 return Qnil; | |
951 } | |
952 | |
953 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 0, 0, | |
954 "Return current buffer's local keymap, or nil if it has none.") | |
955 () | |
956 { | |
957 return current_buffer->keymap; | |
958 } | |
959 | |
960 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0, | |
961 "Return the current global keymap.") | |
962 () | |
963 { | |
964 return current_global_map; | |
965 } | |
465 | 966 |
967 DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps, Scurrent_minor_mode_maps, 0, 0, 0, | |
968 "Return a list of keymaps for the minor modes of the current buffer.") | |
969 () | |
970 { | |
971 Lisp_Object *maps; | |
972 int nmaps = current_minor_maps (0, &maps); | |
973 | |
974 return Flist (nmaps, maps); | |
975 } | |
250 | 976 |
465 | 977 /* Help functions for describing and documenting keymaps. */ |
978 | |
250 | 979 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, |
980 1, 1, 0, | |
981 "Find all keymaps accessible via prefix characters from KEYMAP.\n\ | |
982 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\ | |
983 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\ | |
984 so that the KEYS increase in length. The first element is (\"\" . KEYMAP).") | |
985 (startmap) | |
986 Lisp_Object startmap; | |
987 { | |
988 Lisp_Object maps, tail; | |
989 | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
990 maps = Fcons (Fcons (Fmake_vector (make_number (0), Qnil), |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
991 get_keymap (startmap)), |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
992 Qnil); |
250 | 993 |
994 /* For each map in the list maps, | |
995 look at any other maps it points to, | |
996 and stick them at the end if they are not already in the list. | |
997 | |
998 This is a breadth-first traversal, where tail is the queue of | |
999 nodes, and maps accumulates a list of all nodes visited. */ | |
1000 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1001 for (tail = maps; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 1002 { |
1003 register Lisp_Object thisseq = Fcar (Fcar (tail)); | |
1004 register Lisp_Object thismap = Fcdr (Fcar (tail)); | |
1005 Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | |
1006 | |
1007 /* Does the current sequence end in the meta-prefix-char? */ | |
1008 int is_metized = (XINT (last) >= 0 | |
1009 && EQ (Faref (thisseq, last), meta_prefix_char)); | |
1010 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1011 for (; CONSP (thismap); thismap = XCONS (thismap)->cdr) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1012 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1013 Lisp_Object elt = XCONS (thismap)->car; |
250 | 1014 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1015 QUIT; |
250 | 1016 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1017 if (XTYPE (elt) == Lisp_Vector) |
250 | 1018 { |
1019 register int i; | |
1020 | |
1021 /* Vector keymap. Scan all the elements. */ | |
1022 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1023 { | |
1024 register Lisp_Object tem; | |
1025 register Lisp_Object cmd; | |
1026 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1027 cmd = get_keyelt (XVECTOR (elt)->contents[i]); |
485 | 1028 if (NILP (cmd)) continue; |
250 | 1029 tem = Fkeymapp (cmd); |
485 | 1030 if (!NILP (tem)) |
250 | 1031 { |
1032 cmd = get_keymap (cmd); | |
1033 /* Ignore keymaps that are already added to maps. */ | |
1034 tem = Frassq (cmd, maps); | |
485 | 1035 if (NILP (tem)) |
250 | 1036 { |
1037 /* If the last key in thisseq is meta-prefix-char, | |
1038 turn it into a meta-ized keystroke. We know | |
1039 that the event we're about to append is an | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1040 ascii keystroke since we're processing a |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1041 keymap table. */ |
250 | 1042 if (is_metized) |
1043 { | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1044 int meta_bit = meta_modifier; |
250 | 1045 tem = Fcopy_sequence (thisseq); |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1046 |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1047 Faset (tem, last, make_number (i | meta_bit)); |
250 | 1048 |
1049 /* This new sequence is the same length as | |
1050 thisseq, so stick it in the list right | |
1051 after this one. */ | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1052 XCONS (tail)->cdr |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1053 = Fcons (Fcons (tem, cmd), XCONS (tail)->cdr); |
250 | 1054 } |
1055 else | |
1056 { | |
1057 tem = append_key (thisseq, make_number (i)); | |
1058 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | |
1059 } | |
1060 } | |
1061 } | |
1062 } | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1063 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1064 else if (CONSP (elt)) |
250 | 1065 { |
1066 register Lisp_Object cmd = get_keyelt (XCONS (elt)->cdr); | |
1067 register Lisp_Object tem; | |
1068 | |
1069 /* Ignore definitions that aren't keymaps themselves. */ | |
1070 tem = Fkeymapp (cmd); | |
485 | 1071 if (!NILP (tem)) |
250 | 1072 { |
1073 /* Ignore keymaps that have been seen already. */ | |
1074 cmd = get_keymap (cmd); | |
1075 tem = Frassq (cmd, maps); | |
485 | 1076 if (NILP (tem)) |
250 | 1077 { |
1078 /* let elt be the event defined by this map entry. */ | |
1079 elt = XCONS (elt)->car; | |
1080 | |
1081 /* If the last key in thisseq is meta-prefix-char, and | |
1082 this entry is a binding for an ascii keystroke, | |
1083 turn it into a meta-ized keystroke. */ | |
1084 if (is_metized && XTYPE (elt) == Lisp_Int) | |
1085 { | |
1086 tem = Fcopy_sequence (thisseq); | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1087 Faset (tem, last, |
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1088 make_number (XINT (elt) | meta_modifier)); |
250 | 1089 |
1090 /* This new sequence is the same length as | |
1091 thisseq, so stick it in the list right | |
1092 after this one. */ | |
1093 XCONS (tail)->cdr = | |
1094 Fcons (Fcons (tem, cmd), XCONS (tail)->cdr); | |
1095 } | |
1096 else | |
1097 nconc2 (tail, | |
1098 Fcons (Fcons (append_key (thisseq, elt), cmd), | |
1099 Qnil)); | |
1100 } | |
1101 } | |
1102 } | |
1103 } | |
1104 } | |
1105 | |
1106 return maps; | |
1107 } | |
1108 | |
1109 Lisp_Object Qsingle_key_description, Qkey_description; | |
1110 | |
1111 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0, | |
1112 "Return a pretty description of key-sequence KEYS.\n\ | |
1113 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\ | |
1114 spaces are put between sequence elements, etc.") | |
1115 (keys) | |
1116 Lisp_Object keys; | |
1117 { | |
2059 | 1118 if (XTYPE (keys) == Lisp_String) |
1119 { | |
1120 Lisp_Object vector; | |
1121 int i; | |
1122 vector = Fmake_vector (Flength (keys), Qnil); | |
1123 for (i = 0; i < XSTRING (keys)->size; i++) | |
1124 { | |
1125 if (XSTRING (keys)->data[i] & 0x80) | |
1126 XFASTINT (XVECTOR (vector)->contents[i]) | |
1127 = meta_modifier | (XSTRING (keys)->data[i] & ~0x80); | |
1128 else | |
1129 XFASTINT (XVECTOR (vector)->contents[i]) | |
1130 = XSTRING (keys)->data[i]; | |
1131 } | |
1132 keys = vector; | |
1133 } | |
250 | 1134 return Fmapconcat (Qsingle_key_description, keys, build_string (" ")); |
1135 } | |
1136 | |
1137 char * | |
1138 push_key_description (c, p) | |
1139 register unsigned int c; | |
1140 register char *p; | |
1141 { | |
2343
ddb30eaf2f56
(push_key_description): Ignore bits above meta_modifier.
Richard M. Stallman <rms@gnu.org>
parents:
2093
diff
changeset
|
1142 /* Clear all the meaningless bits above the meta bit. */ |
ddb30eaf2f56
(push_key_description): Ignore bits above meta_modifier.
Richard M. Stallman <rms@gnu.org>
parents:
2093
diff
changeset
|
1143 c &= meta_modifier | ~ - meta_modifier; |
ddb30eaf2f56
(push_key_description): Ignore bits above meta_modifier.
Richard M. Stallman <rms@gnu.org>
parents:
2093
diff
changeset
|
1144 |
2059 | 1145 if (c & alt_modifier) |
1146 { | |
1147 *p++ = 'A'; | |
1148 *p++ = '-'; | |
1149 c -= alt_modifier; | |
1150 } | |
1151 if (c & ctrl_modifier) | |
1152 { | |
1153 *p++ = 'C'; | |
1154 *p++ = '-'; | |
1155 c -= ctrl_modifier; | |
1156 } | |
1157 if (c & hyper_modifier) | |
1158 { | |
1159 *p++ = 'H'; | |
1160 *p++ = '-'; | |
1161 c -= hyper_modifier; | |
1162 } | |
1163 if (c & meta_modifier) | |
250 | 1164 { |
1165 *p++ = 'M'; | |
1166 *p++ = '-'; | |
2059 | 1167 c -= meta_modifier; |
1168 } | |
1169 if (c & shift_modifier) | |
1170 { | |
1171 *p++ = 'S'; | |
1172 *p++ = '-'; | |
1173 c -= shift_modifier; | |
1174 } | |
1175 if (c & super_modifier) | |
1176 { | |
1177 *p++ = 's'; | |
1178 *p++ = '-'; | |
1179 c -= super_modifier; | |
250 | 1180 } |
1181 if (c < 040) | |
1182 { | |
1183 if (c == 033) | |
1184 { | |
1185 *p++ = 'E'; | |
1186 *p++ = 'S'; | |
1187 *p++ = 'C'; | |
1188 } | |
2059 | 1189 else if (c == '\t') |
250 | 1190 { |
1191 *p++ = 'T'; | |
1192 *p++ = 'A'; | |
1193 *p++ = 'B'; | |
1194 } | |
1195 else if (c == Ctl('J')) | |
1196 { | |
1197 *p++ = 'L'; | |
1198 *p++ = 'F'; | |
1199 *p++ = 'D'; | |
1200 } | |
1201 else if (c == Ctl('M')) | |
1202 { | |
1203 *p++ = 'R'; | |
1204 *p++ = 'E'; | |
1205 *p++ = 'T'; | |
1206 } | |
1207 else | |
1208 { | |
1209 *p++ = 'C'; | |
1210 *p++ = '-'; | |
1211 if (c > 0 && c <= Ctl ('Z')) | |
1212 *p++ = c + 0140; | |
1213 else | |
1214 *p++ = c + 0100; | |
1215 } | |
1216 } | |
1217 else if (c == 0177) | |
1218 { | |
1219 *p++ = 'D'; | |
1220 *p++ = 'E'; | |
1221 *p++ = 'L'; | |
1222 } | |
1223 else if (c == ' ') | |
1224 { | |
1225 *p++ = 'S'; | |
1226 *p++ = 'P'; | |
1227 *p++ = 'C'; | |
1228 } | |
2059 | 1229 else if (c < 256) |
1230 *p++ = c; | |
250 | 1231 else |
2059 | 1232 { |
1233 *p++ = '\\'; | |
1234 *p++ = (7 & (c >> 15)) + '0'; | |
1235 *p++ = (7 & (c >> 12)) + '0'; | |
1236 *p++ = (7 & (c >> 9)) + '0'; | |
1237 *p++ = (7 & (c >> 6)) + '0'; | |
1238 *p++ = (7 & (c >> 3)) + '0'; | |
1239 *p++ = (7 & (c >> 0)) + '0'; | |
1240 } | |
250 | 1241 |
1242 return p; | |
1243 } | |
1244 | |
1245 DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0, | |
1246 "Return a pretty description of command character KEY.\n\ | |
1247 Control characters turn into C-whatever, etc.") | |
1248 (key) | |
1249 Lisp_Object key; | |
1250 { | |
2059 | 1251 char tem[20]; |
250 | 1252 |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
1253 key = EVENT_HEAD (key); |
517 | 1254 |
250 | 1255 switch (XTYPE (key)) |
1256 { | |
1257 case Lisp_Int: /* Normal character */ | |
2059 | 1258 *push_key_description (XUINT (key), tem) = 0; |
250 | 1259 return build_string (tem); |
1260 | |
1261 case Lisp_Symbol: /* Function key or event-symbol */ | |
1262 return Fsymbol_name (key); | |
1263 | |
1264 default: | |
1265 error ("KEY must be an integer, cons, or symbol."); | |
1266 } | |
1267 } | |
1268 | |
1269 char * | |
1270 push_text_char_description (c, p) | |
1271 register unsigned int c; | |
1272 register char *p; | |
1273 { | |
1274 if (c >= 0200) | |
1275 { | |
1276 *p++ = 'M'; | |
1277 *p++ = '-'; | |
1278 c -= 0200; | |
1279 } | |
1280 if (c < 040) | |
1281 { | |
1282 *p++ = '^'; | |
1283 *p++ = c + 64; /* 'A' - 1 */ | |
1284 } | |
1285 else if (c == 0177) | |
1286 { | |
1287 *p++ = '^'; | |
1288 *p++ = '?'; | |
1289 } | |
1290 else | |
1291 *p++ = c; | |
1292 return p; | |
1293 } | |
1294 | |
1295 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, | |
1296 "Return a pretty description of file-character CHAR.\n\ | |
1297 Control characters turn into \"^char\", etc.") | |
1298 (chr) | |
1299 Lisp_Object chr; | |
1300 { | |
1301 char tem[6]; | |
1302 | |
1303 CHECK_NUMBER (chr, 0); | |
1304 | |
1305 *push_text_char_description (XINT (chr) & 0377, tem) = 0; | |
1306 | |
1307 return build_string (tem); | |
1308 } | |
1309 | |
465 | 1310 /* where-is - finding a command in a set of keymaps. */ |
1311 | |
250 | 1312 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, |
1313 "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\ | |
1314 If KEYMAP is nil, search only KEYMAP1.\n\ | |
1315 If KEYMAP1 is nil, use the current global map.\n\ | |
1316 \n\ | |
1317 If optional 4th arg FIRSTONLY is non-nil,\n\ | |
1318 return a string representing the first key sequence found,\n\ | |
1319 rather than a list of all possible key sequences.\n\ | |
1320 \n\ | |
1321 If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\ | |
1322 to other keymaps or slots. This makes it possible to search for an\n\ | |
1323 indirect definition itself.") | |
1324 (definition, local_keymap, global_keymap, firstonly, noindirect) | |
1325 Lisp_Object definition, local_keymap, global_keymap; | |
1326 Lisp_Object firstonly, noindirect; | |
1327 { | |
1328 register Lisp_Object maps; | |
1329 Lisp_Object found; | |
1330 | |
485 | 1331 if (NILP (global_keymap)) |
250 | 1332 global_keymap = current_global_map; |
1333 | |
485 | 1334 if (!NILP (local_keymap)) |
250 | 1335 maps = nconc2 (Faccessible_keymaps (get_keymap (local_keymap)), |
1336 Faccessible_keymaps (get_keymap (global_keymap))); | |
1337 else | |
1338 maps = Faccessible_keymaps (get_keymap (global_keymap)); | |
1339 | |
1340 found = Qnil; | |
1341 | |
485 | 1342 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1343 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1344 /* Key sequence to reach map */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1345 register Lisp_Object this = Fcar (Fcar (maps)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1346 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1347 /* The map that it reaches */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1348 register Lisp_Object map = Fcdr (Fcar (maps)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1349 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1350 /* If Fcar (map) is a VECTOR, the current element within that vector. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1351 int i = 0; |
250 | 1352 |
1353 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into | |
1354 [M-CHAR] sequences, check if last character of the sequence | |
1355 is the meta-prefix char. */ | |
1356 Lisp_Object last = make_number (XINT (Flength (this)) - 1); | |
1357 int last_is_meta = (XINT (last) >= 0 | |
1358 && EQ (Faref (this, last), meta_prefix_char)); | |
1359 | |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1360 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1361 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1362 while (CONSP (map)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1363 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1364 /* Because the code we want to run on each binding is rather |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1365 large, we don't want to have two separate loop bodies for |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1366 sparse keymap bindings and tables; we want to iterate one |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1367 loop body over both keymap and vector bindings. |
250 | 1368 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1369 For this reason, if Fcar (map) is a vector, we don't |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1370 advance map to the next element until i indicates that we |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1371 have finished off the vector. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1372 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1373 Lisp_Object elt = XCONS (map)->car; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1374 Lisp_Object key, binding, sequence; |
250 | 1375 |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1376 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1377 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1378 /* Set key and binding to the current key and binding, and |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1379 advance map and i to the next binding. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1380 if (XTYPE (elt) == Lisp_Vector) |
250 | 1381 { |
1382 /* In a vector, look at each element. */ | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1383 binding = XVECTOR (elt)->contents[i]; |
250 | 1384 XFASTINT (key) = i; |
1385 i++; | |
1386 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1387 /* If we've just finished scanning a vector, advance map |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1388 to the next element, and reset i in anticipation of the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1389 next vector we may find. */ |
250 | 1390 if (i >= DENSE_TABLE_SIZE) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1391 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1392 map = XCONS (map)->cdr; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1393 i = 0; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1394 } |
250 | 1395 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1396 else if (CONSP (elt)) |
250 | 1397 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1398 key = Fcar (Fcar (map)); |
250 | 1399 binding = Fcdr (Fcar (map)); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1400 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1401 map = XCONS (map)->cdr; |
250 | 1402 } |
1403 else | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1404 /* We want to ignore keymap elements that are neither |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1405 vectors nor conses. */ |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1406 { |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1407 map = XCONS (map)->cdr; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1408 continue; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1409 } |
250 | 1410 |
1411 /* Search through indirections unless that's not wanted. */ | |
485 | 1412 if (NILP (noindirect)) |
250 | 1413 binding = get_keyelt (binding); |
1414 | |
1415 /* End this iteration if this element does not match | |
1416 the target. */ | |
1417 | |
1418 if (XTYPE (definition) == Lisp_Cons) | |
1419 { | |
1420 Lisp_Object tem; | |
1421 tem = Fequal (binding, definition); | |
485 | 1422 if (NILP (tem)) |
250 | 1423 continue; |
1424 } | |
1425 else | |
1426 if (!EQ (binding, definition)) | |
1427 continue; | |
1428 | |
1429 /* We have found a match. | |
1430 Construct the key sequence where we found it. */ | |
1431 if (XTYPE (key) == Lisp_Int && last_is_meta) | |
1432 { | |
1433 sequence = Fcopy_sequence (this); | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1434 Faset (sequence, last, make_number (XINT (key) | meta_modifier)); |
250 | 1435 } |
1436 else | |
1437 sequence = append_key (this, key); | |
1438 | |
1439 /* Verify that this key binding is not shadowed by another | |
1440 binding for the same key, before we say it exists. | |
1441 | |
1442 Mechanism: look for local definition of this key and if | |
1443 it is defined and does not match what we found then | |
1444 ignore this key. | |
1445 | |
1446 Either nil or number as value from Flookup_key | |
1447 means undefined. */ | |
485 | 1448 if (!NILP (local_keymap)) |
250 | 1449 { |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1450 binding = Flookup_key (local_keymap, sequence, Qnil); |
485 | 1451 if (!NILP (binding) && XTYPE (binding) != Lisp_Int) |
250 | 1452 { |
1453 if (XTYPE (definition) == Lisp_Cons) | |
1454 { | |
1455 Lisp_Object tem; | |
1456 tem = Fequal (binding, definition); | |
485 | 1457 if (NILP (tem)) |
250 | 1458 continue; |
1459 } | |
1460 else | |
1461 if (!EQ (binding, definition)) | |
1462 continue; | |
1463 } | |
1464 } | |
1465 | |
1466 /* It is a true unshadowed match. Record it. */ | |
1467 | |
485 | 1468 if (!NILP (firstonly)) |
250 | 1469 return sequence; |
1470 found = Fcons (sequence, found); | |
1471 } | |
1472 } | |
1473 return Fnreverse (found); | |
1474 } | |
1475 | |
1476 /* Return a string listing the keys and buttons that run DEFINITION. */ | |
1477 | |
1478 static Lisp_Object | |
1479 where_is_string (definition) | |
1480 Lisp_Object definition; | |
1481 { | |
1482 register Lisp_Object keys, keys1; | |
1483 | |
1484 keys = Fwhere_is_internal (definition, | |
1485 current_buffer->keymap, Qnil, Qnil, Qnil); | |
1486 keys1 = Fmapconcat (Qkey_description, keys, build_string (", ")); | |
1487 | |
1488 return keys1; | |
1489 } | |
1490 | |
1491 DEFUN ("where-is", Fwhere_is, Swhere_is, 1, 1, "CWhere is command: ", | |
1492 "Print message listing key sequences that invoke specified command.\n\ | |
1493 Argument is a command definition, usually a symbol with a function definition.") | |
1494 (definition) | |
1495 Lisp_Object definition; | |
1496 { | |
1497 register Lisp_Object string; | |
1498 | |
1499 CHECK_SYMBOL (definition, 0); | |
1500 string = where_is_string (definition); | |
1501 | |
1502 if (XSTRING (string)->size) | |
1503 message ("%s is on %s", XSYMBOL (definition)->name->data, | |
1504 XSTRING (string)->data); | |
1505 else | |
1506 message ("%s is not on any key", XSYMBOL (definition)->name->data); | |
1507 return Qnil; | |
1508 } | |
1509 | |
465 | 1510 /* describe-bindings - summarizing all the bindings in a set of keymaps. */ |
1511 | |
250 | 1512 DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "", |
1513 "Show a list of all defined keys, and their definitions.\n\ | |
1514 The list is put in a buffer, which is displayed.") | |
1515 () | |
1516 { | |
1517 register Lisp_Object thisbuf; | |
1518 XSET (thisbuf, Lisp_Buffer, current_buffer); | |
1519 internal_with_output_to_temp_buffer ("*Help*", | |
1520 describe_buffer_bindings, | |
1521 thisbuf); | |
1522 return Qnil; | |
1523 } | |
1524 | |
1525 static Lisp_Object | |
1526 describe_buffer_bindings (descbuf) | |
1527 Lisp_Object descbuf; | |
1528 { | |
1529 register Lisp_Object start1, start2; | |
1530 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1531 char *key_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1532 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1533 key binding\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1534 --- -------\n"; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1535 char *alternate_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1536 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1537 Alternate Characters (use anywhere the nominal character is listed):\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1538 nominal alternate\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1539 ------- ---------\n"; |
250 | 1540 |
1541 Fset_buffer (Vstandard_output); | |
1542 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1543 /* Report on alternates for keys. */ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1544 if (XTYPE (Vkeyboard_translate_table) == Lisp_String) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1545 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1546 int c; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1547 unsigned char *translate = XSTRING (Vkeyboard_translate_table)->data; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1548 int translate_len = XSTRING (Vkeyboard_translate_table)->size; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1549 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1550 for (c = 0; c < translate_len; c++) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1551 if (translate[c] != c) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1552 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1553 char buf[20]; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1554 char *bufend; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1555 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1556 if (alternate_heading) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1557 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1558 insert_string (alternate_heading); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1559 alternate_heading = 0; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1560 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1561 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1562 bufend = push_key_description (translate[c], buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1563 insert (buf, bufend - buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1564 Findent_to (make_number (16), make_number (1)); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1565 bufend = push_key_description (c, buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1566 insert (buf, bufend - buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1567 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1568 insert ("\n", 1); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1569 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1570 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1571 insert ("\n", 1); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1572 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1573 |
465 | 1574 { |
1575 int i, nmaps; | |
1576 Lisp_Object *modes, *maps; | |
1577 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1578 /* Temporarily switch to descbuf, so that we can get that buffer's |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1579 minor modes correctly. */ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1580 Fset_buffer (descbuf); |
465 | 1581 nmaps = current_minor_maps (&modes, &maps); |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1582 Fset_buffer (Vstandard_output); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1583 |
465 | 1584 for (i = 0; i < nmaps; i++) |
1585 { | |
1586 if (XTYPE (modes[i]) == Lisp_Symbol) | |
1587 { | |
1588 insert_char ('`'); | |
1589 insert_string (XSYMBOL (modes[i])->name->data); | |
1590 insert_char ('\''); | |
1591 } | |
1592 else | |
1593 insert_string ("Strangely Named"); | |
1594 insert_string (" Minor Mode Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1595 insert_string (key_heading); |
465 | 1596 describe_map_tree (maps[i], 0, Qnil); |
1597 insert_char ('\n'); | |
1598 } | |
1599 } | |
1600 | |
250 | 1601 start1 = XBUFFER (descbuf)->keymap; |
485 | 1602 if (!NILP (start1)) |
250 | 1603 { |
1604 insert_string ("Local Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1605 insert_string (key_heading); |
465 | 1606 describe_map_tree (start1, 0, Qnil); |
250 | 1607 insert_string ("\n"); |
1608 } | |
1609 | |
1610 insert_string ("Global Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1611 if (NILP (start1)) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1612 insert_string (key_heading); |
250 | 1613 |
465 | 1614 describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap); |
250 | 1615 |
1616 Fset_buffer (descbuf); | |
1617 return Qnil; | |
1618 } | |
1619 | |
1620 /* Insert a desription of the key bindings in STARTMAP, | |
1621 followed by those of all maps reachable through STARTMAP. | |
1622 If PARTIAL is nonzero, omit certain "uninteresting" commands | |
1623 (such as `undefined'). | |
1624 If SHADOW is non-nil, it is another map; | |
1625 don't mention keys which would be shadowed by it. */ | |
1626 | |
1627 void | |
1628 describe_map_tree (startmap, partial, shadow) | |
1629 Lisp_Object startmap, shadow; | |
1630 int partial; | |
1631 { | |
1632 register Lisp_Object elt, sh; | |
1633 Lisp_Object maps; | |
1634 struct gcpro gcpro1; | |
1635 | |
1636 maps = Faccessible_keymaps (startmap); | |
1637 GCPRO1 (maps); | |
1638 | |
485 | 1639 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1640 { |
1641 elt = Fcar (maps); | |
1642 sh = Fcar (elt); | |
1643 | |
1644 /* If there is no shadow keymap given, don't shadow. */ | |
485 | 1645 if (NILP (shadow)) |
250 | 1646 sh = Qnil; |
1647 | |
1648 /* If the sequence by which we reach this keymap is zero-length, | |
1649 then the shadow map for this keymap is just SHADOW. */ | |
1650 else if ((XTYPE (sh) == Lisp_String | |
1651 && XSTRING (sh)->size == 0) | |
1652 || (XTYPE (sh) == Lisp_Vector | |
1653 && XVECTOR (sh)->size == 0)) | |
1654 sh = shadow; | |
1655 | |
1656 /* If the sequence by which we reach this keymap actually has | |
1657 some elements, then the sequence's definition in SHADOW is | |
1658 what we should use. */ | |
1659 else | |
1660 { | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1661 sh = Flookup_key (shadow, Fcar (elt), Qt); |
250 | 1662 if (XTYPE (sh) == Lisp_Int) |
1663 sh = Qnil; | |
1664 } | |
1665 | |
1666 /* If sh is null (meaning that the current map is not shadowed), | |
1667 or a keymap (meaning that bindings from the current map might | |
1668 show through), describe the map. Otherwise, sh is a command | |
1669 that completely shadows the current map, and we shouldn't | |
1670 bother. */ | |
485 | 1671 if (NILP (sh) || !NILP (Fkeymapp (sh))) |
250 | 1672 describe_map (Fcdr (elt), Fcar (elt), partial, sh); |
1673 } | |
1674 | |
1675 UNGCPRO; | |
1676 } | |
1677 | |
1678 static void | |
1679 describe_command (definition) | |
1680 Lisp_Object definition; | |
1681 { | |
1682 register Lisp_Object tem1; | |
1683 | |
1684 Findent_to (make_number (16), make_number (1)); | |
1685 | |
1686 if (XTYPE (definition) == Lisp_Symbol) | |
1687 { | |
1688 XSET (tem1, Lisp_String, XSYMBOL (definition)->name); | |
1689 insert1 (tem1); | |
1690 insert_string ("\n"); | |
1691 } | |
1692 else | |
1693 { | |
1694 tem1 = Fkeymapp (definition); | |
485 | 1695 if (!NILP (tem1)) |
250 | 1696 insert_string ("Prefix Command\n"); |
1697 else | |
1698 insert_string ("??\n"); | |
1699 } | |
1700 } | |
1701 | |
1702 /* Describe the contents of map MAP, assuming that this map itself is | |
1703 reached by the sequence of prefix keys KEYS (a string or vector). | |
1704 PARTIAL, SHADOW is as in `describe_map_tree' above. */ | |
1705 | |
1706 static void | |
1707 describe_map (map, keys, partial, shadow) | |
1708 Lisp_Object map, keys; | |
1709 int partial; | |
1710 Lisp_Object shadow; | |
1711 { | |
1712 register Lisp_Object keysdesc; | |
1713 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
1714 if (!NILP (keys) && XFASTINT (Flength (keys)) > 0) |
1890
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1715 { |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1716 Lisp_Object tem; |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1717 /* Call Fkey_description first, to avoid GC bug for the other string. */ |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1718 tem = Fkey_description (keys); |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1719 keysdesc = concat2 (tem, build_string (" ")); |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1720 } |
250 | 1721 else |
1722 keysdesc = Qnil; | |
1723 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1724 describe_map_2 (map, keysdesc, describe_command, partial, shadow); |
250 | 1725 } |
1726 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1727 /* Insert a description of KEYMAP into the current buffer. */ |
250 | 1728 |
1729 static void | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1730 describe_map_2 (keymap, elt_prefix, elt_describer, partial, shadow) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1731 register Lisp_Object keymap; |
250 | 1732 Lisp_Object elt_prefix; |
1733 int (*elt_describer) (); | |
1734 int partial; | |
1735 Lisp_Object shadow; | |
1736 { | |
1737 Lisp_Object this; | |
1738 Lisp_Object tem1, tem2 = Qnil; | |
1739 Lisp_Object suppress; | |
1740 Lisp_Object kludge; | |
1741 int first = 1; | |
1742 struct gcpro gcpro1, gcpro2, gcpro3; | |
1743 | |
1744 if (partial) | |
1745 suppress = intern ("suppress-keymap"); | |
1746 | |
1747 /* This vector gets used to present single keys to Flookup_key. Since | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1748 that is done once per keymap element, we don't want to cons up a |
250 | 1749 fresh vector every time. */ |
1750 kludge = Fmake_vector (make_number (1), Qnil); | |
1751 | |
1752 GCPRO3 (elt_prefix, tem2, kludge); | |
1753 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1754 for (; CONSP (keymap); keymap = Fcdr (keymap)) |
250 | 1755 { |
1756 QUIT; | |
1757 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1758 if (XTYPE (XCONS (keymap)->car) == Lisp_Vector) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1759 describe_vector (XCONS (keymap)->car, |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1760 elt_prefix, elt_describer, partial, shadow); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1761 else |
250 | 1762 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1763 tem1 = Fcar_safe (Fcar (keymap)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1764 tem2 = get_keyelt (Fcdr_safe (Fcar (keymap))); |
250 | 1765 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1766 /* Don't show undefined commands or suppressed commands. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1767 if (NILP (tem2)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1768 if (XTYPE (tem2) == Lisp_Symbol && partial) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1769 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1770 this = Fget (tem2, suppress); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1771 if (!NILP (this)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1772 continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1773 } |
250 | 1774 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1775 /* Don't show a command that isn't really visible |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1776 because a local definition of the same key shadows it. */ |
250 | 1777 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1778 if (!NILP (shadow)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1779 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1780 Lisp_Object tem; |
250 | 1781 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1782 XVECTOR (kludge)->contents[0] = tem1; |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1783 tem = Flookup_key (shadow, kludge, Qt); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1784 if (!NILP (tem)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1785 } |
250 | 1786 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1787 if (first) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1788 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1789 insert ("\n", 1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1790 first = 0; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1791 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1792 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1793 if (!NILP (elt_prefix)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1794 insert1 (elt_prefix); |
250 | 1795 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1796 /* THIS gets the string to describe the character TEM1. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1797 this = Fsingle_key_description (tem1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1798 insert1 (this); |
250 | 1799 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1800 /* Print a description of the definition of this character. |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1801 elt_describer will take care of spacing out far enough |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1802 for alignment purposes. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1803 (*elt_describer) (tem2); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1804 } |
250 | 1805 } |
1806 | |
1807 UNGCPRO; | |
1808 } | |
1809 | |
1810 static int | |
1811 describe_vector_princ (elt) | |
1812 Lisp_Object elt; | |
1813 { | |
1814 Fprinc (elt, Qnil); | |
1815 } | |
1816 | |
1817 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 1, 0, | |
1818 "Print on `standard-output' a description of contents of VECTOR.\n\ | |
1819 This is text showing the elements of vector matched against indices.") | |
1820 (vector) | |
1821 Lisp_Object vector; | |
1822 { | |
1823 CHECK_VECTOR (vector, 0); | |
1922
648bc44d182a
* keymap.c (Fdescribe_vector): Pass the proper number of arguments
Jim Blandy <jimb@redhat.com>
parents:
1890
diff
changeset
|
1824 describe_vector (vector, Qnil, describe_vector_princ, 0, Qnil); |
250 | 1825 } |
1826 | |
1827 describe_vector (vector, elt_prefix, elt_describer, partial, shadow) | |
1828 register Lisp_Object vector; | |
1829 Lisp_Object elt_prefix; | |
1830 int (*elt_describer) (); | |
1831 int partial; | |
1832 Lisp_Object shadow; | |
1833 { | |
1834 Lisp_Object this; | |
1835 Lisp_Object dummy; | |
1836 Lisp_Object tem1, tem2; | |
1837 register int i; | |
1838 Lisp_Object suppress; | |
1839 Lisp_Object kludge; | |
1840 int first = 1; | |
1841 struct gcpro gcpro1, gcpro2, gcpro3; | |
1842 | |
1843 tem1 = Qnil; | |
1844 | |
1845 /* This vector gets used to present single keys to Flookup_key. Since | |
1846 that is done once per vector element, we don't want to cons up a | |
1847 fresh vector every time. */ | |
1848 kludge = Fmake_vector (make_number (1), Qnil); | |
1849 GCPRO3 (elt_prefix, tem1, kludge); | |
1850 | |
1851 if (partial) | |
1852 suppress = intern ("suppress-keymap"); | |
1853 | |
1854 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1855 { | |
1856 QUIT; | |
1857 tem1 = get_keyelt (XVECTOR (vector)->contents[i]); | |
1858 | |
485 | 1859 if (NILP (tem1)) continue; |
250 | 1860 |
1861 /* Don't mention suppressed commands. */ | |
1862 if (XTYPE (tem1) == Lisp_Symbol && partial) | |
1863 { | |
1864 this = Fget (tem1, suppress); | |
485 | 1865 if (!NILP (this)) |
250 | 1866 continue; |
1867 } | |
1868 | |
1869 /* If this command in this map is shadowed by some other map, | |
1870 ignore it. */ | |
485 | 1871 if (!NILP (shadow)) |
250 | 1872 { |
1873 Lisp_Object tem; | |
1874 | |
1875 XVECTOR (kludge)->contents[0] = make_number (i); | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1876 tem = Flookup_key (shadow, kludge, Qt); |
250 | 1877 |
485 | 1878 if (!NILP (tem)) continue; |
250 | 1879 } |
1880 | |
1881 if (first) | |
1882 { | |
1883 insert ("\n", 1); | |
1884 first = 0; | |
1885 } | |
1886 | |
1887 /* Output the prefix that applies to every entry in this map. */ | |
485 | 1888 if (!NILP (elt_prefix)) |
250 | 1889 insert1 (elt_prefix); |
1890 | |
1891 /* Get the string to describe the character I, and print it. */ | |
1892 XFASTINT (dummy) = i; | |
1893 | |
1894 /* THIS gets the string to describe the character DUMMY. */ | |
1895 this = Fsingle_key_description (dummy); | |
1896 insert1 (this); | |
1897 | |
1898 /* Find all consecutive characters that have the same definition. */ | |
1899 while (i + 1 < DENSE_TABLE_SIZE | |
1900 && (tem2 = get_keyelt (XVECTOR (vector)->contents[i+1]), | |
1901 EQ (tem2, tem1))) | |
1902 i++; | |
1903 | |
1904 /* If we have a range of more than one character, | |
1905 print where the range reaches to. */ | |
1906 | |
1907 if (i != XINT (dummy)) | |
1908 { | |
1909 insert (" .. ", 4); | |
485 | 1910 if (!NILP (elt_prefix)) |
250 | 1911 insert1 (elt_prefix); |
1912 | |
1913 XFASTINT (dummy) = i; | |
1914 insert1 (Fsingle_key_description (dummy)); | |
1915 } | |
1916 | |
1917 /* Print a description of the definition of this character. | |
1918 elt_describer will take care of spacing out far enough | |
1919 for alignment purposes. */ | |
1920 (*elt_describer) (tem1); | |
1921 } | |
1922 | |
1923 UNGCPRO; | |
1924 } | |
1925 | |
465 | 1926 /* Apropos - finding all symbols whose names match a regexp. */ |
250 | 1927 Lisp_Object apropos_predicate; |
1928 Lisp_Object apropos_accumulate; | |
1929 | |
1930 static void | |
1931 apropos_accum (symbol, string) | |
1932 Lisp_Object symbol, string; | |
1933 { | |
1934 register Lisp_Object tem; | |
1935 | |
1936 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil); | |
485 | 1937 if (!NILP (tem) && !NILP (apropos_predicate)) |
250 | 1938 tem = call1 (apropos_predicate, symbol); |
485 | 1939 if (!NILP (tem)) |
250 | 1940 apropos_accumulate = Fcons (symbol, apropos_accumulate); |
1941 } | |
1942 | |
1943 DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0, | |
1944 "Show all symbols whose names contain match for REGEXP.\n\ | |
1945 If optional 2nd arg PRED is non-nil, (funcall PRED SYM) is done\n\ | |
1946 for each symbol and a symbol is mentioned only if that returns non-nil.\n\ | |
1947 Return list of symbols found.") | |
1948 (string, pred) | |
1949 Lisp_Object string, pred; | |
1950 { | |
1951 struct gcpro gcpro1, gcpro2; | |
1952 CHECK_STRING (string, 0); | |
1953 apropos_predicate = pred; | |
1954 GCPRO2 (apropos_predicate, apropos_accumulate); | |
1955 apropos_accumulate = Qnil; | |
1956 map_obarray (Vobarray, apropos_accum, string); | |
1957 apropos_accumulate = Fsort (apropos_accumulate, Qstring_lessp); | |
1958 UNGCPRO; | |
1959 return apropos_accumulate; | |
1960 } | |
1961 | |
1962 syms_of_keymap () | |
1963 { | |
1964 Lisp_Object tem; | |
1965 | |
1966 Qkeymap = intern ("keymap"); | |
1967 staticpro (&Qkeymap); | |
1968 | |
1969 /* Initialize the keymaps standardly used. | |
1970 Each one is the value of a Lisp variable, and is also | |
1971 pointed to by a C variable */ | |
1972 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1973 global_map = Fmake_keymap (Qnil); |
250 | 1974 Fset (intern ("global-map"), global_map); |
1975 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1976 meta_map = Fmake_keymap (Qnil); |
250 | 1977 Fset (intern ("esc-map"), meta_map); |
1978 Ffset (intern ("ESC-prefix"), meta_map); | |
1979 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1980 control_x_map = Fmake_keymap (Qnil); |
250 | 1981 Fset (intern ("ctl-x-map"), control_x_map); |
1982 Ffset (intern ("Control-X-prefix"), control_x_map); | |
1983 | |
1984 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map, | |
1985 "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>
parents:
647
diff
changeset
|
1986 Vminibuffer_local_map = Fmake_sparse_keymap (Qnil); |
250 | 1987 |
1988 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map, | |
1989 "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>
parents:
647
diff
changeset
|
1990 Vminibuffer_local_ns_map = Fmake_sparse_keymap (Qnil); |
250 | 1991 |
1992 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map, | |
1993 "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>
parents:
647
diff
changeset
|
1994 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); |
250 | 1995 |
1996 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, | |
1997 "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>
parents:
647
diff
changeset
|
1998 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); |
250 | 1999 |
2000 current_global_map = global_map; | |
2001 | |
465 | 2002 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, |
2003 "Alist of keymaps to use for minor modes.\n\ | |
2004 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\ | |
2005 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\ | |
2006 If two active keymaps bind the same key, the keymap appearing earlier\n\ | |
2007 in the list takes precedence."); | |
2008 Vminor_mode_map_alist = Qnil; | |
2009 | |
517 | 2010 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, |
2011 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\ | |
2012 This allows Emacs to recognize function keys sent from ASCII\n\ | |
2013 terminals at any point in a key sequence.\n\ | |
2014 \n\ | |
2015 The read-key-sequence function replaces subsequences bound by\n\ | |
2016 function-key-map with their bindings. When the current local and global\n\ | |
2017 keymaps have no binding for the current key sequence but\n\ | |
2018 function-key-map binds a suffix of the sequence to a vector,\n\ | |
2019 read-key-sequence replaces the matching suffix with its binding, and\n\ | |
2020 continues with the new sequence.\n\ | |
2021 \n\ | |
2022 For example, suppose function-key-map binds `ESC O P' to [pf1].\n\ | |
2023 Typing `ESC O P' to read-key-sequence would return [pf1]. Typing\n\ | |
2024 `C-x ESC O P' would return [?\C-x pf1]. If [pf1] were a prefix\n\ | |
2025 key, typing `ESC O P x' would return [pf1 x]."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
2026 Vfunction_key_map = Fmake_sparse_keymap (Qnil); |
517 | 2027 |
250 | 2028 Qsingle_key_description = intern ("single-key-description"); |
2029 staticpro (&Qsingle_key_description); | |
2030 | |
2031 Qkey_description = intern ("key-description"); | |
2032 staticpro (&Qkey_description); | |
2033 | |
2034 Qkeymapp = intern ("keymapp"); | |
2035 staticpro (&Qkeymapp); | |
2036 | |
2037 defsubr (&Skeymapp); | |
2038 defsubr (&Smake_keymap); | |
2039 defsubr (&Smake_sparse_keymap); | |
2040 defsubr (&Scopy_keymap); | |
2041 defsubr (&Skey_binding); | |
2042 defsubr (&Slocal_key_binding); | |
2043 defsubr (&Sglobal_key_binding); | |
465 | 2044 defsubr (&Sminor_mode_key_binding); |
250 | 2045 defsubr (&Sglobal_set_key); |
2046 defsubr (&Slocal_set_key); | |
2047 defsubr (&Sdefine_key); | |
2048 defsubr (&Slookup_key); | |
2049 defsubr (&Sglobal_unset_key); | |
2050 defsubr (&Slocal_unset_key); | |
2051 defsubr (&Sdefine_prefix_command); | |
2052 defsubr (&Suse_global_map); | |
2053 defsubr (&Suse_local_map); | |
2054 defsubr (&Scurrent_local_map); | |
2055 defsubr (&Scurrent_global_map); | |
465 | 2056 defsubr (&Scurrent_minor_mode_maps); |
250 | 2057 defsubr (&Saccessible_keymaps); |
2058 defsubr (&Skey_description); | |
2059 defsubr (&Sdescribe_vector); | |
2060 defsubr (&Ssingle_key_description); | |
2061 defsubr (&Stext_char_description); | |
2062 defsubr (&Swhere_is_internal); | |
2063 defsubr (&Swhere_is); | |
2064 defsubr (&Sdescribe_bindings); | |
2065 defsubr (&Sapropos_internal); | |
2066 } | |
2067 | |
2068 keys_of_keymap () | |
2069 { | |
2070 Lisp_Object tem; | |
2071 | |
2072 initial_define_key (global_map, 033, "ESC-prefix"); | |
2073 initial_define_key (global_map, Ctl('X'), "Control-X-prefix"); | |
2074 } |