Mercurial > hg > xemacs-beta
annotate src/keymap.c @ 5182:2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
lisp/ChangeLog addition:
2010-04-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el (fill, sort*, merge): Move these functions to fns.c.
(stable-sort): Make this docstring reflect the argument names used
in the #'sort* docstring.
* cl-macs.el (stable-sort): Make #'stable-sort exactly equivalent
to #'sort* in compiled code.
* bytecomp.el (byte-compile-maybe-add-*):
New macro, for functions like #'sort and #'mapcar that, to be
strictly compatible, should only take two args, but in our
implementation can take more, because they're aliases of #'sort*
and #'mapcar*.
(byte-compile-mapcar, byte-compile-sort, byte-compile-fillarray):
Use this new macro.
(map-into): Add a byte-compile method for #'map-into in passing.
* apropos.el (apropos-print): Use #'sort* with a :key argument,
now it's in C.
* compat.el (extent-at): Ditto.
* register.el (list-registers): Ditto.
* package-ui.el (pui-list-packages): Ditto.
* help.el (sorted-key-descriptions): Ditto.
src/ChangeLog addition:
2010-03-31 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (STRING_DATA_TO_OBJECT_ARRAY)
(BIT_VECTOR_TO_OBJECT_ARRAY, c_merge_predicate_key)
(c_merge_predicate_nokey, list_merge, array_merge)
(list_array_merge_into_list, list_list_merge_into_array)
(list_array_merge_into_array, CHECK_KEY_ARGUMENT, Fmerge)
(list_sort, array_sort, FsortX):
Move #'sort*, #'fill, #'merge from cl-seq.el to C, extending the
implementations of Fsort, Ffillarray, and merge() to do so.
* keymap.c (keymap_submaps, map_keymap_sort_predicate)
(describe_map_sort_predicate):
Change the calling semantics of the C sort predicates to return a
non-nil Lisp object if the first argument is less than the second,
rather than C integers.
* fontcolor-msw.c (sort_font_list_function):
* fileio.c (build_annotations):
* dired.c (Fdirectory_files):
* abbrev.c (Finsert_abbrev_table_description):
Call list_sort instead of Fsort, list_merge instead of merge() in
these functions.
man/ChangeLog addition:
2010-04-01 Aidan Kehoe <kehoea@parhasard.net>
* lispref/lists.texi (Rearrangement):
Update the documentation of #'sort here, now that it accepts any
type of sequence and the KEY keyword argument. (Though this is
probably now the wrong place for this function, given that.)
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 01 Apr 2010 20:22:50 +0100 |
parents | 88bd4f3ef8e4 |
children | f283b08ff0c9 |
rev | line source |
---|---|
428 | 1 /* Manipulation of keymaps |
2 Copyright (C) 1985, 1991-1995 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Board of Trustees, University of Illinois. | |
4 Copyright (C) 1995 Sun Microsystems, Inc. | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
5 Copyright (C) 2001, 2002, 2010 Ben Wing. |
428 | 6 Totally redesigned by jwz in 1991. |
7 | |
8 This file is part of XEmacs. | |
9 | |
10 XEmacs is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
12 Free Software Foundation; either version 2, or (at your option) any | |
13 later version. | |
14 | |
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with XEmacs; see the file COPYING. If not, write to | |
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 Boston, MA 02111-1307, USA. */ | |
24 | |
25 /* Synched up with: Mule 2.0. Not synched with FSF. Substantially | |
26 different from FSF. */ | |
27 | |
28 | |
29 #include <config.h> | |
30 #include "lisp.h" | |
31 | |
32 #include "buffer.h" | |
33 #include "bytecode.h" | |
872 | 34 #include "console-impl.h" |
428 | 35 #include "elhash.h" |
36 #include "events.h" | |
872 | 37 #include "extents.h" |
428 | 38 #include "frame.h" |
39 #include "insdel.h" | |
40 #include "keymap.h" | |
41 #include "window.h" | |
42 | |
43 | |
44 /* A keymap contains six slots: | |
45 | |
46 parents Ordered list of keymaps to search after | |
47 this one if no match is found. | |
48 Keymaps can thus be arranged in a hierarchy. | |
49 | |
50 table A hash table, hashing keysyms to their bindings. | |
51 It will be one of the following: | |
52 | |
3025 | 53 -- a symbol, e.g. `home' |
428 | 54 -- a character, representing something printable |
55 (not ?\C-c meaning C-c, for instance) | |
56 -- an integer representing a modifier combination | |
57 | |
58 inverse_table A hash table, hashing bindings to the list of keysyms | |
59 in this keymap which are bound to them. This is to make | |
60 the Fwhere_is_internal() function be fast. It needs to be | |
61 fast because we want to be able to call it in realtime to | |
62 update the keyboard-equivalents on the pulldown menus. | |
63 Values of the table are either atoms (keysyms) | |
64 or a dotted list of keysyms. | |
65 | |
66 sub_maps_cache An alist; for each entry in this keymap whose binding is | |
67 a keymap (that is, Fkeymapp()) this alist associates that | |
68 keysym with that binding. This is used to optimize both | |
69 Fwhere_is_internal() and Faccessible_keymaps(). This slot | |
70 gets set to the symbol `t' every time a change is made to | |
71 this keymap, causing it to be recomputed when next needed. | |
72 | |
73 prompt See `set-keymap-prompt'. | |
74 | |
75 default_binding See `set-keymap-default-binding'. | |
76 | |
77 Sequences of keys are stored in the obvious way: if the sequence of keys | |
78 "abc" was bound to some command `foo', the hierarchy would look like | |
79 | |
80 keymap-1: associates "a" with keymap-2 | |
81 keymap-2: associates "b" with keymap-3 | |
82 keymap-3: associates "c" with foo | |
83 | |
84 However, bucky bits ("modifiers" to the X-minded) are represented in the | |
85 keymap hierarchy as well. (This lets us use EQable objects as hash keys.) | |
86 Each combination of modifiers (e.g. control-hyper) gets its own submap | |
87 off of the main map. The hash key for a modifier combination is | |
88 an integer, computed by MAKE_MODIFIER_HASH_KEY(). | |
89 | |
90 If the key `C-a' was bound to some command, the hierarchy would look like | |
91 | |
442 | 92 keymap-1: associates the integer XEMACS_MOD_CONTROL with keymap-2 |
428 | 93 keymap-2: associates "a" with the command |
94 | |
95 Similarly, if the key `C-H-a' was bound to some command, the hierarchy | |
96 would look like | |
97 | |
442 | 98 keymap-1: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) |
428 | 99 with keymap-2 |
100 keymap-2: associates "a" with the command | |
101 | |
102 Note that a special exception is made for the meta modifier, in order | |
103 to deal with ESC/meta lossage. Any key combination containing the | |
104 meta modifier is first indexed off of the main map into the meta | |
442 | 105 submap (with hash key XEMACS_MOD_META) and then indexed off of the |
428 | 106 meta submap with the meta modifier removed from the key combination. |
107 For example, when associating a command with C-M-H-a, we'd have | |
108 | |
442 | 109 keymap-1: associates the integer XEMACS_MOD_META with keymap-2 |
110 keymap-2: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) | |
428 | 111 with keymap-3 |
112 keymap-3: associates "a" with the command | |
113 | |
114 Note that keymap-2 might have normal bindings in it; these would be | |
115 for key combinations containing only the meta modifier, such as | |
116 M-y or meta-backspace. | |
117 | |
118 If the command that "a" was bound to in keymap-3 was itself a keymap, | |
119 then that would make the key "C-M-H-a" be a prefix character. | |
120 | |
121 Note that this new model of keymaps takes much of the magic away from | |
122 the Escape key: the value of the variable `esc-map' is no longer indexed | |
123 in the `global-map' under the ESC key. It's indexed under the integer | |
442 | 124 XEMACS_MOD_META. This is not user-visible, however; none of the "bucky" |
428 | 125 maps are. |
126 | |
127 There is a hack in Flookup_key() that makes (lookup-key global-map "\^[") | |
128 and (define-key some-random-map "\^[" my-esc-map) work as before, for | |
129 compatibility. | |
130 | |
131 Since keymaps are opaque, the only way to extract information from them | |
132 is with the functions lookup-key, key-binding, local-key-binding, and | |
133 global-key-binding, which work just as before, and the new function | |
440 | 134 map-keymap, which is roughly analogous to maphash. |
428 | 135 |
136 Note that map-keymap perpetuates the illusion that the "bucky" submaps | |
137 don't exist: if you map over a keymap with bucky submaps, it will also | |
138 map over those submaps. It does not, however, map over other random | |
139 submaps of the keymap, just the bucky ones. | |
140 | |
141 One implication of this is that when you map over `global-map', you will | |
142 also map over `esc-map'. It is merely for compatibility that the esc-map | |
143 is accessible at all; I think that's a bad thing, since it blurs the | |
144 distinction between ESC and "meta" even more. "M-x" is no more a two- | |
145 key sequence than "C-x" is. | |
146 | |
147 */ | |
148 | |
440 | 149 struct Lisp_Keymap |
428 | 150 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
151 NORMAL_LISP_OBJECT_HEADER header; |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
152 #define MARKED_SLOT(x) Lisp_Object x; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
153 #include "keymap-slots.h" |
440 | 154 }; |
428 | 155 |
156 #define MAKE_MODIFIER_HASH_KEY(modifier) make_int (modifier) | |
157 #define MODIFIER_HASH_KEY_BITS(x) (INTP (x) ? XINT (x) : 0) | |
158 | |
159 | |
160 | |
161 /* Actually allocate storage for these variables */ | |
162 | |
440 | 163 Lisp_Object Vcurrent_global_map; /* Always a keymap */ |
428 | 164 |
771 | 165 static Lisp_Object Vglobal_tty_map, Vglobal_window_system_map; |
166 | |
428 | 167 static Lisp_Object Vmouse_grabbed_buffer; |
168 | |
169 /* Alist of minor mode variables and keymaps. */ | |
170 static Lisp_Object Qminor_mode_map_alist; | |
171 | |
172 static Lisp_Object Voverriding_local_map; | |
173 | |
174 static Lisp_Object Vkey_translation_map; | |
175 | |
176 static Lisp_Object Vvertical_divider_map; | |
177 | |
178 /* This is incremented whenever a change is made to a keymap. This is | |
179 so that things which care (such as the menubar code) can recompute | |
180 privately-cached data when the user has changed keybindings. | |
181 */ | |
458 | 182 Fixnum keymap_tick; |
428 | 183 |
184 /* Prefixing a key with this character is the same as sending a meta bit. */ | |
185 Lisp_Object Vmeta_prefix_char; | |
186 | |
187 Lisp_Object Qkeymapp; | |
188 Lisp_Object Vsingle_space_string; | |
189 Lisp_Object Qsuppress_keymap; | |
190 Lisp_Object Qmodeline_map; | |
191 Lisp_Object Qtoolbar_map; | |
192 | |
193 EXFUN (Fkeymap_fullness, 1); | |
194 EXFUN (Fset_keymap_name, 2); | |
195 EXFUN (Fsingle_key_description, 1); | |
196 | |
197 static void describe_command (Lisp_Object definition, Lisp_Object buffer); | |
198 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, | |
199 void (*elt_describer) (Lisp_Object, Lisp_Object), | |
200 int partial, | |
201 Lisp_Object shadow, | |
202 int mice_only_p, | |
203 Lisp_Object buffer); | |
440 | 204 static Lisp_Object keymap_submaps (Lisp_Object keymap); |
428 | 205 |
206 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
207 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
208 #define INCLUDE_BUTTON_ZERO |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
209 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
210 Lisp_Object Qbutton##num; \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
211 Lisp_Object Qbutton##num##up; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
212 #include "keymap-buttons.h" |
428 | 213 |
214 Lisp_Object Qmenu_selection; | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
215 |
428 | 216 /* Emacs compatibility */ |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
217 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
218 Lisp_Object Qmouse_##num; \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
219 Lisp_Object Qdown_mouse_##num; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
220 #include "keymap-buttons.h" |
428 | 221 |
222 /* Kludge kludge kludge */ | |
223 Lisp_Object QLFD, QTAB, QRET, QESC, QDEL, QSPC, QBS; | |
224 | |
225 | |
226 /************************************************************************/ | |
227 /* The keymap Lisp object */ | |
228 /************************************************************************/ | |
229 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
230 /* Keymaps are equal if Faces are equal if all of their display attributes are equal. We |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
231 don't compare names or doc-strings, because that would make equal |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
232 be eq. |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
233 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
234 This isn't concerned with "unspecified" attributes, that's what |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
235 #'face-differs-from-default-p is for. */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
236 static int |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
237 keymap_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
238 int UNUSED (foldcase)) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
239 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
240 Lisp_Keymap *k1 = XKEYMAP (obj1); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
241 Lisp_Keymap *k2 = XKEYMAP (obj2); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
242 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
243 depth++; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
244 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
245 return |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
246 ( |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
247 #define MARKED_SLOT(x) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
248 internal_equal (k1->x, k2->x, depth) && |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
249 #define MARKED_SLOT_NOCOMPARE(x) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
250 #include "keymap-slots.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
251 1 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
252 ); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
253 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
254 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
255 static Hashcode |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
256 keymap_hash (Lisp_Object obj, int depth) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
257 { |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
258 Lisp_Keymap *k = XKEYMAP (obj); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
259 Hashcode hash = 0xCAFEBABE; /* why not? */ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
260 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
261 depth++; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
262 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
263 #define MARKED_SLOT(x) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
264 hash = HASH2 (hash, internal_hash (k->x, depth)); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
265 #define MARKED_SLOT_NOCOMPARE(x) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
266 #include "keymap-slots.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
267 |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
268 return hash; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
269 } |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
270 |
428 | 271 static Lisp_Object |
272 mark_keymap (Lisp_Object obj) | |
273 { | |
274 Lisp_Keymap *keymap = XKEYMAP (obj); | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
275 #define MARKED_SLOT(x) mark_object (keymap->x); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
276 #include "keymap-slots.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
277 return Qnil; |
428 | 278 } |
279 | |
280 static void | |
2286 | 281 print_keymap (Lisp_Object obj, Lisp_Object printcharfun, |
282 int UNUSED (escapeflag)) | |
428 | 283 { |
284 /* This function can GC */ | |
285 Lisp_Keymap *keymap = XKEYMAP (obj); | |
286 if (print_readably) | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5128
diff
changeset
|
287 printing_unreadable_lisp_object (obj, 0); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
288 write_ascstring (printcharfun, "#<keymap "); |
428 | 289 if (!NILP (keymap->name)) |
440 | 290 { |
800 | 291 write_fmt_string_lisp (printcharfun, "%S ", 1, keymap->name); |
440 | 292 } |
800 | 293 write_fmt_string (printcharfun, "size %ld 0x%x>", |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
294 (long) XINT (Fkeymap_fullness (obj)), |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
295 LISP_OBJECT_UID (obj)); |
428 | 296 } |
297 | |
1204 | 298 static const struct memory_description keymap_description[] = { |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
299 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Keymap, x) }, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
300 #include "keymap-slots.h" |
428 | 301 { XD_END } |
302 }; | |
303 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
304 DEFINE_DUMPABLE_LISP_OBJECT ("keymap", keymap, |
5125 | 305 mark_keymap, print_keymap, 0, |
306 keymap_equal, keymap_hash, | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
307 keymap_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
308 Lisp_Keymap); |
428 | 309 |
310 /************************************************************************/ | |
311 /* Traversing keymaps and their parents */ | |
312 /************************************************************************/ | |
313 | |
314 static Lisp_Object | |
315 traverse_keymaps (Lisp_Object start_keymap, Lisp_Object start_parents, | |
316 Lisp_Object (*mapper) (Lisp_Object keymap, void *mapper_arg), | |
317 void *mapper_arg) | |
318 { | |
319 /* This function can GC */ | |
320 Lisp_Object keymap; | |
321 Lisp_Object tail = start_parents; | |
322 Lisp_Object malloc_sucks[10]; | |
323 Lisp_Object malloc_bites = Qnil; | |
324 int stack_depth = 0; | |
325 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
326 GCPRO4 (*malloc_sucks, malloc_bites, start_keymap, tail); | |
327 gcpro1.nvars = 0; | |
328 | |
329 start_keymap = get_keymap (start_keymap, 1, 1); | |
330 keymap = start_keymap; | |
331 /* Hack special-case parents at top-level */ | |
440 | 332 tail = !NILP (tail) ? tail : XKEYMAP (keymap)->parents; |
428 | 333 |
334 for (;;) | |
335 { | |
336 Lisp_Object result; | |
337 | |
338 QUIT; | |
440 | 339 result = mapper (keymap, mapper_arg); |
428 | 340 if (!NILP (result)) |
341 { | |
342 while (CONSP (malloc_bites)) | |
343 { | |
853 | 344 Lisp_Object victim = malloc_bites; |
345 malloc_bites = XCDR (victim); | |
428 | 346 free_cons (victim); |
347 } | |
348 UNGCPRO; | |
349 return result; | |
350 } | |
351 if (NILP (tail)) | |
352 { | |
353 if (stack_depth == 0) | |
354 { | |
355 UNGCPRO; | |
356 return Qnil; /* Nothing found */ | |
357 } | |
358 stack_depth--; | |
359 if (CONSP (malloc_bites)) | |
360 { | |
853 | 361 Lisp_Object victim = malloc_bites; |
362 tail = XCAR (victim); | |
363 malloc_bites = XCDR (victim); | |
428 | 364 free_cons (victim); |
365 } | |
366 else | |
367 { | |
368 tail = malloc_sucks[stack_depth]; | |
369 gcpro1.nvars = stack_depth; | |
370 } | |
371 keymap = XCAR (tail); | |
372 tail = XCDR (tail); | |
373 } | |
374 else | |
375 { | |
376 Lisp_Object parents; | |
377 | |
378 keymap = XCAR (tail); | |
379 tail = XCDR (tail); | |
380 parents = XKEYMAP (keymap)->parents; | |
381 if (!CONSP (parents)) | |
382 ; | |
383 else if (NILP (tail)) | |
384 /* Tail-recurse */ | |
385 tail = parents; | |
386 else | |
387 { | |
388 if (CONSP (malloc_bites)) | |
389 malloc_bites = noseeum_cons (tail, malloc_bites); | |
390 else if (stack_depth < countof (malloc_sucks)) | |
391 { | |
392 malloc_sucks[stack_depth++] = tail; | |
393 gcpro1.nvars = stack_depth; | |
394 } | |
395 else | |
396 { | |
397 /* *&@##[*&^$ C. @#[$*&@# Unix. Losers all. */ | |
398 int i; | |
399 for (i = 0, malloc_bites = Qnil; | |
400 i < countof (malloc_sucks); | |
401 i++) | |
402 malloc_bites = noseeum_cons (malloc_sucks[i], | |
403 malloc_bites); | |
404 gcpro1.nvars = 0; | |
405 } | |
406 tail = parents; | |
407 } | |
408 } | |
409 keymap = get_keymap (keymap, 1, 1); | |
410 if (EQ (keymap, start_keymap)) | |
411 { | |
563 | 412 invalid_argument ("Cyclic keymap indirection", start_keymap); |
428 | 413 } |
414 } | |
415 } | |
416 | |
417 | |
418 /************************************************************************/ | |
419 /* Some low-level functions */ | |
420 /************************************************************************/ | |
421 | |
442 | 422 static int |
428 | 423 bucky_sym_to_bucky_bit (Lisp_Object sym) |
424 { | |
442 | 425 if (EQ (sym, Qcontrol)) return XEMACS_MOD_CONTROL; |
426 if (EQ (sym, Qmeta)) return XEMACS_MOD_META; | |
427 if (EQ (sym, Qsuper)) return XEMACS_MOD_SUPER; | |
428 if (EQ (sym, Qhyper)) return XEMACS_MOD_HYPER; | |
429 if (EQ (sym, Qalt)) return XEMACS_MOD_ALT; | |
430 if (EQ (sym, Qsymbol)) return XEMACS_MOD_ALT; /* #### - reverse compat */ | |
431 if (EQ (sym, Qshift)) return XEMACS_MOD_SHIFT; | |
428 | 432 |
433 return 0; | |
434 } | |
435 | |
436 static Lisp_Object | |
442 | 437 control_meta_superify (Lisp_Object frob, int modifiers) |
428 | 438 { |
439 if (modifiers == 0) | |
440 return frob; | |
441 frob = Fcons (frob, Qnil); | |
442 | 442 if (modifiers & XEMACS_MOD_SHIFT) frob = Fcons (Qshift, frob); |
443 if (modifiers & XEMACS_MOD_ALT) frob = Fcons (Qalt, frob); | |
444 if (modifiers & XEMACS_MOD_HYPER) frob = Fcons (Qhyper, frob); | |
445 if (modifiers & XEMACS_MOD_SUPER) frob = Fcons (Qsuper, frob); | |
446 if (modifiers & XEMACS_MOD_CONTROL) frob = Fcons (Qcontrol, frob); | |
447 if (modifiers & XEMACS_MOD_META) frob = Fcons (Qmeta, frob); | |
428 | 448 return frob; |
449 } | |
450 | |
451 static Lisp_Object | |
934 | 452 make_key_description (const Lisp_Key_Data *key, int prettify) |
453 { | |
1204 | 454 Lisp_Object keysym = KEY_DATA_KEYSYM (key); |
934 | 455 int modifiers = KEY_DATA_MODIFIERS (key); |
428 | 456 if (prettify && CHARP (keysym)) |
457 { | |
458 /* This is a little slow, but (control a) is prettier than (control 65). | |
459 It's now ok to do this for digit-chars too, since we've fixed the | |
460 bug where \9 read as the integer 9 instead of as the symbol with | |
461 "9" as its name. | |
462 */ | |
463 /* !!#### I'm not sure how correct this is. */ | |
867 | 464 Ibyte str [1 + MAX_ICHAR_LEN]; |
465 Bytecount count = set_itext_ichar (str, XCHAR (keysym)); | |
428 | 466 str[count] = 0; |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
467 keysym = intern_istring (str); |
428 | 468 } |
469 return control_meta_superify (keysym, modifiers); | |
470 } | |
471 | |
472 | |
473 /************************************************************************/ | |
474 /* Low-level keymap-store functions */ | |
475 /************************************************************************/ | |
476 | |
477 static Lisp_Object | |
478 raw_lookup_key (Lisp_Object keymap, | |
934 | 479 const Lisp_Key_Data *raw_keys, int raw_keys_count, |
428 | 480 int keys_so_far, int accept_default); |
481 | |
482 /* Relies on caller to gc-protect args */ | |
483 static Lisp_Object | |
484 keymap_lookup_directly (Lisp_Object keymap, | |
442 | 485 Lisp_Object keysym, int modifiers) |
428 | 486 { |
487 Lisp_Keymap *k; | |
488 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
489 modifiers &= ~( |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
490 #define FROB(num) XEMACS_MOD_BUTTON##num | |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
491 #include "keymap-buttons.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
492 0); |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
493 assert ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META | |
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
494 XEMACS_MOD_SUPER | XEMACS_MOD_HYPER | |
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
495 XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) |
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
496 == 0); |
428 | 497 |
498 k = XKEYMAP (keymap); | |
499 | |
500 /* If the keysym is a one-character symbol, use the char code instead. */ | |
826 | 501 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1) |
428 | 502 { |
503 Lisp_Object i_fart_on_gcc = | |
867 | 504 make_char (string_ichar (XSYMBOL (keysym)->name, 0)); |
428 | 505 keysym = i_fart_on_gcc; |
506 } | |
507 | |
442 | 508 if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ |
428 | 509 { |
442 | 510 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
428 | 511 k->table, Qnil); |
512 if (NILP (submap)) | |
513 return Qnil; | |
514 k = XKEYMAP (submap); | |
442 | 515 modifiers &= ~XEMACS_MOD_META; |
428 | 516 } |
517 | |
518 if (modifiers != 0) | |
519 { | |
520 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), | |
521 k->table, Qnil); | |
522 if (NILP (submap)) | |
523 return Qnil; | |
524 k = XKEYMAP (submap); | |
525 } | |
526 return Fgethash (keysym, k->table, Qnil); | |
527 } | |
528 | |
529 static void | |
530 keymap_store_inverse_internal (Lisp_Object inverse_table, | |
531 Lisp_Object keysym, | |
532 Lisp_Object value) | |
533 { | |
534 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound); | |
535 | |
536 if (UNBOUNDP (keys)) | |
537 { | |
538 keys = keysym; | |
539 /* Don't cons this unless necessary */ | |
540 /* keys = Fcons (keysym, Qnil); */ | |
541 Fputhash (value, keys, inverse_table); | |
542 } | |
543 else if (!CONSP (keys)) | |
544 { | |
545 /* Now it's necessary to cons */ | |
546 keys = Fcons (keys, keysym); | |
547 Fputhash (value, keys, inverse_table); | |
548 } | |
549 else | |
550 { | |
551 while (CONSP (XCDR (keys))) | |
552 keys = XCDR (keys); | |
553 XCDR (keys) = Fcons (XCDR (keys), keysym); | |
554 /* No need to call puthash because we've destructively | |
555 modified the list tail in place */ | |
556 } | |
557 } | |
558 | |
559 | |
560 static void | |
561 keymap_delete_inverse_internal (Lisp_Object inverse_table, | |
562 Lisp_Object keysym, | |
563 Lisp_Object value) | |
564 { | |
565 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound); | |
566 Lisp_Object new_keys = keys; | |
567 Lisp_Object tail; | |
568 Lisp_Object *prev; | |
569 | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
570 assert (!UNBOUNDP (keys)); |
428 | 571 |
572 for (prev = &new_keys, tail = new_keys; | |
573 ; | |
574 prev = &(XCDR (tail)), tail = XCDR (tail)) | |
575 { | |
576 if (EQ (tail, keysym)) | |
577 { | |
578 *prev = Qnil; | |
579 break; | |
580 } | |
581 else if (EQ (keysym, XCAR (tail))) | |
582 { | |
583 *prev = XCDR (tail); | |
584 break; | |
585 } | |
586 } | |
587 | |
588 if (NILP (new_keys)) | |
589 Fremhash (value, inverse_table); | |
590 else if (!EQ (keys, new_keys)) | |
591 /* Removed the first elt */ | |
592 Fputhash (value, new_keys, inverse_table); | |
593 /* else the list's tail has been modified, so we don't need to | |
594 touch the hash table again (the pointer in there is ok). | |
595 */ | |
596 } | |
597 | |
440 | 598 /* Prevent luser from shooting herself in the foot using something like |
599 (define-key ctl-x-4-map "p" global-map) */ | |
600 static void | |
601 check_keymap_definition_loop (Lisp_Object def, Lisp_Keymap *to_keymap) | |
602 { | |
603 def = get_keymap (def, 0, 0); | |
604 | |
605 if (KEYMAPP (def)) | |
606 { | |
607 Lisp_Object maps; | |
608 | |
609 if (XKEYMAP (def) == to_keymap) | |
563 | 610 invalid_argument ("Cyclic keymap definition", def); |
440 | 611 |
612 for (maps = keymap_submaps (def); | |
613 CONSP (maps); | |
614 maps = XCDR (maps)) | |
615 check_keymap_definition_loop (XCDR (XCAR (maps)), to_keymap); | |
616 } | |
617 } | |
428 | 618 |
619 static void | |
620 keymap_store_internal (Lisp_Object keysym, Lisp_Keymap *keymap, | |
440 | 621 Lisp_Object def) |
428 | 622 { |
440 | 623 Lisp_Object prev_def = Fgethash (keysym, keymap->table, Qnil); |
624 | |
625 if (EQ (prev_def, def)) | |
428 | 626 return; |
440 | 627 |
628 check_keymap_definition_loop (def, keymap); | |
629 | |
630 if (!NILP (prev_def)) | |
428 | 631 keymap_delete_inverse_internal (keymap->inverse_table, |
440 | 632 keysym, prev_def); |
633 if (NILP (def)) | |
428 | 634 { |
635 Fremhash (keysym, keymap->table); | |
636 } | |
637 else | |
638 { | |
440 | 639 Fputhash (keysym, def, keymap->table); |
428 | 640 keymap_store_inverse_internal (keymap->inverse_table, |
440 | 641 keysym, def); |
428 | 642 } |
643 keymap_tick++; | |
644 } | |
645 | |
646 | |
647 static Lisp_Object | |
442 | 648 create_bucky_submap (Lisp_Keymap *k, int modifiers, |
428 | 649 Lisp_Object parent_for_debugging_info) |
650 { | |
651 Lisp_Object submap = Fmake_sparse_keymap (Qnil); | |
652 /* User won't see this, but it is nice for debugging Emacs */ | |
653 XKEYMAP (submap)->name | |
654 = control_meta_superify (parent_for_debugging_info, modifiers); | |
655 /* Invalidate cache */ | |
656 k->sub_maps_cache = Qt; | |
657 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (modifiers), k, submap); | |
658 return submap; | |
659 } | |
660 | |
661 | |
662 /* Relies on caller to gc-protect keymap, keysym, value */ | |
663 static void | |
934 | 664 keymap_store (Lisp_Object keymap, const Lisp_Key_Data *key, |
428 | 665 Lisp_Object value) |
666 { | |
934 | 667 Lisp_Object keysym = KEY_DATA_KEYSYM (key); |
668 int modifiers = KEY_DATA_MODIFIERS (key); | |
440 | 669 Lisp_Keymap *k = XKEYMAP (keymap); |
670 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
671 modifiers &= ~( |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
672 #define FROB(num) XEMACS_MOD_BUTTON##num | |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
673 #include "keymap-buttons.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
674 0); |
442 | 675 assert ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META |
676 | XEMACS_MOD_SUPER | XEMACS_MOD_HYPER | |
677 | XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) == 0); | |
428 | 678 |
679 /* If the keysym is a one-character symbol, use the char code instead. */ | |
826 | 680 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1) |
867 | 681 keysym = make_char (string_ichar (XSYMBOL (keysym)->name, 0)); |
428 | 682 |
442 | 683 if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ |
428 | 684 { |
442 | 685 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
428 | 686 k->table, Qnil); |
687 if (NILP (submap)) | |
442 | 688 submap = create_bucky_submap (k, XEMACS_MOD_META, keymap); |
428 | 689 k = XKEYMAP (submap); |
442 | 690 modifiers &= ~XEMACS_MOD_META; |
428 | 691 } |
692 | |
693 if (modifiers != 0) | |
694 { | |
695 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), | |
696 k->table, Qnil); | |
697 if (NILP (submap)) | |
698 submap = create_bucky_submap (k, modifiers, keymap); | |
699 k = XKEYMAP (submap); | |
700 } | |
701 k->sub_maps_cache = Qt; /* Invalidate cache */ | |
702 keymap_store_internal (keysym, k, value); | |
703 } | |
704 | |
705 | |
706 /************************************************************************/ | |
707 /* Listing the submaps of a keymap */ | |
708 /************************************************************************/ | |
709 | |
710 struct keymap_submaps_closure | |
711 { | |
712 Lisp_Object *result_locative; | |
713 }; | |
714 | |
715 static int | |
2286 | 716 keymap_submaps_mapper_0 (Lisp_Object UNUSED (key), Lisp_Object value, |
717 void *UNUSED (keymap_submaps_closure)) | |
428 | 718 { |
719 /* This function can GC */ | |
720 /* Perform any autoloads, etc */ | |
721 Fkeymapp (value); | |
722 return 0; | |
723 } | |
724 | |
725 static int | |
726 keymap_submaps_mapper (Lisp_Object key, Lisp_Object value, | |
727 void *keymap_submaps_closure) | |
728 { | |
729 /* This function can GC */ | |
730 Lisp_Object *result_locative; | |
731 struct keymap_submaps_closure *cl = | |
732 (struct keymap_submaps_closure *) keymap_submaps_closure; | |
733 result_locative = cl->result_locative; | |
734 | |
735 if (!NILP (Fkeymapp (value))) | |
736 *result_locative = Fcons (Fcons (key, value), *result_locative); | |
737 return 0; | |
738 } | |
739 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
740 static Lisp_Object map_keymap_sort_predicate (Lisp_Object obj1, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
741 Lisp_Object obj2, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
742 Lisp_Object pred, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
743 Lisp_Object key_func); |
428 | 744 |
745 static Lisp_Object | |
746 keymap_submaps (Lisp_Object keymap) | |
747 { | |
748 /* This function can GC */ | |
749 Lisp_Keymap *k = XKEYMAP (keymap); | |
750 | |
751 if (EQ (k->sub_maps_cache, Qt)) /* Unknown */ | |
752 { | |
753 Lisp_Object result = Qnil; | |
754 struct gcpro gcpro1, gcpro2; | |
755 struct keymap_submaps_closure keymap_submaps_closure; | |
756 | |
757 GCPRO2 (keymap, result); | |
758 keymap_submaps_closure.result_locative = &result; | |
759 /* Do this first pass to touch (and load) any autoloaded maps */ | |
760 elisp_maphash (keymap_submaps_mapper_0, k->table, | |
761 &keymap_submaps_closure); | |
762 result = Qnil; | |
763 elisp_maphash (keymap_submaps_mapper, k->table, | |
764 &keymap_submaps_closure); | |
765 /* keep it sorted so that the result of accessible-keymaps is ordered */ | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
766 k->sub_maps_cache = list_sort (result, map_keymap_sort_predicate, |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
767 Qnil, Qidentity); |
428 | 768 UNGCPRO; |
769 } | |
770 return k->sub_maps_cache; | |
771 } | |
772 | |
773 | |
774 /************************************************************************/ | |
775 /* Basic operations on keymaps */ | |
776 /************************************************************************/ | |
777 | |
778 static Lisp_Object | |
665 | 779 make_keymap (Elemcount size) |
428 | 780 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5126
diff
changeset
|
781 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (keymap); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
782 Lisp_Keymap *keymap = XKEYMAP (obj); |
428 | 783 |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
784 #define MARKED_SLOT(x) keymap->x = Qnil; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
785 #include "keymap-slots.h" |
428 | 786 |
787 if (size != 0) /* hack for copy-keymap */ | |
788 { | |
789 keymap->table = | |
790 make_lisp_hash_table (size, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ); | |
791 /* Inverse table is often less dense because of duplicate key-bindings. | |
792 If not, it will grow anyway. */ | |
793 keymap->inverse_table = | |
647 | 794 make_lisp_hash_table (size * 3 / 4, HASH_TABLE_NON_WEAK, |
795 HASH_TABLE_EQ); | |
428 | 796 } |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
797 return obj; |
428 | 798 } |
799 | |
800 DEFUN ("make-keymap", Fmake_keymap, 0, 1, 0, /* | |
801 Construct and return a new keymap object. | |
802 All entries in it are nil, meaning "command undefined". | |
803 | |
804 Optional argument NAME specifies a name to assign to the keymap, | |
805 as in `set-keymap-name'. This name is only a debugging convenience; | |
806 it is not used except when printing the keymap. | |
807 */ | |
808 (name)) | |
809 { | |
810 Lisp_Object keymap = make_keymap (60); | |
811 if (!NILP (name)) | |
812 Fset_keymap_name (keymap, name); | |
813 return keymap; | |
814 } | |
815 | |
816 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, 0, 1, 0, /* | |
817 Construct and return a new keymap object. | |
818 All entries in it are nil, meaning "command undefined". The only | |
444 | 819 difference between this function and `make-keymap' is that this function |
428 | 820 returns a "smaller" keymap (one that is expected to contain fewer |
444 | 821 entries). As keymaps dynamically resize, this distinction is not great. |
428 | 822 |
823 Optional argument NAME specifies a name to assign to the keymap, | |
824 as in `set-keymap-name'. This name is only a debugging convenience; | |
825 it is not used except when printing the keymap. | |
826 */ | |
827 (name)) | |
828 { | |
829 Lisp_Object keymap = make_keymap (8); | |
830 if (!NILP (name)) | |
831 Fset_keymap_name (keymap, name); | |
832 return keymap; | |
833 } | |
834 | |
835 DEFUN ("keymap-parents", Fkeymap_parents, 1, 1, 0, /* | |
836 Return the `parent' keymaps of KEYMAP, or nil. | |
837 The parents of a keymap are searched for keybindings when a key sequence | |
838 isn't bound in this one. `(current-global-map)' is the default parent | |
839 of all keymaps. | |
840 */ | |
841 (keymap)) | |
842 { | |
843 keymap = get_keymap (keymap, 1, 1); | |
844 return Fcopy_sequence (XKEYMAP (keymap)->parents); | |
845 } | |
846 | |
847 | |
848 | |
849 static Lisp_Object | |
2286 | 850 traverse_keymaps_noop (Lisp_Object UNUSED (keymap), void *UNUSED (arg)) |
428 | 851 { |
852 return Qnil; | |
853 } | |
854 | |
855 DEFUN ("set-keymap-parents", Fset_keymap_parents, 2, 2, 0, /* | |
856 Set the `parent' keymaps of KEYMAP to PARENTS. | |
857 The parents of a keymap are searched for keybindings when a key sequence | |
858 isn't bound in this one. `(current-global-map)' is the default parent | |
859 of all keymaps. | |
860 */ | |
861 (keymap, parents)) | |
862 { | |
863 /* This function can GC */ | |
864 Lisp_Object k; | |
865 struct gcpro gcpro1, gcpro2; | |
866 | |
867 GCPRO2 (keymap, parents); | |
868 keymap = get_keymap (keymap, 1, 1); | |
869 | |
870 if (KEYMAPP (parents)) /* backwards-compatibility */ | |
871 parents = list1 (parents); | |
872 if (!NILP (parents)) | |
873 { | |
874 Lisp_Object tail = parents; | |
875 while (!NILP (tail)) | |
876 { | |
877 QUIT; | |
878 CHECK_CONS (tail); | |
879 k = XCAR (tail); | |
880 /* Require that it be an actual keymap object, rather than a symbol | |
881 with a (crockish) symbol-function which is a keymap */ | |
882 CHECK_KEYMAP (k); /* get_keymap (k, 1, 1); */ | |
883 tail = XCDR (tail); | |
884 } | |
885 } | |
886 | |
887 /* Check for circularities */ | |
888 traverse_keymaps (keymap, parents, traverse_keymaps_noop, 0); | |
889 keymap_tick++; | |
890 XKEYMAP (keymap)->parents = Fcopy_sequence (parents); | |
891 UNGCPRO; | |
892 return parents; | |
893 } | |
894 | |
895 DEFUN ("set-keymap-name", Fset_keymap_name, 2, 2, 0, /* | |
896 Set the `name' of the KEYMAP to NEW-NAME. | |
897 The name is only a debugging convenience; it is not used except | |
898 when printing the keymap. | |
899 */ | |
900 (keymap, new_name)) | |
901 { | |
902 keymap = get_keymap (keymap, 1, 1); | |
903 | |
904 XKEYMAP (keymap)->name = new_name; | |
905 return new_name; | |
906 } | |
907 | |
908 DEFUN ("keymap-name", Fkeymap_name, 1, 1, 0, /* | |
909 Return the `name' of KEYMAP. | |
910 The name is only a debugging convenience; it is not used except | |
911 when printing the keymap. | |
912 */ | |
913 (keymap)) | |
914 { | |
915 keymap = get_keymap (keymap, 1, 1); | |
916 | |
917 return XKEYMAP (keymap)->name; | |
918 } | |
919 | |
920 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, 2, 2, 0, /* | |
921 Set the `prompt' of KEYMAP to string NEW-PROMPT, or `nil' | |
922 if no prompt is desired. The prompt is shown in the echo-area | |
923 when reading a key-sequence to be looked-up in this keymap. | |
924 */ | |
925 (keymap, new_prompt)) | |
926 { | |
927 keymap = get_keymap (keymap, 1, 1); | |
928 | |
929 if (!NILP (new_prompt)) | |
930 CHECK_STRING (new_prompt); | |
931 | |
932 XKEYMAP (keymap)->prompt = new_prompt; | |
933 return new_prompt; | |
934 } | |
935 | |
936 static Lisp_Object | |
2286 | 937 keymap_prompt_mapper (Lisp_Object keymap, void *UNUSED (arg)) |
428 | 938 { |
939 return XKEYMAP (keymap)->prompt; | |
940 } | |
941 | |
942 | |
943 DEFUN ("keymap-prompt", Fkeymap_prompt, 1, 2, 0, /* | |
944 Return the `prompt' of KEYMAP. | |
945 If non-nil, the prompt is shown in the echo-area | |
946 when reading a key-sequence to be looked-up in this keymap. | |
947 */ | |
948 (keymap, use_inherited)) | |
949 { | |
950 /* This function can GC */ | |
951 Lisp_Object prompt; | |
952 | |
953 keymap = get_keymap (keymap, 1, 1); | |
954 prompt = XKEYMAP (keymap)->prompt; | |
955 if (!NILP (prompt) || NILP (use_inherited)) | |
956 return prompt; | |
957 else | |
958 return traverse_keymaps (keymap, Qnil, keymap_prompt_mapper, 0); | |
959 } | |
960 | |
961 DEFUN ("set-keymap-default-binding", Fset_keymap_default_binding, 2, 2, 0, /* | |
962 Sets the default binding of KEYMAP to COMMAND, or `nil' | |
963 if no default is desired. The default-binding is returned when | |
964 no other binding for a key-sequence is found in the keymap. | |
965 If a keymap has a non-nil default-binding, neither the keymap's | |
966 parents nor the current global map are searched for key bindings. | |
967 */ | |
968 (keymap, command)) | |
969 { | |
970 /* This function can GC */ | |
971 keymap = get_keymap (keymap, 1, 1); | |
972 | |
973 XKEYMAP (keymap)->default_binding = command; | |
974 return command; | |
975 } | |
976 | |
977 DEFUN ("keymap-default-binding", Fkeymap_default_binding, 1, 1, 0, /* | |
978 Return the default binding of KEYMAP, or `nil' if it has none. | |
979 The default-binding is returned when no other binding for a key-sequence | |
980 is found in the keymap. | |
981 If a keymap has a non-nil default-binding, neither the keymap's | |
982 parents nor the current global map are searched for key bindings. | |
983 */ | |
984 (keymap)) | |
985 { | |
986 /* This function can GC */ | |
987 keymap = get_keymap (keymap, 1, 1); | |
988 return XKEYMAP (keymap)->default_binding; | |
989 } | |
990 | |
991 DEFUN ("keymapp", Fkeymapp, 1, 1, 0, /* | |
444 | 992 Return t if OBJECT is a keymap object. |
428 | 993 The keymap may be autoloaded first if necessary. |
994 */ | |
995 (object)) | |
996 { | |
997 /* This function can GC */ | |
998 return KEYMAPP (get_keymap (object, 0, 0)) ? Qt : Qnil; | |
999 } | |
1000 | |
1001 /* Check that OBJECT is a keymap (after dereferencing through any | |
1002 symbols). If it is, return it. | |
1003 | |
1004 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value | |
1005 is an autoload form, do the autoload and try again. | |
1006 If AUTOLOAD is nonzero, callers must assume GC is possible. | |
1007 | |
1008 ERRORP controls how we respond if OBJECT isn't a keymap. | |
1009 If ERRORP is non-zero, signal an error; otherwise, just return Qnil. | |
1010 | |
1011 Note that most of the time, we don't want to pursue autoloads. | |
1012 Functions like Faccessible_keymaps which scan entire keymap trees | |
1013 shouldn't load every autoloaded keymap. I'm not sure about this, | |
1014 but it seems to me that only read_key_sequence, Flookup_key, and | |
1015 Fdefine_key should cause keymaps to be autoloaded. */ | |
1016 | |
1017 Lisp_Object | |
1018 get_keymap (Lisp_Object object, int errorp, int autoload) | |
1019 { | |
1020 /* This function can GC */ | |
1021 while (1) | |
1022 { | |
1023 Lisp_Object tem = indirect_function (object, 0); | |
1024 | |
1025 if (KEYMAPP (tem)) | |
1026 return tem; | |
1027 /* Should we do an autoload? */ | |
1028 else if (autoload | |
1029 /* (autoload "filename" doc nil keymap) */ | |
1030 && SYMBOLP (object) | |
1031 && CONSP (tem) | |
1032 && EQ (XCAR (tem), Qautoload) | |
1033 && EQ (Fcar (Fcdr (Fcdr (Fcdr (Fcdr (tem))))), Qkeymap)) | |
1034 { | |
970 | 1035 /* do_autoload GCPROs both arguments */ |
428 | 1036 do_autoload (tem, object); |
1037 } | |
1038 else if (errorp) | |
1039 object = wrong_type_argument (Qkeymapp, object); | |
1040 else | |
1041 return Qnil; | |
1042 } | |
1043 } | |
1044 | |
1045 /* Given OBJECT which was found in a slot in a keymap, | |
1046 trace indirect definitions to get the actual definition of that slot. | |
1047 An indirect definition is a list of the form | |
1048 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one | |
1049 and INDEX is an ASCII code, or a cons of (KEYSYM . MODIFIERS). | |
1050 */ | |
1051 static Lisp_Object | |
1052 get_keyelt (Lisp_Object object, int accept_default) | |
1053 { | |
1054 /* This function can GC */ | |
1055 Lisp_Object map; | |
1056 | |
1057 tail_recurse: | |
1058 if (!CONSP (object)) | |
1059 return object; | |
1060 | |
1061 { | |
1062 struct gcpro gcpro1; | |
1063 GCPRO1 (object); | |
1064 map = XCAR (object); | |
1065 map = get_keymap (map, 0, 1); | |
1066 UNGCPRO; | |
1067 } | |
1068 /* If the contents are (KEYMAP . ELEMENT), go indirect. */ | |
1069 if (!NILP (map)) | |
1070 { | |
1071 Lisp_Object idx = Fcdr (object); | |
934 | 1072 Lisp_Key_Data indirection; |
428 | 1073 if (CHARP (idx)) |
1074 { | |
934 | 1075 Lisp_Object event = Fmake_event (Qnil, Qnil); |
1076 struct gcpro gcpro1; | |
1077 GCPRO1 (event); | |
1078 character_to_event (XCHAR (idx), XEVENT (event), | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
1079 XCONSOLE (Vselected_console), |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
1080 high_bit_is_meta, 0); |
1204 | 1081 indirection.keysym = XEVENT_KEY_KEYSYM (event); |
1082 indirection.modifiers = XEVENT_KEY_MODIFIERS (event); | |
1083 UNGCPRO; | |
428 | 1084 } |
1085 else if (CONSP (idx)) | |
1086 { | |
1087 if (!INTP (XCDR (idx))) | |
1088 return Qnil; | |
1089 indirection.keysym = XCAR (idx); | |
442 | 1090 indirection.modifiers = (unsigned char) XINT (XCDR (idx)); |
428 | 1091 } |
1092 else if (SYMBOLP (idx)) | |
1093 { | |
1094 indirection.keysym = idx; | |
934 | 1095 SET_KEY_DATA_MODIFIERS (&indirection, XINT (XCDR (idx))); |
428 | 1096 } |
1097 else | |
1098 { | |
1099 /* Random junk */ | |
1100 return Qnil; | |
1101 } | |
1102 return raw_lookup_key (map, &indirection, 1, 0, accept_default); | |
1103 } | |
1104 else if (STRINGP (XCAR (object))) | |
1105 { | |
1106 /* If the keymap contents looks like (STRING . DEFN), | |
1107 use DEFN. | |
1108 Keymap alist elements like (CHAR MENUSTRING . DEFN) | |
1109 will be used by HierarKey menus. */ | |
1110 object = XCDR (object); | |
1111 goto tail_recurse; | |
1112 } | |
1113 else | |
1114 { | |
1115 /* Anything else is really the value. */ | |
1116 return object; | |
1117 } | |
1118 } | |
1119 | |
1120 static Lisp_Object | |
934 | 1121 keymap_lookup_1 (Lisp_Object keymap, const Lisp_Key_Data *key, |
428 | 1122 int accept_default) |
1123 { | |
1124 /* This function can GC */ | |
934 | 1125 return get_keyelt (keymap_lookup_directly (keymap, |
1126 KEY_DATA_KEYSYM (key), | |
1127 KEY_DATA_MODIFIERS (key)), | |
1128 accept_default); | |
428 | 1129 } |
1130 | |
1131 | |
1132 /************************************************************************/ | |
1133 /* Copying keymaps */ | |
1134 /************************************************************************/ | |
1135 | |
1136 struct copy_keymap_inverse_closure | |
1137 { | |
1138 Lisp_Object inverse_table; | |
1139 }; | |
1140 | |
1141 static int | |
1142 copy_keymap_inverse_mapper (Lisp_Object key, Lisp_Object value, | |
1143 void *copy_keymap_inverse_closure) | |
1144 { | |
1145 struct copy_keymap_inverse_closure *closure = | |
1146 (struct copy_keymap_inverse_closure *) copy_keymap_inverse_closure; | |
1147 | |
1148 /* copy-sequence deals with dotted lists. */ | |
1149 if (CONSP (value)) | |
1150 value = Fcopy_list (value); | |
1151 Fputhash (key, value, closure->inverse_table); | |
1152 | |
1153 return 0; | |
1154 } | |
1155 | |
1156 | |
1157 static Lisp_Object | |
1158 copy_keymap_internal (Lisp_Keymap *keymap) | |
1159 { | |
1160 Lisp_Object nkm = make_keymap (0); | |
1161 Lisp_Keymap *new_keymap = XKEYMAP (nkm); | |
1162 struct copy_keymap_inverse_closure copy_keymap_inverse_closure; | |
1163 copy_keymap_inverse_closure.inverse_table = keymap->inverse_table; | |
1164 | |
1165 new_keymap->parents = Fcopy_sequence (keymap->parents); | |
1166 new_keymap->sub_maps_cache = Qnil; /* No submaps */ | |
1167 new_keymap->table = Fcopy_hash_table (keymap->table); | |
1168 new_keymap->inverse_table = Fcopy_hash_table (keymap->inverse_table); | |
1169 new_keymap->default_binding = keymap->default_binding; | |
1170 /* After copying the inverse map, we need to copy the conses which | |
1171 are its values, lest they be shared by the copy, and mangled. | |
1172 */ | |
1173 elisp_maphash (copy_keymap_inverse_mapper, keymap->inverse_table, | |
1174 ©_keymap_inverse_closure); | |
1175 return nkm; | |
1176 } | |
1177 | |
1178 | |
1179 static Lisp_Object copy_keymap (Lisp_Object keymap); | |
1180 | |
1181 struct copy_keymap_closure | |
1182 { | |
1183 Lisp_Keymap *self; | |
1184 }; | |
1185 | |
1186 static int | |
1187 copy_keymap_mapper (Lisp_Object key, Lisp_Object value, | |
1188 void *copy_keymap_closure) | |
1189 { | |
1190 /* This function can GC */ | |
1191 struct copy_keymap_closure *closure = | |
1192 (struct copy_keymap_closure *) copy_keymap_closure; | |
1193 | |
1194 /* When we encounter a keymap which is indirected through a | |
1195 symbol, we need to copy the sub-map. In v18, the form | |
1196 (lookup-key (copy-keymap global-map) "\C-x") | |
3025 | 1197 returned a new keymap, not the symbol `Control-X-prefix'. |
428 | 1198 */ |
1199 value = get_keymap (value, 0, 1); /* #### autoload GC-safe here? */ | |
1200 if (KEYMAPP (value)) | |
1201 keymap_store_internal (key, closure->self, | |
1202 copy_keymap (value)); | |
1203 return 0; | |
1204 } | |
1205 | |
1206 static Lisp_Object | |
1207 copy_keymap (Lisp_Object keymap) | |
1208 { | |
1209 /* This function can GC */ | |
1210 struct copy_keymap_closure copy_keymap_closure; | |
1211 | |
1212 keymap = copy_keymap_internal (XKEYMAP (keymap)); | |
1213 copy_keymap_closure.self = XKEYMAP (keymap); | |
1214 elisp_maphash (copy_keymap_mapper, | |
1215 XKEYMAP (keymap)->table, | |
1216 ©_keymap_closure); | |
1217 return keymap; | |
1218 } | |
1219 | |
1220 DEFUN ("copy-keymap", Fcopy_keymap, 1, 1, 0, /* | |
1221 Return a copy of the keymap KEYMAP. | |
1222 The copy starts out with the same definitions of KEYMAP, | |
1223 but changing either the copy or KEYMAP does not affect the other. | |
1224 Any key definitions that are subkeymaps are recursively copied. | |
1225 */ | |
1226 (keymap)) | |
1227 { | |
1228 /* This function can GC */ | |
1229 keymap = get_keymap (keymap, 1, 1); | |
1230 return copy_keymap (keymap); | |
1231 } | |
1232 | |
1233 | |
1234 static int | |
1235 keymap_fullness (Lisp_Object keymap) | |
1236 { | |
1237 /* This function can GC */ | |
1238 int fullness; | |
1239 Lisp_Object sub_maps; | |
1240 struct gcpro gcpro1, gcpro2; | |
1241 | |
1242 keymap = get_keymap (keymap, 1, 1); | |
440 | 1243 fullness = XINT (Fhash_table_count (XKEYMAP (keymap)->table)); |
428 | 1244 GCPRO2 (keymap, sub_maps); |
440 | 1245 for (sub_maps = keymap_submaps (keymap); |
1246 !NILP (sub_maps); | |
1247 sub_maps = XCDR (sub_maps)) | |
428 | 1248 { |
1249 if (MODIFIER_HASH_KEY_BITS (XCAR (XCAR (sub_maps))) != 0) | |
1250 { | |
440 | 1251 Lisp_Object bucky_map = XCDR (XCAR (sub_maps)); |
1252 fullness--; /* don't count bucky maps themselves. */ | |
1253 fullness += keymap_fullness (bucky_map); | |
428 | 1254 } |
1255 } | |
1256 UNGCPRO; | |
1257 return fullness; | |
1258 } | |
1259 | |
1260 DEFUN ("keymap-fullness", Fkeymap_fullness, 1, 1, 0, /* | |
1261 Return the number of bindings in the keymap. | |
1262 */ | |
1263 (keymap)) | |
1264 { | |
1265 /* This function can GC */ | |
1266 return make_int (keymap_fullness (get_keymap (keymap, 1, 1))); | |
1267 } | |
1268 | |
1269 | |
1270 /************************************************************************/ | |
1271 /* Defining keys in keymaps */ | |
1272 /************************************************************************/ | |
1273 | |
1274 /* Given a keysym (should be a symbol, int, char), make sure it's valid | |
1275 and perform any necessary canonicalization. */ | |
1276 | |
1277 static void | |
1278 define_key_check_and_coerce_keysym (Lisp_Object spec, | |
1279 Lisp_Object *keysym, | |
442 | 1280 int modifiers) |
428 | 1281 { |
1282 /* Now, check and massage the trailing keysym specifier. */ | |
1283 if (SYMBOLP (*keysym)) | |
1284 { | |
826 | 1285 if (string_char_length (XSYMBOL (*keysym)->name) == 1) |
428 | 1286 { |
1287 Lisp_Object ream_gcc_up_the_ass = | |
867 | 1288 make_char (string_ichar (XSYMBOL (*keysym)->name, 0)); |
428 | 1289 *keysym = ream_gcc_up_the_ass; |
1290 goto fixnum_keysym; | |
1291 } | |
1292 } | |
1293 else if (CHAR_OR_CHAR_INTP (*keysym)) | |
1294 { | |
1295 CHECK_CHAR_COERCE_INT (*keysym); | |
1296 fixnum_keysym: | |
1297 if (XCHAR (*keysym) < ' ' | |
1298 /* || (XCHAR (*keysym) >= 128 && XCHAR (*keysym) < 160) */) | |
1299 /* yuck! Can't make the above restriction; too many compatibility | |
1300 problems ... */ | |
563 | 1301 invalid_argument ("keysym char must be printable", *keysym); |
428 | 1302 /* #### This bites! I want to be able to write (control shift a) */ |
442 | 1303 if (modifiers & XEMACS_MOD_SHIFT) |
563 | 1304 invalid_argument |
428 | 1305 ("The `shift' modifier may not be applied to ASCII keysyms", |
1306 spec); | |
1307 } | |
1308 else | |
1309 { | |
563 | 1310 invalid_argument ("Unknown keysym specifier", *keysym); |
428 | 1311 } |
1312 | |
1313 if (SYMBOLP (*keysym)) | |
1314 { | |
867 | 1315 Ibyte *name = XSTRING_DATA (XSYMBOL (*keysym)->name); |
428 | 1316 |
3025 | 1317 /* GNU Emacs uses symbols with the printed representation of keysyms in |
1318 their names, like `M-x', and we use the syntax '(meta x). So, to | |
1319 avoid confusion, notice the M-x syntax and signal an error - | |
1320 because otherwise it would be interpreted as a regular keysym, and | |
1321 would even show up in the list-buffers output, causing confusion | |
1322 to the naive. | |
428 | 1323 |
1324 We can get away with this because none of the X keysym names contain | |
1325 a hyphen (some contain underscore, however). | |
1326 | |
1327 It might be useful to reject keysyms which are not x-valid-keysym- | |
1328 name-p, but that would interfere with various tricks we do to | |
1329 sanitize the Sun keyboards, and would make it trickier to | |
1330 conditionalize a .emacs file for multiple X servers. | |
1331 */ | |
793 | 1332 if (((int) qxestrlen (name) >= 2 && name[1] == '-') |
428 | 1333 #if 1 |
1334 || | |
1335 /* Ok, this is a bit more dubious - prevent people from doing things | |
1336 like (global-set-key 'RET 'something) because that will have the | |
1337 same problem as above. (Gag!) Maybe we should just silently | |
1338 accept these as aliases for the "real" names? | |
1339 */ | |
793 | 1340 (XSTRING_LENGTH (XSYMBOL (*keysym)->name) <= 3 && |
2367 | 1341 (!qxestrcmp_ascii (name, "LFD") || |
1342 !qxestrcmp_ascii (name, "TAB") || | |
1343 !qxestrcmp_ascii (name, "RET") || | |
1344 !qxestrcmp_ascii (name, "ESC") || | |
1345 !qxestrcmp_ascii (name, "DEL") || | |
1346 !qxestrcmp_ascii (name, "SPC") || | |
1347 !qxestrcmp_ascii (name, "BS"))) | |
428 | 1348 #endif /* unused */ |
1349 ) | |
563 | 1350 invalid_argument |
3086 | 1351 ("Invalid (GNU Emacs) key format (see doc of define-key)", |
428 | 1352 *keysym); |
1353 | |
1354 /* #### Ok, this is a bit more dubious - make people not lose if they | |
1355 do things like (global-set-key 'RET 'something) because that would | |
1356 otherwise have the same problem as above. (Gag!) We silently | |
1357 accept these as aliases for the "real" names. | |
1358 */ | |
2367 | 1359 else if (!qxestrncmp_ascii (name, "kp_", 3)) |
793 | 1360 { |
1361 /* Likewise, the obsolete keysym binding of kp_.* should not lose. */ | |
1362 DECLARE_EISTRING (temp); | |
1363 eicpy_raw (temp, name, qxestrlen (name)); | |
1364 eisetch_char (temp, 2, '-'); | |
4355
a2af1ff1761f
Provide a DEFAULT argument in #'intern-soft.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4272
diff
changeset
|
1365 *keysym = Fintern_soft (eimake_string (temp), Qnil, Qnil); |
793 | 1366 } |
1367 else if (EQ (*keysym, QLFD)) | |
428 | 1368 *keysym = QKlinefeed; |
1369 else if (EQ (*keysym, QTAB)) | |
1370 *keysym = QKtab; | |
1371 else if (EQ (*keysym, QRET)) | |
1372 *keysym = QKreturn; | |
1373 else if (EQ (*keysym, QESC)) | |
1374 *keysym = QKescape; | |
1375 else if (EQ (*keysym, QDEL)) | |
1376 *keysym = QKdelete; | |
1377 else if (EQ (*keysym, QSPC)) | |
1378 *keysym = QKspace; | |
1379 else if (EQ (*keysym, QBS)) | |
1380 *keysym = QKbackspace; | |
1381 /* Emacs compatibility */ | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1382 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1383 else if (EQ(*keysym, Qdown_mouse_##num)) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1384 *keysym = Qbutton##num; \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1385 else if (EQ(*keysym, Qmouse_##num)) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1386 *keysym = Qbutton##num##up; |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1387 #include "keymap-buttons.h" |
428 | 1388 } |
1389 } | |
1390 | |
1391 | |
1392 /* Given any kind of key-specifier, return a keysym and modifier mask. | |
1393 Proper canonicalization is performed: | |
1394 | |
1395 -- integers are converted into the equivalent characters. | |
1396 -- one-character strings are converted into the equivalent characters. | |
1397 */ | |
1398 | |
1399 static void | |
934 | 1400 define_key_parser (Lisp_Object spec, Lisp_Key_Data *returned_value) |
428 | 1401 { |
1402 if (CHAR_OR_CHAR_INTP (spec)) | |
1403 { | |
934 | 1404 Lisp_Object event = Fmake_event (Qnil, Qnil); |
1405 struct gcpro gcpro1; | |
1406 GCPRO1 (event); | |
1407 character_to_event (XCHAR_OR_CHAR_INT (spec), XEVENT (event), | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
1408 XCONSOLE (Vselected_console), high_bit_is_meta, 0); |
1204 | 1409 SET_KEY_DATA_KEYSYM (returned_value, XEVENT_KEY_KEYSYM (event)); |
934 | 1410 SET_KEY_DATA_MODIFIERS (returned_value, |
1204 | 1411 XEVENT_KEY_MODIFIERS (event)); |
1412 UNGCPRO; | |
428 | 1413 } |
1414 else if (EVENTP (spec)) | |
1415 { | |
934 | 1416 switch (XEVENT_TYPE (spec)) |
428 | 1417 { |
1418 case key_press_event: | |
1419 { | |
1204 | 1420 SET_KEY_DATA_KEYSYM (returned_value, XEVENT_KEY_KEYSYM (spec)); |
1421 SET_KEY_DATA_MODIFIERS (returned_value, XEVENT_KEY_MODIFIERS (spec)); | |
428 | 1422 break; |
1423 } | |
1424 case button_press_event: | |
1425 case button_release_event: | |
1426 { | |
934 | 1427 int down = (XEVENT_TYPE (spec) == button_press_event); |
1204 | 1428 switch (XEVENT_BUTTON_BUTTON (spec)) |
934 | 1429 { |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1430 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1431 case num: \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1432 SET_KEY_DATA_KEYSYM (returned_value, \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1433 (down ? Qbutton##num : \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1434 Qbutton##num##up)); \ |
934 | 1435 break; |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1436 #include "keymap-buttons.h" |
934 | 1437 default: |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1438 SET_KEY_DATA_KEYSYM (returned_value, (down ? Qbutton0 : |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1439 Qbutton0up)); |
934 | 1440 break; |
1441 } | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1442 SET_KEY_DATA_MODIFIERS (returned_value, |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1443 XEVENT_BUTTON_MODIFIERS (spec)); |
428 | 1444 break; |
1445 } | |
1446 default: | |
563 | 1447 wtaerror ("unable to bind this type of event", spec); |
428 | 1448 } |
1449 } | |
1450 else if (SYMBOLP (spec)) | |
1451 { | |
1452 /* Be nice, allow = to mean (=) */ | |
1453 if (bucky_sym_to_bucky_bit (spec) != 0) | |
563 | 1454 invalid_argument ("Key is a modifier name", spec); |
428 | 1455 define_key_check_and_coerce_keysym (spec, &spec, 0); |
934 | 1456 SET_KEY_DATA_KEYSYM (returned_value, spec); |
1457 SET_KEY_DATA_MODIFIERS (returned_value, 0); | |
428 | 1458 } |
1459 else if (CONSP (spec)) | |
1460 { | |
442 | 1461 int modifiers = 0; |
428 | 1462 Lisp_Object keysym = Qnil; |
1463 Lisp_Object rest = spec; | |
1464 | |
1465 /* First, parse out the leading modifier symbols. */ | |
1466 while (CONSP (rest)) | |
1467 { | |
442 | 1468 int modifier; |
428 | 1469 |
1470 keysym = XCAR (rest); | |
1471 modifier = bucky_sym_to_bucky_bit (keysym); | |
1472 modifiers |= modifier; | |
1473 if (!NILP (XCDR (rest))) | |
1474 { | |
1475 if (! modifier) | |
563 | 1476 invalid_argument ("Unknown modifier", keysym); |
428 | 1477 } |
1478 else | |
1479 { | |
1480 if (modifier) | |
563 | 1481 sferror ("Nothing but modifiers here", |
428 | 1482 spec); |
1483 } | |
1484 rest = XCDR (rest); | |
1485 QUIT; | |
1486 } | |
1487 if (!NILP (rest)) | |
563 | 1488 signal_error (Qlist_formation_error, |
1489 "List must be nil-terminated", spec); | |
428 | 1490 |
1491 define_key_check_and_coerce_keysym (spec, &keysym, modifiers); | |
934 | 1492 SET_KEY_DATA_KEYSYM(returned_value, keysym); |
1493 SET_KEY_DATA_MODIFIERS (returned_value, modifiers); | |
428 | 1494 } |
1495 else | |
1496 { | |
563 | 1497 invalid_argument ("Unknown key-sequence specifier", |
428 | 1498 spec); |
1499 } | |
1500 } | |
1501 | |
1502 /* Used by character-to-event */ | |
1503 void | |
1504 key_desc_list_to_event (Lisp_Object list, Lisp_Object event, | |
1505 int allow_menu_events) | |
1506 { | |
934 | 1507 Lisp_Key_Data raw_key; |
428 | 1508 |
1509 if (allow_menu_events && | |
1510 CONSP (list) && | |
1511 /* #### where the hell does this come from? */ | |
1512 EQ (XCAR (list), Qmenu_selection)) | |
1513 { | |
1514 Lisp_Object fn, arg; | |
1515 if (! NILP (Fcdr (Fcdr (list)))) | |
563 | 1516 invalid_argument ("Invalid menu event desc", list); |
428 | 1517 arg = Fcar (Fcdr (list)); |
1518 if (SYMBOLP (arg)) | |
1519 fn = Qcall_interactively; | |
1520 else | |
1521 fn = Qeval; | |
934 | 1522 XSET_EVENT_TYPE (event, misc_user_event); |
1204 | 1523 XSET_EVENT_CHANNEL (event, wrap_frame (selected_frame ())); |
1524 XSET_EVENT_MISC_USER_FUNCTION (event, fn); | |
1525 XSET_EVENT_MISC_USER_OBJECT (event, arg); | |
428 | 1526 return; |
1527 } | |
1528 | |
1529 define_key_parser (list, &raw_key); | |
1530 | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1531 if ( |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1532 #define INCLUDE_BUTTON_ZERO |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1533 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1534 EQ (raw_key.keysym, Qbutton##num) || \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1535 EQ (raw_key.keysym, Qbutton##num##up) || |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1536 #include "keymap-buttons.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1537 0) |
563 | 1538 invalid_operation ("Mouse-clicks can't appear in saved keyboard macros", |
1539 Qunbound); | |
428 | 1540 |
934 | 1541 XSET_EVENT_CHANNEL (event, Vselected_console); |
1542 XSET_EVENT_TYPE (event, key_press_event); | |
1204 | 1543 XSET_EVENT_KEY_KEYSYM (event, raw_key.keysym); |
1544 XSET_EVENT_KEY_MODIFIERS (event, KEY_DATA_MODIFIERS (&raw_key)); | |
428 | 1545 } |
1546 | |
1547 | |
1548 int | |
1204 | 1549 event_matches_key_specifier_p (Lisp_Object event, Lisp_Object key_specifier) |
428 | 1550 { |
446 | 1551 Lisp_Object event2 = Qnil; |
428 | 1552 int retval; |
1553 struct gcpro gcpro1; | |
1554 | |
1204 | 1555 if (XEVENT_TYPE (event) != key_press_event || NILP (key_specifier) || |
428 | 1556 (INTP (key_specifier) && !CHAR_INTP (key_specifier))) |
1557 return 0; | |
1558 | |
1559 /* if the specifier is an integer such as 27, then it should match | |
3025 | 1560 both of the events `escape' and `control ['. Calling |
1561 Fcharacter_to_event() will only match `escape'. */ | |
428 | 1562 if (CHAR_OR_CHAR_INTP (key_specifier)) |
1563 return (XCHAR_OR_CHAR_INT (key_specifier) | |
2828 | 1564 == event_to_character (event, 0, 0)); |
428 | 1565 |
1566 /* Otherwise, we cannot call event_to_character() because we may | |
1567 be dealing with non-ASCII keystrokes. In any case, if I ask | |
3025 | 1568 for `control [' then I should get exactly that, and not |
1569 `escape'. | |
1570 | |
1571 However, we have to behave differently on TTY's, where `control [' | |
1572 is silently converted into `escape' by the keyboard driver. | |
428 | 1573 In this case, ASCII is the only thing we know about, so we have |
1574 to compare the ASCII values. */ | |
1575 | |
1576 GCPRO1 (event2); | |
1204 | 1577 if (EVENTP (key_specifier)) |
1578 event2 = Fcopy_event (key_specifier, Qnil); | |
1579 else | |
1580 event2 = Fcharacter_to_event (key_specifier, Qnil, Qnil, Qnil); | |
428 | 1581 if (XEVENT (event2)->event_type != key_press_event) |
1582 retval = 0; | |
1204 | 1583 else if (CONSOLE_TTY_P (XCONSOLE (XEVENT_CHANNEL (event)))) |
428 | 1584 { |
1585 int ch1, ch2; | |
1586 | |
2828 | 1587 ch1 = event_to_character (event, 0, 0); |
1588 ch2 = event_to_character (event2, 0, 0); | |
428 | 1589 retval = (ch1 >= 0 && ch2 >= 0 && ch1 == ch2); |
1590 } | |
1204 | 1591 else if (EQ (XEVENT_KEY_KEYSYM (event), XEVENT_KEY_KEYSYM (event2)) && |
1592 XEVENT_KEY_MODIFIERS (event) == XEVENT_KEY_MODIFIERS (event2)) | |
428 | 1593 retval = 1; |
1594 else | |
1595 retval = 0; | |
1596 Fdeallocate_event (event2); | |
1597 UNGCPRO; | |
1598 return retval; | |
1599 } | |
1600 | |
1601 static int | |
934 | 1602 meta_prefix_char_p (const Lisp_Key_Data *key) |
428 | 1603 { |
934 | 1604 Lisp_Object event = Fmake_event (Qnil, Qnil); |
1605 struct gcpro gcpro1; | |
1204 | 1606 int retval; |
1607 | |
934 | 1608 GCPRO1 (event); |
1609 | |
1610 XSET_EVENT_TYPE (event, key_press_event); | |
1611 XSET_EVENT_CHANNEL (event, Vselected_console); | |
1204 | 1612 XSET_EVENT_KEY_KEYSYM (event, KEY_DATA_KEYSYM (key)); |
1613 XSET_EVENT_KEY_MODIFIERS (event, KEY_DATA_MODIFIERS (key)); | |
1614 retval = event_matches_key_specifier_p (event, Vmeta_prefix_char); | |
1615 UNGCPRO; | |
1616 return retval; | |
428 | 1617 } |
1618 | |
1619 DEFUN ("event-matches-key-specifier-p", Fevent_matches_key_specifier_p, 2, 2, 0, /* | |
1620 Return non-nil if EVENT matches KEY-SPECIFIER. | |
1621 This can be useful, e.g., to determine if the user pressed `help-char' or | |
1622 `quit-char'. | |
1204 | 1623 |
1624 KEY-SPECIFIER can be a character, integer, a symbol, a list of modifiers | |
1625 and symbols, or an event. | |
1626 | |
1627 What this actually happens is this: | |
1628 | |
1629 \(1) Return no, if EVENT is not a key press event or if KEY-SPECIFIER is nil | |
1630 or an integer that cannot be converted to a character. | |
1631 | |
1632 \(2) If KEY-SPECIFIER is a character or integer, | |
1633 (event-to-character EVENT nil nil nil) is called, and the characters are | |
1634 compared to get the result. The reason for special-casing this and doing | |
1635 it this way is to ensure that, e.g., a KEY-SPECIFIER of 27 matches both | |
1636 a key-press `escape' and a key-press `control ['. #### Think about META | |
1637 argument to event-to-character. | |
1638 | |
1639 \(3) If KEY-SPECIFIER is an event, fine; else, convert to an event using | |
1640 \(character-to-event KEY-SPECIFIER nil nil nil). If EVENT is not on a TTY, | |
1641 we just compare keysyms and modifiers and return yes if both are equal. | |
1642 For TTY, we do character-level comparison by converting both to a character | |
1643 with (event-to-character ... nil nil nil) and comparing the characters. | |
1644 | |
428 | 1645 */ |
1646 (event, key_specifier)) | |
1647 { | |
1648 CHECK_LIVE_EVENT (event); | |
1204 | 1649 return (event_matches_key_specifier_p (event, key_specifier) ? Qt : Qnil); |
428 | 1650 } |
1204 | 1651 #define MACROLET(k, m) do { \ |
1652 SET_KEY_DATA_KEYSYM (returned_value, k); \ | |
1653 SET_KEY_DATA_MODIFIERS (returned_value, m); \ | |
1654 RETURN_SANS_WARNINGS; \ | |
934 | 1655 } while (0) |
428 | 1656 /* ASCII grunge. |
1657 Given a keysym, return another keysym/modifier pair which could be | |
1658 considered the same key in an ASCII world. Backspace returns ^H, for | |
1659 example. | |
1660 */ | |
1661 static void | |
934 | 1662 define_key_alternate_name (Lisp_Key_Data *key, |
1663 Lisp_Key_Data *returned_value) | |
428 | 1664 { |
934 | 1665 Lisp_Object keysym = KEY_DATA_KEYSYM (key); |
1666 int modifiers = KEY_DATA_MODIFIERS (key); | |
442 | 1667 int modifiers_sans_control = (modifiers & (~XEMACS_MOD_CONTROL)); |
1668 int modifiers_sans_meta = (modifiers & (~XEMACS_MOD_META)); | |
934 | 1669 SET_KEY_DATA_KEYSYM (returned_value, Qnil); /* By default, no "alternate" key */ |
1670 SET_KEY_DATA_MODIFIERS (returned_value, 0); | |
442 | 1671 if (modifiers_sans_meta == XEMACS_MOD_CONTROL) |
428 | 1672 { |
722 | 1673 if (EQ (keysym, QKspace)) |
428 | 1674 MACROLET (make_char ('@'), modifiers); |
1675 else if (!CHARP (keysym)) | |
1676 return; | |
1677 else switch (XCHAR (keysym)) | |
1678 { | |
1679 case '@': /* c-@ => c-space */ | |
1680 MACROLET (QKspace, modifiers); | |
1681 case 'h': /* c-h => backspace */ | |
1682 MACROLET (QKbackspace, modifiers_sans_control); | |
1683 case 'i': /* c-i => tab */ | |
1684 MACROLET (QKtab, modifiers_sans_control); | |
1685 case 'j': /* c-j => linefeed */ | |
1686 MACROLET (QKlinefeed, modifiers_sans_control); | |
1687 case 'm': /* c-m => return */ | |
1688 MACROLET (QKreturn, modifiers_sans_control); | |
1689 case '[': /* c-[ => escape */ | |
1690 MACROLET (QKescape, modifiers_sans_control); | |
1691 default: | |
1692 return; | |
1693 } | |
1694 } | |
1695 else if (modifiers_sans_meta != 0) | |
1696 return; | |
1697 else if (EQ (keysym, QKbackspace)) /* backspace => c-h */ | |
442 | 1698 MACROLET (make_char ('h'), (modifiers | XEMACS_MOD_CONTROL)); |
428 | 1699 else if (EQ (keysym, QKtab)) /* tab => c-i */ |
442 | 1700 MACROLET (make_char ('i'), (modifiers | XEMACS_MOD_CONTROL)); |
428 | 1701 else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */ |
442 | 1702 MACROLET (make_char ('j'), (modifiers | XEMACS_MOD_CONTROL)); |
428 | 1703 else if (EQ (keysym, QKreturn)) /* return => c-m */ |
442 | 1704 MACROLET (make_char ('m'), (modifiers | XEMACS_MOD_CONTROL)); |
428 | 1705 else if (EQ (keysym, QKescape)) /* escape => c-[ */ |
442 | 1706 MACROLET (make_char ('['), (modifiers | XEMACS_MOD_CONTROL)); |
428 | 1707 else |
1708 return; | |
1709 #undef MACROLET | |
1710 } | |
1711 | |
1712 static void | |
1713 ensure_meta_prefix_char_keymapp (Lisp_Object keys, int indx, | |
1714 Lisp_Object keymap) | |
1715 { | |
1716 /* This function can GC */ | |
1717 Lisp_Object new_keys; | |
1718 int i; | |
1719 Lisp_Object mpc_binding; | |
934 | 1720 Lisp_Key_Data meta_key; |
428 | 1721 if (NILP (Vmeta_prefix_char) || |
1722 (INTP (Vmeta_prefix_char) && !CHAR_INTP (Vmeta_prefix_char))) | |
1723 return; | |
1724 | |
1725 define_key_parser (Vmeta_prefix_char, &meta_key); | |
1726 mpc_binding = keymap_lookup_1 (keymap, &meta_key, 0); | |
1727 if (NILP (mpc_binding) || !NILP (Fkeymapp (mpc_binding))) | |
1728 return; | |
1729 | |
1730 if (indx == 0) | |
1731 new_keys = keys; | |
1732 else if (STRINGP (keys)) | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5050
diff
changeset
|
1733 new_keys = Fsubseq (keys, Qzero, make_int (indx)); |
428 | 1734 else if (VECTORP (keys)) |
1735 { | |
1736 new_keys = make_vector (indx, Qnil); | |
1737 for (i = 0; i < indx; i++) | |
1738 XVECTOR_DATA (new_keys) [i] = XVECTOR_DATA (keys) [i]; | |
1739 } | |
1740 else | |
442 | 1741 { |
1742 new_keys = Qnil; | |
2500 | 1743 ABORT (); |
442 | 1744 } |
428 | 1745 |
1746 if (EQ (keys, new_keys)) | |
563 | 1747 signal_ferror_with_frob (Qinvalid_operation, mpc_binding, |
1748 "can't bind %s: %s has a non-keymap binding", | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1749 (CIbyte *) XSTRING_DATA (Fkey_description (keys)), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1750 (CIbyte *) XSTRING_DATA (Fsingle_key_description |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1751 (Vmeta_prefix_char))); |
428 | 1752 else |
563 | 1753 signal_ferror_with_frob (Qinvalid_operation, mpc_binding, |
1754 "can't bind %s: %s %s has a non-keymap binding", | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1755 (CIbyte *) XSTRING_DATA (Fkey_description (keys)), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1756 (CIbyte *) XSTRING_DATA (Fkey_description |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1757 (new_keys)), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1758 (CIbyte *) XSTRING_DATA (Fsingle_key_description |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1759 (Vmeta_prefix_char))); |
428 | 1760 } |
1761 | |
1762 DEFUN ("define-key", Fdefine_key, 3, 3, 0, /* | |
1763 Define key sequence KEYS, in KEYMAP, as DEF. | |
1764 KEYMAP is a keymap object. | |
3086 | 1765 KEYS is the key sequence to bind, described below. |
428 | 1766 DEF is anything that can be a key's definition: |
1767 nil (means key is undefined in this keymap); | |
1768 a command (a Lisp function suitable for interactive calling); | |
1769 a string or key sequence vector (treated as a keyboard macro); | |
1770 a keymap (to define a prefix key); | |
1771 a symbol; when the key is looked up, the symbol will stand for its | |
1772 function definition, that should at that time be one of the above, | |
1773 or another symbol whose function definition is used, and so on. | |
1774 a cons (STRING . DEFN), meaning that DEFN is the definition | |
1775 (DEFN should be a valid definition in its own right); | |
1776 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP. | |
1777 | |
3086 | 1778 A `key sequence' is a vector of one or more keystrokes. |
1779 A `keystroke' is a list containing a key and zero or more modifiers. The | |
1780 key must be the last element of the list. | |
1781 A `key' is a symbol corresponding to a key on the keyboard, or to a mouse | |
1782 gesture. Mouse clicks are denoted by symbols prefixed with "button", | |
1783 followed by a digit for which button, and optionally "up". Thus `button1' | |
1784 means the down-stroke and `button1up' means the up-stroke when clicking | |
1785 mouse button 1. | |
1786 A `modifier' is a symbol naming a physical key which is only "noticed" by | |
1787 XEmacs when chorded with another key. The `shift' modifier is a special | |
1788 case. You cannot use `(meta shift a)' to mean `(meta A)', since for | |
1789 characters that have ASCII equivalents, the state of the shift key is | |
1790 implicit in the keysym (a vs. A). You also cannot say `(shift =)' to mean | |
1791 `+', as that correspondence varies from keyboard to keyboard. The shift | |
1792 modifier can only be applied to keys that do not have a second keysym on the | |
1793 same key, such as `backspace' and `tab'. A mouse click may be combined with | |
1794 modifiers to create a compound "keystroke". | |
1795 | |
1796 The keys, mouse gestures, and modifiers that are available depend on your | |
1797 console and its driver. At a minimum the ASCII graphic characters will be | |
1798 available as keys, and shift, control, and meta as modifiers. | |
1799 | |
1800 To find out programmatically what a key is bound to, use `key-binding' to | |
1801 check all applicable keymaps, or `lookup-key' to check a specific keymap. | |
1802 The documentation for `key-binding' also contains a description of which | |
1803 keymaps are applicable in various situations. `where-is-internal' does | |
1804 the opposite of `key-binding', i.e. searches keymaps for the keys that | |
1805 map to a particular binding. | |
1806 | |
1807 If you are confused about why a particular key sequence is generating a | |
1808 particular binding, and looking through the keymaps doesn't help, setting | |
1809 the variable `debug-emacs-events' may help. If not, try checking | |
1810 what's in `function-key-map' and `key-translation-map'. | |
1811 | |
1812 When running under a window system, typically the repertoire of keys is | |
1813 vastly expanded. XEmacs does its best to use the names defined on each | |
1814 platform. Also, when running under a window system, XEmacs can tell the | |
1815 difference between the keystrokes control-h, control-shift-h, and backspace. | |
1816 If the symbols differ, you can bind different actions to each. For mouse | |
1817 clicks, different commands may be bound to the up and down strokes, though | |
1818 that is probably not what you want, so be careful. | |
1819 | |
1820 Variant representations: | |
1821 | |
1822 Besides the canonical representation as a vector of lists of symbols, | |
1823 `define-key' also accepts a number of abbreviations, aliases, and variants | |
1824 for convenience, compatibility, and internal use. | |
1825 | |
1826 A keystroke may be represented by a key; this is treated as though it were a | |
1827 list containing that key as the only element. A keystroke may also be | |
1828 represented by an event object, as returned by the `next-command-event' and | |
1829 `read-key-sequence' functions. A key sequence may be represented by a | |
1830 single keystroke; this is treated as a vector containing that keystroke as | |
1831 its only element. | |
1832 | |
1833 A key may be represented by a character or its equivalent integer code, | |
1834 if and only if it is equivalent to a character with a code in the range | |
1835 32 - 255. | |
1836 | |
1837 For backward compatibility, a key sequence may also be represented by a | |
1838 string. In this case, it represents the key sequence(s) that would | |
1839 produce that sequence of ASCII characters in a purely ASCII world. An | |
1840 alternative string representation is keyboard macro notation, which can | |
1841 be translated to the canonical representation with `kbd'. | |
1842 | |
1843 Examples: | |
1844 | |
1845 The key sequence `A' (which invokes `self-insert-command') is represented | |
1846 by all of these forms: | |
428 | 1847 A ?A 65 (A) (?A) (65) |
1848 [A] [?A] [65] [(A)] [(?A)] [(65)] | |
1849 | |
3086 | 1850 The key sequence `control-a' is represented by these forms: |
428 | 1851 (control A) (control ?A) (control 65) |
1852 [(control A)] [(control ?A)] [(control 65)] | |
3086 | 1853 |
1854 The key sequence `control-c control-a' is represented by these forms: | |
428 | 1855 [(control c) (control a)] [(control ?c) (control ?a)] |
1856 [(control 99) (control 65)] etc. | |
1857 | |
3086 | 1858 The keystroke `control-b' *may not* be represented by the number 2 (the |
1859 ASCII code for ^B) or the character `?\^B'. | |
1860 | |
1861 The `break' key may be represented only by the symbol `break'. | |
1862 | |
428 | 1863 Mouse button clicks work just like keypresses: (control button1) means |
1864 pressing the left mouse button while holding down the control key. | |
3086 | 1865 |
1866 A string containing the ASCII backspace character, "\\^H", would represent | |
1867 two key sequences: `(control h)' and `backspace'. Binding a | |
428 | 1868 command to this will actually bind both of those key sequences. Likewise |
1869 for the following pairs: | |
1870 | |
1871 control h backspace | |
1872 control i tab | |
1873 control m return | |
1874 control j linefeed | |
1875 control [ escape | |
1876 control @ control space | |
1877 | |
1878 After binding a command to two key sequences with a form like | |
1879 | |
1880 (define-key global-map "\\^X\\^I" \'command-1) | |
1881 | |
1882 it is possible to redefine only one of those sequences like so: | |
1883 | |
1884 (define-key global-map [(control x) (control i)] \'command-2) | |
1885 (define-key global-map [(control x) tab] \'command-3) | |
1886 */ | |
1887 (keymap, keys, def)) | |
1888 { | |
1889 /* This function can GC */ | |
1890 int idx; | |
1891 int metized = 0; | |
1892 int len; | |
1893 int ascii_hack; | |
1894 struct gcpro gcpro1, gcpro2, gcpro3; | |
1895 | |
1896 if (VECTORP (keys)) | |
1897 len = XVECTOR_LENGTH (keys); | |
1898 else if (STRINGP (keys)) | |
826 | 1899 len = string_char_length (keys); |
428 | 1900 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys)) |
1901 { | |
1902 if (!CONSP (keys)) keys = list1 (keys); | |
1903 len = 1; | |
1904 keys = make_vector (1, keys); /* this is kinda sleazy. */ | |
1905 } | |
1906 else | |
1907 { | |
1908 keys = wrong_type_argument (Qsequencep, keys); | |
1909 len = XINT (Flength (keys)); | |
1910 } | |
1911 if (len == 0) | |
1912 return Qnil; | |
1913 | |
1914 GCPRO3 (keymap, keys, def); | |
1915 | |
1916 /* ASCII grunge. | |
1917 When the user defines a key which, in a strictly ASCII world, would be | |
1918 produced by two different keys (^J and linefeed, or ^H and backspace, | |
1919 for example) then the binding will be made for both keysyms. | |
1920 | |
1921 This is done if the user binds a command to a string, as in | |
3086 | 1922 (define-key map "\^H" 'something), but not when using the canonical |
1923 syntax (define-key map '(control h) 'something). | |
428 | 1924 */ |
1925 ascii_hack = (STRINGP (keys)); | |
1926 | |
1927 keymap = get_keymap (keymap, 1, 1); | |
1928 | |
1929 idx = 0; | |
1930 while (1) | |
1931 { | |
1932 Lisp_Object c; | |
934 | 1933 Lisp_Key_Data raw_key1; |
1934 Lisp_Key_Data raw_key2; | |
428 | 1935 if (STRINGP (keys)) |
867 | 1936 c = make_char (string_ichar (keys, idx)); |
428 | 1937 else |
1938 c = XVECTOR_DATA (keys) [idx]; | |
1939 | |
1940 define_key_parser (c, &raw_key1); | |
1941 | |
1942 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1)) | |
1943 { | |
1944 if (idx == (len - 1)) | |
1945 { | |
1946 /* This is a hack to prevent a binding for the meta-prefix-char | |
1947 from being made in a map which already has a non-empty "meta" | |
1948 submap. That is, we can't let both "escape" and "meta" have | |
1949 a binding in the same keymap. This implies that the idiom | |
1950 (define-key my-map "\e" my-escape-map) | |
1951 (define-key my-escape-map "a" 'my-command) | |
1952 no longer works. That's ok. Instead the luser should do | |
1953 (define-key my-map "\ea" 'my-command) | |
1954 or, more correctly | |
1955 (define-key my-map "\M-a" 'my-command) | |
1956 and then perhaps | |
1957 (defvar my-escape-map (lookup-key my-map "\e")) | |
1958 if the luser really wants the map in a variable. | |
1959 */ | |
440 | 1960 Lisp_Object meta_map; |
428 | 1961 struct gcpro ngcpro1; |
1962 | |
1963 NGCPRO1 (c); | |
442 | 1964 meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
440 | 1965 XKEYMAP (keymap)->table, Qnil); |
1966 if (!NILP (meta_map) | |
1967 && keymap_fullness (meta_map) != 0) | |
563 | 1968 invalid_operation_2 |
440 | 1969 ("Map contains meta-bindings, can't bind", |
1970 Fsingle_key_description (Vmeta_prefix_char), keymap); | |
428 | 1971 NUNGCPRO; |
1972 } | |
1973 else | |
1974 { | |
1975 metized = 1; | |
1976 idx++; | |
1977 continue; | |
1978 } | |
1979 } | |
1980 | |
1981 if (ascii_hack) | |
1982 define_key_alternate_name (&raw_key1, &raw_key2); | |
1983 else | |
1984 { | |
1985 raw_key2.keysym = Qnil; | |
1986 raw_key2.modifiers = 0; | |
1987 } | |
1988 | |
1989 if (metized) | |
1990 { | |
442 | 1991 raw_key1.modifiers |= XEMACS_MOD_META; |
1992 raw_key2.modifiers |= XEMACS_MOD_META; | |
428 | 1993 metized = 0; |
1994 } | |
1995 | |
1996 /* This crap is to make sure that someone doesn't bind something like | |
1997 "C-x M-a" while "C-x ESC" has a non-keymap binding. */ | |
442 | 1998 if (raw_key1.modifiers & XEMACS_MOD_META) |
428 | 1999 ensure_meta_prefix_char_keymapp (keys, idx, keymap); |
2000 | |
2001 if (++idx == len) | |
2002 { | |
2003 keymap_store (keymap, &raw_key1, def); | |
2004 if (ascii_hack && !NILP (raw_key2.keysym)) | |
2005 keymap_store (keymap, &raw_key2, def); | |
2006 UNGCPRO; | |
2007 return def; | |
2008 } | |
2009 | |
2010 { | |
2011 Lisp_Object cmd; | |
2012 struct gcpro ngcpro1; | |
2013 NGCPRO1 (c); | |
2014 | |
2015 cmd = keymap_lookup_1 (keymap, &raw_key1, 0); | |
2016 if (NILP (cmd)) | |
2017 { | |
2018 cmd = Fmake_sparse_keymap (Qnil); | |
2019 XKEYMAP (cmd)->name /* for debugging */ | |
2020 = list2 (make_key_description (&raw_key1, 1), keymap); | |
2021 keymap_store (keymap, &raw_key1, cmd); | |
2022 } | |
2023 if (NILP (Fkeymapp (cmd))) | |
563 | 2024 sferror_2 ("Invalid prefix keys in sequence", |
428 | 2025 c, keys); |
2026 | |
2027 if (ascii_hack && !NILP (raw_key2.keysym) && | |
2028 NILP (keymap_lookup_1 (keymap, &raw_key2, 0))) | |
2029 keymap_store (keymap, &raw_key2, cmd); | |
2030 | |
2031 keymap = get_keymap (cmd, 1, 1); | |
2032 NUNGCPRO; | |
2033 } | |
2034 } | |
2035 } | |
2036 | |
2037 | |
2038 /************************************************************************/ | |
2039 /* Looking up keys in keymaps */ | |
2040 /************************************************************************/ | |
2041 | |
2042 /* We need a very fast (i.e., non-consing) version of lookup-key in order | |
2043 to make where-is-internal really fly. */ | |
2044 | |
2045 struct raw_lookup_key_mapper_closure | |
2046 { | |
2047 int remaining; | |
934 | 2048 const Lisp_Key_Data *raw_keys; |
428 | 2049 int raw_keys_count; |
2050 int keys_so_far; | |
2051 int accept_default; | |
2052 }; | |
2053 | |
2054 static Lisp_Object raw_lookup_key_mapper (Lisp_Object k, void *); | |
2055 | |
2056 /* Caller should gc-protect args (keymaps may autoload) */ | |
2057 static Lisp_Object | |
2058 raw_lookup_key (Lisp_Object keymap, | |
934 | 2059 const Lisp_Key_Data *raw_keys, int raw_keys_count, |
428 | 2060 int keys_so_far, int accept_default) |
2061 { | |
2062 /* This function can GC */ | |
2063 struct raw_lookup_key_mapper_closure c; | |
2064 c.remaining = raw_keys_count - 1; | |
2065 c.raw_keys = raw_keys; | |
2066 c.raw_keys_count = raw_keys_count; | |
2067 c.keys_so_far = keys_so_far; | |
2068 c.accept_default = accept_default; | |
2069 | |
2070 return traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper, &c); | |
2071 } | |
2072 | |
2073 static Lisp_Object | |
2074 raw_lookup_key_mapper (Lisp_Object k, void *arg) | |
2075 { | |
2076 /* This function can GC */ | |
2077 struct raw_lookup_key_mapper_closure *c = | |
2078 (struct raw_lookup_key_mapper_closure *) arg; | |
2079 int accept_default = c->accept_default; | |
2080 int remaining = c->remaining; | |
2081 int keys_so_far = c->keys_so_far; | |
934 | 2082 const Lisp_Key_Data *raw_keys = c->raw_keys; |
428 | 2083 Lisp_Object cmd; |
2084 | |
2085 if (! meta_prefix_char_p (&(raw_keys[0]))) | |
2086 { | |
2087 /* Normal case: every case except the meta-hack (see below). */ | |
2088 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); | |
2089 | |
2090 if (remaining == 0) | |
2091 /* Return whatever we found if we're out of keys */ | |
2092 ; | |
2093 else if (NILP (cmd)) | |
2094 /* Found nothing (though perhaps parent map may have binding) */ | |
2095 ; | |
2096 else if (NILP (Fkeymapp (cmd))) | |
2097 /* Didn't find a keymap, and we have more keys. | |
2098 * Return a fixnum to indicate that keys were too long. | |
2099 */ | |
2100 cmd = make_int (keys_so_far + 1); | |
2101 else | |
2102 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, | |
2103 keys_so_far + 1, accept_default); | |
2104 } | |
2105 else | |
2106 { | |
2107 /* This is a hack so that looking up a key-sequence whose last | |
2108 * element is the meta-prefix-char will return the keymap that | |
2109 * the "meta" keys are stored in, if there is no binding for | |
2110 * the meta-prefix-char (and if this map has a "meta" submap). | |
2111 * If this map doesn't have a "meta" submap, then the | |
2112 * meta-prefix-char is looked up just like any other key. | |
2113 */ | |
2114 if (remaining == 0) | |
2115 { | |
2116 /* First look for the prefix-char directly */ | |
2117 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); | |
2118 if (NILP (cmd)) | |
2119 { | |
2120 /* Do kludgy return of the meta-map */ | |
442 | 2121 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
428 | 2122 XKEYMAP (k)->table, Qnil); |
2123 } | |
2124 } | |
2125 else | |
2126 { | |
2127 /* Search for the prefix-char-prefixed sequence directly */ | |
2128 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); | |
2129 cmd = get_keymap (cmd, 0, 1); | |
2130 if (!NILP (cmd)) | |
2131 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, | |
2132 keys_so_far + 1, accept_default); | |
442 | 2133 else if ((raw_keys[1].modifiers & XEMACS_MOD_META) == 0) |
428 | 2134 { |
934 | 2135 Lisp_Key_Data metified; |
428 | 2136 metified.keysym = raw_keys[1].keysym; |
442 | 2137 metified.modifiers = raw_keys[1].modifiers | |
2138 (unsigned char) XEMACS_MOD_META; | |
428 | 2139 |
2140 /* Search for meta-next-char sequence directly */ | |
2141 cmd = keymap_lookup_1 (k, &metified, accept_default); | |
2142 if (remaining == 1) | |
2143 ; | |
2144 else | |
2145 { | |
2146 cmd = get_keymap (cmd, 0, 1); | |
2147 if (!NILP (cmd)) | |
2148 cmd = raw_lookup_key (cmd, raw_keys + 2, remaining - 1, | |
2149 keys_so_far + 2, | |
2150 accept_default); | |
2151 } | |
2152 } | |
2153 } | |
2154 } | |
2155 if (accept_default && NILP (cmd)) | |
2156 cmd = XKEYMAP (k)->default_binding; | |
2157 return cmd; | |
2158 } | |
2159 | |
2160 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/ | |
2161 /* Caller should gc-protect arguments */ | |
2162 static Lisp_Object | |
2163 lookup_keys (Lisp_Object keymap, int nkeys, Lisp_Object *keys, | |
2164 int accept_default) | |
2165 { | |
2166 /* This function can GC */ | |
934 | 2167 Lisp_Key_Data kkk[20]; |
2168 Lisp_Key_Data *raw_keys; | |
428 | 2169 int i; |
2170 | |
2171 if (nkeys == 0) | |
2172 return Qnil; | |
2173 | |
438 | 2174 if (nkeys < countof (kkk)) |
428 | 2175 raw_keys = kkk; |
2176 else | |
934 | 2177 raw_keys = alloca_array (Lisp_Key_Data, nkeys); |
428 | 2178 |
2179 for (i = 0; i < nkeys; i++) | |
2180 { | |
2181 define_key_parser (keys[i], &(raw_keys[i])); | |
2182 } | |
2183 return raw_lookup_key (keymap, raw_keys, nkeys, 0, accept_default); | |
2184 } | |
2185 | |
2186 static Lisp_Object | |
2187 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[], | |
2188 int accept_default) | |
2189 { | |
2190 /* This function can GC */ | |
934 | 2191 Lisp_Key_Data kkk[20]; |
428 | 2192 Lisp_Object event; |
2193 | |
2194 int nkeys; | |
934 | 2195 Lisp_Key_Data *raw_keys; |
428 | 2196 Lisp_Object tem = Qnil; |
2197 struct gcpro gcpro1, gcpro2; | |
2198 int iii; | |
2199 | |
2200 CHECK_LIVE_EVENT (event_head); | |
2201 | |
2202 nkeys = event_chain_count (event_head); | |
2203 | |
438 | 2204 if (nkeys < countof (kkk)) |
428 | 2205 raw_keys = kkk; |
2206 else | |
934 | 2207 raw_keys = alloca_array (Lisp_Key_Data, nkeys); |
428 | 2208 |
2209 nkeys = 0; | |
2210 EVENT_CHAIN_LOOP (event, event_head) | |
2211 define_key_parser (event, &(raw_keys[nkeys++])); | |
2212 GCPRO2 (keymaps[0], event_head); | |
2213 gcpro1.nvars = nmaps; | |
2214 /* ####raw_keys[].keysym slots aren't gc-protected. We rely (but shouldn't) | |
2215 * on somebody else somewhere (obarray) having a pointer to all keysyms. */ | |
2216 for (iii = 0; iii < nmaps; iii++) | |
2217 { | |
2218 tem = raw_lookup_key (keymaps[iii], raw_keys, nkeys, 0, | |
2219 accept_default); | |
2220 if (INTP (tem)) | |
2221 { | |
2222 /* Too long in some local map means don't look at global map */ | |
2223 tem = Qnil; | |
2224 break; | |
2225 } | |
2226 else if (!NILP (tem)) | |
2227 break; | |
2228 } | |
2229 UNGCPRO; | |
2230 return tem; | |
2231 } | |
2232 | |
2233 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /* | |
2234 In keymap KEYMAP, look up key-sequence KEYS. Return the definition. | |
2235 Nil is returned if KEYS is unbound. See documentation of `define-key' | |
2236 for valid key definitions and key-sequence specifications. | |
2237 A number is returned if KEYS is "too long"; that is, the leading | |
2238 characters fail to be a valid sequence of prefix characters in KEYMAP. | |
444 | 2239 The number is how many key strokes at the front of KEYS it takes to |
2240 reach a non-prefix command. | |
428 | 2241 */ |
2242 (keymap, keys, accept_default)) | |
2243 { | |
2244 /* This function can GC */ | |
2245 if (VECTORP (keys)) | |
2246 return lookup_keys (keymap, | |
2247 XVECTOR_LENGTH (keys), | |
2248 XVECTOR_DATA (keys), | |
2249 !NILP (accept_default)); | |
2250 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys)) | |
2251 return lookup_keys (keymap, 1, &keys, !NILP (accept_default)); | |
2252 else if (STRINGP (keys)) | |
2253 { | |
826 | 2254 int length = string_char_length (keys); |
428 | 2255 int i; |
934 | 2256 Lisp_Key_Data *raw_keys = alloca_array (Lisp_Key_Data, length); |
428 | 2257 if (length == 0) |
2258 return Qnil; | |
2259 | |
2260 for (i = 0; i < length; i++) | |
2261 { | |
867 | 2262 Ichar n = string_ichar (keys, i); |
428 | 2263 define_key_parser (make_char (n), &(raw_keys[i])); |
2264 } | |
2265 return raw_lookup_key (keymap, raw_keys, length, 0, | |
2266 !NILP (accept_default)); | |
2267 } | |
2268 else | |
2269 { | |
2270 keys = wrong_type_argument (Qsequencep, keys); | |
2271 return Flookup_key (keymap, keys, accept_default); | |
2272 } | |
2273 } | |
2274 | |
2275 /* Given a key sequence, returns a list of keymaps to search for bindings. | |
2276 Does all manner of semi-hairy heuristics, like looking in the current | |
2277 buffer's map before looking in the global map and looking in the local | |
2278 map of the buffer in which the mouse was clicked in event0 is a click. | |
2279 | |
2280 It would be kind of nice if this were in Lisp so that this semi-hairy | |
2281 semi-heuristic command-lookup behavior could be readily understood and | |
2282 customised. However, this needs to be pretty fast, or performance of | |
2283 keyboard macros goes to shit; putting this in lisp slows macros down | |
2284 2-3x. And they're already slower than v18 by 5-6x. | |
2285 */ | |
2286 | |
2287 struct relevant_maps | |
2288 { | |
2289 int nmaps; | |
647 | 2290 int max_maps; |
428 | 2291 Lisp_Object *maps; |
2292 struct gcpro *gcpro; | |
2293 }; | |
2294 | |
2295 static void get_relevant_extent_keymaps (Lisp_Object pos, | |
2296 Lisp_Object buffer_or_string, | |
2297 Lisp_Object glyph, | |
2298 struct relevant_maps *closure); | |
2299 static void get_relevant_minor_maps (Lisp_Object buffer, | |
2300 struct relevant_maps *closure); | |
2301 | |
2302 static void | |
2303 relevant_map_push (Lisp_Object map, struct relevant_maps *closure) | |
2304 { | |
647 | 2305 int nmaps = closure->nmaps; |
428 | 2306 |
2307 if (!KEYMAPP (map)) | |
2308 return; | |
2309 closure->nmaps = nmaps + 1; | |
2310 if (nmaps < closure->max_maps) | |
2311 { | |
2312 closure->maps[nmaps] = map; | |
2313 closure->gcpro->nvars = nmaps; | |
2314 } | |
2315 } | |
2316 | |
2317 static int | |
2318 get_relevant_keymaps (Lisp_Object keys, | |
2319 int max_maps, Lisp_Object maps[]) | |
2320 { | |
2321 /* This function can GC */ | |
2322 Lisp_Object terminal = Qnil; | |
2323 struct gcpro gcpro1; | |
2324 struct relevant_maps closure; | |
2325 struct console *con; | |
2326 | |
2327 GCPRO1 (*maps); | |
2328 gcpro1.nvars = 0; | |
2329 closure.nmaps = 0; | |
2330 closure.max_maps = max_maps; | |
2331 closure.maps = maps; | |
2332 closure.gcpro = &gcpro1; | |
2333 | |
2334 if (EVENTP (keys)) | |
2335 terminal = event_chain_tail (keys); | |
2336 else if (VECTORP (keys)) | |
2337 { | |
2338 int len = XVECTOR_LENGTH (keys); | |
2339 if (len > 0) | |
2340 terminal = XVECTOR_DATA (keys)[len - 1]; | |
2341 } | |
2342 | |
2343 if (EVENTP (terminal)) | |
2344 { | |
2345 CHECK_LIVE_EVENT (terminal); | |
2346 con = event_console_or_selected (terminal); | |
2347 } | |
2348 else | |
2349 con = XCONSOLE (Vselected_console); | |
2350 | |
2351 if (KEYMAPP (con->overriding_terminal_local_map) | |
2352 || KEYMAPP (Voverriding_local_map)) | |
2353 { | |
2354 if (KEYMAPP (con->overriding_terminal_local_map)) | |
2355 relevant_map_push (con->overriding_terminal_local_map, &closure); | |
2356 if (KEYMAPP (Voverriding_local_map)) | |
2357 relevant_map_push (Voverriding_local_map, &closure); | |
2358 } | |
2359 else if (!EVENTP (terminal) | |
2360 || (XEVENT (terminal)->event_type != button_press_event | |
2361 && XEVENT (terminal)->event_type != button_release_event)) | |
2362 { | |
793 | 2363 Lisp_Object tem = wrap_buffer (current_buffer); |
2364 | |
428 | 2365 /* It's not a mouse event; order of keymaps searched is: |
2366 o keymap of any/all extents under the mouse | |
2367 o minor-mode maps | |
2368 o local-map of current-buffer | |
771 | 2369 o global-tty-map or global-window-system-map |
428 | 2370 o global-map |
2371 */ | |
2372 /* The terminal element of the lookup may be nil or a keysym. | |
2373 In those cases we don't want to check for an extent | |
2374 keymap. */ | |
2375 if (EVENTP (terminal)) | |
2376 { | |
2377 get_relevant_extent_keymaps (make_int (BUF_PT (current_buffer)), | |
2378 tem, Qnil, &closure); | |
2379 } | |
2380 get_relevant_minor_maps (tem, &closure); | |
2381 | |
2382 tem = current_buffer->keymap; | |
2383 if (!NILP (tem)) | |
2384 relevant_map_push (tem, &closure); | |
2385 } | |
2386 #ifdef HAVE_WINDOW_SYSTEM | |
2387 else | |
2388 { | |
2389 /* It's a mouse event; order of keymaps searched is: | |
2390 o vertical-divider-map, if event is over a divider | |
2391 o local-map of mouse-grabbed-buffer | |
2392 o keymap of any/all extents under the mouse | |
2393 if the mouse is over a modeline: | |
2394 o modeline-map of buffer corresponding to that modeline | |
2395 o else, local-map of buffer under the mouse | |
2396 o minor-mode maps | |
2397 o local-map of current-buffer | |
771 | 2398 o global-tty-map or global-window-system-map |
428 | 2399 o global-map |
2400 */ | |
2401 Lisp_Object window = Fevent_window (terminal); | |
2402 | |
2403 if (!NILP (Fevent_over_vertical_divider_p (terminal))) | |
2404 { | |
2405 if (KEYMAPP (Vvertical_divider_map)) | |
2406 relevant_map_push (Vvertical_divider_map, &closure); | |
2407 } | |
2408 | |
2409 if (BUFFERP (Vmouse_grabbed_buffer)) | |
2410 { | |
2411 Lisp_Object map = XBUFFER (Vmouse_grabbed_buffer)->keymap; | |
2412 | |
2413 get_relevant_minor_maps (Vmouse_grabbed_buffer, &closure); | |
2414 if (!NILP (map)) | |
2415 relevant_map_push (map, &closure); | |
2416 } | |
2417 | |
2418 if (!NILP (window)) | |
2419 { | |
2420 Lisp_Object buffer = Fwindow_buffer (window); | |
2421 | |
2422 if (!NILP (buffer)) | |
2423 { | |
2424 if (!NILP (Fevent_over_modeline_p (terminal))) | |
2425 { | |
2426 Lisp_Object map = symbol_value_in_buffer (Qmodeline_map, | |
2427 buffer); | |
2428 | |
2429 get_relevant_extent_keymaps | |
2430 (Fevent_modeline_position (terminal), | |
2431 XBUFFER (buffer)->generated_modeline_string, | |
438 | 2432 Fevent_glyph_extent (terminal), &closure); |
428 | 2433 |
2434 if (!UNBOUNDP (map) && !NILP (map)) | |
2435 relevant_map_push (get_keymap (map, 1, 1), &closure); | |
2436 } | |
2437 else | |
2438 { | |
2439 get_relevant_extent_keymaps (Fevent_point (terminal), buffer, | |
2440 Fevent_glyph_extent (terminal), | |
2441 &closure); | |
2442 } | |
2443 | |
2444 if (!EQ (buffer, Vmouse_grabbed_buffer)) /* already pushed */ | |
2445 { | |
2446 Lisp_Object map = XBUFFER (buffer)->keymap; | |
2447 | |
2448 get_relevant_minor_maps (buffer, &closure); | |
2449 if (!NILP(map)) | |
2450 relevant_map_push (map, &closure); | |
2451 } | |
2452 } | |
2453 } | |
2454 else if (!NILP (Fevent_over_toolbar_p (terminal))) | |
2455 { | |
2456 Lisp_Object map = Fsymbol_value (Qtoolbar_map); | |
2457 | |
2458 if (!UNBOUNDP (map) && !NILP (map)) | |
2459 relevant_map_push (map, &closure); | |
2460 } | |
2461 } | |
2462 #endif /* HAVE_WINDOW_SYSTEM */ | |
2463 | |
771 | 2464 if (CONSOLE_TTY_P (con)) |
2465 relevant_map_push (Vglobal_tty_map, &closure); | |
2466 else | |
2467 relevant_map_push (Vglobal_window_system_map, &closure); | |
2468 | |
428 | 2469 { |
2470 int nmaps = closure.nmaps; | |
2471 /* Silently truncate at 100 keymaps to prevent infinite lossage */ | |
2472 if (nmaps >= max_maps && max_maps > 0) | |
2473 maps[max_maps - 1] = Vcurrent_global_map; | |
2474 else | |
2475 maps[nmaps] = Vcurrent_global_map; | |
2476 UNGCPRO; | |
2477 return nmaps + 1; | |
2478 } | |
2479 } | |
2480 | |
2481 /* Returns a set of keymaps extracted from the extents at POS in | |
2482 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent | |
2483 to look for a keymap in, and if it has one, its keymap will be the | |
2484 first element in the list returned. This is so we can correctly | |
2485 search the keymaps associated with glyphs which may be physically | |
2486 disjoint from their extents: for example, if a glyph is out in the | |
2487 margin, we should still consult the keymap of that glyph's extent, | |
2488 which may not itself be under the mouse. | |
2489 */ | |
2490 | |
2491 static void | |
2492 get_relevant_extent_keymaps (Lisp_Object pos, Lisp_Object buffer_or_string, | |
2493 Lisp_Object glyph, | |
2494 struct relevant_maps *closure) | |
2495 { | |
2496 /* This function can GC */ | |
2497 /* the glyph keymap, if any, comes first. | |
2498 (Processing it twice is no big deal: noop.) */ | |
2499 if (!NILP (glyph)) | |
2500 { | |
2501 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil); | |
2502 if (!NILP (keymap)) | |
2503 relevant_map_push (get_keymap (keymap, 1, 1), closure); | |
2504 } | |
2505 | |
2506 /* Next check the extents at the text position, if any */ | |
2507 if (!NILP (pos)) | |
2508 { | |
2509 Lisp_Object extent; | |
2510 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qnil); | |
2511 !NILP (extent); | |
2512 extent = Fextent_at (pos, buffer_or_string, Qkeymap, extent, Qnil)) | |
2513 { | |
2514 Lisp_Object keymap = Fextent_property (extent, Qkeymap, Qnil); | |
2515 if (!NILP (keymap)) | |
2516 relevant_map_push (get_keymap (keymap, 1, 1), closure); | |
2517 QUIT; | |
2518 } | |
2519 } | |
2520 } | |
2521 | |
2522 static Lisp_Object | |
2523 minor_mode_keymap_predicate (Lisp_Object assoc, Lisp_Object buffer) | |
2524 { | |
2525 /* This function can GC */ | |
2526 if (CONSP (assoc)) | |
2527 { | |
2528 Lisp_Object sym = XCAR (assoc); | |
2529 if (SYMBOLP (sym)) | |
2530 { | |
2531 Lisp_Object val = symbol_value_in_buffer (sym, buffer); | |
2532 if (!NILP (val) && !UNBOUNDP (val)) | |
2533 { | |
793 | 2534 return get_keymap (XCDR (assoc), 0, 1); |
428 | 2535 } |
2536 } | |
2537 } | |
2538 return Qnil; | |
2539 } | |
2540 | |
2541 static void | |
2542 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure) | |
2543 { | |
2544 /* This function can GC */ | |
2545 Lisp_Object alist; | |
2546 | |
2547 /* Will you ever lose badly if you make this circular! */ | |
2548 for (alist = symbol_value_in_buffer (Qminor_mode_map_alist, buffer); | |
2549 CONSP (alist); | |
2550 alist = XCDR (alist)) | |
2551 { | |
2552 Lisp_Object m = minor_mode_keymap_predicate (XCAR (alist), | |
2553 buffer); | |
2554 if (!NILP (m)) relevant_map_push (m, closure); | |
2555 QUIT; | |
2556 } | |
2557 } | |
2558 | |
2559 /* #### Would map-current-keymaps be a better thing?? */ | |
2560 DEFUN ("current-keymaps", Fcurrent_keymaps, 0, 1, 0, /* | |
2561 Return a list of the current keymaps that will be searched for bindings. | |
2562 This lists keymaps such as the current local map and the minor-mode maps, | |
2563 but does not list the parents of those keymaps. | |
2564 EVENT-OR-KEYS controls which keymaps will be listed. | |
2565 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a | |
2566 mouse event), the keymaps for that mouse event will be listed (see | |
2567 `key-binding'). Otherwise, the keymaps for key presses will be listed. | |
771 | 2568 See `key-binding' for a description of which keymaps are searched in |
2569 various situations. | |
428 | 2570 */ |
2571 (event_or_keys)) | |
2572 { | |
2573 /* This function can GC */ | |
2574 struct gcpro gcpro1; | |
2575 Lisp_Object maps[100]; | |
2576 Lisp_Object *gubbish = maps; | |
2577 int nmaps; | |
2578 | |
2579 GCPRO1 (event_or_keys); | |
2580 nmaps = get_relevant_keymaps (event_or_keys, countof (maps), | |
2581 gubbish); | |
2582 if (nmaps > countof (maps)) | |
2583 { | |
2584 gubbish = alloca_array (Lisp_Object, nmaps); | |
2585 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish); | |
2586 } | |
2587 UNGCPRO; | |
2588 return Flist (nmaps, gubbish); | |
2589 } | |
2590 | |
2591 DEFUN ("key-binding", Fkey_binding, 1, 2, 0, /* | |
2592 Return the binding for command KEYS in current keymaps. | |
2593 KEYS is a string, a vector of events, or a vector of key-description lists | |
2594 as described in the documentation for the `define-key' function. | |
2595 The binding is probably a symbol with a function definition; see | |
2596 the documentation for `lookup-key' for more information. | |
2597 | |
2598 For key-presses, the order of keymaps searched is: | |
2599 - the `keymap' property of any extent(s) at point; | |
2600 - any applicable minor-mode maps; | |
444 | 2601 - the current local map of the current-buffer; |
771 | 2602 - either `global-tty-map' or `global-window-system-map', depending on |
2603 whether the current console is a TTY or non-TTY console; | |
428 | 2604 - the current global map. |
2605 | |
2606 For mouse-clicks, the order of keymaps searched is: | |
2607 - the current-local-map of the `mouse-grabbed-buffer' if any; | |
2608 - vertical-divider-map, if the event happened over a vertical divider | |
2609 - the `keymap' property of any extent(s) at the position of the click | |
2610 (this includes modeline extents); | |
2611 - the modeline-map of the buffer corresponding to the modeline under | |
2612 the mouse (if the click happened over a modeline); | |
444 | 2613 - the value of `toolbar-map' in the current-buffer (if the click |
428 | 2614 happened over a toolbar); |
444 | 2615 - the current local map of the buffer under the mouse (does not |
428 | 2616 apply to toolbar clicks); |
2617 - any applicable minor-mode maps; | |
771 | 2618 - either `global-tty-map' or `global-window-system-map', depending on |
2619 whether the current console is a TTY or non-TTY console; | |
428 | 2620 - the current global map. |
2621 | |
2622 Note that if `overriding-local-map' or `overriding-terminal-local-map' | |
2623 is non-nil, *only* those two maps and the current global map are searched. | |
771 | 2624 |
2625 Note also that key sequences actually received from the keyboard driver | |
2626 may be processed in various ways to generate the key sequence that is | |
2627 actually looked up in the keymaps. In particular: | |
2628 | |
2629 -- Keysyms are individually passed through `keyboard-translate-table' before | |
2630 any other processing. | |
2631 -- After this, key sequences as a whole are passed through | |
2632 `key-translation-map'. | |
2633 -- The resulting key sequence is actually looked up in the keymaps. | |
2634 -- If there's no binding found, the key sequence is passed through | |
2635 `function-key-map' and looked up again. | |
2636 -- If no binding is found and `retry-undefined-key-binding-unshifted' is | |
2637 set (it usually is) and the final keysym is an uppercase character, | |
2638 we lowercase it and start over from the `key-translation-map' stage. | |
2639 -- If no binding is found and we're on MS Windows and have international | |
2640 support, we successively remap the key sequence using the keyboard layouts | |
2641 of various default locales (current language environment, user default, | |
2642 system default, US ASCII) and try again. This makes (e.g.) sequences | |
2643 such as `C-x b' work in a Russian locale, where the alphabetic keys are | |
2644 actually generating Russian characters and not the Roman letters written | |
2645 on the keycaps. (Not yet implemented) | |
2646 -- Finally, if the last keystroke matches `help-char', we automatically | |
2647 generate and display a list of possible key sequences and bindings | |
2648 given the prefix so far generated. | |
428 | 2649 */ |
2650 (keys, accept_default)) | |
2651 { | |
2652 /* This function can GC */ | |
2653 int i; | |
2654 Lisp_Object maps[100]; | |
2655 int nmaps; | |
2656 struct gcpro gcpro1, gcpro2; | |
2657 GCPRO2 (keys, accept_default); /* get_relevant_keymaps may autoload */ | |
2658 | |
2659 nmaps = get_relevant_keymaps (keys, countof (maps), maps); | |
2660 | |
2661 UNGCPRO; | |
2662 | |
2663 if (EVENTP (keys)) /* unadvertised "feature" for the future */ | |
2664 return lookup_events (keys, nmaps, maps, !NILP (accept_default)); | |
2665 | |
2666 for (i = 0; i < nmaps; i++) | |
2667 { | |
2668 Lisp_Object tem = Flookup_key (maps[i], keys, | |
2669 accept_default); | |
2670 if (INTP (tem)) | |
2671 { | |
2672 /* Too long in some local map means don't look at global map */ | |
2673 return Qnil; | |
2674 } | |
2675 else if (!NILP (tem)) | |
2676 return tem; | |
2677 } | |
2678 return Qnil; | |
2679 } | |
2680 | |
2681 static Lisp_Object | |
2682 process_event_binding_result (Lisp_Object result) | |
2683 { | |
2684 if (EQ (result, Qundefined)) | |
3025 | 2685 /* The suppress-keymap function binds keys to `undefined' - special-case |
428 | 2686 that here, so that being bound to that has the same error-behavior as |
2687 not being defined at all. | |
2688 */ | |
2689 result = Qnil; | |
2690 if (!NILP (result)) | |
2691 { | |
2692 Lisp_Object map; | |
2693 /* Snap out possible keymap indirections */ | |
2694 map = get_keymap (result, 0, 1); | |
2695 if (!NILP (map)) | |
2696 result = map; | |
2697 } | |
2698 | |
2699 return result; | |
2700 } | |
2701 | |
2702 /* Attempts to find a command corresponding to the event-sequence | |
2703 whose head is event0 (sequence is threaded though event_next). | |
2704 | |
2705 The return value will be | |
2706 | |
2707 -- nil (there is no binding; this will also be returned | |
2708 whenever the event chain is "too long", i.e. there | |
2709 is a non-nil, non-keymap binding for a prefix of | |
2710 the event chain) | |
2711 -- a keymap (part of a command has been specified) | |
2712 -- a command (anything that satisfies `commandp'; this includes | |
2713 some symbols, lists, subrs, strings, vectors, and | |
2714 compiled-function objects) */ | |
2715 Lisp_Object | |
2716 event_binding (Lisp_Object event0, int accept_default) | |
2717 { | |
2718 /* This function can GC */ | |
2719 Lisp_Object maps[100]; | |
2720 int nmaps; | |
2721 | |
2722 assert (EVENTP (event0)); | |
2723 | |
2724 nmaps = get_relevant_keymaps (event0, countof (maps), maps); | |
2725 if (nmaps > countof (maps)) | |
2726 nmaps = countof (maps); | |
2727 return process_event_binding_result (lookup_events (event0, nmaps, maps, | |
2728 accept_default)); | |
2729 } | |
2730 | |
2731 /* like event_binding, but specify a keymap to search */ | |
2732 | |
2733 Lisp_Object | |
2734 event_binding_in (Lisp_Object event0, Lisp_Object keymap, int accept_default) | |
2735 { | |
2736 /* This function can GC */ | |
2737 if (!KEYMAPP (keymap)) | |
2738 return Qnil; | |
2739 | |
2740 return process_event_binding_result (lookup_events (event0, 1, &keymap, | |
2741 accept_default)); | |
2742 } | |
2743 | |
2744 /* Attempts to find a function key mapping corresponding to the | |
2745 event-sequence whose head is event0 (sequence is threaded through | |
2746 event_next). The return value will be the same as for event_binding(). */ | |
2747 Lisp_Object | |
2748 munging_key_map_event_binding (Lisp_Object event0, | |
2749 enum munge_me_out_the_door munge) | |
2750 { | |
2751 Lisp_Object keymap = (munge == MUNGE_ME_FUNCTION_KEY) ? | |
2752 CONSOLE_FUNCTION_KEY_MAP (event_console_or_selected (event0)) : | |
2753 Vkey_translation_map; | |
2754 | |
2755 if (NILP (keymap)) | |
2756 return Qnil; | |
2757 | |
2758 return process_event_binding_result (lookup_events (event0, 1, &keymap, 1)); | |
2759 } | |
2760 | |
2761 | |
2762 /************************************************************************/ | |
2763 /* Setting/querying the global and local maps */ | |
2764 /************************************************************************/ | |
2765 | |
2766 DEFUN ("use-global-map", Fuse_global_map, 1, 1, 0, /* | |
2767 Select KEYMAP as the global keymap. | |
2768 */ | |
2769 (keymap)) | |
2770 { | |
2771 /* This function can GC */ | |
2772 keymap = get_keymap (keymap, 1, 1); | |
2773 Vcurrent_global_map = keymap; | |
2774 return Qnil; | |
2775 } | |
2776 | |
2777 DEFUN ("use-local-map", Fuse_local_map, 1, 2, 0, /* | |
2778 Select KEYMAP as the local keymap in BUFFER. | |
2779 If KEYMAP is nil, that means no local keymap. | |
2780 If BUFFER is nil, the current buffer is assumed. | |
2781 */ | |
2782 (keymap, buffer)) | |
2783 { | |
2784 /* This function can GC */ | |
2785 struct buffer *b = decode_buffer (buffer, 0); | |
2786 if (!NILP (keymap)) | |
2787 keymap = get_keymap (keymap, 1, 1); | |
2788 | |
2789 b->keymap = keymap; | |
2790 | |
2791 return Qnil; | |
2792 } | |
2793 | |
2794 DEFUN ("current-local-map", Fcurrent_local_map, 0, 1, 0, /* | |
2795 Return BUFFER's local keymap, or nil if it has none. | |
2796 If BUFFER is nil, the current buffer is assumed. | |
2797 */ | |
2798 (buffer)) | |
2799 { | |
2800 struct buffer *b = decode_buffer (buffer, 0); | |
2801 return b->keymap; | |
2802 } | |
2803 | |
2804 DEFUN ("current-global-map", Fcurrent_global_map, 0, 0, 0, /* | |
2805 Return the current global keymap. | |
2806 */ | |
2807 ()) | |
2808 { | |
2809 return Vcurrent_global_map; | |
2810 } | |
2811 | |
2812 | |
2813 /************************************************************************/ | |
2814 /* Mapping over keymap elements */ | |
2815 /************************************************************************/ | |
2816 | |
2817 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or | |
2818 prefix key, it's not entirely obvious what map-keymap should do, but | |
2819 what it does is: map over all keys in this map; then recursively map | |
2820 over all submaps of this map that are "bucky" submaps. This means that, | |
2821 when mapping over a keymap, it appears that "x" and "C-x" are in the | |
2822 same map, although "C-x" is really in the "control" submap of this one. | |
2823 However, since we don't recursively descend the submaps that are bound | |
2824 to prefix keys (like C-x, C-h, etc) the caller will have to recurse on | |
2825 those explicitly, if that's what they want. | |
2826 | |
2827 So the end result of this is that the bucky keymaps (the ones indexed | |
2828 under the large integers returned from MAKE_MODIFIER_HASH_KEY()) are | |
2829 invisible from elisp. They're just an implementation detail that code | |
2830 outside of this file doesn't need to know about. | |
2831 */ | |
2832 | |
2833 struct map_keymap_unsorted_closure | |
2834 { | |
934 | 2835 void (*fn) (const Lisp_Key_Data *, Lisp_Object binding, void *arg); |
428 | 2836 void *arg; |
442 | 2837 int modifiers; |
428 | 2838 }; |
2839 | |
2840 /* used by map_keymap() */ | |
2841 static int | |
2842 map_keymap_unsorted_mapper (Lisp_Object keysym, Lisp_Object value, | |
2843 void *map_keymap_unsorted_closure) | |
2844 { | |
2845 /* This function can GC */ | |
2846 struct map_keymap_unsorted_closure *closure = | |
2847 (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure; | |
442 | 2848 int modifiers = closure->modifiers; |
2849 int mod_bit; | |
428 | 2850 mod_bit = MODIFIER_HASH_KEY_BITS (keysym); |
2851 if (mod_bit != 0) | |
2852 { | |
2853 int omod = modifiers; | |
2854 closure->modifiers = (modifiers | mod_bit); | |
2855 value = get_keymap (value, 1, 0); | |
2856 elisp_maphash (map_keymap_unsorted_mapper, | |
2857 XKEYMAP (value)->table, | |
2858 map_keymap_unsorted_closure); | |
2859 closure->modifiers = omod; | |
2860 } | |
2861 else | |
2862 { | |
934 | 2863 Lisp_Key_Data key; |
428 | 2864 key.keysym = keysym; |
2865 key.modifiers = modifiers; | |
2866 ((*closure->fn) (&key, value, closure->arg)); | |
2867 } | |
2868 return 0; | |
2869 } | |
2870 | |
2871 | |
2872 struct map_keymap_sorted_closure | |
2873 { | |
2874 Lisp_Object *result_locative; | |
2875 }; | |
2876 | |
2877 /* used by map_keymap_sorted() */ | |
2878 static int | |
2879 map_keymap_sorted_mapper (Lisp_Object key, Lisp_Object value, | |
2880 void *map_keymap_sorted_closure) | |
2881 { | |
2882 struct map_keymap_sorted_closure *cl = | |
2883 (struct map_keymap_sorted_closure *) map_keymap_sorted_closure; | |
2884 Lisp_Object *list = cl->result_locative; | |
2885 *list = Fcons (Fcons (key, value), *list); | |
2886 return 0; | |
2887 } | |
2888 | |
2889 | |
2890 /* used by map_keymap_sorted(), describe_map_sort_predicate(), | |
2891 and keymap_submaps(). | |
2892 */ | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2893 static Lisp_Object |
428 | 2894 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2895 Lisp_Object UNUSED (pred), |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2896 Lisp_Object UNUSED (key_func)) |
428 | 2897 { |
2898 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored. | |
2899 */ | |
442 | 2900 int bit1, bit2; |
428 | 2901 int sym1_p = 0; |
2902 int sym2_p = 0; | |
2828 | 2903 extern Lisp_Object Qcharacter_of_keysym; |
2904 | |
428 | 2905 obj1 = XCAR (obj1); |
2906 obj2 = XCAR (obj2); | |
2907 | |
2908 if (EQ (obj1, obj2)) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2909 return Qnil; |
428 | 2910 bit1 = MODIFIER_HASH_KEY_BITS (obj1); |
2911 bit2 = MODIFIER_HASH_KEY_BITS (obj2); | |
2912 | |
2828 | 2913 /* If either is a symbol with a Qcharacter_of_keysym property, then sort it by |
428 | 2914 that code instead of alphabetically. |
2915 */ | |
2916 if (! bit1 && SYMBOLP (obj1)) | |
2917 { | |
2828 | 2918 Lisp_Object code = Fget (obj1, Qcharacter_of_keysym, Qnil); |
428 | 2919 if (CHAR_OR_CHAR_INTP (code)) |
2920 { | |
2921 obj1 = code; | |
2922 CHECK_CHAR_COERCE_INT (obj1); | |
2923 sym1_p = 1; | |
2924 } | |
2925 } | |
2926 if (! bit2 && SYMBOLP (obj2)) | |
2927 { | |
2828 | 2928 Lisp_Object code = Fget (obj2, Qcharacter_of_keysym, Qnil); |
428 | 2929 if (CHAR_OR_CHAR_INTP (code)) |
2930 { | |
2931 obj2 = code; | |
2932 CHECK_CHAR_COERCE_INT (obj2); | |
2933 sym2_p = 1; | |
2934 } | |
2935 } | |
2936 | |
2937 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */ | |
2938 if (XTYPE (obj1) != XTYPE (obj2)) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2939 return SYMBOLP (obj2) ? Qt : Qnil; |
428 | 2940 |
2941 if (! bit1 && CHARP (obj1)) /* they're both ASCII */ | |
2942 { | |
2943 int o1 = XCHAR (obj1); | |
2944 int o2 = XCHAR (obj2); | |
2945 if (o1 == o2 && /* If one started out as a symbol and the */ | |
2946 sym1_p != sym2_p) /* other didn't, the symbol comes last. */ | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2947 return sym2_p ? Qt : Qnil; |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2948 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2949 return o1 < o2 ? Qt : Qnil; /* else just compare them */ |
428 | 2950 } |
2951 | |
2952 /* else they're both symbols. If they're both buckys, then order them. */ | |
2953 if (bit1 && bit2) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2954 return bit1 < bit2 ? Qt : Qnil; |
428 | 2955 |
2956 /* if only one is a bucky, then it comes later */ | |
2957 if (bit1 || bit2) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2958 return bit2 ? Qt : Qnil; |
428 | 2959 |
2960 /* otherwise, string-sort them. */ | |
2961 { | |
867 | 2962 Ibyte *s1 = XSTRING_DATA (XSYMBOL (obj1)->name); |
2963 Ibyte *s2 = XSTRING_DATA (XSYMBOL (obj2)->name); | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2964 return 0 > qxestrcmp (s1, s2) ? Qt : Qnil; |
428 | 2965 } |
2966 } | |
2967 | |
2968 | |
2969 /* used by map_keymap() */ | |
2970 static void | |
2971 map_keymap_sorted (Lisp_Object keymap_table, | |
442 | 2972 int modifiers, |
934 | 2973 void (*function) (const Lisp_Key_Data *key, |
428 | 2974 Lisp_Object binding, |
2975 void *map_keymap_sorted_closure), | |
2976 void *map_keymap_sorted_closure) | |
2977 { | |
2978 /* This function can GC */ | |
2979 struct gcpro gcpro1; | |
2980 Lisp_Object contents = Qnil; | |
2981 | |
2982 if (XINT (Fhash_table_count (keymap_table)) == 0) | |
2983 return; | |
2984 | |
2985 GCPRO1 (contents); | |
2986 | |
2987 { | |
2988 struct map_keymap_sorted_closure c1; | |
2989 c1.result_locative = &contents; | |
2990 elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1); | |
2991 } | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
2992 contents = list_sort (contents, map_keymap_sort_predicate, Qnil, Qidentity); |
428 | 2993 for (; !NILP (contents); contents = XCDR (contents)) |
2994 { | |
2995 Lisp_Object keysym = XCAR (XCAR (contents)); | |
2996 Lisp_Object binding = XCDR (XCAR (contents)); | |
442 | 2997 int sub_bits = MODIFIER_HASH_KEY_BITS (keysym); |
428 | 2998 if (sub_bits != 0) |
2999 map_keymap_sorted (XKEYMAP (get_keymap (binding, | |
3000 1, 1))->table, | |
3001 (modifiers | sub_bits), | |
3002 function, | |
3003 map_keymap_sorted_closure); | |
3004 else | |
3005 { | |
934 | 3006 Lisp_Key_Data k; |
428 | 3007 k.keysym = keysym; |
3008 k.modifiers = modifiers; | |
3009 ((*function) (&k, binding, map_keymap_sorted_closure)); | |
3010 } | |
3011 } | |
3012 UNGCPRO; | |
3013 } | |
3014 | |
3015 | |
3016 /* used by Fmap_keymap() */ | |
3017 static void | |
934 | 3018 map_keymap_mapper (const Lisp_Key_Data *key, |
428 | 3019 Lisp_Object binding, |
3020 void *function) | |
3021 { | |
3022 /* This function can GC */ | |
3023 Lisp_Object fn; | |
5013 | 3024 fn = GET_LISP_FROM_VOID (function); |
428 | 3025 call2 (fn, make_key_description (key, 1), binding); |
3026 } | |
3027 | |
3028 | |
3029 static void | |
3030 map_keymap (Lisp_Object keymap_table, int sort_first, | |
934 | 3031 void (*function) (const Lisp_Key_Data *key, |
428 | 3032 Lisp_Object binding, |
3033 void *fn_arg), | |
3034 void *fn_arg) | |
3035 { | |
3036 /* This function can GC */ | |
3037 if (sort_first) | |
3038 map_keymap_sorted (keymap_table, 0, function, fn_arg); | |
3039 else | |
3040 { | |
3041 struct map_keymap_unsorted_closure map_keymap_unsorted_closure; | |
3042 map_keymap_unsorted_closure.fn = function; | |
3043 map_keymap_unsorted_closure.arg = fn_arg; | |
3044 map_keymap_unsorted_closure.modifiers = 0; | |
3045 elisp_maphash (map_keymap_unsorted_mapper, keymap_table, | |
3046 &map_keymap_unsorted_closure); | |
3047 } | |
3048 } | |
3049 | |
3050 DEFUN ("map-keymap", Fmap_keymap, 2, 3, 0, /* | |
3051 Apply FUNCTION to each element of KEYMAP. | |
3052 FUNCTION will be called with two arguments: a key-description list, and | |
3053 the binding. The order in which the elements of the keymap are passed to | |
3054 the function is unspecified. If the function inserts new elements into | |
3055 the keymap, it may or may not be called with them later. No element of | |
3056 the keymap will ever be passed to the function more than once. | |
3057 | |
3058 The function will not be called on elements of this keymap's parents | |
3059 \(see the function `keymap-parents') or upon keymaps which are contained | |
3060 within this keymap (multi-character definitions). | |
3061 It will be called on "meta" characters since they are not really | |
3062 two-character sequences. | |
3063 | |
3064 If the optional third argument SORT-FIRST is non-nil, then the elements of | |
3065 the keymap will be passed to the mapper function in a canonical order. | |
3066 Otherwise, they will be passed in hash (that is, random) order, which is | |
3067 faster. | |
3068 */ | |
3069 (function, keymap, sort_first)) | |
3070 { | |
3071 /* This function can GC */ | |
489 | 3072 struct gcpro gcpro1, gcpro2; |
428 | 3073 |
3074 /* tolerate obviously transposed args */ | |
3075 if (!NILP (Fkeymapp (function))) | |
3076 { | |
3077 Lisp_Object tmp = function; | |
3078 function = keymap; | |
3079 keymap = tmp; | |
3080 } | |
489 | 3081 GCPRO2 (function, keymap); |
428 | 3082 keymap = get_keymap (keymap, 1, 1); |
489 | 3083 map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first), |
5013 | 3084 map_keymap_mapper, STORE_LISP_IN_VOID (function)); |
428 | 3085 UNGCPRO; |
3086 return Qnil; | |
3087 } | |
3088 | |
3089 | |
3090 | |
3091 /************************************************************************/ | |
3092 /* Accessible keymaps */ | |
3093 /************************************************************************/ | |
3094 | |
3095 struct accessible_keymaps_closure | |
3096 { | |
3097 Lisp_Object tail; | |
3098 }; | |
3099 | |
3100 | |
3101 static void | |
3102 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents, | |
442 | 3103 int modifiers, |
428 | 3104 struct accessible_keymaps_closure *closure) |
3105 { | |
3106 /* This function can GC */ | |
442 | 3107 int subbits = MODIFIER_HASH_KEY_BITS (keysym); |
428 | 3108 |
3109 if (subbits != 0) | |
3110 { | |
3111 Lisp_Object submaps; | |
3112 | |
3113 contents = get_keymap (contents, 1, 1); | |
3114 submaps = keymap_submaps (contents); | |
3115 for (; !NILP (submaps); submaps = XCDR (submaps)) | |
3116 { | |
3117 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)), | |
3118 XCDR (XCAR (submaps)), | |
3119 (subbits | modifiers), | |
3120 closure); | |
3121 } | |
3122 } | |
3123 else | |
3124 { | |
3125 Lisp_Object thisseq = Fcar (Fcar (closure->tail)); | |
3126 Lisp_Object cmd = get_keyelt (contents, 1); | |
3127 Lisp_Object vec; | |
3128 int j; | |
3129 int len; | |
934 | 3130 Lisp_Key_Data key; |
428 | 3131 key.keysym = keysym; |
3132 key.modifiers = modifiers; | |
3133 | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3134 assert (!NILP (cmd)); |
428 | 3135 cmd = get_keymap (cmd, 0, 1); |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3136 assert (KEYMAPP (cmd)); |
428 | 3137 |
3138 vec = make_vector (XVECTOR_LENGTH (thisseq) + 1, Qnil); | |
3139 len = XVECTOR_LENGTH (thisseq); | |
3140 for (j = 0; j < len; j++) | |
3141 XVECTOR_DATA (vec) [j] = XVECTOR_DATA (thisseq) [j]; | |
3142 XVECTOR_DATA (vec) [j] = make_key_description (&key, 1); | |
3143 | |
3144 nconc2 (closure->tail, list1 (Fcons (vec, cmd))); | |
3145 } | |
3146 } | |
3147 | |
3148 | |
3149 static Lisp_Object | |
3150 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg) | |
3151 { | |
3152 /* This function can GC */ | |
3153 struct accessible_keymaps_closure *closure = | |
3154 (struct accessible_keymaps_closure *) arg; | |
3155 Lisp_Object submaps = keymap_submaps (thismap); | |
3156 | |
3157 for (; !NILP (submaps); submaps = XCDR (submaps)) | |
3158 { | |
3159 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)), | |
3160 XCDR (XCAR (submaps)), | |
3161 0, | |
3162 closure); | |
3163 } | |
3164 return Qnil; | |
3165 } | |
3166 | |
3167 | |
3168 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /* | |
3169 Find all keymaps accessible via prefix characters from KEYMAP. | |
3170 Returns a list of elements of the form (KEYS . MAP), where the sequence | |
3171 KEYS starting from KEYMAP gets you to MAP. These elements are ordered | |
3172 so that the KEYS increase in length. The first element is ([] . KEYMAP). | |
3173 An optional argument PREFIX, if non-nil, should be a key sequence; | |
3174 then the value includes only maps for prefixes that start with PREFIX. | |
3175 */ | |
3176 (keymap, prefix)) | |
3177 { | |
3178 /* This function can GC */ | |
3179 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
3180 Lisp_Object accessible_keymaps = Qnil; | |
3181 struct accessible_keymaps_closure c; | |
3182 c.tail = Qnil; | |
3183 GCPRO4 (accessible_keymaps, c.tail, prefix, keymap); | |
3184 | |
440 | 3185 keymap = get_keymap (keymap, 1, 1); |
3186 | |
428 | 3187 retry: |
3188 if (NILP (prefix)) | |
3189 { | |
440 | 3190 prefix = make_vector (0, Qnil); |
428 | 3191 } |
440 | 3192 else if (VECTORP (prefix) || STRINGP (prefix)) |
428 | 3193 { |
3194 int len = XINT (Flength (prefix)); | |
440 | 3195 Lisp_Object def; |
428 | 3196 Lisp_Object p; |
3197 int iii; | |
3198 struct gcpro ngcpro1; | |
3199 | |
440 | 3200 if (len == 0) |
3201 { | |
3202 prefix = Qnil; | |
3203 goto retry; | |
3204 } | |
3205 | |
3206 def = Flookup_key (keymap, prefix, Qnil); | |
428 | 3207 def = get_keymap (def, 0, 1); |
3208 if (!KEYMAPP (def)) | |
3209 goto RETURN; | |
3210 | |
3211 keymap = def; | |
3212 p = make_vector (len, Qnil); | |
3213 NGCPRO1 (p); | |
3214 for (iii = 0; iii < len; iii++) | |
3215 { | |
934 | 3216 Lisp_Key_Data key; |
428 | 3217 define_key_parser (Faref (prefix, make_int (iii)), &key); |
3218 XVECTOR_DATA (p)[iii] = make_key_description (&key, 1); | |
3219 } | |
3220 NUNGCPRO; | |
3221 prefix = p; | |
3222 } | |
440 | 3223 else |
3224 { | |
3225 prefix = wrong_type_argument (Qarrayp, prefix); | |
3226 goto retry; | |
3227 } | |
428 | 3228 |
3229 accessible_keymaps = list1 (Fcons (prefix, keymap)); | |
3230 | |
440 | 3231 /* For each map in the list maps, look at any other maps it points |
3232 to and stick them at the end if they are not already in the list */ | |
428 | 3233 |
3234 for (c.tail = accessible_keymaps; | |
3235 !NILP (c.tail); | |
3236 c.tail = XCDR (c.tail)) | |
3237 { | |
3238 Lisp_Object thismap = Fcdr (Fcar (c.tail)); | |
3239 CHECK_KEYMAP (thismap); | |
3240 traverse_keymaps (thismap, Qnil, | |
3241 accessible_keymaps_keymap_mapper, &c); | |
3242 } | |
3243 RETURN: | |
3244 UNGCPRO; | |
3245 return accessible_keymaps; | |
3246 } | |
3247 | |
3248 | |
3249 | |
3250 /************************************************************************/ | |
3251 /* Pretty descriptions of key sequences */ | |
3252 /************************************************************************/ | |
3253 | |
3254 DEFUN ("key-description", Fkey_description, 1, 1, 0, /* | |
3255 Return a pretty description of key-sequence KEYS. | |
3256 Control characters turn into "C-foo" sequences, meta into "M-foo", | |
3257 spaces are put between sequence elements, etc... | |
3258 */ | |
3259 (keys)) | |
3260 { | |
3261 if (CHAR_OR_CHAR_INTP (keys) || CONSP (keys) || SYMBOLP (keys) | |
3262 || EVENTP (keys)) | |
3263 { | |
3264 return Fsingle_key_description (keys); | |
3265 } | |
3266 else if (VECTORP (keys) || | |
3267 STRINGP (keys)) | |
3268 { | |
3269 Lisp_Object string = Qnil; | |
3270 /* Lisp_Object sep = Qnil; */ | |
3271 int size = XINT (Flength (keys)); | |
3272 int i; | |
3273 | |
3274 for (i = 0; i < size; i++) | |
3275 { | |
3276 Lisp_Object s2 = Fsingle_key_description | |
3277 (STRINGP (keys) | |
867 | 3278 ? make_char (string_ichar (keys, i)) |
428 | 3279 : XVECTOR_DATA (keys)[i]); |
3280 | |
3281 if (i == 0) | |
3282 string = s2; | |
3283 else | |
3284 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3285 /* if (NILP (sep)) Lisp_Object sep = build_ascstring (" ") */; |
428 | 3286 string = concat2 (string, concat2 (Vsingle_space_string, s2)); |
3287 } | |
3288 } | |
3289 return string; | |
3290 } | |
3291 return Fkey_description (wrong_type_argument (Qsequencep, keys)); | |
3292 } | |
3293 | |
3294 DEFUN ("single-key-description", Fsingle_key_description, 1, 1, 0, /* | |
3295 Return a pretty description of command character KEY. | |
3296 Control characters turn into C-whatever, etc. | |
3297 This differs from `text-char-description' in that it returns a description | |
3298 of a key read from the user rather than a character from a buffer. | |
3299 */ | |
3300 (key)) | |
3301 { | |
3302 if (SYMBOLP (key)) | |
3303 key = Fcons (key, Qnil); /* sleaze sleaze */ | |
3304 | |
3305 if (EVENTP (key) || CHAR_OR_CHAR_INTP (key)) | |
3306 { | |
793 | 3307 DECLARE_EISTRING_MALLOC (buf); |
3308 Lisp_Object str; | |
3309 | |
428 | 3310 if (!EVENTP (key)) |
3311 { | |
934 | 3312 Lisp_Object event = Fmake_event (Qnil, Qnil); |
3313 CHECK_CHAR_COERCE_INT (key); | |
1204 | 3314 character_to_event (XCHAR (key), XEVENT (event), |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3315 XCONSOLE (Vselected_console), |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4355
diff
changeset
|
3316 high_bit_is_meta, 1); |
934 | 3317 format_event_object (buf, event, 1); |
1204 | 3318 Fdeallocate_event (event); |
934 | 3319 } |
3320 else | |
3321 format_event_object (buf, key, 1); | |
793 | 3322 str = eimake_string (buf); |
3323 eifree (buf); | |
3324 return str; | |
428 | 3325 } |
3326 | |
3327 if (CONSP (key)) | |
3328 { | |
793 | 3329 DECLARE_EISTRING (bufp); |
3330 | |
428 | 3331 Lisp_Object rest; |
3332 LIST_LOOP (rest, key) | |
3333 { | |
3334 Lisp_Object keysym = XCAR (rest); | |
2421 | 3335 if (EQ (keysym, Qcontrol)) eicat_ascii (bufp, "C-"); |
3336 else if (EQ (keysym, Qctrl)) eicat_ascii (bufp, "C-"); | |
3337 else if (EQ (keysym, Qmeta)) eicat_ascii (bufp, "M-"); | |
3338 else if (EQ (keysym, Qsuper)) eicat_ascii (bufp, "S-"); | |
3339 else if (EQ (keysym, Qhyper)) eicat_ascii (bufp, "H-"); | |
3340 else if (EQ (keysym, Qalt)) eicat_ascii (bufp, "A-"); | |
3341 else if (EQ (keysym, Qshift)) eicat_ascii (bufp, "Sh-"); | |
428 | 3342 else if (CHAR_OR_CHAR_INTP (keysym)) |
793 | 3343 eicat_ch (bufp, XCHAR_OR_CHAR_INT (keysym)); |
428 | 3344 else |
3345 { | |
3346 CHECK_SYMBOL (keysym); | |
3347 #if 0 /* This is bogus */ | |
2421 | 3348 if (EQ (keysym, QKlinefeed)) eicat_ascii (bufp, "LFD"); |
3349 else if (EQ (keysym, QKtab)) eicat_ascii (bufp, "TAB"); | |
3350 else if (EQ (keysym, QKreturn)) eicat_ascii (bufp, "RET"); | |
3351 else if (EQ (keysym, QKescape)) eicat_ascii (bufp, "ESC"); | |
3352 else if (EQ (keysym, QKdelete)) eicat_ascii (bufp, "DEL"); | |
3353 else if (EQ (keysym, QKspace)) eicat_ascii (bufp, "SPC"); | |
3354 else if (EQ (keysym, QKbackspace)) eicat_ascii (bufp, "BS"); | |
428 | 3355 else |
3356 #endif | |
793 | 3357 eicat_lstr (bufp, XSYMBOL (keysym)->name); |
428 | 3358 if (!NILP (XCDR (rest))) |
793 | 3359 invalid_argument ("Invalid key description", key); |
428 | 3360 } |
3361 } | |
793 | 3362 return eimake_string (bufp); |
428 | 3363 } |
3364 return Fsingle_key_description | |
3365 (wrong_type_argument (intern ("char-or-event-p"), key)); | |
3366 } | |
3367 | |
3368 DEFUN ("text-char-description", Ftext_char_description, 1, 1, 0, /* | |
3369 Return a pretty description of file-character CHR. | |
3370 Unprintable characters turn into "^char" or \\NNN, depending on the value | |
3371 of the `ctl-arrow' variable. | |
3372 This differs from `single-key-description' in that it returns a description | |
3373 of a character from a buffer rather than a key read from the user. | |
3374 */ | |
3375 (chr)) | |
3376 { | |
867 | 3377 Ibyte buf[200]; |
3378 Ibyte *p; | |
3379 Ichar c; | |
428 | 3380 Lisp_Object ctl_arrow = current_buffer->ctl_arrow; |
3381 int ctl_p = !NILP (ctl_arrow); | |
867 | 3382 Ichar printable_min = (CHAR_OR_CHAR_INTP (ctl_arrow) |
428 | 3383 ? XCHAR_OR_CHAR_INT (ctl_arrow) |
3384 : ((EQ (ctl_arrow, Qt) || NILP (ctl_arrow)) | |
3385 ? 256 : 160)); | |
3386 | |
3387 if (EVENTP (chr)) | |
3388 { | |
2862 | 3389 Lisp_Object ch = Fevent_to_character (chr, Qnil, Qnil, Qnil); |
428 | 3390 if (NILP (ch)) |
3391 return | |
563 | 3392 signal_continuable_error |
3393 (Qinvalid_argument, | |
2828 | 3394 "key has no character equivalent (that we know of)", |
3395 Fcopy_event (chr, Qnil)); | |
428 | 3396 chr = ch; |
3397 } | |
3398 | |
3399 CHECK_CHAR_COERCE_INT (chr); | |
3400 | |
3401 c = XCHAR (chr); | |
3402 p = buf; | |
3403 | |
3404 if (c >= printable_min) | |
3405 { | |
867 | 3406 p += set_itext_ichar (p, c); |
428 | 3407 } |
3408 else if (c < 040 && ctl_p) | |
3409 { | |
3410 *p++ = '^'; | |
3411 *p++ = c + 64; /* 'A' - 1 */ | |
3412 } | |
3413 else if (c == 0177) | |
3414 { | |
3415 *p++ = '^'; | |
3416 *p++ = '?'; | |
3417 } | |
3418 else if (c >= 0200 || c < 040) | |
3419 { | |
3420 *p++ = '\\'; | |
3421 #ifdef MULE | |
3422 /* !!#### This syntax is not readable. It will | |
3423 be interpreted as a 3-digit octal number rather | |
3424 than a 7-digit octal number. */ | |
3425 if (c >= 0400) | |
3426 { | |
3427 *p++ = '0' + ((c & 07000000) >> 18); | |
3428 *p++ = '0' + ((c & 0700000) >> 15); | |
3429 *p++ = '0' + ((c & 070000) >> 12); | |
3430 *p++ = '0' + ((c & 07000) >> 9); | |
3431 } | |
3432 #endif | |
3433 *p++ = '0' + ((c & 0700) >> 6); | |
3434 *p++ = '0' + ((c & 0070) >> 3); | |
3435 *p++ = '0' + ((c & 0007)); | |
3436 } | |
3437 else | |
3438 { | |
867 | 3439 p += set_itext_ichar (p, c); |
428 | 3440 } |
3441 | |
3442 *p = 0; | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3443 return build_istring (buf); |
428 | 3444 } |
3445 | |
3446 | |
3447 /************************************************************************/ | |
3448 /* where-is (mapping bindings to keys) */ | |
3449 /************************************************************************/ | |
3450 | |
3451 static Lisp_Object | |
3452 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps, | |
793 | 3453 Lisp_Object firstonly, Eistring *target_buffer); |
428 | 3454 |
3455 DEFUN ("where-is-internal", Fwhere_is_internal, 1, 5, 0, /* | |
3456 Return list of keys that invoke DEFINITION in KEYMAPS. | |
3457 KEYMAPS can be either a keymap (meaning search in that keymap and the | |
3458 current global keymap) or a list of keymaps (meaning search in exactly | |
3096 | 3459 those keymaps and no others). |
428 | 3460 |
3461 If optional 3rd arg FIRSTONLY is non-nil, return a vector representing | |
3462 the first key sequence found, rather than a list of all possible key | |
3463 sequences. | |
3464 | |
3096 | 3465 Optional 4th argument NOINDIRECT is ignored. (GNU Emacs uses it to allow |
3466 searching for an indirect keymap by inhibiting following of indirections to | |
3467 keymaps or slots, but XEmacs doesn't need it because keymaps are a type.) | |
3468 | |
3469 If optional 5th argument EVENT-OR-KEYS is non-nil and KEYMAPS is nil, | |
3470 search in the currently applicable maps for EVENT-OR-KEYS (this is | |
3471 equivalent to specifying `(current-keymaps EVENT-OR-KEYS)' as the | |
3472 argument to KEYMAPS). | |
428 | 3473 */ |
2286 | 3474 (definition, keymaps, firstonly, UNUSED (noindirect), event_or_keys)) |
428 | 3475 { |
3476 /* This function can GC */ | |
3477 Lisp_Object maps[100]; | |
3478 Lisp_Object *gubbish = maps; | |
3479 int nmaps; | |
3480 | |
3481 /* Get keymaps as an array */ | |
3482 if (NILP (keymaps)) | |
3483 { | |
3484 nmaps = get_relevant_keymaps (event_or_keys, countof (maps), | |
3485 gubbish); | |
3486 if (nmaps > countof (maps)) | |
3487 { | |
3488 gubbish = alloca_array (Lisp_Object, nmaps); | |
3489 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish); | |
3490 } | |
3491 } | |
3492 else if (CONSP (keymaps)) | |
3493 { | |
3494 Lisp_Object rest; | |
3495 int i; | |
3496 | |
3497 nmaps = XINT (Flength (keymaps)); | |
3498 if (nmaps > countof (maps)) | |
3499 { | |
3500 gubbish = alloca_array (Lisp_Object, nmaps); | |
3501 } | |
3502 for (rest = keymaps, i = 0; !NILP (rest); | |
3503 rest = XCDR (keymaps), i++) | |
3504 { | |
3505 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1); | |
3506 } | |
3507 } | |
3508 else | |
3509 { | |
3510 nmaps = 1; | |
3511 gubbish[0] = get_keymap (keymaps, 1, 1); | |
3512 if (!EQ (gubbish[0], Vcurrent_global_map)) | |
3513 { | |
3514 gubbish[1] = Vcurrent_global_map; | |
3515 nmaps++; | |
3516 } | |
3517 } | |
3518 | |
3519 return where_is_internal (definition, gubbish, nmaps, firstonly, 0); | |
3520 } | |
3521 | |
3522 /* This function is like | |
3523 (key-description (where-is-internal definition nil t)) | |
3524 except that it writes its output into a (char *) buffer that you | |
3525 provide; it doesn't cons (or allocate memory) at all, so it's | |
3526 very fast. This is used by menubar.c. | |
3527 */ | |
3528 void | |
793 | 3529 where_is_to_char (Lisp_Object definition, Eistring *buffer) |
428 | 3530 { |
3531 /* This function can GC */ | |
3532 Lisp_Object maps[100]; | |
3533 Lisp_Object *gubbish = maps; | |
3534 int nmaps; | |
3535 | |
3536 /* Get keymaps as an array */ | |
3537 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish); | |
3538 if (nmaps > countof (maps)) | |
3539 { | |
3540 gubbish = alloca_array (Lisp_Object, nmaps); | |
3541 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish); | |
3542 } | |
3543 | |
3544 where_is_internal (definition, maps, nmaps, Qt, buffer); | |
3545 } | |
3546 | |
3547 | |
3548 static Lisp_Object | |
934 | 3549 raw_keys_to_keys (Lisp_Key_Data *keys, int count) |
428 | 3550 { |
3551 Lisp_Object result = make_vector (count, Qnil); | |
3552 while (count--) | |
3553 XVECTOR_DATA (result) [count] = make_key_description (&(keys[count]), 1); | |
3554 return result; | |
3555 } | |
3556 | |
3557 | |
3558 static void | |
934 | 3559 format_raw_keys (Lisp_Key_Data *keys, int count, Eistring *buf) |
428 | 3560 { |
3561 int i; | |
934 | 3562 Lisp_Object event = Fmake_event (Qnil, Qnil); |
3563 XSET_EVENT_TYPE (event, key_press_event); | |
3564 XSET_EVENT_CHANNEL (event, Vselected_console); | |
428 | 3565 for (i = 0; i < count; i++) |
3566 { | |
1204 | 3567 XSET_EVENT_KEY_KEYSYM (event, keys[i].keysym); |
3568 XSET_EVENT_KEY_MODIFIERS (event, KEY_DATA_MODIFIERS (&keys[i])); | |
934 | 3569 format_event_object (buf, event, 1); |
793 | 3570 if (i < count - 1) |
2421 | 3571 eicat_ascii (buf, " "); |
428 | 3572 } |
1204 | 3573 Fdeallocate_event (event); |
428 | 3574 } |
3575 | |
3576 | |
3577 /* definition is the thing to look for. | |
3578 map is a keymap. | |
3579 shadow is an array of shadow_count keymaps; if there is a different | |
3580 binding in any of the keymaps of a key that we are considering | |
3581 returning, then we reconsider. | |
3582 firstonly means give up after finding the first match; | |
3583 keys_so_far and modifiers_so_far describe which map we're looking in; | |
3584 If we're in the "meta" submap of the map that "C-x 4" is bound to, | |
3585 then keys_so_far will be {(control x), \4}, and modifiers_so_far | |
442 | 3586 will be XEMACS_MOD_META. That is, keys_so_far is the chain of keys that we |
428 | 3587 have followed, and modifiers_so_far_so_far is the bits (partial keys) |
3588 beyond that. | |
3589 | |
3590 (keys_so_far is a global buffer and the keys_count arg says how much | |
3591 of it we're currently interested in.) | |
3592 | |
3593 If target_buffer is provided, then we write a key-description into it, | |
3594 to avoid consing a string. This only works with firstonly on. | |
3595 */ | |
3596 | |
3597 struct where_is_closure | |
3598 { | |
3599 Lisp_Object definition; | |
3600 Lisp_Object *shadow; | |
3601 int shadow_count; | |
3602 int firstonly; | |
3603 int keys_count; | |
442 | 3604 int modifiers_so_far; |
793 | 3605 Eistring *target_buffer; |
934 | 3606 Lisp_Key_Data *keys_so_far; |
428 | 3607 int keys_so_far_total_size; |
3608 int keys_so_far_malloced; | |
3609 }; | |
3610 | |
3611 static Lisp_Object where_is_recursive_mapper (Lisp_Object map, void *arg); | |
3612 | |
3613 static Lisp_Object | |
3614 where_is_recursive_mapper (Lisp_Object map, void *arg) | |
3615 { | |
3616 /* This function can GC */ | |
3617 struct where_is_closure *c = (struct where_is_closure *) arg; | |
3618 Lisp_Object definition = c->definition; | |
442 | 3619 const int firstonly = c->firstonly; |
3620 const int keys_count = c->keys_count; | |
3621 const int modifiers_so_far = c->modifiers_so_far; | |
793 | 3622 Eistring *target_buffer = c->target_buffer; |
428 | 3623 Lisp_Object keys = Fgethash (definition, |
3624 XKEYMAP (map)->inverse_table, | |
3625 Qnil); | |
3626 Lisp_Object submaps; | |
3627 Lisp_Object result = Qnil; | |
3628 | |
3629 if (!NILP (keys)) | |
3630 { | |
3631 /* One or more keys in this map match the definition we're looking for. | |
3632 Verify that these bindings aren't shadowed by other bindings | |
3633 in the shadow maps. Either nil or number as value from | |
3634 raw_lookup_key() means undefined. */ | |
934 | 3635 Lisp_Key_Data *so_far = c->keys_so_far; |
428 | 3636 |
3637 for (;;) /* loop over all keys that match */ | |
3638 { | |
3639 Lisp_Object k = CONSP (keys) ? XCAR (keys) : keys; | |
3640 int i; | |
3641 | |
3642 so_far [keys_count].keysym = k; | |
934 | 3643 SET_KEY_DATA_MODIFIERS (&so_far [keys_count], modifiers_so_far); |
428 | 3644 |
3645 /* now loop over all shadow maps */ | |
3646 for (i = 0; i < c->shadow_count; i++) | |
3647 { | |
3648 Lisp_Object shadowed = raw_lookup_key (c->shadow[i], | |
3649 so_far, | |
3650 keys_count + 1, | |
3651 0, 1); | |
3652 | |
3653 if (NILP (shadowed) || CHARP (shadowed) || | |
3654 EQ (shadowed, definition)) | |
3655 continue; /* we passed this test; it's not shadowed here. */ | |
3656 else | |
3657 /* ignore this key binding, since it actually has a | |
3658 different binding in a shadowing map */ | |
3659 goto c_doesnt_have_proper_loop_exit_statements; | |
3660 } | |
3661 | |
3662 /* OK, the key is for real */ | |
3663 if (target_buffer) | |
3664 { | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3665 assert (firstonly); |
428 | 3666 format_raw_keys (so_far, keys_count + 1, target_buffer); |
3667 return make_int (1); | |
3668 } | |
3669 else if (firstonly) | |
3670 return raw_keys_to_keys (so_far, keys_count + 1); | |
3671 else | |
3672 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1), | |
3673 result); | |
3674 | |
3675 c_doesnt_have_proper_loop_exit_statements: | |
3676 /* now on to the next matching key ... */ | |
3677 if (!CONSP (keys)) break; | |
3678 keys = XCDR (keys); | |
3679 } | |
3680 } | |
3681 | |
3682 /* Now search the sub-keymaps of this map. | |
3683 If we're in "firstonly" mode and have already found one, this | |
3684 point is not reached. If we get one from lower down, either | |
3685 return it immediately (in firstonly mode) or tack it onto the | |
3686 end of the ones we've gotten so far. | |
3687 */ | |
3688 for (submaps = keymap_submaps (map); | |
3689 !NILP (submaps); | |
3690 submaps = XCDR (submaps)) | |
3691 { | |
3692 Lisp_Object key = XCAR (XCAR (submaps)); | |
3693 Lisp_Object submap = XCDR (XCAR (submaps)); | |
442 | 3694 int lower_modifiers; |
428 | 3695 int lower_keys_count = keys_count; |
442 | 3696 int bucky; |
428 | 3697 |
3698 submap = get_keymap (submap, 0, 0); | |
3699 | |
3700 if (EQ (submap, map)) | |
3701 /* Arrgh! Some loser has introduced a loop... */ | |
3702 continue; | |
3703 | |
3704 /* If this is not a keymap, then that's probably because someone | |
3705 did an `fset' of a symbol that used to point to a map such that | |
3706 it no longer does. Sigh. Ignore this, and invalidate the cache | |
3707 so that it doesn't happen to us next time too. | |
3708 */ | |
3709 if (NILP (submap)) | |
3710 { | |
3711 XKEYMAP (map)->sub_maps_cache = Qt; | |
3712 continue; | |
3713 } | |
3714 | |
3715 /* If the map is a "bucky" map, then add a bit to the | |
3716 modifiers_so_far list. | |
3717 Otherwise, add a new raw_key onto the end of keys_so_far. | |
3718 */ | |
3719 bucky = MODIFIER_HASH_KEY_BITS (key); | |
3720 if (bucky != 0) | |
3721 lower_modifiers = (modifiers_so_far | bucky); | |
3722 else | |
3723 { | |
934 | 3724 Lisp_Key_Data *so_far = c->keys_so_far; |
428 | 3725 lower_modifiers = 0; |
3726 so_far [lower_keys_count].keysym = key; | |
934 | 3727 SET_KEY_DATA_MODIFIERS (&so_far [lower_keys_count], modifiers_so_far); |
428 | 3728 lower_keys_count++; |
3729 } | |
3730 | |
3731 if (lower_keys_count >= c->keys_so_far_total_size) | |
3732 { | |
3733 int size = lower_keys_count + 50; | |
3734 if (! c->keys_so_far_malloced) | |
3735 { | |
3025 | 3736 Lisp_Key_Data *new_ = xnew_array (Lisp_Key_Data, size); |
3737 memcpy ((void *)new_, (const void *)c->keys_so_far, | |
934 | 3738 c->keys_so_far_total_size * sizeof (Lisp_Key_Data)); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
3739 xfree (c->keys_so_far); |
3550 | 3740 c->keys_so_far = new_; |
428 | 3741 } |
3742 else | |
934 | 3743 XREALLOC_ARRAY (c->keys_so_far, Lisp_Key_Data, size); |
428 | 3744 |
3745 c->keys_so_far_total_size = size; | |
3746 c->keys_so_far_malloced = 1; | |
3747 } | |
3748 | |
3749 { | |
3750 Lisp_Object lower; | |
3751 | |
3752 c->keys_count = lower_keys_count; | |
3753 c->modifiers_so_far = lower_modifiers; | |
3754 | |
3755 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper, c); | |
3756 | |
3757 c->keys_count = keys_count; | |
3758 c->modifiers_so_far = modifiers_so_far; | |
3759 | |
3760 if (!firstonly) | |
3761 result = nconc2 (lower, result); | |
3762 else if (!NILP (lower)) | |
3763 return lower; | |
3764 } | |
3765 } | |
3766 return result; | |
3767 } | |
3768 | |
3769 | |
3770 static Lisp_Object | |
3771 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps, | |
793 | 3772 Lisp_Object firstonly, Eistring *target_buffer) |
428 | 3773 { |
3774 /* This function can GC */ | |
3775 Lisp_Object result = Qnil; | |
3776 int i; | |
934 | 3777 Lisp_Key_Data raw[20]; |
428 | 3778 struct where_is_closure c; |
3779 | |
3780 c.definition = definition; | |
3781 c.shadow = maps; | |
3782 c.firstonly = !NILP (firstonly); | |
3783 c.target_buffer = target_buffer; | |
3784 c.keys_so_far = raw; | |
3785 c.keys_so_far_total_size = countof (raw); | |
3786 c.keys_so_far_malloced = 0; | |
3787 | |
3788 /* Loop over each of the maps, accumulating the keys found. | |
3789 For each map searched, all previous maps shadow this one | |
3790 so that bogus keys aren't listed. */ | |
3791 for (i = 0; i < nmaps; i++) | |
3792 { | |
3793 Lisp_Object this_result; | |
3794 c.shadow_count = i; | |
3795 /* Reset the things set in each iteration */ | |
3796 c.keys_count = 0; | |
3797 c.modifiers_so_far = 0; | |
3798 | |
3799 this_result = traverse_keymaps (maps[i], Qnil, where_is_recursive_mapper, | |
3800 &c); | |
3801 if (!NILP (firstonly)) | |
3802 { | |
3803 result = this_result; | |
3804 if (!NILP (result)) | |
3805 break; | |
3806 } | |
3807 else | |
3808 result = nconc2 (this_result, result); | |
3809 } | |
3810 | |
3811 if (NILP (firstonly)) | |
3812 result = Fnreverse (result); | |
3813 | |
3814 if (c.keys_so_far_malloced) | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4962
diff
changeset
|
3815 xfree (c.keys_so_far); |
428 | 3816 return result; |
3817 } | |
3818 | |
3819 | |
3820 /************************************************************************/ | |
3821 /* Describing keymaps */ | |
3822 /************************************************************************/ | |
3823 | |
3824 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, 1, 5, 0, /* | |
3825 Insert a list of all defined keys and their definitions in MAP. | |
3826 Optional second argument ALL says whether to include even "uninteresting" | |
3827 definitions (ie symbols with a non-nil `suppress-keymap' property. | |
3828 Third argument SHADOW is a list of keymaps whose bindings shadow those | |
3829 of map; if a binding is present in any shadowing map, it is not printed. | |
3830 Fourth argument PREFIX, if non-nil, should be a key sequence; | |
3831 only bindings which start with that key sequence will be printed. | |
3832 Fifth argument MOUSE-ONLY-P says to only print bindings for mouse clicks. | |
3833 */ | |
3834 (map, all, shadow, prefix, mouse_only_p)) | |
3835 { | |
3836 /* This function can GC */ | |
3837 | |
3838 /* #### At some point, this function should be changed to accept a | |
3839 BUFFER argument. Currently, the BUFFER argument to | |
3840 describe_map_tree is being used only internally. */ | |
3841 describe_map_tree (map, NILP (all), shadow, prefix, | |
3842 !NILP (mouse_only_p), Fcurrent_buffer ()); | |
3843 return Qnil; | |
3844 } | |
3845 | |
3846 | |
3847 /* Insert a description of the key bindings in STARTMAP, | |
3848 followed by those of all maps reachable through STARTMAP. | |
3849 If PARTIAL is nonzero, omit certain "uninteresting" commands | |
3850 (such as `undefined'). | |
3851 If SHADOW is non-nil, it is a list of other maps; | |
3852 don't mention keys which would be shadowed by any of them | |
3853 If PREFIX is non-nil, only list bindings which start with those keys. | |
3854 */ | |
3855 | |
3856 void | |
3857 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow, | |
3858 Lisp_Object prefix, int mice_only_p, Lisp_Object buffer) | |
3859 { | |
3860 /* This function can GC */ | |
3861 Lisp_Object maps = Qnil; | |
3862 struct gcpro gcpro1, gcpro2; /* get_keymap may autoload */ | |
3863 GCPRO2 (maps, shadow); | |
3864 | |
3865 maps = Faccessible_keymaps (startmap, prefix); | |
3866 | |
3867 for (; !NILP (maps); maps = Fcdr (maps)) | |
3868 { | |
3869 Lisp_Object sub_shadow = Qnil; | |
3870 Lisp_Object elt = Fcar (maps); | |
3871 Lisp_Object tail; | |
3872 int no_prefix = (VECTORP (Fcar (elt)) | |
3873 && XINT (Flength (Fcar (elt))) == 0); | |
3874 struct gcpro ngcpro1, ngcpro2, ngcpro3; | |
3875 NGCPRO3 (sub_shadow, elt, tail); | |
3876 | |
3877 for (tail = shadow; CONSP (tail); tail = XCDR (tail)) | |
3878 { | |
3879 Lisp_Object shmap = XCAR (tail); | |
3880 | |
3881 /* If the sequence by which we reach this keymap is zero-length, | |
3882 then the shadow maps for this keymap are just SHADOW. */ | |
3883 if (no_prefix) | |
3884 ; | |
3885 /* If the sequence by which we reach this keymap actually has | |
3886 some elements, then the sequence's definition in SHADOW is | |
3887 what we should use. */ | |
3888 else | |
3889 { | |
3890 shmap = Flookup_key (shmap, Fcar (elt), Qt); | |
3891 if (CHARP (shmap)) | |
3892 shmap = Qnil; | |
3893 } | |
3894 | |
3895 if (!NILP (shmap)) | |
3896 { | |
3897 Lisp_Object shm = get_keymap (shmap, 0, 1); | |
3898 /* If shmap is not nil and not a keymap, it completely | |
3899 shadows this map, so don't describe this map at all. */ | |
3900 if (!KEYMAPP (shm)) | |
3901 goto SKIP; | |
3902 sub_shadow = Fcons (shm, sub_shadow); | |
3903 } | |
3904 } | |
3905 | |
3906 { | |
3907 /* Describe the contents of map MAP, assuming that this map | |
3908 itself is reached by the sequence of prefix keys KEYS (a vector). | |
3909 PARTIAL and SHADOW are as in `describe_map_tree'. */ | |
3910 Lisp_Object keysdesc | |
3911 = ((!no_prefix) | |
3912 ? concat2 (Fkey_description (Fcar (elt)), Vsingle_space_string) | |
3913 : Qnil); | |
3914 describe_map (Fcdr (elt), keysdesc, | |
3915 describe_command, | |
3916 partial, | |
3917 sub_shadow, | |
3918 mice_only_p, | |
3919 buffer); | |
3920 } | |
3921 SKIP: | |
3922 NUNGCPRO; | |
3923 } | |
3924 UNGCPRO; | |
3925 } | |
3926 | |
3927 | |
3928 static void | |
3929 describe_command (Lisp_Object definition, Lisp_Object buffer) | |
3930 { | |
3931 /* This function can GC */ | |
3932 int keymapp = !NILP (Fkeymapp (definition)); | |
3933 struct gcpro gcpro1; | |
3934 GCPRO1 (definition); | |
3935 | |
3936 Findent_to (make_int (16), make_int (3), buffer); | |
3937 if (keymapp) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3938 buffer_insert_ascstring (XBUFFER (buffer), "<< "); |
428 | 3939 |
3940 if (SYMBOLP (definition)) | |
3941 { | |
3942 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (definition)); | |
3943 } | |
3944 else if (STRINGP (definition) || VECTORP (definition)) | |
3945 { | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3946 buffer_insert_ascstring (XBUFFER (buffer), "Kbd Macro: "); |
428 | 3947 buffer_insert1 (XBUFFER (buffer), Fkey_description (definition)); |
3948 } | |
3949 else if (COMPILED_FUNCTIONP (definition)) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3950 buffer_insert_ascstring (XBUFFER (buffer), "Anonymous Compiled Function"); |
428 | 3951 else if (CONSP (definition) && EQ (XCAR (definition), Qlambda)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3952 buffer_insert_ascstring (XBUFFER (buffer), "Anonymous Lambda"); |
428 | 3953 else if (KEYMAPP (definition)) |
3954 { | |
3955 Lisp_Object name = XKEYMAP (definition)->name; | |
3956 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name))) | |
3957 { | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3958 buffer_insert_ascstring (XBUFFER (buffer), "Prefix command "); |
428 | 3959 if (SYMBOLP (name) |
3960 && EQ (find_symbol_value (name), definition)) | |
3961 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name)); | |
3962 else | |
3963 { | |
3964 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil)); | |
3965 } | |
3966 } | |
3967 else | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3968 buffer_insert_ascstring (XBUFFER (buffer), "Prefix Command"); |
428 | 3969 } |
3970 else | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3971 buffer_insert_ascstring (XBUFFER (buffer), "??"); |
428 | 3972 |
3973 if (keymapp) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3974 buffer_insert_ascstring (XBUFFER (buffer), " >>"); |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3975 buffer_insert_ascstring (XBUFFER (buffer), "\n"); |
428 | 3976 UNGCPRO; |
3977 } | |
3978 | |
3979 struct describe_map_closure | |
3980 { | |
3981 Lisp_Object *list; /* pointer to the list to update */ | |
3982 Lisp_Object partial; /* whether to ignore suppressed commands */ | |
3983 Lisp_Object shadow; /* list of maps shadowing this one */ | |
3984 Lisp_Object self; /* this map */ | |
3985 Lisp_Object self_root; /* this map, or some map that has this map as | |
3986 a parent. this is the base of the tree */ | |
3987 int mice_only_p; /* whether we are to display only button bindings */ | |
3988 }; | |
3989 | |
3990 struct describe_map_shadow_closure | |
3991 { | |
934 | 3992 const Lisp_Key_Data *raw_key; |
428 | 3993 Lisp_Object self; |
3994 }; | |
3995 | |
3996 static Lisp_Object | |
3997 describe_map_mapper_shadow_search (Lisp_Object map, void *arg) | |
3998 { | |
3999 struct describe_map_shadow_closure *c = | |
4000 (struct describe_map_shadow_closure *) arg; | |
4001 | |
4002 if (EQ (map, c->self)) | |
4003 return Qzero; /* Not shadowed; terminate search */ | |
4004 | |
934 | 4005 return !NILP (keymap_lookup_directly (map, |
4006 KEY_DATA_KEYSYM (c->raw_key), | |
4007 KEY_DATA_MODIFIERS (c->raw_key))) | |
428 | 4008 ? Qt : Qnil; |
4009 } | |
4010 | |
4011 | |
4012 static Lisp_Object | |
4013 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg) | |
4014 { | |
934 | 4015 Lisp_Key_Data *k = (Lisp_Key_Data *) arg; |
4016 return keymap_lookup_directly (km, KEY_DATA_KEYSYM (k), KEY_DATA_MODIFIERS (k)); | |
428 | 4017 } |
4018 | |
4019 | |
4020 static void | |
934 | 4021 describe_map_mapper (const Lisp_Key_Data *key, |
428 | 4022 Lisp_Object binding, |
4023 void *describe_map_closure) | |
4024 { | |
4025 /* This function can GC */ | |
4026 struct describe_map_closure *closure = | |
4027 (struct describe_map_closure *) describe_map_closure; | |
934 | 4028 Lisp_Object keysym = KEY_DATA_KEYSYM (key); |
4029 int modifiers = KEY_DATA_MODIFIERS (key); | |
428 | 4030 |
4031 /* Don't mention suppressed commands. */ | |
4032 if (SYMBOLP (binding) | |
4033 && !NILP (closure->partial) | |
4034 && !NILP (Fget (binding, closure->partial, Qnil))) | |
4035 return; | |
4036 | |
4037 /* If we're only supposed to display mouse bindings and this isn't one, | |
4038 then bug out. */ | |
4039 if (closure->mice_only_p && | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4040 (! ( |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4041 #define INCLUDE_BUTTON_ZERO |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4042 #define FROB(num) EQ (keysym, Qbutton##num) || \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4043 EQ (keysym, Qbutton##num##up) || |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4044 #include "keymap-buttons.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4045 0))) |
428 | 4046 return; |
4047 | |
4048 /* If this command in this map is shadowed by some other map, ignore it. */ | |
4049 { | |
4050 Lisp_Object tail; | |
4051 | |
4052 for (tail = closure->shadow; CONSP (tail); tail = XCDR (tail)) | |
4053 { | |
4054 QUIT; | |
4055 if (!NILP (traverse_keymaps (XCAR (tail), Qnil, | |
4056 keymap_lookup_inherited_mapper, | |
4057 /* Cast to discard `const' */ | |
4058 (void *)key))) | |
4059 return; | |
4060 } | |
4061 } | |
4062 | |
4063 /* If this key is in some map of which this map is a parent, then ignore | |
4064 it (in that case, it has been shadowed). | |
4065 */ | |
4066 { | |
4067 Lisp_Object sh; | |
4068 struct describe_map_shadow_closure c; | |
4069 c.raw_key = key; | |
4070 c.self = closure->self; | |
4071 | |
4072 sh = traverse_keymaps (closure->self_root, Qnil, | |
4073 describe_map_mapper_shadow_search, &c); | |
4074 if (!NILP (sh) && !ZEROP (sh)) | |
4075 return; | |
4076 } | |
4077 | |
4078 /* Otherwise add it to the list to be sorted. */ | |
4079 *(closure->list) = Fcons (Fcons (Fcons (keysym, make_int (modifiers)), | |
4080 binding), | |
4081 *(closure->list)); | |
4082 } | |
4083 | |
4084 | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
4085 static Lisp_Object |
428 | 4086 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
4087 Lisp_Object pred, Lisp_Object key_func) |
428 | 4088 { |
4089 /* obj1 and obj2 are conses of the form | |
4090 ( ( <keysym> . <modifiers> ) . <binding> ) | |
4091 keysym and modifiers are used, binding is ignored. | |
4092 */ | |
442 | 4093 int bit1, bit2; |
428 | 4094 obj1 = XCAR (obj1); |
4095 obj2 = XCAR (obj2); | |
4096 bit1 = XINT (XCDR (obj1)); | |
4097 bit2 = XINT (XCDR (obj2)); | |
4098 if (bit1 != bit2) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
4099 return bit1 < bit2 ? Qt : Qnil; |
428 | 4100 else |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
4101 return map_keymap_sort_predicate (obj1, obj2, pred, key_func); |
428 | 4102 } |
4103 | |
4104 /* Elide 2 or more consecutive numeric keysyms bound to the same thing, | |
4105 or 2 or more symbolic keysyms that are bound to the same thing and | |
4106 have consecutive character-set-properties. | |
4107 */ | |
4108 static int | |
4109 elide_next_two_p (Lisp_Object list) | |
4110 { | |
4111 Lisp_Object s1, s2; | |
2828 | 4112 extern Lisp_Object Qcharacter_of_keysym; |
428 | 4113 |
4114 if (NILP (XCDR (list))) | |
4115 return 0; | |
4116 | |
4117 /* next two bindings differ */ | |
4118 if (!EQ (XCDR (XCAR (list)), | |
4119 XCDR (XCAR (XCDR (list))))) | |
4120 return 0; | |
4121 | |
4122 /* next two modifier-sets differ */ | |
4123 if (!EQ (XCDR (XCAR (XCAR (list))), | |
4124 XCDR (XCAR (XCAR (XCDR (list)))))) | |
4125 return 0; | |
4126 | |
4127 s1 = XCAR (XCAR (XCAR (list))); | |
4128 s2 = XCAR (XCAR (XCAR (XCDR (list)))); | |
4129 | |
4130 if (SYMBOLP (s1)) | |
4131 { | |
2828 | 4132 Lisp_Object code = Fget (s1, Qcharacter_of_keysym, Qnil); |
428 | 4133 if (CHAR_OR_CHAR_INTP (code)) |
4134 { | |
4135 s1 = code; | |
4136 CHECK_CHAR_COERCE_INT (s1); | |
4137 } | |
4138 else return 0; | |
4139 } | |
4140 if (SYMBOLP (s2)) | |
4141 { | |
2828 | 4142 Lisp_Object code = Fget (s2, Qcharacter_of_keysym, Qnil); |
428 | 4143 if (CHAR_OR_CHAR_INTP (code)) |
4144 { | |
4145 s2 = code; | |
4146 CHECK_CHAR_COERCE_INT (s2); | |
4147 } | |
4148 else return 0; | |
4149 } | |
4150 | |
4151 return (XCHAR (s1) == XCHAR (s2) || | |
4152 XCHAR (s1) + 1 == XCHAR (s2)); | |
4153 } | |
4154 | |
4155 | |
4156 static Lisp_Object | |
4157 describe_map_parent_mapper (Lisp_Object keymap, void *arg) | |
4158 { | |
4159 /* This function can GC */ | |
4160 struct describe_map_closure *describe_map_closure = | |
4161 (struct describe_map_closure *) arg; | |
4162 describe_map_closure->self = keymap; | |
4163 map_keymap (XKEYMAP (keymap)->table, | |
4164 0, /* don't sort: we'll do it later */ | |
4165 describe_map_mapper, describe_map_closure); | |
4166 return Qnil; | |
4167 } | |
4168 | |
4169 | |
4170 /* Describe the contents of map MAP, assuming that this map itself is | |
4171 reached by the sequence of prefix keys KEYS (a string or vector). | |
4172 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */ | |
4173 | |
4174 static void | |
4175 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, | |
4176 void (*elt_describer) (Lisp_Object, Lisp_Object), | |
4177 int partial, | |
4178 Lisp_Object shadow, | |
4179 int mice_only_p, | |
4180 Lisp_Object buffer) | |
4181 { | |
4182 /* This function can GC */ | |
4183 struct describe_map_closure describe_map_closure; | |
4184 Lisp_Object list = Qnil; | |
4185 struct buffer *buf = XBUFFER (buffer); | |
867 | 4186 Ichar printable_min = (CHAR_OR_CHAR_INTP (buf->ctl_arrow) |
428 | 4187 ? XCHAR_OR_CHAR_INT (buf->ctl_arrow) |
4188 : ((EQ (buf->ctl_arrow, Qt) | |
4189 || EQ (buf->ctl_arrow, Qnil)) | |
4190 ? 256 : 160)); | |
4191 int elided = 0; | |
4192 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
2828 | 4193 extern Lisp_Object Qcharacter_of_keysym; |
428 | 4194 |
4195 keymap = get_keymap (keymap, 1, 1); | |
4196 describe_map_closure.partial = (partial ? Qsuppress_keymap : Qnil); | |
4197 describe_map_closure.shadow = shadow; | |
4198 describe_map_closure.list = &list; | |
4199 describe_map_closure.self_root = keymap; | |
4200 describe_map_closure.mice_only_p = mice_only_p; | |
4201 | |
4202 GCPRO4 (keymap, elt_prefix, shadow, list); | |
4203 | |
4204 traverse_keymaps (keymap, Qnil, | |
4205 describe_map_parent_mapper, &describe_map_closure); | |
4206 | |
4207 if (!NILP (list)) | |
4208 { | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5146
diff
changeset
|
4209 list = list_sort (list, describe_map_sort_predicate, Qnil, Qidentity); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4210 buffer_insert_ascstring (buf, "\n"); |
428 | 4211 while (!NILP (list)) |
4212 { | |
4213 Lisp_Object elt = XCAR (XCAR (list)); | |
4214 Lisp_Object keysym = XCAR (elt); | |
442 | 4215 int modifiers = XINT (XCDR (elt)); |
428 | 4216 |
4217 if (!NILP (elt_prefix)) | |
4218 buffer_insert_lisp_string (buf, elt_prefix); | |
4219 | |
442 | 4220 if (modifiers & XEMACS_MOD_META) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4221 buffer_insert_ascstring (buf, "M-"); |
442 | 4222 if (modifiers & XEMACS_MOD_CONTROL) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4223 buffer_insert_ascstring (buf, "C-"); |
442 | 4224 if (modifiers & XEMACS_MOD_SUPER) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4225 buffer_insert_ascstring (buf, "S-"); |
442 | 4226 if (modifiers & XEMACS_MOD_HYPER) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4227 buffer_insert_ascstring (buf, "H-"); |
442 | 4228 if (modifiers & XEMACS_MOD_ALT) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4229 buffer_insert_ascstring (buf, "Alt-"); |
442 | 4230 if (modifiers & XEMACS_MOD_SHIFT) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4231 buffer_insert_ascstring (buf, "Sh-"); |
428 | 4232 if (SYMBOLP (keysym)) |
4233 { | |
2828 | 4234 Lisp_Object code = Fget (keysym, Qcharacter_of_keysym, Qnil); |
867 | 4235 Ichar c = (CHAR_OR_CHAR_INTP (code) |
4236 ? XCHAR_OR_CHAR_INT (code) : (Ichar) -1); | |
428 | 4237 /* Calling Fsingle_key_description() would cons more */ |
4238 #if 0 /* This is bogus */ | |
4239 if (EQ (keysym, QKlinefeed)) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4240 buffer_insert_ascstring (buf, "LFD"); |
428 | 4241 else if (EQ (keysym, QKtab)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4242 buffer_insert_ascstring (buf, "TAB"); |
428 | 4243 else if (EQ (keysym, QKreturn)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4244 buffer_insert_ascstring (buf, "RET"); |
428 | 4245 else if (EQ (keysym, QKescape)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4246 buffer_insert_ascstring (buf, "ESC"); |
428 | 4247 else if (EQ (keysym, QKdelete)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4248 buffer_insert_ascstring (buf, "DEL"); |
428 | 4249 else if (EQ (keysym, QKspace)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4250 buffer_insert_ascstring (buf, "SPC"); |
428 | 4251 else if (EQ (keysym, QKbackspace)) |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4252 buffer_insert_ascstring (buf, "BS"); |
428 | 4253 else |
4254 #endif | |
4255 if (c >= printable_min) | |
4256 buffer_insert_emacs_char (buf, c); | |
4257 else buffer_insert1 (buf, Fsymbol_name (keysym)); | |
4258 } | |
4259 else if (CHARP (keysym)) | |
4260 buffer_insert_emacs_char (buf, XCHAR (keysym)); | |
4261 else | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4262 buffer_insert_ascstring (buf, "---bad keysym---"); |
428 | 4263 |
4264 if (elided) | |
4265 elided = 0; | |
4266 else | |
4267 { | |
4268 int k = 0; | |
4269 | |
4270 while (elide_next_two_p (list)) | |
4271 { | |
4272 k++; | |
4273 list = XCDR (list); | |
4274 } | |
4275 if (k != 0) | |
4276 { | |
4277 if (k == 1) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4278 buffer_insert_ascstring (buf, ", "); |
428 | 4279 else |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
4280 buffer_insert_ascstring (buf, " .. "); |
428 | 4281 elided = 1; |
4282 continue; | |
4283 } | |
4284 } | |
4285 | |
4286 /* Print a description of the definition of this character. */ | |
4287 (*elt_describer) (XCDR (XCAR (list)), buffer); | |
4288 list = XCDR (list); | |
4289 } | |
4290 } | |
4291 UNGCPRO; | |
4292 } | |
4293 | |
4294 | |
4295 void | |
4296 syms_of_keymap (void) | |
4297 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
4298 INIT_LISP_OBJECT (keymap); |
442 | 4299 |
502 | 4300 DEFSYMBOL (Qminor_mode_map_alist); |
4301 | |
4302 DEFSYMBOL (Qkeymapp); | |
4303 | |
4304 DEFSYMBOL (Qsuppress_keymap); | |
4305 | |
4306 DEFSYMBOL (Qmodeline_map); | |
4307 DEFSYMBOL (Qtoolbar_map); | |
428 | 4308 |
4309 DEFSUBR (Fkeymap_parents); | |
4310 DEFSUBR (Fset_keymap_parents); | |
4311 DEFSUBR (Fkeymap_name); | |
4312 DEFSUBR (Fset_keymap_name); | |
4313 DEFSUBR (Fkeymap_prompt); | |
4314 DEFSUBR (Fset_keymap_prompt); | |
4315 DEFSUBR (Fkeymap_default_binding); | |
4316 DEFSUBR (Fset_keymap_default_binding); | |
4317 | |
4318 DEFSUBR (Fkeymapp); | |
4319 DEFSUBR (Fmake_keymap); | |
4320 DEFSUBR (Fmake_sparse_keymap); | |
4321 | |
4322 DEFSUBR (Fcopy_keymap); | |
4323 DEFSUBR (Fkeymap_fullness); | |
4324 DEFSUBR (Fmap_keymap); | |
4325 DEFSUBR (Fevent_matches_key_specifier_p); | |
4326 DEFSUBR (Fdefine_key); | |
4327 DEFSUBR (Flookup_key); | |
4328 DEFSUBR (Fkey_binding); | |
4329 DEFSUBR (Fuse_global_map); | |
4330 DEFSUBR (Fuse_local_map); | |
4331 DEFSUBR (Fcurrent_local_map); | |
4332 DEFSUBR (Fcurrent_global_map); | |
4333 DEFSUBR (Fcurrent_keymaps); | |
4334 DEFSUBR (Faccessible_keymaps); | |
4335 DEFSUBR (Fkey_description); | |
4336 DEFSUBR (Fsingle_key_description); | |
4337 DEFSUBR (Fwhere_is_internal); | |
4338 DEFSUBR (Fdescribe_bindings_internal); | |
4339 | |
4340 DEFSUBR (Ftext_char_description); | |
4341 | |
502 | 4342 DEFSYMBOL (Qcontrol); |
4343 DEFSYMBOL (Qctrl); | |
4344 DEFSYMBOL (Qmeta); | |
4345 DEFSYMBOL (Qsuper); | |
4346 DEFSYMBOL (Qhyper); | |
4347 DEFSYMBOL (Qalt); | |
4348 DEFSYMBOL (Qshift); | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4349 #define INCLUDE_BUTTON_ZERO |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4350 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4351 DEFSYMBOL (Qbutton##num); \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4352 DEFSYMBOL (Qbutton##num##up); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4353 #include "keymap-buttons.h" |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4354 #define FROB(num) \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4355 DEFSYMBOL (Qmouse_##num); \ |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4356 DEFSYMBOL (Qdown_mouse_##num); |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4357 #include "keymap-buttons.h" |
502 | 4358 DEFSYMBOL (Qmenu_selection); |
4359 DEFSYMBOL (QLFD); | |
4360 DEFSYMBOL (QTAB); | |
4361 DEFSYMBOL (QRET); | |
4362 DEFSYMBOL (QESC); | |
4363 DEFSYMBOL (QDEL); | |
4364 DEFSYMBOL (QSPC); | |
4365 DEFSYMBOL (QBS); | |
428 | 4366 } |
4367 | |
4368 void | |
4369 vars_of_keymap (void) | |
4370 { | |
4371 DEFVAR_LISP ("meta-prefix-char", &Vmeta_prefix_char /* | |
4372 Meta-prefix character. | |
4373 This character followed by some character `foo' turns into `Meta-foo'. | |
4374 This can be any form recognized as a single key specifier. | |
4375 To disable the meta-prefix-char, set it to a negative number. | |
4376 */ ); | |
4377 Vmeta_prefix_char = make_char (033); | |
4378 | |
4379 DEFVAR_LISP ("mouse-grabbed-buffer", &Vmouse_grabbed_buffer /* | |
4380 A buffer which should be consulted first for all mouse activity. | |
4381 When a mouse-click is processed, it will first be looked up in the | |
4382 local-map of this buffer, and then through the normal mechanism if there | |
4383 is no binding for that click. This buffer's value of `mode-motion-hook' | |
4384 will be consulted instead of the `mode-motion-hook' of the buffer of the | |
4385 window under the mouse. You should *bind* this, not set it. | |
4386 */ ); | |
4387 Vmouse_grabbed_buffer = Qnil; | |
4388 | |
4389 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map /* | |
4390 Keymap that overrides all other local keymaps. | |
4391 If this variable is non-nil, it is used as a keymap instead of the | |
4392 buffer's local map, and the minor mode keymaps and extent-local keymaps. | |
4393 You should *bind* this, not set it. | |
4394 */ ); | |
4395 Voverriding_local_map = Qnil; | |
4396 | |
4397 Fset (Qminor_mode_map_alist, Qnil); | |
4398 | |
4399 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /* | |
4400 Keymap of key translations that can override keymaps. | |
2027 | 4401 |
4402 This keymap works like `function-key-map', but is searched before it, | |
428 | 4403 and applies even for keys that have ordinary bindings. |
2027 | 4404 |
4405 The `read-key-sequence' function replaces any subsequence bound by | |
4406 `key-translation-map' with its binding. More precisely, when the active | |
4407 keymaps have no binding for the current key sequence but | |
4408 `key-translation-map' binds a suffix of the sequence to a vector or string, | |
4409 `read-key-sequence' replaces the matching suffix with its binding, and | |
4410 continues with the new sequence. See `key-binding' for details. | |
4411 | |
4412 The events that come from bindings in `key-translation-map' are not | |
4413 themselves looked up in `key-translation-map'. | |
4414 | |
4415 #### FIXME: stolen from `function-key-map'; need better example. | |
4416 #### I guess you could implement a Dvorak keyboard with this? | |
4417 For example, suppose `key-translation-map' binds `ESC O P' to [f1]. | |
4418 Typing `ESC O P' to `read-key-sequence' would return | |
4419 \[#<keypress-event f1>]. Typing `C-x ESC O P' would return | |
4420 \[#<keypress-event control-X> #<keypress-event f1>]. If [f1] | |
4421 were a prefix key, typing `ESC O P x' would return | |
4422 \[#<keypress-event f1> #<keypress-event x>]. | |
428 | 4423 */ ); |
4424 Vkey_translation_map = Qnil; | |
4425 | |
771 | 4426 DEFVAR_LISP ("global-tty-map", &Vglobal_tty_map /* |
4427 Global keymap that applies only to TTY's. | |
4428 Key bindings are looked up in this map just before looking in the global map, | |
4429 but only when the current console is a TTY console. See also | |
4430 `global-window-system-map'. | |
4431 */ ); | |
4432 Vglobal_tty_map = Qnil; | |
4433 | |
4434 DEFVAR_LISP ("global-window-system-map", &Vglobal_window_system_map /* | |
4435 Global keymap that applies only to window systems. | |
4436 Key bindings are looked up in this map just before looking in the global map, | |
4437 but only when the current console is not a TTY console. See also | |
4438 `global-tty-map'. | |
4439 */ ); | |
4440 Vglobal_window_system_map = Qnil; | |
4441 | |
428 | 4442 DEFVAR_LISP ("vertical-divider-map", &Vvertical_divider_map /* |
4443 Keymap which handles mouse clicks over vertical dividers. | |
4444 */ ); | |
4445 Vvertical_divider_map = Qnil; | |
4446 | |
4447 DEFVAR_INT ("keymap-tick", &keymap_tick /* | |
4448 Incremented for each change to any keymap. | |
4449 */ ); | |
4450 keymap_tick = 0; | |
4451 | |
4452 staticpro (&Vcurrent_global_map); | |
4453 | |
867 | 4454 Vsingle_space_string = make_string ((const Ibyte *) " ", 1); |
428 | 4455 staticpro (&Vsingle_space_string); |
4456 } | |
4457 | |
4458 void | |
4459 complex_vars_of_keymap (void) | |
4460 { | |
4461 /* This function can GC */ | |
4462 Lisp_Object ESC_prefix = intern ("ESC-prefix"); | |
4463 Lisp_Object meta_disgustitute; | |
4464 | |
4465 Vcurrent_global_map = Fmake_keymap (Qnil); | |
771 | 4466 Vglobal_tty_map = Fmake_keymap (intern ("global-tty-map")); |
4467 Vglobal_window_system_map = | |
4468 Fmake_keymap (intern ("global-window-system-map")); | |
428 | 4469 |
4470 meta_disgustitute = Fmake_keymap (Qnil); | |
4471 Ffset (ESC_prefix, meta_disgustitute); | |
4472 /* no need to protect meta_disgustitute, though */ | |
442 | 4473 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
428 | 4474 XKEYMAP (Vcurrent_global_map), |
4475 meta_disgustitute); | |
4476 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt; | |
4477 | |
4478 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map")); | |
4479 } |