annotate lisp/keymap.el @ 272:c5d627a313b1 r21-0b34

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