1 ;;; viper-keym.el --- Viper keymaps
3 ;; Copyright (C) 1994, 95, 96, 97, 2000, 01, 02 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
32 (defvar viper-current-state
)
33 (defvar viper-mode-string
)
34 (defvar viper-expert-level
)
35 (defvar viper-ex-style-editing
)
36 (defvar viper-ex-style-motion
)
38 ;; loading happens only in non-interactive compilation
39 ;; in order to spare non-viperized emacs from being viperized
42 (let ((load-path (cons (expand-file-name ".") load-path
)))
43 (or (featurep 'viper-util
)
44 (load "viper-util.el" nil nil
'nosuffix
))
53 (defvar viper-toggle-key
"\C-z"
54 "The key used to change states from emacs to Vi and back.
55 In insert mode, this key also functions as Meta.
56 Must be set in .viper file or prior to loading Viper.
57 This setting cannot be changed interactively.")
59 (defvar viper-ESC-key
"\e"
61 Must be set in .viper file or prior to loading Viper.
62 This setting cannot be changed interactively.")
64 ;;; Emacs keys in other states.
66 (defcustom viper-want-emacs-keys-in-insert t
67 "*Set to nil if you want complete Vi compatibility in insert mode.
68 Complete compatibility with Vi is not recommended for power use of Viper."
72 (defcustom viper-want-emacs-keys-in-vi t
73 "*Set to nil if you want complete Vi compatibility in Vi mode.
74 Full Vi compatibility is not recommended for power use of Viper."
78 (defcustom viper-no-multiple-ESC t
79 "*If true, multiple ESC in Vi mode will cause bell to ring.
80 This is set to t on a windowing terminal and to 'twice on a dumb
81 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
82 enables cursor keys and is generally more convenient, as terminals usually
83 don't have a convenient Meta key.
84 Setting viper-no-multiple-ESC to nil will allow as many multiple ESC,
85 as is allowed by the major mode in effect."
89 (defcustom viper-want-ctl-h-help nil
90 "*If non-nil, C-h gets bound to help-command; otherwise, C-h gets the usual Vi bindings."
97 ;; Keymaps for vital things like \e and C-z.
99 (defvar viper-vi-intercept-map
(make-sparse-keymap))
100 (defvar viper-insert-intercept-map
(make-sparse-keymap))
101 (defvar viper-emacs-intercept-map
(make-sparse-keymap))
103 ;; keymap used to zap all keymaps other than function-key-map,
104 ;; device-function-key-map, etc.
105 (defvar viper-overriding-map
(make-sparse-keymap))
107 (viper-deflocalvar viper-vi-local-user-map
(make-sparse-keymap)
108 "Keymap for user-defined local bindings.
109 Useful for changing bindings such as ZZ in certain major modes.
110 For instance, in letter-mode, one may want to bind ZZ to
111 mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound
112 to save-buffers-kill-emacs then post article, etc.")
113 (put 'viper-vi-local-user-map
'permanent-local t
)
115 (defvar viper-vi-global-user-map
(make-sparse-keymap)
116 "Keymap for user-defined global bindings.
117 These bindings are seen in all Viper buffers.")
119 (defvar viper-vi-basic-map
(make-keymap)
120 "This is the main keymap in effect in Viper's Vi state.
121 This map is global, shared by all buffers.")
123 (defvar viper-vi-kbd-map
(make-sparse-keymap)
124 "This keymap keeps keyboard macros defined via the :map command.")
126 (defvar viper-vi-diehard-map
(make-sparse-keymap)
127 "This keymap is in use when the user asks Viper to simulate Vi very closely.
128 This happens when viper-expert-level is 1 or 2. See viper-set-expert-level.")
131 (viper-deflocalvar viper-insert-local-user-map
(make-sparse-keymap)
132 "Auxiliary map for per-buffer user-defined keybindings in Insert state.")
133 (put 'viper-insert-local-user-map
'permanent-local t
)
135 (defvar viper-insert-global-user-map
(make-sparse-keymap)
136 "Auxiliary map for global user-defined bindings in Insert state.")
138 (defvar viper-insert-basic-map
(make-sparse-keymap)
139 "The basic insert-mode keymap.")
141 (defvar viper-insert-diehard-map
(make-keymap)
142 "Map used when user wants vi-style keys in insert mode.
143 Most of the Emacs keys are suppressed. This map overshadows
144 viper-insert-basic-map. Not recommended, except for novice users.")
146 (defvar viper-insert-kbd-map
(make-sparse-keymap)
147 "This keymap keeps VI-style kbd macros for insert mode.")
149 (defvar viper-replace-map
(make-sparse-keymap)
150 "Map used in Viper's replace state.")
152 (defvar viper-emacs-global-user-map
(make-sparse-keymap)
153 "Auxiliary map for global user-defined bindings in Emacs state.")
155 (defvar viper-emacs-kbd-map
(make-sparse-keymap)
156 "This keymap keeps Vi-style kbd macros for emacs mode.")
158 (viper-deflocalvar viper-emacs-local-user-map
(make-sparse-keymap)
159 "Auxiliary map for local user-defined bindings in Emacs state.")
160 (put 'viper-emacs-local-user-map
'permanent-local t
)
162 ;; This keymap should stay empty
163 (defvar viper-empty-keymap
(make-sparse-keymap))
165 ;; This was the main Vi mode in old versions of VIP which may have been
166 ;; extensively used by VIP users. We declare it as a global var
167 ;; and, after .viper is loaded, we add this keymap to viper-vi-basic-map.
168 (defvar viper-mode-map
(make-sparse-keymap))
171 ;;; Variables used by minor modes
173 ;; Association list of the form
174 ;; ((major-mode . keymap) (major-mode . keymap) ...)
175 ;; Viper uses these keymaps to make user-requested adjustments
176 ;; to its Vi state in various major modes.")
177 (defvar viper-vi-state-modifier-alist nil
)
179 ;; Association list of the form
180 ;; ((major-mode . keymap) (major-mode . keymap) ...)
181 ;; Viper uses these keymaps to make user-requested adjustments
182 ;; to its Insert state in various major modes.")
183 (defvar viper-insert-state-modifier-alist nil
)
185 ;; Association list of the form
186 ;; ((major-mode . keymap) (major-mode . keymap) ...)
187 ;; Viper uses these keymaps to make user-requested adjustments
188 ;; to its Emacs state in various major modes.
189 (defvar viper-emacs-state-modifier-alist nil
)
191 ;; Tells viper-add-local-keys to create a new viper-vi-local-user-map for new
192 ;; buffers. Not a user option.
193 (viper-deflocalvar viper-need-new-vi-local-map t
"")
194 (put 'viper-need-new-vi-local-map
'permanent-local t
)
196 ;; Tells viper-add-local-keys to create a new viper-insert-local-user-map for
197 ;; new buffers. Not a user option.
198 (viper-deflocalvar viper-need-new-insert-local-map t
"")
199 (put 'viper-need-new-insert-local-map
'permanent-local t
)
201 ;; Tells viper-add-local-keys to create a new viper-emacs-local-user-map for
202 ;; new buffers. Not a user option.
203 (viper-deflocalvar viper-need-new-emacs-local-map t
"")
204 (put 'viper-need-new-emacs-local-map
'permanent-local t
)
208 ;; Insert mode keymap
210 ;; for novice users, pretend you are the real vi.
211 (define-key viper-insert-diehard-map
"\t" 'viper-insert-tab
)
212 (define-key viper-insert-diehard-map
"\C-a" 'self-insert-command
)
213 (define-key viper-insert-diehard-map
"\C-b" 'self-insert-command
)
214 (define-key viper-insert-diehard-map
"\C-c" 'viper-change-state-to-vi
)
215 (define-key viper-insert-diehard-map
"\C-e" 'self-insert-command
)
216 (define-key viper-insert-diehard-map
"\C-f" 'self-insert-command
)
217 (define-key viper-insert-diehard-map
"\C-g" 'self-insert-command
)
218 (define-key viper-insert-diehard-map
"\C-i" 'self-insert-command
)
219 (define-key viper-insert-diehard-map
"\C-k" 'self-insert-command
)
220 (define-key viper-insert-diehard-map
"\C-l" 'self-insert-command
)
221 (define-key viper-insert-diehard-map
"\C-n" 'self-insert-command
)
222 (define-key viper-insert-diehard-map
"\C-o" 'self-insert-command
)
223 (define-key viper-insert-diehard-map
"\C-p" 'self-insert-command
)
224 (define-key viper-insert-diehard-map
"\C-q" 'self-insert-command
)
225 (define-key viper-insert-diehard-map
"\C-r" 'self-insert-command
)
226 (define-key viper-insert-diehard-map
"\C-s" 'self-insert-command
)
227 (define-key viper-insert-diehard-map
"\C-u" 'viper-erase-line
)
228 (define-key viper-insert-diehard-map
"\C-x" 'self-insert-command
)
229 (define-key viper-insert-diehard-map
"\C-y" 'self-insert-command
)
230 (define-key viper-insert-diehard-map
"\C-z" 'self-insert-command
)
231 (define-key viper-insert-diehard-map
"\C-]" 'self-insert-command
)
232 (define-key viper-insert-diehard-map
"\C-_" 'self-insert-command
)
236 (define-key viper-insert-diehard-map
(make-string 1 i
) 'self-insert-command
)
239 ;; Insert mode map when user wants emacs style
240 (define-key viper-insert-basic-map
"\C-d" 'viper-backward-indent
)
241 (define-key viper-insert-basic-map
"\C-w" 'viper-delete-backward-word
)
242 (define-key viper-insert-basic-map
"\C-t" 'viper-forward-indent
)
243 (define-key viper-insert-basic-map
244 (if viper-xemacs-p
[(shift tab
)] [S-tab
]) 'viper-insert-tab
)
245 (define-key viper-insert-basic-map
"\C-v" 'quoted-insert
)
246 (define-key viper-insert-basic-map
"\C-?" 'viper-del-backward-char-in-insert
)
247 (define-key viper-insert-basic-map
[backspace] 'viper-del-backward-char-in-insert)
248 (define-key viper-insert-basic-map "\C-\\" 'viper-alternate-Meta-key)
249 (define-key viper-insert-basic-map viper-toggle-key 'viper-escape-to-vi)
250 (define-key viper-insert-basic-map "\C-c\M-p"
251 'viper-insert-prev-from-insertion-ring)
252 (define-key viper-insert-basic-map "\C-c\M-n"
253 'viper-insert-next-from-insertion-ring)
257 (define-key viper-replace-map "\C-t" 'viper-forward-indent)
258 (define-key viper-replace-map "\C-j" 'viper-replace-state-carriage-return)
259 (define-key viper-replace-map "\C-m" 'viper-replace-state-carriage-return)
260 (define-key viper-replace-map "\C-?" 'viper-del-backward-char-in-replace)
261 (define-key viper-replace-map [backspace] 'viper-del-backward-char-in-replace
)
267 (define-key viper-vi-basic-map
"\C-^" (lambda ()
268 (interactive) (viper-ex nil
"e#")))
269 (define-key viper-vi-basic-map
"\C-b" 'viper-scroll-screen-back
)
270 (define-key viper-vi-basic-map
"\C-d" 'viper-scroll-up
)
271 (define-key viper-vi-basic-map
"\C-e" 'viper-scroll-up-one
)
272 (define-key viper-vi-basic-map
"\C-f" 'viper-scroll-screen
)
273 (define-key viper-vi-basic-map
"\C-m" 'viper-next-line-at-bol
)
274 (define-key viper-vi-basic-map
"\C-u" 'viper-scroll-down
)
275 (define-key viper-vi-basic-map
"\C-y" 'viper-scroll-down-one
)
276 (define-key viper-vi-basic-map
"\C-s" 'viper-isearch-forward
)
277 (define-key viper-vi-basic-map
"\C-r" 'viper-isearch-backward
)
278 (define-key viper-vi-basic-map
"\C-c/" 'viper-toggle-search-style
)
279 (define-key viper-vi-basic-map
"\C-c\C-g" 'viper-info-on-file
)
281 (define-key viper-vi-basic-map
"\C-c\M-p" 'viper-prev-destructive-command
)
282 (define-key viper-vi-basic-map
"\C-c\M-n" 'viper-next-destructive-command
)
285 (define-key viper-vi-basic-map
" " 'viper-forward-char
)
286 (define-key viper-vi-basic-map
"!" 'viper-command-argument
)
287 (define-key viper-vi-basic-map
"\"" 'viper-command-argument
)
288 (define-key viper-vi-basic-map
"#" 'viper-command-argument
)
289 (define-key viper-vi-basic-map
"$" 'viper-goto-eol
)
290 (define-key viper-vi-basic-map
"%" 'viper-paren-match
)
291 (define-key viper-vi-basic-map
"&" (lambda ()
292 (interactive) (viper-ex nil
"&")))
293 (define-key viper-vi-basic-map
"'" 'viper-goto-mark-and-skip-white
)
294 (define-key viper-vi-basic-map
"(" 'viper-backward-sentence
)
295 (define-key viper-vi-basic-map
")" 'viper-forward-sentence
)
296 (define-key viper-vi-basic-map
"*" 'call-last-kbd-macro
)
297 (define-key viper-vi-basic-map
"+" 'viper-next-line-at-bol
)
298 (define-key viper-vi-basic-map
"," 'viper-repeat-find-opposite
)
299 (define-key viper-vi-basic-map
"-" 'viper-previous-line-at-bol
)
300 (define-key viper-vi-basic-map
"." 'viper-repeat
)
301 (define-key viper-vi-basic-map
"/" 'viper-search-forward
)
303 (define-key viper-vi-basic-map
"0" 'viper-beginning-of-line
)
304 (define-key viper-vi-basic-map
"1" 'viper-digit-argument
)
305 (define-key viper-vi-basic-map
"2" 'viper-digit-argument
)
306 (define-key viper-vi-basic-map
"3" 'viper-digit-argument
)
307 (define-key viper-vi-basic-map
"4" 'viper-digit-argument
)
308 (define-key viper-vi-basic-map
"5" 'viper-digit-argument
)
309 (define-key viper-vi-basic-map
"6" 'viper-digit-argument
)
310 (define-key viper-vi-basic-map
"7" 'viper-digit-argument
)
311 (define-key viper-vi-basic-map
"8" 'viper-digit-argument
)
312 (define-key viper-vi-basic-map
"9" 'viper-digit-argument
)
314 (define-key viper-vi-basic-map
":" 'viper-ex
)
315 (define-key viper-vi-basic-map
";" 'viper-repeat-find
)
316 (define-key viper-vi-basic-map
"<" 'viper-command-argument
)
317 (define-key viper-vi-basic-map
"=" 'viper-command-argument
)
318 (define-key viper-vi-basic-map
">" 'viper-command-argument
)
319 (define-key viper-vi-basic-map
"?" 'viper-search-backward
)
320 (define-key viper-vi-basic-map
"@" 'viper-register-macro
)
322 (define-key viper-vi-basic-map
"A" 'viper-Append
)
323 (define-key viper-vi-basic-map
"B" 'viper-backward-Word
)
324 (define-key viper-vi-basic-map
"C" 'viper-change-to-eol
)
325 (define-key viper-vi-basic-map
"D" 'viper-kill-line
)
326 (define-key viper-vi-basic-map
"E" 'viper-end-of-Word
)
327 (define-key viper-vi-basic-map
"F" 'viper-find-char-backward
)
328 (define-key viper-vi-basic-map
"G" 'viper-goto-line
)
329 (define-key viper-vi-basic-map
"H" 'viper-window-top
)
330 (define-key viper-vi-basic-map
"I" 'viper-Insert
)
331 (define-key viper-vi-basic-map
"J" 'viper-join-lines
)
332 (define-key viper-vi-basic-map
"K" 'viper-nil
)
333 (define-key viper-vi-basic-map
"L" 'viper-window-bottom
)
334 (define-key viper-vi-basic-map
"M" 'viper-window-middle
)
335 (define-key viper-vi-basic-map
"N" 'viper-search-Next
)
336 (define-key viper-vi-basic-map
"O" 'viper-Open-line
)
337 (define-key viper-vi-basic-map
"P" 'viper-Put-back
)
338 (define-key viper-vi-basic-map
"Q" 'viper-query-replace
)
339 (define-key viper-vi-basic-map
"R" 'viper-overwrite
)
340 (define-key viper-vi-basic-map
"S" 'viper-substitute-line
)
341 (define-key viper-vi-basic-map
"T" 'viper-goto-char-backward
)
342 (define-key viper-vi-basic-map
"U" 'viper-undo
)
343 (define-key viper-vi-basic-map
"V" 'find-file-other-window
)
344 (define-key viper-vi-basic-map
"W" 'viper-forward-Word
)
345 (define-key viper-vi-basic-map
"X" 'viper-delete-backward-char
)
346 (define-key viper-vi-basic-map
"Y" 'viper-yank-line
)
347 (define-key viper-vi-basic-map
"ZZ" 'viper-save-kill-buffer
)
349 (define-key viper-vi-basic-map
"\\" 'viper-escape-to-emacs
)
350 (define-key viper-vi-basic-map
"[" 'viper-brac-function
)
351 (define-key viper-vi-basic-map
"]" 'viper-ket-function
)
352 (define-key viper-vi-basic-map
"\C-\\" 'viper-alternate-Meta-key
)
353 (define-key viper-vi-basic-map
"^" 'viper-bol-and-skip-white
)
354 (define-key viper-vi-basic-map
"`" 'viper-goto-mark
)
356 (define-key viper-vi-basic-map
"a" 'viper-append
)
357 (define-key viper-vi-basic-map
"b" 'viper-backward-word
)
358 (define-key viper-vi-basic-map
"c" 'viper-command-argument
)
359 (define-key viper-vi-basic-map
"d" 'viper-command-argument
)
360 (define-key viper-vi-basic-map
"e" 'viper-end-of-word
)
361 (define-key viper-vi-basic-map
"f" 'viper-find-char-forward
)
362 (define-key viper-vi-basic-map
"g" 'viper-nil
)
363 (define-key viper-vi-basic-map
"h" 'viper-backward-char
)
364 (define-key viper-vi-basic-map
[backspace] 'viper-backward-char)
365 (define-key viper-vi-basic-map "i" 'viper-insert)
366 (define-key viper-vi-basic-map "j" 'viper-next-line)
367 (define-key viper-vi-basic-map "k" 'viper-previous-line)
368 (define-key viper-vi-basic-map "l" 'viper-forward-char)
369 (define-key viper-vi-basic-map "m" 'viper-mark-point)
370 (define-key viper-vi-basic-map "n" 'viper-search-next)
371 (define-key viper-vi-basic-map "o" 'viper-open-line)
372 (define-key viper-vi-basic-map "p" 'viper-put-back)
373 (define-key viper-vi-basic-map "q" 'viper-nil)
374 (define-key viper-vi-basic-map "r" 'viper-replace-char)
375 (define-key viper-vi-basic-map "s" 'viper-substitute)
376 (define-key viper-vi-basic-map "t" 'viper-goto-char-forward)
377 (define-key viper-vi-basic-map "u" 'viper-undo)
378 (define-key viper-vi-basic-map "v" 'find-file)
379 (define-key viper-vi-basic-map "\C-v" 'find-file-other-frame)
380 (define-key viper-vi-basic-map "w" 'viper-forward-word)
381 (define-key viper-vi-basic-map "x" 'viper-delete-char)
382 (define-key viper-vi-basic-map "y" 'viper-command-argument)
383 (define-key viper-vi-basic-map "zH" 'viper-line-to-top)
384 (define-key viper-vi-basic-map "zM" 'viper-line-to-middle)
385 (define-key viper-vi-basic-map "zL" 'viper-line-to-bottom)
386 (define-key viper-vi-basic-map "z\C-m" 'viper-line-to-top)
387 (define-key viper-vi-basic-map "z." 'viper-line-to-middle)
388 (define-key viper-vi-basic-map "z-" 'viper-line-to-bottom)
390 (define-key viper-vi-basic-map "{" 'viper-backward-paragraph)
391 (define-key viper-vi-basic-map "|" 'viper-goto-col)
392 (define-key viper-vi-basic-map "}" 'viper-forward-paragraph)
393 (define-key viper-vi-basic-map "~" 'viper-toggle-case)
394 (define-key viper-vi-basic-map "\C-?" 'viper-backward-char)
395 (define-key viper-vi-basic-map "_" 'viper-nil)
397 ;;; This is viper-vi-diehard-map. Used when viper-vi-diehard-minor-mode is on.
399 (define-key viper-vi-diehard-map "\C-a" 'viper-nil)
400 (define-key viper-vi-diehard-map "\C-c" 'viper-nil)
401 (define-key viper-vi-diehard-map "\C-g" 'viper-info-on-file)
402 (define-key viper-vi-diehard-map "\C-i" 'viper-nil)
403 (define-key viper-vi-diehard-map "\C-k" 'viper-nil)
404 (define-key viper-vi-diehard-map "\C-l" 'redraw-display)
405 (define-key viper-vi-diehard-map "\C-n" 'viper-next-line)
406 (define-key viper-vi-diehard-map "\C-o" 'viper-nil)
407 (define-key viper-vi-diehard-map "\C-p" 'viper-previous-line)
408 (define-key viper-vi-diehard-map "\C-q" 'viper-nil)
409 (define-key viper-vi-diehard-map "\C-r" 'redraw-display)
410 (define-key viper-vi-diehard-map "\C-s" 'viper-nil)
411 (define-key viper-vi-diehard-map "\C-t" 'viper-nil)
412 (define-key viper-vi-diehard-map "\C-v" 'viper-nil)
413 (define-key viper-vi-diehard-map "\C-w" 'viper-nil)
414 (define-key viper-vi-diehard-map "@" 'viper-nil)
415 (define-key viper-vi-diehard-map "_" 'viper-nil)
416 (define-key viper-vi-diehard-map "*" 'viper-nil)
417 (define-key viper-vi-diehard-map "#" 'viper-nil)
418 (define-key viper-vi-diehard-map "\C-_" 'viper-nil)
419 (define-key viper-vi-diehard-map "\C-]" 'viper-nil) ; This is actually tags.
422 ;;; Minibuffer keymap
425 (defvar viper-minibuffer-map (make-sparse-keymap)
426 "Keymap used to modify keys when Minibuffer is in Insert state.")
428 (define-key viper-minibuffer-map "\C-m" 'viper-exit-minibuffer)
429 (define-key viper-minibuffer-map "\C-j" 'viper-exit-minibuffer)
431 ;; Map used to read Ex-style commands.
432 (defvar viper-ex-cmd-map (make-sparse-keymap))
433 (define-key viper-ex-cmd-map " " 'ex-cmd-read-exit)
434 (define-key viper-ex-cmd-map "\t" 'ex-cmd-complete)
436 ;; Keymap for reading file names in Ex-style commands.
437 (defvar ex-read-filename-map (make-sparse-keymap))
438 (define-key ex-read-filename-map " " 'viper-complete-filename-or-exit)
439 (define-key ex-read-filename-map "!" 'viper-handle-!)
442 (defvar viper-slash-and-colon-map (make-sparse-keymap)
443 "This map redefines `/' and `:' to behave as in Vi.
444 Useful in some modes, such as Gnus, MH, etc.")
445 (define-key viper-slash-and-colon-map ":" 'viper-ex)
446 (define-key viper-slash-and-colon-map "/" 'viper-search-forward)
448 (defvar viper-comint-mode-modifier-map (make-sparse-keymap)
449 "This map modifies comint mode.")
450 (define-key viper-comint-mode-modifier-map "\C-m" 'viper-exec-key-in-emacs)
451 (define-key viper-comint-mode-modifier-map "\C-d" 'viper-exec-key-in-emacs)
453 (defvar viper-dired-modifier-map (make-sparse-keymap)
454 "This map modifies Dired behavior.")
455 (define-key viper-dired-modifier-map ":" 'viper-ex)
456 (define-key viper-dired-modifier-map "/" 'viper-search-forward)
462 (defun viper-add-local-keys (state alist)
463 "Override some vi-state or insert-state bindings in the current buffer.
464 The effect is seen in the current buffer only.
465 Useful for customizing mailer buffers, gnus, etc.
466 STATE is 'vi-state, 'insert-state, or 'emacs-state
467 ALIST is of the form ((key . func) (key . func) ...)
468 Normally, this would be called from a hook to a major mode or
469 on a per buffer basis.
471 (viper-add-local-keys state '((key-str . func) (key-str . func)...)) "
474 (cond ((eq state 'vi-state)
475 (if viper-need-new-vi-local-map
476 (setq viper-vi-local-user-map (make-sparse-keymap)))
477 (setq viper-need-new-vi-local-map nil
478 map viper-vi-local-user-map))
479 ((eq state 'insert-state)
480 (if viper-need-new-insert-local-map
481 (setq viper-insert-local-user-map (make-sparse-keymap)))
482 (setq viper-need-new-insert-local-map nil
483 map viper-insert-local-user-map))
484 ((eq state 'emacs-state)
485 (if viper-need-new-emacs-local-map
486 (setq viper-emacs-local-user-map (make-sparse-keymap)))
487 (setq viper-need-new-emacs-local-map nil
488 map viper-emacs-local-user-map))
491 "Invalid state in viper-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state)))
493 (viper-modify-keymap map alist)
494 (viper-normalize-minor-mode-map-alist)
495 (viper-set-mode-vars-for viper-current-state)))
497 (defun viper-zap-local-keys ()
498 "Unconditionally reset Viper viper-*-local-user-map's.
499 Rarely useful, but if u made a mistake by switching to a mode that adds
500 undesirable local keys, e.g., comint-mode, then this function can restore
503 (setq viper-vi-local-user-map (make-sparse-keymap)
504 viper-need-new-vi-local-map nil
505 viper-insert-local-user-map (make-sparse-keymap)
506 viper-need-new-insert-local-map nil
507 viper-emacs-local-user-map (make-sparse-keymap)
508 viper-need-new-emacs-local-map nil)
509 (viper-normalize-minor-mode-map-alist))
512 (defun viper-modify-major-mode (mode state keymap)
513 "Modify key bindings in a major-mode in a Viper state using a keymap.
515 If the default for a major mode is emacs-state, then modifications to this
516 major mode may not take effect until the buffer switches state to Vi,
517 Insert or Emacs. If this happens, add viper-change-state-to-emacs to this
518 major mode's hook. If no such hook exists, you may have to put an advice on
519 the function that invokes the major mode. See viper-set-hooks for hints.
521 The above needs not to be done for major modes that come up in Vi or Insert
524 Arguments: (major-mode viper-state keymap)"
526 (cond ((eq state 'vi-state) 'viper-vi-state-modifier-alist)
527 ((eq state 'insert-state) 'viper-insert-state-modifier-alist)
528 ((eq state 'emacs-state) 'viper-emacs-state-modifier-alist)))
530 (if (setq elt (assoc mode (eval alist)))
531 (set alist (delq elt (eval alist))))
532 (set alist (cons (cons mode keymap) (eval alist)))
534 ;; Normalization usually doesn't help here, since one needs to
535 ;; normalize in the actual buffer where changes to the keymap are
536 ;; to take place. However, it doesn't hurt, and it helps whenever this
537 ;; function is actually called from within the affected buffer.
538 (viper-normalize-minor-mode-map-alist)
540 (viper-set-mode-vars-for viper-current-state)))
543 ;; Displays variables that control Viper's keymaps
544 (defun viper-debug-keymaps ()
546 (with-output-to-temp-buffer " *viper-debug*"
547 (princ (format "Buffer name: %s\n\n" (buffer-name)))
548 (princ "Variables: \n")
549 (princ (format "major-mode: %S\n" major-mode))
550 (princ (format "viper-current-state: %S\n" viper-current-state))
551 (princ (format "viper-mode-string: %S\n\n" viper-mode-string))
552 (princ (format "viper-vi-intercept-minor-mode: %S\n"
553 viper-vi-intercept-minor-mode))
554 (princ (format "viper-insert-intercept-minor-mode: %S\n"
555 viper-insert-intercept-minor-mode))
556 (princ (format "viper-emacs-intercept-minor-mode: %S\n"
557 viper-emacs-intercept-minor-mode))
558 (princ (format "viper-vi-minibuffer-minor-mode: %S\n"
559 viper-vi-minibuffer-minor-mode))
560 (princ (format "viper-insert-minibuffer-minor-mode: %S\n\n"
561 viper-insert-minibuffer-minor-mode))
562 (princ (format "viper-vi-local-user-minor-mode: %S\n"
563 viper-vi-local-user-minor-mode))
564 (princ (format "viper-vi-global-user-minor-mode: %S\n"
565 viper-vi-global-user-minor-mode))
566 (princ (format "viper-vi-kbd-minor-mode: %S\n" viper-vi-kbd-minor-mode))
567 (princ (format "viper-vi-state-modifier-minor-mode: %S\n"
568 viper-vi-state-modifier-minor-mode))
569 (princ (format "viper-vi-diehard-minor-mode: %S\n"
570 viper-vi-diehard-minor-mode))
571 (princ (format "viper-vi-basic-minor-mode: %S\n" viper-vi-basic-minor-mode))
572 (princ (format "viper-replace-minor-mode: %S\n" viper-replace-minor-mode))
573 (princ (format "viper-insert-local-user-minor-mode: %S\n"
574 viper-insert-local-user-minor-mode))
575 (princ (format "viper-insert-global-user-minor-mode: %S\n"
576 viper-insert-global-user-minor-mode))
577 (princ (format "viper-insert-kbd-minor-mode: %S\n"
578 viper-insert-kbd-minor-mode))
579 (princ (format "viper-insert-state-modifier-minor-mode: %S\n"
580 viper-insert-state-modifier-minor-mode))
581 (princ (format "viper-insert-diehard-minor-mode: %S\n"
582 viper-insert-diehard-minor-mode))
583 (princ (format "viper-insert-basic-minor-mode: %S\n"
584 viper-insert-basic-minor-mode))
585 (princ (format "viper-emacs-local-user-minor-mode: %S\n"
586 viper-emacs-local-user-minor-mode))
587 (princ (format "viper-emacs-kbd-minor-mode: %S\n"
588 viper-emacs-kbd-minor-mode))
589 (princ (format "viper-emacs-global-user-minor-mode: %S\n"
590 viper-emacs-global-user-minor-mode))
591 (princ (format "viper-emacs-state-modifier-minor-mode: %S\n"
592 viper-emacs-state-modifier-minor-mode))
594 (princ (format "\nviper-expert-level %S\n" viper-expert-level))
595 (princ (format "viper-no-multiple-ESC %S\n" viper-no-multiple-ESC))
596 (princ (format "viper-always %S\n" viper-always))
597 (princ (format "viper-ex-style-motion %S\n"
598 viper-ex-style-motion))
599 (princ (format "viper-ex-style-editing %S\n"
600 viper-ex-style-editing))
601 (princ (format "viper-want-emacs-keys-in-vi %S\n"
602 viper-want-emacs-keys-in-vi))
603 (princ (format "viper-want-emacs-keys-in-insert %S\n"
604 viper-want-emacs-keys-in-insert))
605 (princ (format "viper-want-ctl-h-help %S\n" viper-want-ctl-h-help))
608 (princ (format "Default value for minor-mode-map-alist: \n%S\n\n"
609 (default-value 'minor-mode-map-alist)))
610 (princ (format "Actual value for minor-mode-map-alist: \n%S\n"
611 minor-mode-map-alist))
617 (defun viper-add-keymap (mapsrc mapdst)
618 "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse."
619 (viper-cond-compile-for-xemacs-or-emacs
621 (map-keymap (lambda (key binding) (define-key mapdst key binding))
624 (mapcar (lambda (p) (define-key mapdst (vector (car p)) (cdr p)))
628 (defun viper-modify-keymap (map alist)
629 "Modifies MAP with bindings specified in the ALIST. The alist has the
630 form ((key . function) (key . function) ... )."
631 (mapcar (lambda (p) (define-key map (eval (car p)) (cdr p)))
636 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
640 ;;; viper-keym.el ends here