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