annotate lisp/keymap.el @ 290:c9fe270a4101 r21-0b43

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