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