comparison lisp/viper/viper-keym.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 4103f0995bd7
children c7528f8e288d
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
1 ;;; viper-keym.el --- Viper keymaps 1 ;;; viper-keym.el --- Viper keymaps
2 2
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
4 4
5 ;; This file is part of GNU Emacs. 5 ;; This file is part of GNU Emacs.
6 6
7 ;; GNU Emacs is free software; you can redistribute it and/or modify 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 8 ;; it under the terms of the GNU General Public License as published by
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA. 20 ;; Boston, MA 02111-1307, USA.
21 21
22 ;; Code 22 ;; Code
23 23
24 (provide 'viper-keym)
25
26 ;; compiler pacifier
27 (defvar vip-always)
28 (defvar vip-current-state)
29 (defvar vip-mode-string)
30 (defvar vip-expert-level)
31 (defvar vip-ex-style-editing-in-insert)
32 (defvar vip-ex-style-motion)
33
34 (eval-when-compile
35 (let ((load-path (cons (expand-file-name ".") load-path)))
36 (or (featurep 'viper-util)
37 (load "viper-util.el" nil nil 'nosuffix))
38 ))
39 ;; end pacifier
40
41 (require 'viper-util) 24 (require 'viper-util)
42 25
43
44 ;;; Variables 26 ;;; Variables
45
46 (defvar vip-toggle-key "\C-z"
47 "The key used to change states from emacs to Vi and back.
48 In insert mode, this key also functions as Meta.
49 Must be set in .vip file or prior to loading Viper.
50 This setting cannot be changed interactively.")
51
52 (defvar vip-ESC-key "\e"
53 "Key used to ESC.
54 Must be set in .vip file or prior to loading Viper.
55 This setting cannot be changed interactively.")
56
57 ;;; Emacs keys in other states.
58
59 (defvar vip-want-emacs-keys-in-insert t
60 "*Set to nil if you want complete Vi compatibility in insert mode.
61 Complete compatibility with Vi is not recommended for power use of Viper.")
62
63 (defvar vip-want-emacs-keys-in-vi t
64 "*Set to nil if you want complete Vi compatibility in Vi mode.
65 Full Vi compatibility is not recommended for power use of Viper.")
66
67 (defvar vip-no-multiple-ESC t
68 "*If true, multiple ESC in Vi mode will cause bell to ring.
69 This is set to t on a windowing terminal and to 'twice on a dumb
70 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
71 enables cursor keys and is generally more convenient, as terminals usually
72 don't have a convenient Meta key.
73 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC,
74 as is allowed by the major mode in effect.")
75
76 (defvar vip-want-ctl-h-help nil
77 "*If t then C-h is bound to help-command in insert mode, if nil then it is
78 bound to delete-backward-char.")
79
80 27
81 ;;; Keymaps 28 ;;; Keymaps
82 29
83 ;; Keymaps for vital things like \e and C-z. 30 ;; Keymaps for vital things like \e and C-z.
84 ;; Not for users 31 ;; Not for users
228 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent) 175 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent)
229 (define-key vip-insert-basic-map 176 (define-key vip-insert-basic-map
230 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab) 177 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
231 (define-key vip-insert-basic-map "\C-v" 'quoted-insert) 178 (define-key vip-insert-basic-map "\C-v" 'quoted-insert)
232 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert) 179 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
233 (define-key vip-insert-basic-map "\C-\\" 'vip-alternate-Meta-key)
234 (define-key vip-insert-basic-map vip-toggle-key 'vip-escape-to-vi)
235 (define-key vip-insert-basic-map "\C-c\M-p" 180 (define-key vip-insert-basic-map "\C-c\M-p"
236 'vip-insert-prev-from-insertion-ring) 181 'vip-insert-prev-from-insertion-ring)
237 (define-key vip-insert-basic-map "\C-c\M-n" 182 (define-key vip-insert-basic-map "\C-c\M-n"
238 'vip-insert-next-from-insertion-ring) 183 'vip-insert-next-from-insertion-ring)
239 184
240 185
241 ;; Replace keymap 186 ;; Replace keymap
242 (define-key vip-replace-map "\C-t" 'vip-forward-indent) 187 (define-key vip-replace-map "\C-t" 'vip-forward-indent)
243 (define-key vip-replace-map "\C-j" 'vip-replace-state-carriage-return) 188 (define-key vip-replace-map "\C-j" 'vip-replace-state-exit-cmd)
244 (define-key vip-replace-map "\C-m" 'vip-replace-state-carriage-return) 189 (define-key vip-replace-map "\C-m" 'vip-replace-state-exit-cmd)
245 (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace) 190 (define-key vip-replace-map "\C-?" 'vip-del-backward-char-in-replace)
246 191
247 192
248 193
249 ;; Vi keymaps 194 ;; Vi keymaps
250 195
251 (define-key vip-vi-basic-map "\C-^" 196 (define-key vip-vi-basic-map "\C-^"
252 (function (lambda () (interactive) (vip-ex "e#")))) 197 (function (lambda () (interactive) (vip-ex "e#"))))
253 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-screen-back) 198 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-back)
254 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up) 199 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up)
255 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one) 200 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one)
256 (define-key vip-vi-basic-map "\C-f" 'vip-scroll-screen) 201 (define-key vip-vi-basic-map "\C-f" 'vip-scroll)
257 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol) 202 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol)
258 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down) 203 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down)
259 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one) 204 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one)
260 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward) 205 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward)
261 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward) 206 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward)
207 ;(define-key vip-vi-basic-map "\C-\\" 'universal-argument)
262 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style) 208 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style)
263 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file) 209 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file)
264 210
265 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command) 211 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command)
266 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command) 212 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command)
331 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer) 277 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer)
332 278
333 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs) 279 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs)
334 (define-key vip-vi-basic-map "[" 'vip-brac-function) 280 (define-key vip-vi-basic-map "[" 'vip-brac-function)
335 (define-key vip-vi-basic-map "]" 'vip-ket-function) 281 (define-key vip-vi-basic-map "]" 'vip-ket-function)
336 (define-key vip-vi-basic-map "\C-\\" 'vip-alternate-Meta-key) 282 (define-key vip-vi-basic-map "_" 'vip-alternate-ESC)
337 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white) 283 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white)
338 (define-key vip-vi-basic-map "`" 'vip-goto-mark) 284 (define-key vip-vi-basic-map "`" 'vip-goto-mark)
339 285
340 (define-key vip-vi-basic-map "a" 'vip-append) 286 (define-key vip-vi-basic-map "a" 'vip-append)
341 (define-key vip-vi-basic-map "b" 'vip-backward-word) 287 (define-key vip-vi-basic-map "b" 'vip-backward-word)
373 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph) 319 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph)
374 (define-key vip-vi-basic-map "|" 'vip-goto-col) 320 (define-key vip-vi-basic-map "|" 'vip-goto-col)
375 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph) 321 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph)
376 (define-key vip-vi-basic-map "~" 'vip-toggle-case) 322 (define-key vip-vi-basic-map "~" 'vip-toggle-case)
377 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char) 323 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char)
378 (define-key vip-vi-basic-map "_" 'vip-nil)
379 324
380 ;;; Escape from Emacs to Vi for one command 325 ;;; Escape from Emacs to Vi for one command
381 (global-set-key "\C-c\\" 'vip-escape-to-vi) ; everywhere 326 (global-set-key "\M-\C-z" 'vip-escape-to-vi) ;; in emacs-state
382 327
383 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on. 328 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on.
384 329
385 (define-key vip-vi-diehard-map "\C-a" 'vip-nil) 330 (define-key vip-vi-diehard-map "\C-a" 'vip-nil)
386 (define-key vip-vi-diehard-map "\C-c" 'vip-nil) 331 (define-key vip-vi-diehard-map "\C-c" 'vip-nil)
396 (define-key vip-vi-diehard-map "\C-s" 'vip-nil) 341 (define-key vip-vi-diehard-map "\C-s" 'vip-nil)
397 (define-key vip-vi-diehard-map "\C-t" 'vip-nil) 342 (define-key vip-vi-diehard-map "\C-t" 'vip-nil)
398 (define-key vip-vi-diehard-map "\C-v" 'vip-nil) 343 (define-key vip-vi-diehard-map "\C-v" 'vip-nil)
399 (define-key vip-vi-diehard-map "\C-w" 'vip-nil) 344 (define-key vip-vi-diehard-map "\C-w" 'vip-nil)
400 (define-key vip-vi-diehard-map "@" 'vip-nil) 345 (define-key vip-vi-diehard-map "@" 'vip-nil)
401 (define-key vip-vi-diehard-map "_" 'vip-nil)
402 (define-key vip-vi-diehard-map "*" 'vip-nil) 346 (define-key vip-vi-diehard-map "*" 'vip-nil)
403 (define-key vip-vi-diehard-map "#" 'vip-nil) 347 (define-key vip-vi-diehard-map "#" 'vip-nil)
404 (define-key vip-vi-diehard-map "\C-_" 'vip-nil) 348 (define-key vip-vi-diehard-map "\C-_" 'vip-nil)
405 (define-key vip-vi-diehard-map "\C-]" 'vip-nil) ; This is actually tags. 349 (define-key vip-vi-diehard-map "\C-]" 'vip-nil);; This is actually tags.
406 350
407 351
408 ;;; Minibuffer keymap 352 ;;; Minibuffer keymap
409 353
410 354
422 ;; Keymap for reading file names in Ex-style commands. 366 ;; Keymap for reading file names in Ex-style commands.
423 (defvar ex-read-filename-map (make-sparse-keymap)) 367 (defvar ex-read-filename-map (make-sparse-keymap))
424 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit) 368 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit)
425 (define-key ex-read-filename-map "!" 'vip-handle-!) 369 (define-key ex-read-filename-map "!" 'vip-handle-!)
426 370
427 ;; Some other maps 371
428 (defvar vip-slash-and-colon-map (make-sparse-keymap) 372
429 "This map redefines `/' and `:' to behave as in Vi.
430 Useful in some modes, such as Gnus, MH, etc.")
431 (define-key vip-slash-and-colon-map ":" 'vip-ex)
432 (define-key vip-slash-and-colon-map "/" 'vip-search-forward)
433
434 (defvar vip-comint-mode-modifier-map (make-sparse-keymap)
435 "This map modifies comint mode.")
436 (define-key vip-comint-mode-modifier-map "\C-m" 'comint-send-input)
437 (define-key vip-comint-mode-modifier-map "\C-d" 'comint-delchar-or-maybe-eof)
438
439 (defvar vip-dired-modifier-map (make-sparse-keymap)
440 "This map modifies Dired behavior.")
441 (define-key vip-dired-modifier-map ":" 'vip-ex)
442 (define-key vip-dired-modifier-map "/" 'vip-search-forward)
443
444 (defvar vip-help-modifier-map (make-sparse-keymap)
445 "This map modifies Help mode behavior.")
446 (define-key vip-help-modifier-map "q" (if vip-xemacs-p 'help-mode-quit))
447
448
449 373
450 ;;; Code 374 ;;; Code
451 375
452 (defun vip-add-local-keys (state alist) 376 (defun vip-add-local-keys (state alist)
453 "Override some vi-state or insert-state bindings in the current buffer. 377 "Override some vi-state or insert-state bindings in the current buffer.
485 (vip-set-mode-vars-for vip-current-state))) 409 (vip-set-mode-vars-for vip-current-state)))
486 410
487 (defun vip-zap-local-keys () 411 (defun vip-zap-local-keys ()
488 "Unconditionally reset Viper vip-*-local-user-map's. 412 "Unconditionally reset Viper vip-*-local-user-map's.
489 Rarely useful, but if u made a mistake by switching to a mode that adds 413 Rarely useful, but if u made a mistake by switching to a mode that adds
490 undesirable local keys, e.g., comint-mode, then this function can restore 414 undesirable local keys, e.g., comint-mode, then this function can return
491 sanity." 415 you to sanity."
492 (interactive) 416 (interactive)
493 (setq vip-vi-local-user-map (make-sparse-keymap) 417 (setq vip-vi-local-user-map (make-sparse-keymap)
494 vip-need-new-vi-local-map nil 418 vip-need-new-vi-local-map nil
495 vip-insert-local-user-map (make-sparse-keymap) 419 vip-insert-local-user-map (make-sparse-keymap)
496 vip-need-new-insert-local-map nil 420 vip-need-new-insert-local-map nil
622 (mapcar (function (lambda (p) 546 (mapcar (function (lambda (p)
623 (define-key map (eval (car p)) (cdr p)))) 547 (define-key map (eval (car p)) (cdr p))))
624 alist)) 548 alist))
625 549
626 550
551 (provide 'viper-keym)
552
627 ;;; viper-keym.el ends here 553 ;;; viper-keym.el ends here