annotate src/keymap.c @ 464:4ddaee1a9029

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Fri, 20 Dec 1991 07:15:37 +0000
parents d04df545062f
children 36359663b6d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Manipulation of keymaps
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include "config.h"
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include <stdio.h>
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #undef NULL
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "lisp.h"
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "commands.h"
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include "buffer.h"
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #define min(a, b) ((a) < (b) ? (a) : (b))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 /* Dense keymaps look like (keymap VECTOR . ALIST), where VECTOR is a
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 128-element vector used to look up bindings for ASCII characters,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 and ALIST is an assoc list for looking up symbols. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #define DENSE_TABLE_SIZE (0200)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 /* Actually allocate storage for these variables */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 Lisp_Object current_global_map; /* Current global keymap */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 Lisp_Object global_map; /* default global key bindings */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 Lisp_Object meta_map; /* The keymap used for globally bound
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ESC-prefixed default commands */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 Lisp_Object control_x_map; /* The keymap used for globally bound
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 C-x-prefixed default commands */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 /* was MinibufLocalMap */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 Lisp_Object Vminibuffer_local_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 /* The keymap used by the minibuf for local
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 bindings when spaces are allowed in the
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 minibuf */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 /* was MinibufLocalNSMap */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 Lisp_Object Vminibuffer_local_ns_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 /* The keymap used by the minibuf for local
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 bindings when spaces are not encouraged
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 in the minibuf */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 /* keymap used for minibuffers when doing completion */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 /* was MinibufLocalCompletionMap */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 Lisp_Object Vminibuffer_local_completion_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 /* keymap used for minibuffers when doing completion and require a match */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 /* was MinibufLocalMustMatchMap */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 Lisp_Object Vminibuffer_local_must_match_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 Lisp_Object Qkeymapp, Qkeymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 /* A char over 0200 in a key sequence
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 is equivalent to prefixing with this character. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 extern Lisp_Object meta_prefix_char;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 void describe_map_tree ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 static Lisp_Object describe_buffer_bindings ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 static void describe_command ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 static void describe_map ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 static void describe_alist ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 0, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 VECTOR is a 128-element vector which holds the bindings for the ASCII\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 characters. ALIST is an assoc-list which holds bindings for function keys,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 mouse events, and any other things that appear in the input stream.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 All entries in it are initially nil, meaning \"command undefined\".")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 return Fcons (Qkeymap,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 Fcons (Fmake_vector (make_number (DENSE_TABLE_SIZE), Qnil),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 Qnil));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, Smake_sparse_keymap, 0, 0, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 "Construct and return a new sparse-keymap list.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 which binds the function key or mouse event SYMBOL to DEFINITION.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 Initially the alist is nil.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 return Fcons (Qkeymap, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 /* This function is used for installing the standard key bindings
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 at initialization time.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 For example:
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 I haven't extended these to allow the initializing code to bind
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 function keys and mouse events; since they are called by many files,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 I'd have to fix lots of callers, and nobody right now would be using
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 the new functionality, so it seems like a waste of time. But there's
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 no technical reason not to. -JimB */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 initial_define_key (keymap, key, defname)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 int key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 char *defname;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 store_in_keymap (keymap, make_number (key), intern (defname));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 /* Define character fromchar in map frommap as an alias for character
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 tochar in map tomap. Subsequent redefinitions of the latter WILL
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 affect the former. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 #if 0
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 synkey (frommap, fromchar, tomap, tochar)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 struct Lisp_Vector *frommap, *tomap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 int fromchar, tochar;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 Lisp_Object v, c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 XSET (v, Lisp_Vector, tomap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 XFASTINT (c) = tochar;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 frommap->contents[fromchar] = Fcons (v, c);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 #endif /* 0 */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 "Return t if ARG is a keymap.\n\
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
145 \n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
146 A keymap is list (keymap . ALIST), a list (keymap VECTOR . ALIST),\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
147 or a symbol whose function definition is a keymap is itself a keymap.\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
148 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
149 VECTOR is a 128-element vector of bindings for ASCII characters.")
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (object)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 Lisp_Object object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 return (NULL (get_keymap_1 (object, 0)) ? Qnil : Qt);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 /* Check that OBJECT is a keymap (after dereferencing through any
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 symbols). If it is, return it; otherwise, return nil, or signal an
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 error if ERROR != 0. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 get_keymap_1 (object, error)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 Lisp_Object object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 int error;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 tem = object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 while (XTYPE (tem) == Lisp_Symbol && !EQ (tem, Qunbound))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 tem = XSYMBOL (tem)->function;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 QUIT;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 return tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 if (error)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 wrong_type_argument (Qkeymapp, object);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 else return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 get_keymap (object)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 Lisp_Object object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 return get_keymap_1 (object, 1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 /* If KEYMAP is a dense keymap, return the vector from its cadr.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 Otherwise, return nil. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 static Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 keymap_table (keymap)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 Lisp_Object cadr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 if (CONSP (XCONS (keymap)->cdr)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 && XTYPE (cadr = XCONS (XCONS (keymap)->cdr)->car) == Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 && XVECTOR (cadr)->size == DENSE_TABLE_SIZE)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 return cadr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 /* Look up IDX in MAP. IDX may be any sort of event.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 Note that this does only one level of lookup; IDX must
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 be a single event, not a sequence. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 access_keymap (map, idx)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 Lisp_Object map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 Lisp_Object idx;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 /* If idx is a list (some sort of mouse click, perhaps?),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 the index we want to use is the car of the list, which
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 ought to be a symbol. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 if (XTYPE (idx) == Lisp_Cons)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 idx = XCONS (idx)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 if (XTYPE (idx) == Lisp_Int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 && (XINT (idx) < 0 || XINT (idx) >= DENSE_TABLE_SIZE))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 error ("Command key is not an ASCII character");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 Lisp_Object table = keymap_table (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 /* A dense keymap indexed by a character? */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 if (XTYPE (idx) == Lisp_Int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 && ! NULL (table))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 return XVECTOR (table)->contents[XFASTINT (idx)];
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 /* This lookup will not involve a vector reference. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 /* If idx is a symbol, it might have modifiers, which need to
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 be put in the canonical order. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 if (XTYPE (idx) == Lisp_Symbol)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 idx = reorder_modifiers (idx);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 return Fcdr (Fassq (idx, map));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 /* Given OBJECT which was found in a slot in a keymap,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 trace indirect definitions to get the actual definition of that slot.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 An indirect definition is a list of the form
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 and INDEX is the object to look up in KEYMAP to yield the definition.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 Also if OBJECT has a menu string as the first element,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 remove that. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 get_keyelt (object)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 register Lisp_Object object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 while (1)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 register Lisp_Object map, tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 map = get_keymap_1 (Fcar_safe (object), 0);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 tem = Fkeymapp (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 if (!NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 object = access_keymap (map, Fcdr (object));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 /* If the keymap contents looks like (STRING . DEFN),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 use DEFN.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 Keymap alist elements like (CHAR MENUSTRING . DEFN)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 will be used by HierarKey menus. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 else if (XTYPE (object) == Lisp_Cons
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 && XTYPE (XCONS (object)->car) == Lisp_String)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 object = XCONS (object)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 /* Anything else is really the value. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 return object;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 store_in_keymap (keymap, idx, def)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 register Lisp_Object idx;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 register Lisp_Object def;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 /* If idx is a list (some sort of mouse click, perhaps?),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 the index we want to use is the car of the list, which
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ought to be a symbol. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 if (XTYPE (idx) == Lisp_Cons)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 idx = Fcar (idx);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 if (XTYPE (idx) == Lisp_Int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 && (XINT (idx) < 0 || XINT (idx) >= DENSE_TABLE_SIZE))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 error ("Command key is a character outside of the ASCII set.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 Lisp_Object table = keymap_table (keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 /* A dense keymap indexed by a character? */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 if (XTYPE (idx) == Lisp_Int && !NULL (table))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 XVECTOR (table)->contents[XFASTINT (idx)] = def;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 /* Must be a sparse keymap, or a dense keymap indexed by a symbol. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 /* Point to the pointer to the start of the assoc-list part
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 of the keymap. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 register Lisp_Object *assoc_head
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 = (NULL (table)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 ? & XCONS (keymap)->cdr
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 : & XCONS (XCONS (keymap)->cdr)->cdr);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 register Lisp_Object defining_pair;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 /* If idx is a symbol, it might have modifiers, which need to
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 be put in the canonical order. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 if (XTYPE (idx) == Lisp_Symbol)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 idx = reorder_modifiers (idx);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 /* Point to the pair where idx is bound, if any. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 defining_pair = Fassq (idx, *assoc_head);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 if (NULL (defining_pair))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 *assoc_head = Fcons (Fcons (idx, def), *assoc_head);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 Fsetcdr (defining_pair, def);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 return def;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 "Return a copy of the keymap KEYMAP.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 The copy starts out with the same definitions of KEYMAP,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 but changing either the copy or KEYMAP does not affect the other.\n\
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
339 Any key definitions that are subkeymaps are recursively copied.\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
340 However, a key definition which is a symbol whose definition is a keymap\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
341 is not copied.")
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 (keymap)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 register Lisp_Object copy, tail;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 copy = Fcopy_alist (get_keymap (keymap));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 tail = XCONS (copy)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 /* If this is a dense keymap, copy the vector. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 if (CONSP (tail))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 register Lisp_Object table = XCONS (tail)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 if (XTYPE (table) == Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 && XVECTOR (table)->size == DENSE_TABLE_SIZE)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 register int i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 table = Fcopy_sequence (table);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 for (i = 0; i < DENSE_TABLE_SIZE; i++)
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
363 if (XTYPE (XVECTOR (copy)->contents[i]) != Lisp_Symbol)
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
364 if (! NULL (Fkeymapp (XVECTOR (table)->contents[i])))
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
365 XVECTOR (table)->contents[i]
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
366 = Fcopy_keymap (XVECTOR (table)->contents[i]);
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 XCONS (tail)->car = table;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 tail = XCONS (tail)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 /* Copy the alist portion of the keymap. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 while (CONSP (tail))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 register Lisp_Object elt;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 elt = XCONS (tail)->car;
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
379 if (CONSP (elt)
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
380 && XTYPE (XCONS (elt)->cdr) != Lisp_Symbol
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
381 && ! NULL (Fkeymapp (XCONS (elt)->cdr)))
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 XCONS (elt)->cdr = Fcopy_keymap (XCONS (elt)->cdr);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 tail = XCONS (tail)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 return copy;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 meaning a sequence of keystrokes and events.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 DEF is anything that can be a key's definition:\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 nil (means key is undefined in this keymap),\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 a command (a Lisp function suitable for interactive calling)\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 a string (treated as a keyboard macro),\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 a keymap (to define a prefix key),\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 a symbol. When the key is looked up, the symbol will stand for its\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 function definition, which should at that time be one of the above,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 or another symbol whose function definition is used, etc.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 a cons (STRING . DEFN), meaning that DEFN is the definition\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (DEFN should be a valid definition in its own right),\n\
368
d04df545062f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 362
diff changeset
404 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\
d04df545062f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 362
diff changeset
405 \n\
d04df545062f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 362
diff changeset
406 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\
d04df545062f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 362
diff changeset
407 the front of KEYMAP.")
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (keymap, key, def)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 register Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 Lisp_Object key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 Lisp_Object def;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 register int idx;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 register Lisp_Object c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 register Lisp_Object cmd;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 int metized = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 int length;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 keymap = get_keymap (keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 if (XTYPE (key) != Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 && XTYPE (key) != Lisp_String)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 key = wrong_type_argument (Qarrayp, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 length = Flength (key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 if (length == 0)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 idx = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 while (1)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 c = Faref (key, make_number (idx));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 if (XTYPE (c) == Lisp_Int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 && XINT (c) >= 0200
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 && !metized)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 c = meta_prefix_char;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 metized = 1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 if (XTYPE (c) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 XSETINT (c, XINT (c) & 0177);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 metized = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 idx++;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 if (idx == length)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 return store_in_keymap (keymap, c, def);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 cmd = get_keyelt (access_keymap (keymap, c));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 if (NULL (cmd))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 cmd = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 store_in_keymap (keymap, c, cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 tem = Fkeymapp (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 error ("Key sequence %s uses invalid prefix characters",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 XSTRING (key)->data);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 keymap = get_keymap (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 /* Value is number if KEY is too long; NIL if valid but has no definition. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 2, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 nil means undefined. See doc of `define-key' for kinds of definitions.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 A number as value means KEY is \"too long\";\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 that is, characters or symbols in it except for the last one\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 fail to be a valid sequence of prefix characters in KEYMAP.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 The number is how many characters at the front of KEY\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 it takes to reach a non-prefix command.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 (keymap, key)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 register Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 Lisp_Object key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 register int idx;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 register Lisp_Object cmd;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 register Lisp_Object c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 int metized = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 int length;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 keymap = get_keymap (keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 if (XTYPE (key) != Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 && XTYPE (key) != Lisp_String)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 key = wrong_type_argument (Qarrayp, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 length = Flength (key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 if (length == 0)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 return keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 idx = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 while (1)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 c = Faref (key, make_number (idx));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 if (XTYPE (c) == Lisp_Int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 && XINT (c) >= 0200
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 && !metized)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 c = meta_prefix_char;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 metized = 1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 if (XTYPE (c) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 XSETINT (c, XINT (c) & 0177);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 metized = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 idx++;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 cmd = get_keyelt (access_keymap (keymap, c));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 if (idx == length)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 return cmd;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 tem = Fkeymapp (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 return make_number (idx);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 keymap = get_keymap (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 QUIT;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 /* Append a key to the end of a key sequence. If key_sequence is a
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 string and key is a character, the result will be another string;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 otherwise, it will be a vector. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 append_key (key_sequence, key)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 Lisp_Object key_sequence, key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 Lisp_Object args[2];
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 args[0] = key_sequence;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 if (XTYPE (key_sequence) == Lisp_String
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 && XTYPE (key) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 args[1] = Fchar_to_string (key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 return Fconcat (2, args);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 args[1] = Fcons (key, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 return Fvconcat (2, args);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 "Return the binding for command KEY in current keymaps.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 KEY is a string, a sequence of keystrokes.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 The binding is probably a symbol with a function definition.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (key)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 Lisp_Object key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 register Lisp_Object map, value, value1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 map = current_buffer->keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 if (!NULL (map))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 value = Flookup_key (map, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 if (NULL (value))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 value1 = Flookup_key (current_global_map, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 if (XTYPE (value1) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 return value1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 else if (XTYPE (value) != Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 return value;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 return Flookup_key (current_global_map, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 "Return the binding for command KEYS in current local keymap only.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 KEYS is a string, a sequence of keystrokes.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 The binding is probably a symbol with a function definition.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (keys)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 Lisp_Object keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 register Lisp_Object map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 map = current_buffer->keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 if (NULL (map))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 return Flookup_key (map, keys);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 "Return the binding for command KEYS in current global keymap only.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 KEYS is a string, a sequence of keystrokes.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 The binding is probably a symbol with a function definition.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 (keys)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 Lisp_Object keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 return Flookup_key (current_global_map, keys);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 DEFUN ("global-set-key", Fglobal_set_key, Sglobal_set_key, 2, 2,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 "kSet key globally: \nCSet key %s to command: ",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 "Give KEY a global binding as COMMAND.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 COMMAND is a symbol naming an interactively-callable function.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 KEY is a string representing a sequence of keystrokes.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 Note that if KEY has a local binding in the current buffer\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 that local binding will continue to shadow any global binding.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (keys, function)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 Lisp_Object keys, function;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 if (XTYPE (keys) != Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 && XTYPE (keys) != Lisp_String)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 keys = wrong_type_argument (Qarrayp, keys);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 Fdefine_key (current_global_map, keys, function);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 DEFUN ("local-set-key", Flocal_set_key, Slocal_set_key, 2, 2,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 "kSet key locally: \nCSet key %s locally to command: ",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 "Give KEY a local binding as COMMAND.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 COMMAND is a symbol naming an interactively-callable function.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 KEY is a string representing a sequence of keystrokes.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 The binding goes in the current buffer's local map,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 which is shared with other buffers in the same major mode.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 (keys, function)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 Lisp_Object keys, function;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 register Lisp_Object map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 map = current_buffer->keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 if (NULL (map))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 current_buffer->keymap = map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 if (XTYPE (keys) != Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 && XTYPE (keys) != Lisp_String)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 keys = wrong_type_argument (Qarrayp, keys);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 Fdefine_key (map, keys, function);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 DEFUN ("global-unset-key", Fglobal_unset_key, Sglobal_unset_key,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 1, 1, "kUnset key globally: ",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 "Remove global binding of KEY.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 KEY is a string representing a sequence of keystrokes.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 (keys)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 Lisp_Object keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 return Fglobal_set_key (keys, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 DEFUN ("local-unset-key", Flocal_unset_key, Slocal_unset_key, 1, 1,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665 "kUnset key locally: ",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 "Remove local binding of KEY.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 KEY is a string representing a sequence of keystrokes.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 (keys)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 Lisp_Object keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 if (!NULL (current_buffer->keymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 Flocal_set_key (keys, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 DEFUN ("define-prefix-command", Fdefine_prefix_command, Sdefine_prefix_command, 1, 2, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 "Define COMMAND as a prefix command.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 A new sparse keymap is stored as COMMAND's function definition and its value.\n\
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
679 If a second optional argument MAPVAR is given, the map is stored as\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
680 its value instead of as COMMAND's value; but COMMAND is still defined\n\
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
681 as a function.")
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 (name, mapvar)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 Lisp_Object name, mapvar;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 Lisp_Object map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 Ffset (name, map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 if (!NULL (mapvar))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 Fset (mapvar, map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 Fset (name, map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 return name;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 "Select KEYMAP as the global keymap.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 (keymap)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 keymap = get_keymap (keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 current_global_map = keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 "Select KEYMAP as the local keymap.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 If KEYMAP is nil, that means no local keymap.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 (keymap)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 Lisp_Object keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 if (!NULL (keymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 keymap = get_keymap (keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 current_buffer->keymap = keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 0, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 "Return current buffer's local keymap, or nil if it has none.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 return current_buffer->keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 "Return the current global keymap.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 return current_global_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 "Find all keymaps accessible via prefix characters from KEYMAP.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 so that the KEYS increase in length. The first element is (\"\" . KEYMAP).")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 (startmap)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
740 Lisp_Object startmap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742 Lisp_Object maps, tail;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 maps = Fcons (Fcons (build_string (""), get_keymap (startmap)), Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745 tail = maps;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 /* For each map in the list maps,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 look at any other maps it points to,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 and stick them at the end if they are not already in the list.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 This is a breadth-first traversal, where tail is the queue of
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 nodes, and maps accumulates a list of all nodes visited. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
754 while (!NULL (tail))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
755 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 register Lisp_Object thisseq = Fcar (Fcar (tail));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 register Lisp_Object thismap = Fcdr (Fcar (tail));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 /* Does the current sequence end in the meta-prefix-char? */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 int is_metized = (XINT (last) >= 0
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 && EQ (Faref (thisseq, last), meta_prefix_char));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 /* Skip the 'keymap element of the list. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 thismap = Fcdr (thismap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 if (CONSP (thismap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
768 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769 register Lisp_Object table = XCONS (thismap)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 if (XTYPE (table) == Lisp_Vector)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 register int i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 /* Vector keymap. Scan all the elements. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 for (i = 0; i < DENSE_TABLE_SIZE; i++)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 register Lisp_Object cmd;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 cmd = get_keyelt (XVECTOR (table)->contents[i]);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 if (NULL (cmd)) continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783 tem = Fkeymapp (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784 if (!NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 cmd = get_keymap (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 /* Ignore keymaps that are already added to maps. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 tem = Frassq (cmd, maps);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 /* If the last key in thisseq is meta-prefix-char,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 turn it into a meta-ized keystroke. We know
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 that the event we're about to append is an
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 ascii keystroke. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 if (is_metized)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 tem = Fcopy_sequence (thisseq);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798 Faset (tem, last, make_number (i | 0200));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 /* This new sequence is the same length as
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 thisseq, so stick it in the list right
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 after this one. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803 XCONS (tail)->cdr =
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 Fcons (Fcons (tem, cmd), XCONS (tail)->cdr);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 tem = append_key (thisseq, make_number (i));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
810 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815 /* Once finished with the lookup elements of the dense
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
816 keymap, go on to scan its assoc list. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 thismap = XCONS (thismap)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 /* The rest is an alist. Scan all the alist elements. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 while (CONSP (thismap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 Lisp_Object elt = XCONS (thismap)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 /* Ignore elements that are not conses. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 if (CONSP (elt))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829 register Lisp_Object cmd = get_keyelt (XCONS (elt)->cdr);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 /* Ignore definitions that aren't keymaps themselves. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 tem = Fkeymapp (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834 if (!NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 /* Ignore keymaps that have been seen already. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 cmd = get_keymap (cmd);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 tem = Frassq (cmd, maps);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 /* let elt be the event defined by this map entry. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842 elt = XCONS (elt)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844 /* If the last key in thisseq is meta-prefix-char, and
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 this entry is a binding for an ascii keystroke,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 turn it into a meta-ized keystroke. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847 if (is_metized && XTYPE (elt) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 tem = Fcopy_sequence (thisseq);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850 Faset (tem, last, make_number (XINT (elt) | 0200));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 /* This new sequence is the same length as
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 thisseq, so stick it in the list right
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 after this one. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 XCONS (tail)->cdr =
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 Fcons (Fcons (tem, cmd), XCONS (tail)->cdr);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 nconc2 (tail,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 Fcons (Fcons (append_key (thisseq, elt), cmd),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 Qnil));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 thismap = XCONS (thismap)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 tail = Fcdr (tail);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 return maps;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 Lisp_Object Qsingle_key_description, Qkey_description;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
877 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
878 "Return a pretty description of key-sequence KEYS.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
879 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 spaces are put between sequence elements, etc.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 (keys)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 Lisp_Object keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 return Fmapconcat (Qsingle_key_description, keys, build_string (" "));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 char *
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 push_key_description (c, p)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 register unsigned int c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 register char *p;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 if (c >= 0200)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 *p++ = 'M';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895 *p++ = '-';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 c -= 0200;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898 if (c < 040)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 if (c == 033)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
901 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902 *p++ = 'E';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 *p++ = 'S';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 *p++ = 'C';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 else if (c == Ctl('I'))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 *p++ = 'T';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 *p++ = 'A';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 *p++ = 'B';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 else if (c == Ctl('J'))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 *p++ = 'L';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 *p++ = 'F';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 *p++ = 'D';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 else if (c == Ctl('M'))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 *p++ = 'R';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921 *p++ = 'E';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 *p++ = 'T';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 *p++ = 'C';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 *p++ = '-';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 if (c > 0 && c <= Ctl ('Z'))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 *p++ = c + 0140;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
931 *p++ = c + 0100;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
932 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 else if (c == 0177)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 *p++ = 'D';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
937 *p++ = 'E';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938 *p++ = 'L';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940 else if (c == ' ')
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942 *p++ = 'S';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
943 *p++ = 'P';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 *p++ = 'C';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 *p++ = c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
949 return p;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 "Return a pretty description of command character KEY.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954 Control characters turn into C-whatever, etc.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955 (key)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 Lisp_Object key;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 register unsigned char c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 char tem[6];
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 switch (XTYPE (key))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 case Lisp_Int: /* Normal character */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 c = XINT (key) & 0377;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 *push_key_description (c, tem) = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 return build_string (tem);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 case Lisp_Symbol: /* Function key or event-symbol */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 return Fsymbol_name (key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 case Lisp_Cons: /* Mouse event */
362
d1e5cf833d37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 250
diff changeset
972 key = XCONS (key)->car;
250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973 if (XTYPE (key) == Lisp_Symbol)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 return Fsymbol_name (key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 /* Mouse events should have an identifying symbol as their car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 fall through when this isn't the case. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
977
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978 default:
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
979 error ("KEY must be an integer, cons, or symbol.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
980 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
981 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
982
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
983 char *
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
984 push_text_char_description (c, p)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
985 register unsigned int c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 register char *p;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
987 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988 if (c >= 0200)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
989 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
990 *p++ = 'M';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
991 *p++ = '-';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
992 c -= 0200;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
993 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
994 if (c < 040)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
995 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
996 *p++ = '^';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 *p++ = c + 64; /* 'A' - 1 */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
999 else if (c == 0177)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1000 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1001 *p++ = '^';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1002 *p++ = '?';
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1003 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1004 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1005 *p++ = c;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1006 return p;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1008
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1009 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1010 "Return a pretty description of file-character CHAR.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011 Control characters turn into \"^char\", etc.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1012 (chr)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1013 Lisp_Object chr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1014 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1015 char tem[6];
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1017 CHECK_NUMBER (chr, 0);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1018
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1019 *push_text_char_description (XINT (chr) & 0377, tem) = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1020
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1021 return build_string (tem);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1022 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1023
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1024 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1025 "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1026 If KEYMAP is nil, search only KEYMAP1.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1027 If KEYMAP1 is nil, use the current global map.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1028 \n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1029 If optional 4th arg FIRSTONLY is non-nil,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1030 return a string representing the first key sequence found,\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1031 rather than a list of all possible key sequences.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032 \n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 to other keymaps or slots. This makes it possible to search for an\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035 indirect definition itself.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 (definition, local_keymap, global_keymap, firstonly, noindirect)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 Lisp_Object definition, local_keymap, global_keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1038 Lisp_Object firstonly, noindirect;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1039 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1040 register Lisp_Object maps;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1041 Lisp_Object found;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1042
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1043 if (NULL (global_keymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1044 global_keymap = current_global_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1045
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046 if (!NULL (local_keymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1047 maps = nconc2 (Faccessible_keymaps (get_keymap (local_keymap)),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1048 Faccessible_keymaps (get_keymap (global_keymap)));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1049 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1050 maps = Faccessible_keymaps (get_keymap (global_keymap));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1051
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1052 found = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 for (; !NULL (maps); maps = Fcdr (maps))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1055 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 register this = Fcar (Fcar (maps)); /* Key sequence to reach map */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1057 register map = Fcdr (Fcar (maps)); /* The map that it reaches */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 register dense_alist;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1059 register int i = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1060
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1061 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1062 [M-CHAR] sequences, check if last character of the sequence
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1063 is the meta-prefix char. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1064 Lisp_Object last = make_number (XINT (Flength (this)) - 1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1065 int last_is_meta = (XINT (last) >= 0
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1066 && EQ (Faref (this, last), meta_prefix_char));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1067
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1068 /* Skip the 'keymap element of the list. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1069 map = Fcdr (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1070
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1071 /* If the keymap is sparse, map traverses the alist to the end.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1072
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1073 If the keymap is dense, we set map to the vector and
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1074 dense_alist to the assoc-list portion of the keymap. When we
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1075 are finished dealing with the vector portion, we set map to
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1076 dense_alist, and handle the rest like a sparse keymap. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1077 if (XTYPE (XCONS (map)->car) == Lisp_Vector)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1078 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 dense_alist = XCONS (map)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1080 map = XCONS (map)->car;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1082
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1083 while (1)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1084 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1085 register Lisp_Object key, binding, sequence;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1086
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1087 QUIT;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1088 if (XTYPE (map) == Lisp_Vector)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1089 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1090 /* In a vector, look at each element. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1091 binding = XVECTOR (map)->contents[i];
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1092 XFASTINT (key) = i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1093 i++;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1094
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1095 /* If we've just finished scanning a vector, switch map to
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1096 the assoc-list at the end of the vector. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1097 if (i >= DENSE_TABLE_SIZE)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1098 map = dense_alist;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1099 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1100 else if (CONSP (map))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1101 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1102 /* In an alist, ignore elements that aren't conses. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1103 if (! CONSP (XCONS (map)->car))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1104 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1105 /* Ignore other elements. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1106 map = Fcdr (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1107 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1108 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1109 binding = Fcdr (Fcar (map));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1110 key = Fcar (Fcar (map));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1111 map = Fcdr (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1112 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1113 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1114 break;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1115
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1116 /* Search through indirections unless that's not wanted. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1117 if (NULL (noindirect))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1118 binding = get_keyelt (binding);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1119
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1120 /* End this iteration if this element does not match
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1121 the target. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1122
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1123 if (XTYPE (definition) == Lisp_Cons)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1124 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1125 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1126 tem = Fequal (binding, definition);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1127 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1128 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1129 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1130 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1131 if (!EQ (binding, definition))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1132 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1133
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1134 /* We have found a match.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1135 Construct the key sequence where we found it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1136 if (XTYPE (key) == Lisp_Int && last_is_meta)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1137 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1138 sequence = Fcopy_sequence (this);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1139 Faset (sequence, last, make_number (XINT (key) | 0200));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1140 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1141 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1142 sequence = append_key (this, key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1143
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1144 /* Verify that this key binding is not shadowed by another
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1145 binding for the same key, before we say it exists.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1146
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1147 Mechanism: look for local definition of this key and if
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1148 it is defined and does not match what we found then
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1149 ignore this key.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1150
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1151 Either nil or number as value from Flookup_key
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1152 means undefined. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1153 if (!NULL (local_keymap))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1154 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1155 binding = Flookup_key (local_keymap, sequence);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1156 if (!NULL (binding) && XTYPE (binding) != Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1157 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1158 if (XTYPE (definition) == Lisp_Cons)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1159 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1160 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1161 tem = Fequal (binding, definition);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1162 if (NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1163 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1164 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1165 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1166 if (!EQ (binding, definition))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1167 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1168 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1169 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1170
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1171 /* It is a true unshadowed match. Record it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1172
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1173 if (!NULL (firstonly))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1174 return sequence;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1175 found = Fcons (sequence, found);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1176 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1177 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1178 return Fnreverse (found);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1179 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1180
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1181 /* Return a string listing the keys and buttons that run DEFINITION. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1182
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1183 static Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1184 where_is_string (definition)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1185 Lisp_Object definition;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1186 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1187 register Lisp_Object keys, keys1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1188
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1189 keys = Fwhere_is_internal (definition,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1190 current_buffer->keymap, Qnil, Qnil, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1191 keys1 = Fmapconcat (Qkey_description, keys, build_string (", "));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1192
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1193 return keys1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1194 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1195
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1196 DEFUN ("where-is", Fwhere_is, Swhere_is, 1, 1, "CWhere is command: ",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1197 "Print message listing key sequences that invoke specified command.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1198 Argument is a command definition, usually a symbol with a function definition.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1199 (definition)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1200 Lisp_Object definition;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1201 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1202 register Lisp_Object string;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1203
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1204 CHECK_SYMBOL (definition, 0);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1205 string = where_is_string (definition);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1206
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1207 if (XSTRING (string)->size)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1208 message ("%s is on %s", XSYMBOL (definition)->name->data,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1209 XSTRING (string)->data);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1210 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1211 message ("%s is not on any key", XSYMBOL (definition)->name->data);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1212 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1213 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1214
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1215 DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1216 "Show a list of all defined keys, and their definitions.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1217 The list is put in a buffer, which is displayed.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1218 ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1219 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1220 register Lisp_Object thisbuf;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1221 XSET (thisbuf, Lisp_Buffer, current_buffer);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1222 internal_with_output_to_temp_buffer ("*Help*",
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1223 describe_buffer_bindings,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1224 thisbuf);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1225 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1226 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1227
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1228 static Lisp_Object
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1229 describe_buffer_bindings (descbuf)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1230 Lisp_Object descbuf;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1231 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1232 register Lisp_Object start1, start2;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1233
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1234 char *heading
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1235 = "key binding\n--- -------\n";
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1236
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1237 Fset_buffer (Vstandard_output);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1238
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1239 start1 = XBUFFER (descbuf)->keymap;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1240 if (!NULL (start1))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1241 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1242 insert_string ("Local Bindings:\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1243 insert_string (heading);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1244 describe_map_tree (start1, 0, Qnil, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1245 insert_string ("\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1246 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1247
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1248 insert_string ("Global Bindings:\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1249 insert_string (heading);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1250
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1251 describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1252
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1253 Fset_buffer (descbuf);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1254 return Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1255 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1256
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1257 /* Insert a desription of the key bindings in STARTMAP,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1258 followed by those of all maps reachable through STARTMAP.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1259 If PARTIAL is nonzero, omit certain "uninteresting" commands
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1260 (such as `undefined').
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1261 If SHADOW is non-nil, it is another map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1262 don't mention keys which would be shadowed by it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1263
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1264 void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1265 describe_map_tree (startmap, partial, shadow)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1266 Lisp_Object startmap, shadow;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1267 int partial;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1268 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1269 register Lisp_Object elt, sh;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1270 Lisp_Object maps;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1271 struct gcpro gcpro1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1272
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1273 maps = Faccessible_keymaps (startmap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1274 GCPRO1 (maps);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1275
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1276 for (; !NULL (maps); maps = Fcdr (maps))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1277 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1278 elt = Fcar (maps);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1279 sh = Fcar (elt);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1280
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1281 /* If there is no shadow keymap given, don't shadow. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1282 if (NULL (shadow))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1283 sh = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1284
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1285 /* If the sequence by which we reach this keymap is zero-length,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1286 then the shadow map for this keymap is just SHADOW. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1287 else if ((XTYPE (sh) == Lisp_String
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1288 && XSTRING (sh)->size == 0)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1289 || (XTYPE (sh) == Lisp_Vector
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1290 && XVECTOR (sh)->size == 0))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1291 sh = shadow;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1292
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1293 /* If the sequence by which we reach this keymap actually has
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1294 some elements, then the sequence's definition in SHADOW is
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1295 what we should use. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1296 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1297 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1298 sh = Flookup_key (shadow, Fcar (elt));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1299 if (XTYPE (sh) == Lisp_Int)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1300 sh = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1301 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1302
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1303 /* If sh is null (meaning that the current map is not shadowed),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1304 or a keymap (meaning that bindings from the current map might
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1305 show through), describe the map. Otherwise, sh is a command
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1306 that completely shadows the current map, and we shouldn't
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1307 bother. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1308 if (NULL (sh) || !NULL (Fkeymapp (sh)))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1309 describe_map (Fcdr (elt), Fcar (elt), partial, sh);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1310 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1311
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1312 UNGCPRO;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1313 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1314
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1315 static void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1316 describe_command (definition)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1317 Lisp_Object definition;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1318 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1319 register Lisp_Object tem1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1320
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1321 Findent_to (make_number (16), make_number (1));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1322
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1323 if (XTYPE (definition) == Lisp_Symbol)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1324 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1325 XSET (tem1, Lisp_String, XSYMBOL (definition)->name);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1326 insert1 (tem1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1327 insert_string ("\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1328 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1329 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1330 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1331 tem1 = Fkeymapp (definition);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1332 if (!NULL (tem1))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1333 insert_string ("Prefix Command\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1334 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1335 insert_string ("??\n");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1336 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1337 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1338
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1339 /* Describe the contents of map MAP, assuming that this map itself is
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1340 reached by the sequence of prefix keys KEYS (a string or vector).
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1341 PARTIAL, SHADOW is as in `describe_map_tree' above. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1342
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1343 static void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1344 describe_map (map, keys, partial, shadow)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1345 Lisp_Object map, keys;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1346 int partial;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1347 Lisp_Object shadow;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1348 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1349 register Lisp_Object keysdesc;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1350
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1351 if (!NULL (keys) && Flength (keys) > 0)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1352 keysdesc = concat2 (Fkey_description (keys),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1353 build_string (" "));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1354 else
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1355 keysdesc = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1356
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1357 /* Skip the 'keymap element of the list. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1358 map = Fcdr (map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1359
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1360 /* If this is a dense keymap, take care of the table. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1361 if (CONSP (map)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1362 && XTYPE (XCONS (map)->car) == Lisp_Vector)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1363 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1364 describe_vector (XCONS (map)->car, keysdesc, describe_command,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1365 partial, shadow);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1366 map = XCONS (map)->cdr;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1367 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1368
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1369 /* Now map is an alist. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1370 describe_alist (map, keysdesc, describe_command, partial, shadow);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1371 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1372
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1373 /* Insert a description of ALIST into the current buffer.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1374 Note that ALIST is just a plain association list, not a keymap. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1375
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1376 static void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1377 describe_alist (alist, elt_prefix, elt_describer, partial, shadow)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1378 register Lisp_Object alist;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1379 Lisp_Object elt_prefix;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1380 int (*elt_describer) ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1381 int partial;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1382 Lisp_Object shadow;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1383 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1384 Lisp_Object this;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1385 Lisp_Object tem1, tem2 = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1386 Lisp_Object suppress;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1387 Lisp_Object kludge;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1388 int first = 1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1389 struct gcpro gcpro1, gcpro2, gcpro3;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1390
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1391 if (partial)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1392 suppress = intern ("suppress-keymap");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1393
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1394 /* This vector gets used to present single keys to Flookup_key. Since
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1395 that is done once per alist element, we don't want to cons up a
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1396 fresh vector every time. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1397 kludge = Fmake_vector (make_number (1), Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1398
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1399 GCPRO3 (elt_prefix, tem2, kludge);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1400
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1401 for (; CONSP (alist); alist = Fcdr (alist))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1402 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1403 QUIT;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1404 tem1 = Fcar_safe (Fcar (alist));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1405 tem2 = get_keyelt (Fcdr_safe (Fcar (alist)));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1406
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1407 /* Don't show undefined commands or suppressed commands. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1408 if (NULL (tem2)) continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1409 if (XTYPE (tem2) == Lisp_Symbol && partial)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1410 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1411 this = Fget (tem2, suppress);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1412 if (!NULL (this))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1413 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1414 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1415
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1416 /* Don't show a command that isn't really visible
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1417 because a local definition of the same key shadows it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1418
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1419 if (!NULL (shadow))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1420 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1421 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1422
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1423 XVECTOR (kludge)->contents[0] = tem1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1424 tem = Flookup_key (shadow, kludge);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1425 if (!NULL (tem)) continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1426 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1427
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1428 if (first)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1429 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1430 insert ("\n", 1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1431 first = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1432 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1433
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1434 if (!NULL (elt_prefix))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1435 insert1 (elt_prefix);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1436
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1437 /* THIS gets the string to describe the character TEM1. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1438 this = Fsingle_key_description (tem1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1439 insert1 (this);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1440
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1441 /* Print a description of the definition of this character.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1442 elt_describer will take care of spacing out far enough
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1443 for alignment purposes. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1444 (*elt_describer) (tem2);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1445 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1446
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1447 UNGCPRO;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1448 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1449
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1450 static int
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1451 describe_vector_princ (elt)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1452 Lisp_Object elt;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1453 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1454 Fprinc (elt, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1455 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1456
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1457 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 1, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1458 "Print on `standard-output' a description of contents of VECTOR.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1459 This is text showing the elements of vector matched against indices.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1460 (vector)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1461 Lisp_Object vector;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1462 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1463 CHECK_VECTOR (vector, 0);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1464 describe_vector (vector, Qnil, describe_vector_princ, 0, Qnil, Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1465 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1466
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1467 describe_vector (vector, elt_prefix, elt_describer, partial, shadow)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1468 register Lisp_Object vector;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1469 Lisp_Object elt_prefix;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1470 int (*elt_describer) ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1471 int partial;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1472 Lisp_Object shadow;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1473 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1474 Lisp_Object this;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1475 Lisp_Object dummy;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1476 Lisp_Object tem1, tem2;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1477 register int i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1478 Lisp_Object suppress;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1479 Lisp_Object kludge;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1480 int first = 1;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1481 struct gcpro gcpro1, gcpro2, gcpro3;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1482
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1483 tem1 = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1484
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1485 /* This vector gets used to present single keys to Flookup_key. Since
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1486 that is done once per vector element, we don't want to cons up a
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1487 fresh vector every time. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1488 kludge = Fmake_vector (make_number (1), Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1489 GCPRO3 (elt_prefix, tem1, kludge);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1490
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1491 if (partial)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1492 suppress = intern ("suppress-keymap");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1493
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1494 for (i = 0; i < DENSE_TABLE_SIZE; i++)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1495 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1496 QUIT;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1497 tem1 = get_keyelt (XVECTOR (vector)->contents[i]);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1498
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1499 if (NULL (tem1)) continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1500
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1501 /* Don't mention suppressed commands. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1502 if (XTYPE (tem1) == Lisp_Symbol && partial)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1503 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1504 this = Fget (tem1, suppress);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1505 if (!NULL (this))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1506 continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1507 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1508
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1509 /* If this command in this map is shadowed by some other map,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1510 ignore it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1511 if (!NULL (shadow))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1512 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1513 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1514
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1515 XVECTOR (kludge)->contents[0] = make_number (i);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1516 tem = Flookup_key (shadow, kludge);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1517
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1518 if (!NULL (tem)) continue;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1519 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1520
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1521 if (first)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1522 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1523 insert ("\n", 1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1524 first = 0;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1525 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1526
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1527 /* Output the prefix that applies to every entry in this map. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1528 if (!NULL (elt_prefix))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1529 insert1 (elt_prefix);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1530
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1531 /* Get the string to describe the character I, and print it. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1532 XFASTINT (dummy) = i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1533
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1534 /* THIS gets the string to describe the character DUMMY. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1535 this = Fsingle_key_description (dummy);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1536 insert1 (this);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1537
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1538 /* Find all consecutive characters that have the same definition. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1539 while (i + 1 < DENSE_TABLE_SIZE
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1540 && (tem2 = get_keyelt (XVECTOR (vector)->contents[i+1]),
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1541 EQ (tem2, tem1)))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1542 i++;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1543
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1544 /* If we have a range of more than one character,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1545 print where the range reaches to. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1546
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1547 if (i != XINT (dummy))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1548 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1549 insert (" .. ", 4);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1550 if (!NULL (elt_prefix))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1551 insert1 (elt_prefix);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1552
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1553 XFASTINT (dummy) = i;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1554 insert1 (Fsingle_key_description (dummy));
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1555 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1556
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1557 /* Print a description of the definition of this character.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1558 elt_describer will take care of spacing out far enough
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1559 for alignment purposes. */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1560 (*elt_describer) (tem1);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1561 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1562
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1563 UNGCPRO;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1564 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1565
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1566 /* Apropos */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1567 Lisp_Object apropos_predicate;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1568 Lisp_Object apropos_accumulate;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1569
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1570 static void
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1571 apropos_accum (symbol, string)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1572 Lisp_Object symbol, string;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1573 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1574 register Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1575
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1576 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1577 if (!NULL (tem) && !NULL (apropos_predicate))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1578 tem = call1 (apropos_predicate, symbol);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1579 if (!NULL (tem))
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1580 apropos_accumulate = Fcons (symbol, apropos_accumulate);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1581 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1582
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1583 DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1584 "Show all symbols whose names contain match for REGEXP.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1585 If optional 2nd arg PRED is non-nil, (funcall PRED SYM) is done\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1586 for each symbol and a symbol is mentioned only if that returns non-nil.\n\
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1587 Return list of symbols found.")
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1588 (string, pred)
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1589 Lisp_Object string, pred;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1590 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1591 struct gcpro gcpro1, gcpro2;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1592 CHECK_STRING (string, 0);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1593 apropos_predicate = pred;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1594 GCPRO2 (apropos_predicate, apropos_accumulate);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1595 apropos_accumulate = Qnil;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1596 map_obarray (Vobarray, apropos_accum, string);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1597 apropos_accumulate = Fsort (apropos_accumulate, Qstring_lessp);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1598 UNGCPRO;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1599 return apropos_accumulate;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1600 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1601
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1602 syms_of_keymap ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1603 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1604 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1605
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1606 Qkeymap = intern ("keymap");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1607 staticpro (&Qkeymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1608
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1609 /* Initialize the keymaps standardly used.
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1610 Each one is the value of a Lisp variable, and is also
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1611 pointed to by a C variable */
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1612
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1613 global_map = Fmake_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1614 Fset (intern ("global-map"), global_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1615
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1616 meta_map = Fmake_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1617 Fset (intern ("esc-map"), meta_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1618 Ffset (intern ("ESC-prefix"), meta_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1619
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1620 control_x_map = Fmake_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1621 Fset (intern ("ctl-x-map"), control_x_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1622 Ffset (intern ("Control-X-prefix"), control_x_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1623
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1624 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1625 "Default keymap to use when reading from the minibuffer.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1626 Vminibuffer_local_map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1627
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1628 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1629 "Local keymap for the minibuffer when spaces are not allowed.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1630 Vminibuffer_local_ns_map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1631
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1632 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1633 "Local keymap for minibuffer input with completion.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1634 Vminibuffer_local_completion_map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1635
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1636 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map,
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1637 "Local keymap for minibuffer input with completion, for exact match.");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1638 Vminibuffer_local_must_match_map = Fmake_sparse_keymap ();
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1639
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1640 current_global_map = global_map;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1641
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1642 Qsingle_key_description = intern ("single-key-description");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1643 staticpro (&Qsingle_key_description);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1644
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1645 Qkey_description = intern ("key-description");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1646 staticpro (&Qkey_description);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1647
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1648 Qkeymapp = intern ("keymapp");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1649 staticpro (&Qkeymapp);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1650
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1651 defsubr (&Skeymapp);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1652 defsubr (&Smake_keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1653 defsubr (&Smake_sparse_keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1654 defsubr (&Scopy_keymap);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1655 defsubr (&Skey_binding);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1656 defsubr (&Slocal_key_binding);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1657 defsubr (&Sglobal_key_binding);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1658 defsubr (&Sglobal_set_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1659 defsubr (&Slocal_set_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1660 defsubr (&Sdefine_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1661 defsubr (&Slookup_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1662 defsubr (&Sglobal_unset_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1663 defsubr (&Slocal_unset_key);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1664 defsubr (&Sdefine_prefix_command);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1665 defsubr (&Suse_global_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1666 defsubr (&Suse_local_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1667 defsubr (&Scurrent_local_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1668 defsubr (&Scurrent_global_map);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1669 defsubr (&Saccessible_keymaps);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1670 defsubr (&Skey_description);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1671 defsubr (&Sdescribe_vector);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1672 defsubr (&Ssingle_key_description);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1673 defsubr (&Stext_char_description);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1674 defsubr (&Swhere_is_internal);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1675 defsubr (&Swhere_is);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1676 defsubr (&Sdescribe_bindings);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1677 defsubr (&Sapropos_internal);
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1678 }
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1679
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1680 keys_of_keymap ()
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1681 {
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1682 Lisp_Object tem;
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1683
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1684 initial_define_key (global_map, 033, "ESC-prefix");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1685 initial_define_key (global_map, Ctl('X'), "Control-X-prefix");
7e94ea5958e0 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1686 }