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