Mercurial > emacs
annotate lisp/emulation/viper-keym.el @ 12468:395a1d99820b
(compute_char_face): Use Fsafe_length.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 01 Jul 1995 22:29:51 +0000 |
parents | 75379a19c5d5 |
children | dbbeba770da4 |
rev | line source |
---|---|
10789 | 1 ;;; viper-keym.el -- Main Viper keymaps |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
2 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
11288 | 3 |
10789 | 4 ;; This file is part of GNU Emacs. |
5 | |
6 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
7 ;; it under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 2, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 | |
21 (require 'viper-util) | |
22 | |
23 ;;; Variables | |
24 | |
25 ;;; Keymaps | |
26 | |
27 ;; Keymaps for vital things like \e and C-z. | |
28 ;; Not for users | |
29 (defvar vip-vi-intercept-map (make-sparse-keymap)) | |
30 (defvar vip-insert-intercept-map (make-sparse-keymap)) | |
31 (defvar vip-emacs-intercept-map (make-sparse-keymap)) | |
32 | |
33 (vip-deflocalvar vip-vi-local-user-map (make-sparse-keymap) | |
34 "Keymap for user-defined local bindings. | |
35 Useful for changing bindings such as ZZ in certain major modes. | |
36 For instance, in letter-mode, one may want to bind ZZ to | |
37 mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound | |
38 to save-buffers-kill-emacs then post article, etc.") | |
39 (put 'vip-vi-local-user-map 'permanent-local t) | |
40 | |
41 (defvar vip-vi-global-user-map (make-sparse-keymap) | |
42 "Keymap for user-defined global bindings. | |
43 These bindings are seen in all Viper buffers.") | |
44 | |
45 (defvar vip-vi-basic-map (make-keymap) | |
46 "This is the main keymap in effect in Viper's Vi state. | |
47 This map is global, shared by all buffers.") | |
48 | |
49 (defvar vip-vi-kbd-map (make-sparse-keymap) | |
50 "This keymap keeps keyboard macros defined via the :map command.") | |
51 | |
52 (defvar vip-vi-diehard-map (make-sparse-keymap) | |
53 "This keymap is in use when the user asks Viper to simulate Vi very closely. | |
54 This happens when vip-expert-level is 1 or 2. See vip-set-expert-level.") | |
55 | |
56 | |
57 (vip-deflocalvar vip-insert-local-user-map (make-sparse-keymap) | |
58 "Auxiliary map for per-buffer user-defined keybindings in Insert state.") | |
59 (put 'vip-insert-local-user-map 'permanent-local t) | |
60 | |
61 (defvar vip-insert-global-user-map (make-sparse-keymap) | |
62 "Auxiliary map for global user-defined bindings in Insert state.") | |
63 | |
64 (defvar vip-insert-basic-map (make-sparse-keymap) | |
65 "The basic insert-mode keymap.") | |
66 | |
67 (defvar vip-insert-diehard-map (make-keymap) | |
68 "Map used when user wants vi-style keys in insert mode. | |
69 Most of the Emacs keys are suppressed. This map overshadows | |
70 vip-insert-basic-map. Not recommended, except for novice users.") | |
71 | |
72 (defvar vip-insert-kbd-map (make-sparse-keymap) | |
73 "This keymap keeps VI-style kbd macros for insert mode.") | |
74 | |
75 (defvar vip-replace-map (make-sparse-keymap) | |
76 "Map used in Viper's replace state.") | |
77 | |
78 (defvar vip-emacs-global-user-map (make-sparse-keymap) | |
79 "Auxiliary map for global user-defined bindings in Emacs state.") | |
80 | |
81 (defvar vip-emacs-kbd-map (make-sparse-keymap) | |
82 "This keymap keeps Vi-style kbd macros for emacs mode.") | |
83 | |
84 (vip-deflocalvar vip-emacs-local-user-map (make-sparse-keymap) | |
85 "Auxiliary map for local user-defined bindings in Emacs state.") | |
86 (put 'vip-emacs-local-user-map 'permanent-local t) | |
87 | |
88 ;; This keymap should stay empty | |
89 (defvar vip-empty-keymap (make-sparse-keymap)) | |
90 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
91 ;; This was the main Vi mode in old versions of VIP which may have been |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
92 ;; extensively used by VIP users. We declare it as a global var |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
93 ;; and, after .vip is loaded, we add this keymap to vip-vi-basic-map. |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
94 (defvar vip-mode-map (make-sparse-keymap)) |
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
95 |
10789 | 96 |
97 ;;; Variables used by minor modes | |
98 | |
99 ;; Association list of the form | |
100 ;; ((major-mode . keymap) (major-mode . keymap) ...) | |
101 ;; Viper uses these keymaps to make user-requested adjustments | |
102 ;; to its Vi state in various major modes.") | |
103 (defvar vip-vi-state-modifier-alist nil) | |
104 | |
105 ;; Association list of the form | |
106 ;; ((major-mode . keymap) (major-mode . keymap) ...) | |
107 ;; Viper uses these keymaps to make user-requested adjustments | |
108 ;; to its Insert state in various major modes.") | |
109 (defvar vip-insert-state-modifier-alist nil) | |
110 | |
111 ;; Association list of the form | |
112 ;; ((major-mode . keymap) (major-mode . keymap) ...) | |
113 ;; Viper uses these keymaps to make user-requested adjustments | |
114 ;; to its Emacs state in various major modes. | |
115 (defvar vip-emacs-state-modifier-alist nil) | |
116 | |
117 ;; Tells vip-add-local-keys to create a new vip-vi-local-user-map for new | |
118 ;; buffers. Not a user option. | |
119 (vip-deflocalvar vip-need-new-vi-local-map t "") | |
120 (put 'vip-need-new-vi-local-map 'permanent-local t) | |
121 | |
122 ;; Tells vip-add-local-keys to create a new vip-insert-local-user-map for new | |
123 ;; buffers. Not a user option. | |
124 (vip-deflocalvar vip-need-new-insert-local-map t "") | |
125 (put 'vip-need-new-insert-local-map 'permanent-local t) | |
126 | |
127 ;; Tells vip-add-local-keys to create a new vip-emacs-local-user-map for new | |
128 ;; buffers. Not a user option. | |
129 (vip-deflocalvar vip-need-new-emacs-local-map t "") | |
130 (put 'vip-need-new-emacs-local-map 'permanent-local t) | |
131 | |
132 | |
133 | |
134 ;; Insert mode keymap | |
135 | |
136 ;; for novice users, pretend you are the real vi. | |
137 (define-key vip-insert-diehard-map "\t" 'vip-insert-tab) | |
138 (define-key vip-insert-diehard-map "\C-a" 'self-insert-command) | |
139 (define-key vip-insert-diehard-map "\C-b" 'self-insert-command) | |
140 (define-key vip-insert-diehard-map "\C-c" 'vip-change-state-to-vi) | |
141 (define-key vip-insert-diehard-map "\C-e" 'self-insert-command) | |
142 (define-key vip-insert-diehard-map "\C-f" 'self-insert-command) | |
143 (define-key vip-insert-diehard-map "\C-g" 'self-insert-command) | |
144 (define-key vip-insert-diehard-map "\C-i" 'self-insert-command) | |
145 (define-key vip-insert-diehard-map "\C-k" 'self-insert-command) | |
146 (define-key vip-insert-diehard-map "\C-l" 'self-insert-command) | |
147 (define-key vip-insert-diehard-map "\C-n" 'self-insert-command) | |
148 (define-key vip-insert-diehard-map "\C-o" 'self-insert-command) | |
149 (define-key vip-insert-diehard-map "\C-p" 'self-insert-command) | |
150 (define-key vip-insert-diehard-map "\C-q" 'self-insert-command) | |
151 (define-key vip-insert-diehard-map "\C-r" 'self-insert-command) | |
152 (define-key vip-insert-diehard-map "\C-s" 'self-insert-command) | |
153 (define-key vip-insert-diehard-map "\C-u" 'vip-erase-line) | |
154 (define-key vip-insert-diehard-map "\C-x" 'self-insert-command) | |
155 (define-key vip-insert-diehard-map "\C-y" 'self-insert-command) | |
156 (define-key vip-insert-diehard-map "\C-z" 'self-insert-command) | |
157 (define-key vip-insert-diehard-map "\C-]" 'self-insert-command) | |
158 (define-key vip-insert-diehard-map "\C-_" 'self-insert-command) | |
159 | |
160 (let ((i ?\ )) | |
161 (while (<= i ?~) | |
162 (define-key vip-insert-diehard-map (make-string 1 i) 'self-insert-command) | |
163 (setq i (1+ i)))) | |
164 | |
165 ;; Insert mode map when user wants emacs style | |
166 (define-key vip-insert-basic-map "\C-d" 'vip-backward-indent) | |
167 (define-key vip-insert-basic-map "\C-w" 'vip-delete-backward-word) | |
168 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent) | |
169 (define-key vip-insert-basic-map | |
170 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab) | |
171 (define-key vip-insert-basic-map "\C-v" 'quoted-insert) | |
172 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert) | |
173 (define-key vip-insert-basic-map "\C-c\M-p" | |
174 'vip-insert-prev-from-insertion-ring) | |
175 (define-key vip-insert-basic-map "\C-c\M-n" | |
176 'vip-insert-next-from-insertion-ring) | |
177 | |
178 | |
179 ;; Replace keymap | |
180 (define-key vip-replace-map "\C-t" 'vip-forward-indent) | |
181 (define-key vip-replace-map "\C-j" 'vip-replace-state-exit-cmd) | |
182 (define-key vip-replace-map "\C-m" 'vip-replace-state-exit-cmd) | |
183 (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace) | |
184 | |
185 | |
186 | |
187 ;; Vi keymaps | |
188 | |
189 (define-key vip-vi-basic-map "\C-^" | |
190 (function (lambda () (interactive) (vip-ex "e#")))) | |
191 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-back) | |
192 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up) | |
193 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one) | |
194 (define-key vip-vi-basic-map "\C-f" 'vip-scroll) | |
195 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol) | |
196 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down) | |
197 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one) | |
198 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward) | |
199 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward) | |
200 ;(define-key vip-vi-basic-map "\C-\\" 'universal-argument) | |
201 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style) | |
202 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file) | |
203 | |
204 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command) | |
205 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command) | |
206 | |
207 | |
208 (define-key vip-vi-basic-map " " 'vip-forward-char) | |
209 (define-key vip-vi-basic-map "!" 'vip-command-argument) | |
210 (define-key vip-vi-basic-map "\"" 'vip-command-argument) | |
211 (define-key vip-vi-basic-map "#" 'vip-command-argument) | |
212 (define-key vip-vi-basic-map "$" 'vip-goto-eol) | |
213 (define-key vip-vi-basic-map "%" 'vip-paren-match) | |
214 (define-key vip-vi-basic-map "&" | |
215 (function (lambda () (interactive) (vip-ex "&")))) | |
216 (define-key vip-vi-basic-map "'" 'vip-goto-mark-and-skip-white) | |
217 (define-key vip-vi-basic-map "(" 'vip-backward-sentence) | |
218 (define-key vip-vi-basic-map ")" 'vip-forward-sentence) | |
219 (define-key vip-vi-basic-map "*" 'call-last-kbd-macro) | |
220 (define-key vip-vi-basic-map "+" 'vip-next-line-at-bol) | |
221 (define-key vip-vi-basic-map "," 'vip-repeat-find-opposite) | |
222 (define-key vip-vi-basic-map "-" 'vip-previous-line-at-bol) | |
223 (define-key vip-vi-basic-map "." 'vip-repeat) | |
224 (define-key vip-vi-basic-map "/" 'vip-search-forward) | |
225 | |
226 (define-key vip-vi-basic-map "0" 'vip-beginning-of-line) | |
227 (define-key vip-vi-basic-map "1" 'vip-digit-argument) | |
228 (define-key vip-vi-basic-map "2" 'vip-digit-argument) | |
229 (define-key vip-vi-basic-map "3" 'vip-digit-argument) | |
230 (define-key vip-vi-basic-map "4" 'vip-digit-argument) | |
231 (define-key vip-vi-basic-map "5" 'vip-digit-argument) | |
232 (define-key vip-vi-basic-map "6" 'vip-digit-argument) | |
233 (define-key vip-vi-basic-map "7" 'vip-digit-argument) | |
234 (define-key vip-vi-basic-map "8" 'vip-digit-argument) | |
235 (define-key vip-vi-basic-map "9" 'vip-digit-argument) | |
236 | |
237 (define-key vip-vi-basic-map ":" 'vip-ex) | |
238 (define-key vip-vi-basic-map ";" 'vip-repeat-find) | |
239 (define-key vip-vi-basic-map "<" 'vip-command-argument) | |
240 (define-key vip-vi-basic-map "=" 'vip-command-argument) | |
241 (define-key vip-vi-basic-map ">" 'vip-command-argument) | |
242 (define-key vip-vi-basic-map "?" 'vip-search-backward) | |
243 (define-key vip-vi-basic-map "@" 'vip-register-macro) | |
244 | |
245 (define-key vip-vi-basic-map "A" 'vip-Append) | |
246 (define-key vip-vi-basic-map "B" 'vip-backward-Word) | |
247 (define-key vip-vi-basic-map "C" 'vip-change-to-eol) | |
248 (define-key vip-vi-basic-map "D" 'vip-kill-line) | |
249 (define-key vip-vi-basic-map "E" 'vip-end-of-Word) | |
250 (define-key vip-vi-basic-map "F" 'vip-find-char-backward) | |
251 (define-key vip-vi-basic-map "G" 'vip-goto-line) | |
252 (define-key vip-vi-basic-map "H" 'vip-window-top) | |
253 (define-key vip-vi-basic-map "I" 'vip-Insert) | |
254 (define-key vip-vi-basic-map "J" 'vip-join-lines) | |
255 (define-key vip-vi-basic-map "K" 'vip-nil) | |
256 (define-key vip-vi-basic-map "L" 'vip-window-bottom) | |
257 (define-key vip-vi-basic-map "M" 'vip-window-middle) | |
258 (define-key vip-vi-basic-map "N" 'vip-search-Next) | |
259 (define-key vip-vi-basic-map "O" 'vip-Open-line) | |
260 (define-key vip-vi-basic-map "P" 'vip-Put-back) | |
261 (define-key vip-vi-basic-map "Q" 'vip-query-replace) | |
262 (define-key vip-vi-basic-map "R" 'vip-overwrite) | |
263 (define-key vip-vi-basic-map "S" 'vip-substitute-line) | |
264 (define-key vip-vi-basic-map "T" 'vip-goto-char-backward) | |
265 (define-key vip-vi-basic-map "U" 'vip-undo) | |
266 (define-key vip-vi-basic-map "V" 'find-file-other-window) | |
267 (define-key vip-vi-basic-map "W" 'vip-forward-Word) | |
268 (define-key vip-vi-basic-map "X" 'vip-delete-backward-char) | |
269 (define-key vip-vi-basic-map "Y" 'vip-yank-line) | |
270 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer) | |
271 | |
272 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs) | |
273 (define-key vip-vi-basic-map "[" 'vip-brac-function) | |
274 (define-key vip-vi-basic-map "]" 'vip-ket-function) | |
275 (define-key vip-vi-basic-map "_" 'vip-alternate-ESC) | |
276 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white) | |
277 (define-key vip-vi-basic-map "`" 'vip-goto-mark) | |
278 | |
279 (define-key vip-vi-basic-map "a" 'vip-append) | |
280 (define-key vip-vi-basic-map "b" 'vip-backward-word) | |
281 (define-key vip-vi-basic-map "c" 'vip-command-argument) | |
282 (define-key vip-vi-basic-map "d" 'vip-command-argument) | |
283 (define-key vip-vi-basic-map "e" 'vip-end-of-word) | |
284 (define-key vip-vi-basic-map "f" 'vip-find-char-forward) | |
285 (define-key vip-vi-basic-map "g" 'vip-nil) | |
286 (define-key vip-vi-basic-map "h" 'vip-backward-char) | |
287 (define-key vip-vi-basic-map "i" 'vip-insert) | |
288 (define-key vip-vi-basic-map "j" 'vip-next-line) | |
289 (define-key vip-vi-basic-map "k" 'vip-previous-line) | |
290 (define-key vip-vi-basic-map "l" 'vip-forward-char) | |
291 (define-key vip-vi-basic-map "m" 'vip-mark-point) | |
292 (define-key vip-vi-basic-map "n" 'vip-search-next) | |
293 (define-key vip-vi-basic-map "o" 'vip-open-line) | |
294 (define-key vip-vi-basic-map "p" 'vip-put-back) | |
295 (define-key vip-vi-basic-map "q" 'vip-nil) | |
296 (define-key vip-vi-basic-map "r" 'vip-replace-char) | |
297 (define-key vip-vi-basic-map "s" 'vip-substitute) | |
298 (define-key vip-vi-basic-map "t" 'vip-goto-char-forward) | |
299 (define-key vip-vi-basic-map "u" 'vip-undo) | |
300 (define-key vip-vi-basic-map "v" 'find-file) | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
301 (define-key vip-vi-basic-map "\C-v" 'find-file-other-frame) |
10789 | 302 (define-key vip-vi-basic-map "w" 'vip-forward-word) |
303 (define-key vip-vi-basic-map "x" 'vip-delete-char) | |
304 (define-key vip-vi-basic-map "y" 'vip-command-argument) | |
305 (define-key vip-vi-basic-map "zH" 'vip-line-to-top) | |
306 (define-key vip-vi-basic-map "zM" 'vip-line-to-middle) | |
307 (define-key vip-vi-basic-map "zL" 'vip-line-to-bottom) | |
308 (define-key vip-vi-basic-map "z\C-m" 'vip-line-to-top) | |
309 (define-key vip-vi-basic-map "z." 'vip-line-to-middle) | |
310 (define-key vip-vi-basic-map "z-" 'vip-line-to-bottom) | |
311 | |
312 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph) | |
313 (define-key vip-vi-basic-map "|" 'vip-goto-col) | |
314 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph) | |
315 (define-key vip-vi-basic-map "~" 'vip-toggle-case) | |
316 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char) | |
317 | |
318 ;;; Escape from Emacs to Vi for one command | |
319 (global-set-key "\M-\C-z" 'vip-escape-to-vi) ;; in emacs-state | |
320 | |
321 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on. | |
322 | |
323 (define-key vip-vi-diehard-map "\C-a" 'vip-nil) | |
324 (define-key vip-vi-diehard-map "\C-c" 'vip-nil) | |
325 (define-key vip-vi-diehard-map "\C-g" 'vip-info-on-file) | |
326 (define-key vip-vi-diehard-map "\C-i" 'vip-nil) | |
327 (define-key vip-vi-diehard-map "\C-k" 'vip-nil) | |
328 (define-key vip-vi-diehard-map "\C-l" 'redraw-display) | |
329 (define-key vip-vi-diehard-map "\C-n" 'vip-next-line) | |
330 (define-key vip-vi-diehard-map "\C-o" 'vip-nil) | |
331 (define-key vip-vi-diehard-map "\C-p" 'vip-previous-line) | |
332 (define-key vip-vi-diehard-map "\C-q" 'vip-nil) | |
333 (define-key vip-vi-diehard-map "\C-r" 'redraw-display) | |
334 (define-key vip-vi-diehard-map "\C-s" 'vip-nil) | |
335 (define-key vip-vi-diehard-map "\C-t" 'vip-nil) | |
336 (define-key vip-vi-diehard-map "\C-v" 'vip-nil) | |
337 (define-key vip-vi-diehard-map "\C-w" 'vip-nil) | |
338 (define-key vip-vi-diehard-map "@" 'vip-nil) | |
339 (define-key vip-vi-diehard-map "*" 'vip-nil) | |
340 (define-key vip-vi-diehard-map "#" 'vip-nil) | |
341 (define-key vip-vi-diehard-map "\C-_" 'vip-nil) | |
342 (define-key vip-vi-diehard-map "\C-]" 'vip-nil);; This is actually tags. | |
343 | |
344 | |
345 ;;; Minibuffer keymap | |
346 | |
347 | |
348 (defvar vip-minibuffer-map (make-sparse-keymap) | |
349 "Keymap used to modify keys when Minibuffer is in Insert state.") | |
350 | |
351 (define-key vip-minibuffer-map "\C-m" 'vip-exit-minibuffer) | |
352 (define-key vip-minibuffer-map "\C-j" 'vip-exit-minibuffer) | |
353 | |
354 ;; Map used to read Ex-style commands. | |
355 (defvar vip-ex-cmd-map (make-sparse-keymap)) | |
356 (define-key vip-ex-cmd-map " " 'ex-cmd-read-exit) | |
357 (define-key vip-ex-cmd-map "\t" 'ex-cmd-complete) | |
358 | |
359 ;; Keymap for reading file names in Ex-style commands. | |
360 (defvar ex-read-filename-map (make-sparse-keymap)) | |
361 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit) | |
362 | |
363 | |
364 | |
365 | |
366 ;;; Code | |
367 | |
368 (defun vip-add-local-keys (state alist) | |
369 "Override some vi-state or insert-state bindings in the current buffer. | |
370 The effect is seen in the current buffer only. | |
371 Useful for customizing mailer buffers, gnus, etc. | |
372 STATE is 'vi-state, 'insert-state, or 'emacs-state | |
373 ALIST is of the form ((key . func) (key . func) ...) | |
374 Normally, this would be called from a hook to a major mode or | |
375 on a per buffer basis. | |
376 Usage: | |
377 (vip-add-local-keys state '((key-str . func) (key-str . func)...)) " | |
378 | |
379 (let (map) | |
380 (cond ((eq state 'vi-state) | |
381 (if vip-need-new-vi-local-map | |
382 (setq vip-vi-local-user-map (make-sparse-keymap))) | |
383 (setq vip-need-new-vi-local-map nil | |
384 map vip-vi-local-user-map)) | |
385 ((eq state 'insert-state) | |
386 (if vip-need-new-insert-local-map | |
387 (setq vip-insert-local-user-map (make-sparse-keymap))) | |
388 (setq vip-need-new-insert-local-map nil | |
389 map vip-insert-local-user-map)) | |
390 ((eq state 'emacs-state) | |
391 (if vip-need-new-emacs-local-map | |
392 (setq vip-emacs-local-user-map (make-sparse-keymap))) | |
393 (setq vip-need-new-emacs-local-map nil | |
394 map vip-emacs-local-user-map)) | |
395 (t | |
396 (error | |
397 "Invalid state in vip-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state))) | |
398 | |
399 (vip-modify-keymap map alist) | |
400 (vip-normalize-minor-mode-map-alist) | |
401 (vip-set-mode-vars-for vip-current-state))) | |
402 | |
403 | |
404 (defun vip-modify-major-mode (mode state keymap) | |
405 "Modify key bindings in a major-mode in a Viper state using a keymap. | |
406 | |
407 If the default for a major mode is emacs-state, then modifications to this | |
408 major mode may not take effect until the buffer switches state to Vi, | |
409 Insert or Emacs. If this happens, add vip-change-state-to-emacs to this | |
410 major mode's hook. If no such hook exists, you may have to put an advice on | |
411 the function that invokes the major mode. See vip-set-hooks for hints. | |
412 | |
413 The above needs not to be done for major modes that come up in Vi or Insert | |
414 state by default. | |
415 | |
416 Arguments: (major-mode vip-state keymap)" | |
417 (let ((alist | |
418 (cond ((eq state 'vi-state) 'vip-vi-state-modifier-alist) | |
419 ((eq state 'insert-state) 'vip-insert-state-modifier-alist) | |
420 ((eq state 'emacs-state) 'vip-emacs-state-modifier-alist))) | |
421 elt) | |
422 (if (setq elt (assoc mode (eval alist))) | |
423 (set alist (delq elt (eval alist)))) | |
424 (set alist (cons (cons mode keymap) (eval alist))) | |
425 | |
426 ;; Normalization usually doesn't help here, since one needs to | |
427 ;; normalize in the actual buffer where changes to the keymap are | |
428 ;; to take place. However, it doesn't hurt, and it helps whenever this | |
429 ;; function is actually called from within the right buffer. | |
430 (vip-normalize-minor-mode-map-alist) | |
431 | |
432 (vip-set-mode-vars-for vip-current-state))) | |
433 | |
434 | |
12140
75379a19c5d5
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings,
Karl Heuer <kwzh@gnu.org>
parents:
11288
diff
changeset
|
435 ;; Displays variables that control Viper's keymaps |
10789 | 436 (defun vip-debug-keymaps () |
437 (interactive) | |
438 (with-output-to-temp-buffer " *vip-debug*" | |
439 (princ (format "Buffer name: %s\n\n" (buffer-name))) | |
440 (princ "Variables: \n") | |
441 (princ (format "major-mode: %S\n" major-mode)) | |
442 (princ (format "vip-current-state: %S\n" vip-current-state)) | |
443 (princ (format "vip-mode-string: %S\n\n" vip-mode-string)) | |
444 (princ (format "vip-vi-intercept-minor-mode: %S\n" | |
445 vip-vi-intercept-minor-mode)) | |
446 (princ (format "vip-insert-intercept-minor-mode: %S\n" | |
447 vip-insert-intercept-minor-mode)) | |
448 (princ (format "vip-emacs-intercept-minor-mode: %S\n" | |
449 vip-emacs-intercept-minor-mode)) | |
450 (princ (format "vip-vi-minibuffer-minor-mode: %S\n" | |
451 vip-vi-minibuffer-minor-mode)) | |
452 (princ (format "vip-insert-minibuffer-minor-mode: %S\n\n" | |
453 vip-insert-minibuffer-minor-mode)) | |
454 (princ (format "vip-vi-local-user-minor-mode: %S\n" | |
455 vip-vi-local-user-minor-mode)) | |
456 (princ (format "vip-vi-global-user-minor-mode: %S\n" | |
457 vip-vi-global-user-minor-mode)) | |
458 (princ (format "vip-vi-kbd-minor-mode: %S\n" vip-vi-kbd-minor-mode)) | |
459 (princ (format "vip-vi-state-modifier-minor-mode: %S\n" | |
460 vip-vi-state-modifier-minor-mode)) | |
461 (princ (format "vip-vi-diehard-minor-mode: %S\n" | |
462 vip-vi-diehard-minor-mode)) | |
463 (princ (format "vip-vi-basic-minor-mode: %S\n" vip-vi-basic-minor-mode)) | |
464 (princ (format "vip-replace-minor-mode: %S\n" vip-replace-minor-mode)) | |
465 (princ (format "vip-insert-local-user-minor-mode: %S\n" | |
466 vip-insert-local-user-minor-mode)) | |
467 (princ (format "vip-insert-global-user-minor-mode: %S\n" | |
468 vip-insert-global-user-minor-mode)) | |
469 (princ (format "vip-insert-kbd-minor-mode: %S\n" | |
470 vip-insert-kbd-minor-mode)) | |
471 (princ (format "vip-insert-state-modifier-minor-mode: %S\n" | |
472 vip-insert-state-modifier-minor-mode)) | |
473 (princ (format "vip-insert-diehard-minor-mode: %S\n" | |
474 vip-insert-diehard-minor-mode)) | |
475 (princ (format "vip-insert-basic-minor-mode: %S\n" | |
476 vip-insert-basic-minor-mode)) | |
477 (princ (format "vip-emacs-local-user-minor-mode: %S\n" | |
478 vip-emacs-local-user-minor-mode)) | |
479 (princ (format "vip-emacs-kbd-minor-mode: %S\n" | |
480 vip-emacs-kbd-minor-mode)) | |
481 (princ (format "vip-emacs-global-user-minor-mode: %S\n" | |
482 vip-emacs-global-user-minor-mode)) | |
483 (princ (format "vip-emacs-state-modifier-minor-mode: %S\n" | |
484 vip-emacs-state-modifier-minor-mode)) | |
485 | |
486 (princ (format "\nvip-expert-level %S\n" vip-expert-level)) | |
487 (princ (format "vip-no-multiple-ESC %S\n" vip-no-multiple-ESC)) | |
488 (princ (format "vip-always %S\n" vip-always)) | |
489 (princ (format "vip-ex-style-motion %S\n" | |
490 vip-ex-style-motion)) | |
491 (princ (format "vip-ex-style-editing-in-insert %S\n" | |
492 vip-ex-style-editing-in-insert)) | |
493 (princ (format "vip-want-emacs-keys-in-vi %S\n" | |
494 vip-want-emacs-keys-in-vi)) | |
495 (princ (format "vip-want-emacs-keys-in-insert %S\n" | |
496 vip-want-emacs-keys-in-insert)) | |
497 (princ (format "vip-want-ctl-h-help %S\n" vip-want-ctl-h-help)) | |
498 | |
499 (princ "\n\n\n") | |
500 (princ (format "Default value for minor-mode-map-alist: \n%S\n\n" | |
501 (default-value 'minor-mode-map-alist))) | |
502 (princ (format "Actual value for minor-mode-map-alist: \n%S\n" | |
503 minor-mode-map-alist)) | |
504 )) | |
505 | |
506 | |
507 ;;; Keymap utils | |
508 | |
509 (defun vip-add-keymap (mapsrc mapdst) | |
510 "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse." | |
511 (if vip-xemacs-p | |
512 (map-keymap (function (lambda (key binding) | |
513 (define-key mapdst key binding))) | |
514 mapsrc) | |
515 (mapcar | |
516 (function (lambda (p) | |
517 (define-key mapdst (vector (car p)) (cdr p)) | |
518 )) | |
519 (cdr mapsrc)))) | |
520 | |
521 (defun vip-modify-keymap (map alist) | |
522 "Modifies MAP with bindings specified in the ALIST. The alist has the | |
523 form ((key . function) (key . function) ... )." | |
524 (mapcar (function (lambda (p) | |
525 (define-key map (eval (car p)) (cdr p)))) | |
526 alist)) | |
527 | |
528 | |
529 (provide 'viper-keym) | |
530 | |
531 ;;; viper-keym.el ends here |