Mercurial > emacs
annotate src/keymap.c @ 2298:872a3a2c3fed
* frame.c (Fhandle_switch_frame): Renamed from Fselect_frame.
Doc changed in anticipation of new purpose.
(Fselect_frame): Just call Fhandle_switch_frame for now.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 21 Mar 1993 06:53:04 +0000 |
parents | ce8bad247b1a |
children | ddb30eaf2f56 |
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\ |
172 A keymap is list (keymap . ALIST), a list (keymap VECTOR . ALIST),\n\ | |
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 { | |
2059 | 1142 if (c & alt_modifier) |
1143 { | |
1144 *p++ = 'A'; | |
1145 *p++ = '-'; | |
1146 c -= alt_modifier; | |
1147 } | |
1148 if (c & ctrl_modifier) | |
1149 { | |
1150 *p++ = 'C'; | |
1151 *p++ = '-'; | |
1152 c -= ctrl_modifier; | |
1153 } | |
1154 if (c & hyper_modifier) | |
1155 { | |
1156 *p++ = 'H'; | |
1157 *p++ = '-'; | |
1158 c -= hyper_modifier; | |
1159 } | |
1160 if (c & meta_modifier) | |
250 | 1161 { |
1162 *p++ = 'M'; | |
1163 *p++ = '-'; | |
2059 | 1164 c -= meta_modifier; |
1165 } | |
1166 if (c & shift_modifier) | |
1167 { | |
1168 *p++ = 'S'; | |
1169 *p++ = '-'; | |
1170 c -= shift_modifier; | |
1171 } | |
1172 if (c & super_modifier) | |
1173 { | |
1174 *p++ = 's'; | |
1175 *p++ = '-'; | |
1176 c -= super_modifier; | |
250 | 1177 } |
1178 if (c < 040) | |
1179 { | |
1180 if (c == 033) | |
1181 { | |
1182 *p++ = 'E'; | |
1183 *p++ = 'S'; | |
1184 *p++ = 'C'; | |
1185 } | |
2059 | 1186 else if (c == '\t') |
250 | 1187 { |
1188 *p++ = 'T'; | |
1189 *p++ = 'A'; | |
1190 *p++ = 'B'; | |
1191 } | |
1192 else if (c == Ctl('J')) | |
1193 { | |
1194 *p++ = 'L'; | |
1195 *p++ = 'F'; | |
1196 *p++ = 'D'; | |
1197 } | |
1198 else if (c == Ctl('M')) | |
1199 { | |
1200 *p++ = 'R'; | |
1201 *p++ = 'E'; | |
1202 *p++ = 'T'; | |
1203 } | |
1204 else | |
1205 { | |
1206 *p++ = 'C'; | |
1207 *p++ = '-'; | |
1208 if (c > 0 && c <= Ctl ('Z')) | |
1209 *p++ = c + 0140; | |
1210 else | |
1211 *p++ = c + 0100; | |
1212 } | |
1213 } | |
1214 else if (c == 0177) | |
1215 { | |
1216 *p++ = 'D'; | |
1217 *p++ = 'E'; | |
1218 *p++ = 'L'; | |
1219 } | |
1220 else if (c == ' ') | |
1221 { | |
1222 *p++ = 'S'; | |
1223 *p++ = 'P'; | |
1224 *p++ = 'C'; | |
1225 } | |
2059 | 1226 else if (c < 256) |
1227 *p++ = c; | |
250 | 1228 else |
2059 | 1229 { |
1230 *p++ = '\\'; | |
1231 *p++ = (7 & (c >> 15)) + '0'; | |
1232 *p++ = (7 & (c >> 12)) + '0'; | |
1233 *p++ = (7 & (c >> 9)) + '0'; | |
1234 *p++ = (7 & (c >> 6)) + '0'; | |
1235 *p++ = (7 & (c >> 3)) + '0'; | |
1236 *p++ = (7 & (c >> 0)) + '0'; | |
1237 } | |
250 | 1238 |
1239 return p; | |
1240 } | |
1241 | |
1242 DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0, | |
1243 "Return a pretty description of command character KEY.\n\ | |
1244 Control characters turn into C-whatever, etc.") | |
1245 (key) | |
1246 Lisp_Object key; | |
1247 { | |
2059 | 1248 char tem[20]; |
250 | 1249 |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
1250 key = EVENT_HEAD (key); |
517 | 1251 |
250 | 1252 switch (XTYPE (key)) |
1253 { | |
1254 case Lisp_Int: /* Normal character */ | |
2059 | 1255 *push_key_description (XUINT (key), tem) = 0; |
250 | 1256 return build_string (tem); |
1257 | |
1258 case Lisp_Symbol: /* Function key or event-symbol */ | |
1259 return Fsymbol_name (key); | |
1260 | |
1261 default: | |
1262 error ("KEY must be an integer, cons, or symbol."); | |
1263 } | |
1264 } | |
1265 | |
1266 char * | |
1267 push_text_char_description (c, p) | |
1268 register unsigned int c; | |
1269 register char *p; | |
1270 { | |
1271 if (c >= 0200) | |
1272 { | |
1273 *p++ = 'M'; | |
1274 *p++ = '-'; | |
1275 c -= 0200; | |
1276 } | |
1277 if (c < 040) | |
1278 { | |
1279 *p++ = '^'; | |
1280 *p++ = c + 64; /* 'A' - 1 */ | |
1281 } | |
1282 else if (c == 0177) | |
1283 { | |
1284 *p++ = '^'; | |
1285 *p++ = '?'; | |
1286 } | |
1287 else | |
1288 *p++ = c; | |
1289 return p; | |
1290 } | |
1291 | |
1292 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, | |
1293 "Return a pretty description of file-character CHAR.\n\ | |
1294 Control characters turn into \"^char\", etc.") | |
1295 (chr) | |
1296 Lisp_Object chr; | |
1297 { | |
1298 char tem[6]; | |
1299 | |
1300 CHECK_NUMBER (chr, 0); | |
1301 | |
1302 *push_text_char_description (XINT (chr) & 0377, tem) = 0; | |
1303 | |
1304 return build_string (tem); | |
1305 } | |
1306 | |
465 | 1307 /* where-is - finding a command in a set of keymaps. */ |
1308 | |
250 | 1309 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, |
1310 "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\ | |
1311 If KEYMAP is nil, search only KEYMAP1.\n\ | |
1312 If KEYMAP1 is nil, use the current global map.\n\ | |
1313 \n\ | |
1314 If optional 4th arg FIRSTONLY is non-nil,\n\ | |
1315 return a string representing the first key sequence found,\n\ | |
1316 rather than a list of all possible key sequences.\n\ | |
1317 \n\ | |
1318 If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\ | |
1319 to other keymaps or slots. This makes it possible to search for an\n\ | |
1320 indirect definition itself.") | |
1321 (definition, local_keymap, global_keymap, firstonly, noindirect) | |
1322 Lisp_Object definition, local_keymap, global_keymap; | |
1323 Lisp_Object firstonly, noindirect; | |
1324 { | |
1325 register Lisp_Object maps; | |
1326 Lisp_Object found; | |
1327 | |
485 | 1328 if (NILP (global_keymap)) |
250 | 1329 global_keymap = current_global_map; |
1330 | |
485 | 1331 if (!NILP (local_keymap)) |
250 | 1332 maps = nconc2 (Faccessible_keymaps (get_keymap (local_keymap)), |
1333 Faccessible_keymaps (get_keymap (global_keymap))); | |
1334 else | |
1335 maps = Faccessible_keymaps (get_keymap (global_keymap)); | |
1336 | |
1337 found = Qnil; | |
1338 | |
485 | 1339 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1340 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1341 /* Key sequence to reach map */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1342 register Lisp_Object this = Fcar (Fcar (maps)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1343 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1344 /* The map that it reaches */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1345 register Lisp_Object map = Fcdr (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 /* 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
|
1348 int i = 0; |
250 | 1349 |
1350 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into | |
1351 [M-CHAR] sequences, check if last character of the sequence | |
1352 is the meta-prefix char. */ | |
1353 Lisp_Object last = make_number (XINT (Flength (this)) - 1); | |
1354 int last_is_meta = (XINT (last) >= 0 | |
1355 && EQ (Faref (this, last), meta_prefix_char)); | |
1356 | |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1357 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1358 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1359 while (CONSP (map)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1360 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1361 /* 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
|
1362 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
|
1363 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
|
1364 loop body over both keymap and vector bindings. |
250 | 1365 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1366 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
|
1367 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
|
1368 have finished off the vector. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1369 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1370 Lisp_Object elt = XCONS (map)->car; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1371 Lisp_Object key, binding, sequence; |
250 | 1372 |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1373 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1374 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1375 /* 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
|
1376 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
|
1377 if (XTYPE (elt) == Lisp_Vector) |
250 | 1378 { |
1379 /* 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
|
1380 binding = XVECTOR (elt)->contents[i]; |
250 | 1381 XFASTINT (key) = i; |
1382 i++; | |
1383 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1384 /* 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
|
1385 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
|
1386 next vector we may find. */ |
250 | 1387 if (i >= DENSE_TABLE_SIZE) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1388 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1389 map = XCONS (map)->cdr; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1390 i = 0; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1391 } |
250 | 1392 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1393 else if (CONSP (elt)) |
250 | 1394 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1395 key = Fcar (Fcar (map)); |
250 | 1396 binding = Fcdr (Fcar (map)); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1397 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1398 map = XCONS (map)->cdr; |
250 | 1399 } |
1400 else | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1401 /* 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
|
1402 vectors nor conses. */ |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1403 { |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1404 map = XCONS (map)->cdr; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1405 continue; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1406 } |
250 | 1407 |
1408 /* Search through indirections unless that's not wanted. */ | |
485 | 1409 if (NILP (noindirect)) |
250 | 1410 binding = get_keyelt (binding); |
1411 | |
1412 /* End this iteration if this element does not match | |
1413 the target. */ | |
1414 | |
1415 if (XTYPE (definition) == Lisp_Cons) | |
1416 { | |
1417 Lisp_Object tem; | |
1418 tem = Fequal (binding, definition); | |
485 | 1419 if (NILP (tem)) |
250 | 1420 continue; |
1421 } | |
1422 else | |
1423 if (!EQ (binding, definition)) | |
1424 continue; | |
1425 | |
1426 /* We have found a match. | |
1427 Construct the key sequence where we found it. */ | |
1428 if (XTYPE (key) == Lisp_Int && last_is_meta) | |
1429 { | |
1430 sequence = Fcopy_sequence (this); | |
2093
ce8bad247b1a
(Fdefine_key): Use proper meta-bit to clear.
Richard M. Stallman <rms@gnu.org>
parents:
2059
diff
changeset
|
1431 Faset (sequence, last, make_number (XINT (key) | meta_modifier)); |
250 | 1432 } |
1433 else | |
1434 sequence = append_key (this, key); | |
1435 | |
1436 /* Verify that this key binding is not shadowed by another | |
1437 binding for the same key, before we say it exists. | |
1438 | |
1439 Mechanism: look for local definition of this key and if | |
1440 it is defined and does not match what we found then | |
1441 ignore this key. | |
1442 | |
1443 Either nil or number as value from Flookup_key | |
1444 means undefined. */ | |
485 | 1445 if (!NILP (local_keymap)) |
250 | 1446 { |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1447 binding = Flookup_key (local_keymap, sequence, Qnil); |
485 | 1448 if (!NILP (binding) && XTYPE (binding) != Lisp_Int) |
250 | 1449 { |
1450 if (XTYPE (definition) == Lisp_Cons) | |
1451 { | |
1452 Lisp_Object tem; | |
1453 tem = Fequal (binding, definition); | |
485 | 1454 if (NILP (tem)) |
250 | 1455 continue; |
1456 } | |
1457 else | |
1458 if (!EQ (binding, definition)) | |
1459 continue; | |
1460 } | |
1461 } | |
1462 | |
1463 /* It is a true unshadowed match. Record it. */ | |
1464 | |
485 | 1465 if (!NILP (firstonly)) |
250 | 1466 return sequence; |
1467 found = Fcons (sequence, found); | |
1468 } | |
1469 } | |
1470 return Fnreverse (found); | |
1471 } | |
1472 | |
1473 /* Return a string listing the keys and buttons that run DEFINITION. */ | |
1474 | |
1475 static Lisp_Object | |
1476 where_is_string (definition) | |
1477 Lisp_Object definition; | |
1478 { | |
1479 register Lisp_Object keys, keys1; | |
1480 | |
1481 keys = Fwhere_is_internal (definition, | |
1482 current_buffer->keymap, Qnil, Qnil, Qnil); | |
1483 keys1 = Fmapconcat (Qkey_description, keys, build_string (", ")); | |
1484 | |
1485 return keys1; | |
1486 } | |
1487 | |
1488 DEFUN ("where-is", Fwhere_is, Swhere_is, 1, 1, "CWhere is command: ", | |
1489 "Print message listing key sequences that invoke specified command.\n\ | |
1490 Argument is a command definition, usually a symbol with a function definition.") | |
1491 (definition) | |
1492 Lisp_Object definition; | |
1493 { | |
1494 register Lisp_Object string; | |
1495 | |
1496 CHECK_SYMBOL (definition, 0); | |
1497 string = where_is_string (definition); | |
1498 | |
1499 if (XSTRING (string)->size) | |
1500 message ("%s is on %s", XSYMBOL (definition)->name->data, | |
1501 XSTRING (string)->data); | |
1502 else | |
1503 message ("%s is not on any key", XSYMBOL (definition)->name->data); | |
1504 return Qnil; | |
1505 } | |
1506 | |
465 | 1507 /* describe-bindings - summarizing all the bindings in a set of keymaps. */ |
1508 | |
250 | 1509 DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "", |
1510 "Show a list of all defined keys, and their definitions.\n\ | |
1511 The list is put in a buffer, which is displayed.") | |
1512 () | |
1513 { | |
1514 register Lisp_Object thisbuf; | |
1515 XSET (thisbuf, Lisp_Buffer, current_buffer); | |
1516 internal_with_output_to_temp_buffer ("*Help*", | |
1517 describe_buffer_bindings, | |
1518 thisbuf); | |
1519 return Qnil; | |
1520 } | |
1521 | |
1522 static Lisp_Object | |
1523 describe_buffer_bindings (descbuf) | |
1524 Lisp_Object descbuf; | |
1525 { | |
1526 register Lisp_Object start1, start2; | |
1527 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1528 char *key_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1529 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1530 key binding\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1531 --- -------\n"; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1532 char *alternate_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1533 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1534 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
|
1535 nominal alternate\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1536 ------- ---------\n"; |
250 | 1537 |
1538 Fset_buffer (Vstandard_output); | |
1539 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1540 /* 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
|
1541 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
|
1542 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1543 int c; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1544 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
|
1545 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
|
1546 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1547 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
|
1548 if (translate[c] != c) |
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 char buf[20]; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1551 char *bufend; |
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 if (alternate_heading) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1554 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1555 insert_string (alternate_heading); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1556 alternate_heading = 0; |
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 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1559 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
|
1560 insert (buf, bufend - buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1561 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
|
1562 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
|
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 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1565 insert ("\n", 1); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1566 } |
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 |
465 | 1571 { |
1572 int i, nmaps; | |
1573 Lisp_Object *modes, *maps; | |
1574 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1575 /* 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
|
1576 minor modes correctly. */ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1577 Fset_buffer (descbuf); |
465 | 1578 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
|
1579 Fset_buffer (Vstandard_output); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1580 |
465 | 1581 for (i = 0; i < nmaps; i++) |
1582 { | |
1583 if (XTYPE (modes[i]) == Lisp_Symbol) | |
1584 { | |
1585 insert_char ('`'); | |
1586 insert_string (XSYMBOL (modes[i])->name->data); | |
1587 insert_char ('\''); | |
1588 } | |
1589 else | |
1590 insert_string ("Strangely Named"); | |
1591 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
|
1592 insert_string (key_heading); |
465 | 1593 describe_map_tree (maps[i], 0, Qnil); |
1594 insert_char ('\n'); | |
1595 } | |
1596 } | |
1597 | |
250 | 1598 start1 = XBUFFER (descbuf)->keymap; |
485 | 1599 if (!NILP (start1)) |
250 | 1600 { |
1601 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
|
1602 insert_string (key_heading); |
465 | 1603 describe_map_tree (start1, 0, Qnil); |
250 | 1604 insert_string ("\n"); |
1605 } | |
1606 | |
1607 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
|
1608 if (NILP (start1)) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1609 insert_string (key_heading); |
250 | 1610 |
465 | 1611 describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap); |
250 | 1612 |
1613 Fset_buffer (descbuf); | |
1614 return Qnil; | |
1615 } | |
1616 | |
1617 /* Insert a desription of the key bindings in STARTMAP, | |
1618 followed by those of all maps reachable through STARTMAP. | |
1619 If PARTIAL is nonzero, omit certain "uninteresting" commands | |
1620 (such as `undefined'). | |
1621 If SHADOW is non-nil, it is another map; | |
1622 don't mention keys which would be shadowed by it. */ | |
1623 | |
1624 void | |
1625 describe_map_tree (startmap, partial, shadow) | |
1626 Lisp_Object startmap, shadow; | |
1627 int partial; | |
1628 { | |
1629 register Lisp_Object elt, sh; | |
1630 Lisp_Object maps; | |
1631 struct gcpro gcpro1; | |
1632 | |
1633 maps = Faccessible_keymaps (startmap); | |
1634 GCPRO1 (maps); | |
1635 | |
485 | 1636 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1637 { |
1638 elt = Fcar (maps); | |
1639 sh = Fcar (elt); | |
1640 | |
1641 /* If there is no shadow keymap given, don't shadow. */ | |
485 | 1642 if (NILP (shadow)) |
250 | 1643 sh = Qnil; |
1644 | |
1645 /* If the sequence by which we reach this keymap is zero-length, | |
1646 then the shadow map for this keymap is just SHADOW. */ | |
1647 else if ((XTYPE (sh) == Lisp_String | |
1648 && XSTRING (sh)->size == 0) | |
1649 || (XTYPE (sh) == Lisp_Vector | |
1650 && XVECTOR (sh)->size == 0)) | |
1651 sh = shadow; | |
1652 | |
1653 /* If the sequence by which we reach this keymap actually has | |
1654 some elements, then the sequence's definition in SHADOW is | |
1655 what we should use. */ | |
1656 else | |
1657 { | |
1871
00bee181f7ed
* keymap.c (Flookup_key, Fkey_binding, Flocal_key_binding,
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1658 sh = Flookup_key (shadow, Fcar (elt), Qt); |
250 | 1659 if (XTYPE (sh) == Lisp_Int) |
1660 sh = Qnil; | |
1661 } | |
1662 | |
1663 /* If sh is null (meaning that the current map is not shadowed), | |
1664 or a keymap (meaning that bindings from the current map might | |
1665 show through), describe the map. Otherwise, sh is a command | |
1666 that completely shadows the current map, and we shouldn't | |
1667 bother. */ | |
485 | 1668 if (NILP (sh) || !NILP (Fkeymapp (sh))) |
250 | 1669 describe_map (Fcdr (elt), Fcar (elt), partial, sh); |
1670 } | |
1671 | |
1672 UNGCPRO; | |
1673 } | |
1674 | |
1675 static void | |
1676 describe_command (definition) | |
1677 Lisp_Object definition; | |
1678 { | |
1679 register Lisp_Object tem1; | |
1680 | |
1681 Findent_to (make_number (16), make_number (1)); | |
1682 | |
1683 if (XTYPE (definition) == Lisp_Symbol) | |
1684 { | |
1685 XSET (tem1, Lisp_String, XSYMBOL (definition)->name); | |
1686 insert1 (tem1); | |
1687 insert_string ("\n"); | |
1688 } | |
1689 else | |
1690 { | |
1691 tem1 = Fkeymapp (definition); | |
485 | 1692 if (!NILP (tem1)) |
250 | 1693 insert_string ("Prefix Command\n"); |
1694 else | |
1695 insert_string ("??\n"); | |
1696 } | |
1697 } | |
1698 | |
1699 /* Describe the contents of map MAP, assuming that this map itself is | |
1700 reached by the sequence of prefix keys KEYS (a string or vector). | |
1701 PARTIAL, SHADOW is as in `describe_map_tree' above. */ | |
1702 | |
1703 static void | |
1704 describe_map (map, keys, partial, shadow) | |
1705 Lisp_Object map, keys; | |
1706 int partial; | |
1707 Lisp_Object shadow; | |
1708 { | |
1709 register Lisp_Object keysdesc; | |
1710 | |
1517
72b7bbcaf7d8
* keymap.c (Fdefine_key, Flookup_key, describe_map): Don't assume
Jim Blandy <jimb@redhat.com>
parents:
1441
diff
changeset
|
1711 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
|
1712 { |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1713 Lisp_Object tem; |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1714 /* 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
|
1715 tem = Fkey_description (keys); |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1716 keysdesc = concat2 (tem, build_string (" ")); |
0ca7640360bd
(describe_map): Call Fkey_description before build_string.
Richard M. Stallman <rms@gnu.org>
parents:
1871
diff
changeset
|
1717 } |
250 | 1718 else |
1719 keysdesc = Qnil; | |
1720 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1721 describe_map_2 (map, keysdesc, describe_command, partial, shadow); |
250 | 1722 } |
1723 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1724 /* Insert a description of KEYMAP into the current buffer. */ |
250 | 1725 |
1726 static void | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1727 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
|
1728 register Lisp_Object keymap; |
250 | 1729 Lisp_Object elt_prefix; |
1730 int (*elt_describer) (); | |
1731 int partial; | |
1732 Lisp_Object shadow; | |
1733 { | |
1734 Lisp_Object this; | |
1735 Lisp_Object tem1, tem2 = Qnil; | |
1736 Lisp_Object suppress; | |
1737 Lisp_Object kludge; | |
1738 int first = 1; | |
1739 struct gcpro gcpro1, gcpro2, gcpro3; | |
1740 | |
1741 if (partial) | |
1742 suppress = intern ("suppress-keymap"); | |
1743 | |
1744 /* 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
|
1745 that is done once per keymap element, we don't want to cons up a |
250 | 1746 fresh vector every time. */ |
1747 kludge = Fmake_vector (make_number (1), Qnil); | |
1748 | |
1749 GCPRO3 (elt_prefix, tem2, kludge); | |
1750 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1751 for (; CONSP (keymap); keymap = Fcdr (keymap)) |
250 | 1752 { |
1753 QUIT; | |
1754 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1755 if (XTYPE (XCONS (keymap)->car) == Lisp_Vector) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1756 describe_vector (XCONS (keymap)->car, |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1757 elt_prefix, elt_describer, partial, shadow); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1758 else |
250 | 1759 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1760 tem1 = Fcar_safe (Fcar (keymap)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1761 tem2 = get_keyelt (Fcdr_safe (Fcar (keymap))); |
250 | 1762 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1763 /* 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
|
1764 if (NILP (tem2)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1765 if (XTYPE (tem2) == Lisp_Symbol && partial) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1766 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1767 this = Fget (tem2, suppress); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1768 if (!NILP (this)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1769 continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1770 } |
250 | 1771 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1772 /* 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
|
1773 because a local definition of the same key shadows it. */ |
250 | 1774 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1775 if (!NILP (shadow)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1776 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1777 Lisp_Object tem; |
250 | 1778 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1779 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
|
1780 tem = Flookup_key (shadow, kludge, Qt); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1781 if (!NILP (tem)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1782 } |
250 | 1783 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1784 if (first) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1785 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1786 insert ("\n", 1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1787 first = 0; |
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 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1790 if (!NILP (elt_prefix)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1791 insert1 (elt_prefix); |
250 | 1792 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1793 /* 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
|
1794 this = Fsingle_key_description (tem1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1795 insert1 (this); |
250 | 1796 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1797 /* 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
|
1798 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
|
1799 for alignment purposes. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1800 (*elt_describer) (tem2); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1801 } |
250 | 1802 } |
1803 | |
1804 UNGCPRO; | |
1805 } | |
1806 | |
1807 static int | |
1808 describe_vector_princ (elt) | |
1809 Lisp_Object elt; | |
1810 { | |
1811 Fprinc (elt, Qnil); | |
1812 } | |
1813 | |
1814 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 1, 0, | |
1815 "Print on `standard-output' a description of contents of VECTOR.\n\ | |
1816 This is text showing the elements of vector matched against indices.") | |
1817 (vector) | |
1818 Lisp_Object vector; | |
1819 { | |
1820 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
|
1821 describe_vector (vector, Qnil, describe_vector_princ, 0, Qnil); |
250 | 1822 } |
1823 | |
1824 describe_vector (vector, elt_prefix, elt_describer, partial, shadow) | |
1825 register Lisp_Object vector; | |
1826 Lisp_Object elt_prefix; | |
1827 int (*elt_describer) (); | |
1828 int partial; | |
1829 Lisp_Object shadow; | |
1830 { | |
1831 Lisp_Object this; | |
1832 Lisp_Object dummy; | |
1833 Lisp_Object tem1, tem2; | |
1834 register int i; | |
1835 Lisp_Object suppress; | |
1836 Lisp_Object kludge; | |
1837 int first = 1; | |
1838 struct gcpro gcpro1, gcpro2, gcpro3; | |
1839 | |
1840 tem1 = Qnil; | |
1841 | |
1842 /* This vector gets used to present single keys to Flookup_key. Since | |
1843 that is done once per vector element, we don't want to cons up a | |
1844 fresh vector every time. */ | |
1845 kludge = Fmake_vector (make_number (1), Qnil); | |
1846 GCPRO3 (elt_prefix, tem1, kludge); | |
1847 | |
1848 if (partial) | |
1849 suppress = intern ("suppress-keymap"); | |
1850 | |
1851 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1852 { | |
1853 QUIT; | |
1854 tem1 = get_keyelt (XVECTOR (vector)->contents[i]); | |
1855 | |
485 | 1856 if (NILP (tem1)) continue; |
250 | 1857 |
1858 /* Don't mention suppressed commands. */ | |
1859 if (XTYPE (tem1) == Lisp_Symbol && partial) | |
1860 { | |
1861 this = Fget (tem1, suppress); | |
485 | 1862 if (!NILP (this)) |
250 | 1863 continue; |
1864 } | |
1865 | |
1866 /* If this command in this map is shadowed by some other map, | |
1867 ignore it. */ | |
485 | 1868 if (!NILP (shadow)) |
250 | 1869 { |
1870 Lisp_Object tem; | |
1871 | |
1872 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
|
1873 tem = Flookup_key (shadow, kludge, Qt); |
250 | 1874 |
485 | 1875 if (!NILP (tem)) continue; |
250 | 1876 } |
1877 | |
1878 if (first) | |
1879 { | |
1880 insert ("\n", 1); | |
1881 first = 0; | |
1882 } | |
1883 | |
1884 /* Output the prefix that applies to every entry in this map. */ | |
485 | 1885 if (!NILP (elt_prefix)) |
250 | 1886 insert1 (elt_prefix); |
1887 | |
1888 /* Get the string to describe the character I, and print it. */ | |
1889 XFASTINT (dummy) = i; | |
1890 | |
1891 /* THIS gets the string to describe the character DUMMY. */ | |
1892 this = Fsingle_key_description (dummy); | |
1893 insert1 (this); | |
1894 | |
1895 /* Find all consecutive characters that have the same definition. */ | |
1896 while (i + 1 < DENSE_TABLE_SIZE | |
1897 && (tem2 = get_keyelt (XVECTOR (vector)->contents[i+1]), | |
1898 EQ (tem2, tem1))) | |
1899 i++; | |
1900 | |
1901 /* If we have a range of more than one character, | |
1902 print where the range reaches to. */ | |
1903 | |
1904 if (i != XINT (dummy)) | |
1905 { | |
1906 insert (" .. ", 4); | |
485 | 1907 if (!NILP (elt_prefix)) |
250 | 1908 insert1 (elt_prefix); |
1909 | |
1910 XFASTINT (dummy) = i; | |
1911 insert1 (Fsingle_key_description (dummy)); | |
1912 } | |
1913 | |
1914 /* Print a description of the definition of this character. | |
1915 elt_describer will take care of spacing out far enough | |
1916 for alignment purposes. */ | |
1917 (*elt_describer) (tem1); | |
1918 } | |
1919 | |
1920 UNGCPRO; | |
1921 } | |
1922 | |
465 | 1923 /* Apropos - finding all symbols whose names match a regexp. */ |
250 | 1924 Lisp_Object apropos_predicate; |
1925 Lisp_Object apropos_accumulate; | |
1926 | |
1927 static void | |
1928 apropos_accum (symbol, string) | |
1929 Lisp_Object symbol, string; | |
1930 { | |
1931 register Lisp_Object tem; | |
1932 | |
1933 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil); | |
485 | 1934 if (!NILP (tem) && !NILP (apropos_predicate)) |
250 | 1935 tem = call1 (apropos_predicate, symbol); |
485 | 1936 if (!NILP (tem)) |
250 | 1937 apropos_accumulate = Fcons (symbol, apropos_accumulate); |
1938 } | |
1939 | |
1940 DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0, | |
1941 "Show all symbols whose names contain match for REGEXP.\n\ | |
1942 If optional 2nd arg PRED is non-nil, (funcall PRED SYM) is done\n\ | |
1943 for each symbol and a symbol is mentioned only if that returns non-nil.\n\ | |
1944 Return list of symbols found.") | |
1945 (string, pred) | |
1946 Lisp_Object string, pred; | |
1947 { | |
1948 struct gcpro gcpro1, gcpro2; | |
1949 CHECK_STRING (string, 0); | |
1950 apropos_predicate = pred; | |
1951 GCPRO2 (apropos_predicate, apropos_accumulate); | |
1952 apropos_accumulate = Qnil; | |
1953 map_obarray (Vobarray, apropos_accum, string); | |
1954 apropos_accumulate = Fsort (apropos_accumulate, Qstring_lessp); | |
1955 UNGCPRO; | |
1956 return apropos_accumulate; | |
1957 } | |
1958 | |
1959 syms_of_keymap () | |
1960 { | |
1961 Lisp_Object tem; | |
1962 | |
1963 Qkeymap = intern ("keymap"); | |
1964 staticpro (&Qkeymap); | |
1965 | |
1966 /* Initialize the keymaps standardly used. | |
1967 Each one is the value of a Lisp variable, and is also | |
1968 pointed to by a C variable */ | |
1969 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1970 global_map = Fmake_keymap (Qnil); |
250 | 1971 Fset (intern ("global-map"), global_map); |
1972 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1973 meta_map = Fmake_keymap (Qnil); |
250 | 1974 Fset (intern ("esc-map"), meta_map); |
1975 Ffset (intern ("ESC-prefix"), meta_map); | |
1976 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1977 control_x_map = Fmake_keymap (Qnil); |
250 | 1978 Fset (intern ("ctl-x-map"), control_x_map); |
1979 Ffset (intern ("Control-X-prefix"), control_x_map); | |
1980 | |
1981 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map, | |
1982 "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
|
1983 Vminibuffer_local_map = Fmake_sparse_keymap (Qnil); |
250 | 1984 |
1985 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map, | |
1986 "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
|
1987 Vminibuffer_local_ns_map = Fmake_sparse_keymap (Qnil); |
250 | 1988 |
1989 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map, | |
1990 "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
|
1991 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); |
250 | 1992 |
1993 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, | |
1994 "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
|
1995 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); |
250 | 1996 |
1997 current_global_map = global_map; | |
1998 | |
465 | 1999 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, |
2000 "Alist of keymaps to use for minor modes.\n\ | |
2001 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\ | |
2002 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\ | |
2003 If two active keymaps bind the same key, the keymap appearing earlier\n\ | |
2004 in the list takes precedence."); | |
2005 Vminor_mode_map_alist = Qnil; | |
2006 | |
517 | 2007 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, |
2008 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\ | |
2009 This allows Emacs to recognize function keys sent from ASCII\n\ | |
2010 terminals at any point in a key sequence.\n\ | |
2011 \n\ | |
2012 The read-key-sequence function replaces subsequences bound by\n\ | |
2013 function-key-map with their bindings. When the current local and global\n\ | |
2014 keymaps have no binding for the current key sequence but\n\ | |
2015 function-key-map binds a suffix of the sequence to a vector,\n\ | |
2016 read-key-sequence replaces the matching suffix with its binding, and\n\ | |
2017 continues with the new sequence.\n\ | |
2018 \n\ | |
2019 For example, suppose function-key-map binds `ESC O P' to [pf1].\n\ | |
2020 Typing `ESC O P' to read-key-sequence would return [pf1]. Typing\n\ | |
2021 `C-x ESC O P' would return [?\C-x pf1]. If [pf1] were a prefix\n\ | |
2022 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
|
2023 Vfunction_key_map = Fmake_sparse_keymap (Qnil); |
517 | 2024 |
250 | 2025 Qsingle_key_description = intern ("single-key-description"); |
2026 staticpro (&Qsingle_key_description); | |
2027 | |
2028 Qkey_description = intern ("key-description"); | |
2029 staticpro (&Qkey_description); | |
2030 | |
2031 Qkeymapp = intern ("keymapp"); | |
2032 staticpro (&Qkeymapp); | |
2033 | |
2034 defsubr (&Skeymapp); | |
2035 defsubr (&Smake_keymap); | |
2036 defsubr (&Smake_sparse_keymap); | |
2037 defsubr (&Scopy_keymap); | |
2038 defsubr (&Skey_binding); | |
2039 defsubr (&Slocal_key_binding); | |
2040 defsubr (&Sglobal_key_binding); | |
465 | 2041 defsubr (&Sminor_mode_key_binding); |
250 | 2042 defsubr (&Sglobal_set_key); |
2043 defsubr (&Slocal_set_key); | |
2044 defsubr (&Sdefine_key); | |
2045 defsubr (&Slookup_key); | |
2046 defsubr (&Sglobal_unset_key); | |
2047 defsubr (&Slocal_unset_key); | |
2048 defsubr (&Sdefine_prefix_command); | |
2049 defsubr (&Suse_global_map); | |
2050 defsubr (&Suse_local_map); | |
2051 defsubr (&Scurrent_local_map); | |
2052 defsubr (&Scurrent_global_map); | |
465 | 2053 defsubr (&Scurrent_minor_mode_maps); |
250 | 2054 defsubr (&Saccessible_keymaps); |
2055 defsubr (&Skey_description); | |
2056 defsubr (&Sdescribe_vector); | |
2057 defsubr (&Ssingle_key_description); | |
2058 defsubr (&Stext_char_description); | |
2059 defsubr (&Swhere_is_internal); | |
2060 defsubr (&Swhere_is); | |
2061 defsubr (&Sdescribe_bindings); | |
2062 defsubr (&Sapropos_internal); | |
2063 } | |
2064 | |
2065 keys_of_keymap () | |
2066 { | |
2067 Lisp_Object tem; | |
2068 | |
2069 initial_define_key (global_map, 033, "ESC-prefix"); | |
2070 initial_define_key (global_map, Ctl('X'), "Control-X-prefix"); | |
2071 } |