Mercurial > hg > xemacs-beta
comparison lisp/keymap.el @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | 3ecd8885ac67 |
children | 7039e6323819 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
68 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix) | 68 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix) |
69 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF. | 69 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF. |
70 In other words, OLDDEF is replaced with NEWDEF wherever it appears. | 70 In other words, OLDDEF is replaced with NEWDEF wherever it appears. |
71 Prefix keymaps are checked recursively. If optional fourth argument OLDMAP | 71 Prefix keymaps are checked recursively. If optional fourth argument OLDMAP |
72 is specified, we redefine in KEYMAP as NEWDEF those chars which are defined | 72 is specified, we redefine in KEYMAP as NEWDEF those chars which are defined |
73 as OLDDEF in OLDMAP, unless that keybinding is already present in keymap. | 73 as OLDDEF in OLDMAP, unless that keybinding is already present in KEYMAP. |
74 If optional fifth argument PREFIX is defined, then only those occurrences of | 74 If optional fifth argument PREFIX is non-nil, then only those occurrences of |
75 OLDDEF found in keymaps accessible through the keymap bound to PREFIX in | 75 OLDDEF found in keymaps accessible through the keymap bound to PREFIX in |
76 KEYMAP are redefined. See also `accessible-keymaps'." | 76 KEYMAP are redefined. See also `accessible-keymaps'." |
77 (let ((maps (accessible-keymaps (or oldmap keymap) prefix)) | 77 (let ((maps (accessible-keymaps (or oldmap keymap) prefix)) |
78 (shadowing (not (null oldmap))) | 78 (shadowing (not (null oldmap))) |
79 prefix map) | 79 prefix map) |
101 newdef)))) | 101 newdef)))) |
102 map) | 102 map) |
103 ))) | 103 ))) |
104 | 104 |
105 | 105 |
106 ;; From Bill Dubuque <wgd@martigny.ai.mit.edu> | |
107 | |
108 ;; This used to wrap forms into an interactive lambda. It is unclear | 106 ;; This used to wrap forms into an interactive lambda. It is unclear |
109 ;; to me why this is needed in this function. Anyway, | 107 ;; to me why this is needed in this function. Anyway, |
110 ;; `key-or-menu-binding' doesn't do it, so this function no longer | 108 ;; `key-or-menu-binding' doesn't do it, so this function no longer |
111 ;; does it, either. | 109 ;; does it, either. |
112 (defun insert-key-binding (key) ; modeled after describe-key | 110 (defun insert-key-binding (key) ; modeled after describe-key |
117 (error "%s is undefined" (key-description key)) | 115 (error "%s is undefined" (key-description key)) |
118 (if (or (stringp defn) (vectorp defn)) | 116 (if (or (stringp defn) (vectorp defn)) |
119 (setq defn (key-binding defn))) ;; a keyboard macro | 117 (setq defn (key-binding defn))) ;; a keyboard macro |
120 (insert (format "%s" defn))))) | 118 (insert (format "%s" defn))))) |
121 | 119 |
122 ;; From Bill Dubuque <wgd@martigny.ai.mit.edu> | |
123 (defun read-command-or-command-sexp (prompt) | 120 (defun read-command-or-command-sexp (prompt) |
124 "Read a command symbol or command sexp. | 121 "Read a command symbol or command sexp. |
125 A command sexp is wrapped in an interactive lambda if needed. | 122 A command sexp is wrapped in an interactive lambda if needed. |
126 Prompts with PROMPT." | 123 Prompts with PROMPT." |
127 ;; Todo: it would be better if we could reject symbols that are not | 124 ;; Todo: it would be better if we could reject symbols that are not |
134 `(lambda () | 131 `(lambda () |
135 (interactive) | 132 (interactive) |
136 ,result) | 133 ,result) |
137 result))) | 134 result))) |
138 | 135 |
139 (defun local-key-binding (keys) | 136 (defun local-key-binding (keys &optional accept-defaults) |
140 "Return the binding for command KEYS in current local keymap only. | 137 "Return the binding for command KEYS in current local keymap only. |
141 KEYS is a string, a vector of events, or a vector of key-description lists | 138 KEYS is a string, a vector of events, or a vector of key-description lists |
142 as described in the documentation for the `define-key' function. | 139 as described in the documentation for the `define-key' function. |
143 The binding is probably a symbol with a function definition; see | 140 The binding is probably a symbol with a function definition; see |
144 the documentation for `lookup-key' for more information." | 141 the documentation for `lookup-key' for more information." |
145 (let ((map (current-local-map))) | 142 (let ((map (current-local-map))) |
146 (if map | 143 (if map |
147 (lookup-key map keys) | 144 (lookup-key map keys accept-defaults) |
148 nil))) | 145 nil))) |
149 | 146 |
150 (defun global-key-binding (keys) | 147 (defun global-key-binding (keys &optional accept-defaults) |
151 "Return the binding for command KEYS in current global keymap only. | 148 "Return the binding for command KEYS in current global keymap only. |
152 KEYS is a string or vector of events, a sequence of keystrokes. | 149 KEYS is a string or vector of events, a sequence of keystrokes. |
153 The binding is probably a symbol with a function definition; see | 150 The binding is probably a symbol with a function definition; see |
154 the documentation for `lookup-key' for more information." | 151 the documentation for `lookup-key' for more information." |
155 (lookup-key (current-global-map) keys)) | 152 (lookup-key (current-global-map) keys accept-defaults)) |
156 | 153 |
157 ;; from Bill Dubuque <wgd@martigny.ai.mit.edu> | |
158 (defun global-set-key (key command) | 154 (defun global-set-key (key command) |
159 "Give KEY a global binding as COMMAND. | 155 "Give KEY a global binding as COMMAND. |
160 COMMAND is a symbol naming an interactively-callable function. | 156 COMMAND is a symbol naming an interactively-callable function. |
161 KEY is a string, a vector of events, or a vector of key-description lists | 157 KEY is a string, a vector of events, or a vector of key-description lists |
162 as described in the documentation for the `define-key' function. | 158 as described in the documentation for the `define-key' function. |
170 (format "Set key %s to command: " | 166 (format "Set key %s to command: " |
171 (key-description key))))) | 167 (key-description key))))) |
172 (define-key (current-global-map) key command) | 168 (define-key (current-global-map) key command) |
173 nil) | 169 nil) |
174 | 170 |
175 ;; from Bill Dubuque <wgd@martigny.ai.mit.edu> | |
176 (defun local-set-key (key command) | 171 (defun local-set-key (key command) |
177 "Give KEY a local binding as COMMAND. | 172 "Give KEY a local binding as COMMAND. |
178 COMMAND is a symbol naming an interactively-callable function. | 173 COMMAND is a symbol naming an interactively-callable function. |
179 KEY is a string, a vector of events, or a vector of key-description lists | 174 KEY is a string, a vector of events, or a vector of key-description lists |
180 as described in the documentation for the `define-key' function. | 175 as described in the documentation for the `define-key' function. |