annotate lisp/prim/keymap.el @ 208:f427b8ec4379

Added tag r20-4b2 for changeset e45d5e7c476e
author cvs
date Mon, 13 Aug 2007 10:03:54 +0200
parents e45d5e7c476e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Keymap functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
19 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
20 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Synched up with: FSF 19.28.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Note: FSF does not have a file keymap.el. This stuff is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; in keymap.c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;Prevent the \{...} documentation construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;from mentioning keys that run this command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (put 'undefined 'suppress-keymap t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defun undefined ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defun suppress-keymap (map &optional nodigits)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Make MAP override all normally self-inserting keys to be undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Normally, as an exception, digits and minus-sign are set to make prefix args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 but optional second arg NODIGITS non-nil treats them like other chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (substitute-key-definition 'self-insert-command 'undefined map global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (or nodigits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (let ((string (make-string 1 ?0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (define-key map "-" 'negative-argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; Make plain numbers do numeric args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (while (<= (aref string 0) ?9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (define-key map string 'digit-argument)
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
45 (incf (aref string 0))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 In other words, OLDDEF is replaced with NEWDEF wherever it appears.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Prefix keymaps are checked recursively. If optional fourth argument OLDMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 is specified, we redefine in KEYMAP as NEWDEF those chars which are defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 as OLDDEF in OLDMAP, unless that keybinding is already present in keymap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 If optional fifth argument PREFIX is defined, then only those occurrences of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 OLDDEF found in keymaps accessible through the keymap bound to PREFIX in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 KEYMAP are redefined. See also `accessible-keymaps'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (let ((maps (accessible-keymaps (or oldmap keymap) prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (shadowing (not (null oldmap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 prefix map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (while maps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq prefix (car (car maps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 map (cdr (car maps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 maps (cdr maps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; Substitute in this keymap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (map-keymap #'(lambda (key binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if (eq binding olddef)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; The new bindings always go in KEYMAP even if we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; found them in OLDMAP or one of it's children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; If KEYMAP will be shadowing OLDMAP, then do not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; redefine the key if there is another binding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; in KEYMAP that will shadow OLDDEF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (or (and shadowing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (lookup-key keymap key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; define-key will give an error if a prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; of the key is already defined. Otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; it will define the key in the map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; #### - Perhaps this should be protected?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 keymap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (vconcat prefix (list key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 newdef))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
84
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
85 ;; From Bill Dubuque <wgd@martigny.ai.mit.edu>
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
86
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
87 ;; This used to wrap forms into an interactive lambda. It is unclear
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
88 ;; to me why this is needed in this function. Anyway,
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
89 ;; `key-or-menu-binding' doesn't do it, so this function no longer
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
90 ;; does it, either.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun insert-key-binding (key) ; modeled after describe-key
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
92 "Insert the command bound to KEY."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (interactive "kInsert command bound to key: ")
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
94 (let ((defn (key-or-menu-binding key)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (or (null defn) (integerp defn))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
96 (error "%s is undefined" (key-description key))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (or (stringp defn) (vectorp defn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq defn (key-binding defn))) ;; a keyboard macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (insert (format "%s" defn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
101 ;; From Bill Dubuque <wgd@martigny.ai.mit.edu>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defun read-command-or-command-sexp (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 "Read a command symbol or command sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 A command sexp is wrapped in an interactive lambda if needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Prompts with PROMPT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Todo: it would be better if we could reject symbols that are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; commandp (as does 'read-command') but that is not easy to do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; because we must supply arg4 = require-match = nil for sexp case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((result (car (read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (completing-read prompt obarray 'commandp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (and (consp result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (not (eq (car result) 'lambda)))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
113 `(lambda ()
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
114 (interactive)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
115 ,result)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defun local-key-binding (keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Return the binding for command KEYS in current local keymap only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 KEYS is a string, a vector of events, or a vector of key-description lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 as described in the documentation for the `define-key' function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 The binding is probably a symbol with a function definition; see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 the documentation for `lookup-key' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((map (current-local-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (if map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (lookup-key map keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (defun global-key-binding (keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 "Return the binding for command KEYS in current global keymap only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 KEYS is a string or vector of events, a sequence of keystrokes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 The binding is probably a symbol with a function definition; see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 the documentation for `lookup-key' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (lookup-key (current-global-map) keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; from Bill Dubuque <wgd@martigny.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun global-set-key (key command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Give KEY a global binding as COMMAND.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 COMMAND is a symbol naming an interactively-callable function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 KEY is a string, a vector of events, or a vector of key-description lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 as described in the documentation for the `define-key' function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 Note that if KEY has a local binding in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 that local binding will continue to shadow any global binding."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;(interactive "KSet key globally: \nCSet key %s to command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (interactive (list (setq key (read-key-sequence "Set key globally: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; Command sexps are allowed here so that this arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; may be supplied interactively via insert-key-binding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (read-command-or-command-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (format "Set key %s to command: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (key-description key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (define-key (current-global-map) key command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; from Bill Dubuque <wgd@martigny.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun local-set-key (key command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Give KEY a local binding as COMMAND.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 COMMAND is a symbol naming an interactively-callable function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 KEY is a string, a vector of events, or a vector of key-description lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 as described in the documentation for the `define-key' function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 The binding goes in the current buffer's local map,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 which is shared with other buffers in the same major mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;(interactive "KSet key locally: \nCSet key %s locally to command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (interactive (list (setq key (read-key-sequence "Set key locally: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; Command sexps are allowed here so that this arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; may be supplied interactively via insert-key-binding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (read-command-or-command-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (format "Set key %s locally to command: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (key-description key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (if (null (current-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (use-local-map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (define-key (current-local-map) key command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defun global-unset-key (key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "Remove global binding of KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 KEY is a string, a vector of events, or a vector of key-description lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 as described in the documentation for the `define-key' function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (interactive "kUnset key globally: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (global-set-key key nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defun local-unset-key (key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "Remove local binding of KEY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 KEY is a string, a vector of events, or a vector of key-description lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 as described in the documentation for the `define-key' function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (interactive "kUnset key locally: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (current-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (define-key (current-local-map) key nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Yet more RMS brain-death.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defun minor-mode-key-binding (key &optional accept-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Find the visible minor mode bindings of KEY.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
193 Return an alist of pairs (MODENAME . BINDING), where MODENAME is
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 the symbol which names the minor mode binding KEY, and BINDING is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 KEY's definition in that mode. In particular, if KEY has no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 minor-mode bindings, return nil. If the first binding is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 non-prefix, all subsequent bindings will be omitted, since they would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 be ignored. Similarly, the list doesn't include non-prefix bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 that come after prefix bindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 If optional argument ACCEPT-DEFAULT is non-nil, recognize default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 bindings; see the description of `lookup-key' for more details about this."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (let ((tail minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 a s v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (while tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (setq a (car tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 tail (cdr tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (and (consp a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (symbolp (setq s (car a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (boundp s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (symbol-value s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; indirect-function deals with autoloadable keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq v (indirect-function (cdr a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (setq v (lookup-key v key accept-default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; Terminate loop, with v set to non-nil value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setq tail nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 v))
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
218
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defun current-minor-mode-maps ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "Return a list of keymaps for the minor modes of the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (let ((l '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (tail minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 a s v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (while tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq a (car tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 tail (cdr tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (and (consp a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (symbolp (setq s (car a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (boundp s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (symbol-value s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; indirect-function deals with autoloadable keymaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq v (indirect-function (cdr a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq l (cons v l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (nreverse l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;;#### What a crock
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (defun define-prefix-command (name &optional mapvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 "Define COMMAND as a prefix command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 A new sparse keymap is stored as COMMAND's function definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 If second optional argument MAPVAR is not specified,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 COMMAND's value (as well as its function definition) is set to the keymap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 If a second optional argument MAPVAR is given and is not `t',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 the map is stored as its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Regardless of MAPVAR, COMMAND's function-value is always set to the keymap."
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
247 (let ((map (make-sparse-keymap name)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (fset name map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (cond ((not mapvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (set name map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ((eq mapvar 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (set mapvar map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;;; Converting vectors of events to a read-equivalent form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;;; This is used both by call-interactively (for the command history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;;; and by macros.el (for saving keyboard macros to a file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
262 ;; ### why does (events-to-keys [backspace]) return "\C-h"?
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
263 ;; BTW, this function is a mess, and macros.el does *not* use it, in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
264 ;; spite of the above comment. `format-kbd-macro' is used to save
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
265 ;; keyboard macros to a file.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun events-to-keys (events &optional no-mice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Given a vector of event objects, returns a vector of key descriptors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 or a string (if they all fit in the ASCII range).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Optional arg NO-MICE means that button events are not allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (if (and events (symbolp events)) (setq events (vector events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (cond ((stringp events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ((not (vectorp events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (signal 'wrong-type-argument (list 'vectorp events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ((let* ((length (length events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (string (make-string length 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 c ce
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (while (< i length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq ce (aref events i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (or (eventp ce) (setq ce (character-to-event ce)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; Normalize `c' to `?c' and `(control k)' to `?\C-k'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; By passing t for the `allow-meta' arg we could get kbd macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; with meta in them to translate to the string form instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; the list/symbol form; but I expect that would cause confusion,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; so let's use the list/symbol form whenever there's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; any ambiguity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (setq c (event-to-character ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (and c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 character-set-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (key-press-event-p ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (cond ((symbolp (event-key ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (get (event-key ce) character-set-property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ;; Don't use a string for `backspace' and `tab' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; avoid that unpleasant little ambiguity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq c nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ((and (= (event-modifier-bits ce) 1) ;control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (integerp (event-key ce)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (let* ((te (character-to-event c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if (and (symbolp (event-key te))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (get (event-key te) character-set-property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; Don't "normalize" (control i) to tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; to avoid the ambiguity in the other direction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq c nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (deallocate-event te)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (aset string i c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq i length string nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let* ((length (length events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (new (copy-sequence events))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 event mods key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (while (< i length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq event (aref events i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (cond ((key-press-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq mods (event-modifiers event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 key (event-key event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (if (numberp key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (setq key (intern (make-string 1 key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (aset new i (if mods
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (nconc mods (cons key nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ((misc-user-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (aset new i (list 'menu-selection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (event-function event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (event-object event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ((or (button-press-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (button-release-event-p event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (if no-mice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 "Mouse events can't be saved in keyboard macros."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (setq mods (event-modifiers event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 key (intern (concat "button"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (event-button event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (if (button-release-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "up" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (aset new i (if mods
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (nconc mods (cons key nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ((or (and event (symbolp event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (and (consp event) (symbolp (car event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (aset new i event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (signal 'wrong-type-argument (list 'eventp event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 new))))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
350
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
352 (defun next-key-event ()
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
353 "Return the next available keyboard event."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
354 (let (event)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
355 (while (not (key-press-event-p (setq event (next-event))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
356 (dispatch-event event))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
357 event))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
358
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
359 (defun key-sequence-list-description (keys)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
360 "Convert a key sequence KEYS to the full [(modifiers... key)...] form.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
361 Argument KEYS can be in any form accepted by `define-key' function."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
362 (let ((vec
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
363 (cond ((vectorp keys)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
364 keys)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
365 ((stringp keys)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
366 (vconcat keys))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
367 (t
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
368 (vector keys))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
369 (event-to-list
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
370 #'(lambda (ev)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
371 (append (event-modifiers ev) (list (event-key ev))))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
372 (mapvector
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
373 #'(lambda (key)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
374 (cond ((key-press-event-p key)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
375 (funcall event-to-list key))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
376 ((characterp key)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
377 (funcall event-to-list (character-to-event key)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
378 ((listp key)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
379 key)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
380 (t
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
381 (list key))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
382 vec)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
383
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
384
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;;; Support keyboard commands to turn on various modifiers.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
386
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;;; These functions -- which are not commands -- each add one modifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;;; to the following event.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
389
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
390 (defun event-apply-alt-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
391 (event-apply-modifier 'alt))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
392 (defun event-apply-super-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
393 (event-apply-modifier 'super))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
394 (defun event-apply-hyper-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
395 (event-apply-modifier 'hyper))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
396 (defun event-apply-shift-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
397 (event-apply-modifier 'shift))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
398 (defun event-apply-control-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
399 (event-apply-modifier 'control))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
400 (defun event-apply-meta-modifier (ignore-prompt)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
401 (event-apply-modifier 'meta))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
402
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
403 ;;; #### `key-translate-map' is ignored for now.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
404 (defun event-apply-modifier (symbol)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
405 "Return the next key event, with a modifier flag applied.
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
406 SYMBOL is the name of this modifier, as a symbol.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
407 `function-key-map' is scanned for prefix bindings."
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
408 (let (events binding)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
409 ;; read keystrokes scanning `function-key-map'
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
410 (while (keymapp
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
411 (setq binding
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
412 (lookup-key
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
413 function-key-map
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
414 (vconcat
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
415 (setq events
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
416 (append events (list (next-key-event)))))))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
417 (if binding ; found a binding
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
418 (progn
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
419 ;; allow for several modifiers
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
420 (if (and (symbolp binding) (fboundp binding))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
421 (setq binding (funcall binding nil)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
422 (setq events (append binding nil))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
423 ;; put remaining keystrokes back into input queue
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
424 (setq unread-command-events
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
425 (mapcar 'character-to-event (cdr events))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
426 (setq unread-command-events (cdr events)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
427 ;; add a modifier SYMBOL to the first keystroke or event
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
428 (vector
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
429 (append (list symbol)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
430 (delq symbol
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
431 (aref (key-sequence-list-description (car events)) 0))))))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
432
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
433 ;; This looks dirty. The following code should maybe go to another
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
434 ;; file, and `create-console-hook' should maybe default to nil.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
435 (add-hook
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
436 'create-console-hook
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
437 #'(lambda (console)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
438 (letf (((selected-console) console))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
439 (define-key function-key-map [?\C-x ?@ ?h] 'event-apply-hyper-modifier)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
440 (define-key function-key-map [?\C-x ?@ ?s] 'event-apply-super-modifier)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
441 (define-key function-key-map [?\C-x ?@ ?m] 'event-apply-meta-modifier)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
442 (define-key function-key-map [?\C-x ?@ ?S] 'event-apply-shift-modifier)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
443 (define-key function-key-map [?\C-x ?@ ?c] 'event-apply-control-modifier)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 70
diff changeset
444 (define-key function-key-map [?\C-x ?@ ?a] 'event-apply-alt-modifier))))