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