comparison lisp/viper/viper-keym.el @ 78:c7528f8e288d r20-0b34

Import from CVS: tag r20-0b34
author cvs
date Mon, 13 Aug 2007 09:05:42 +0200
parents 131b0175ea99
children 1ce6082ce73f
comparison
equal deleted inserted replaced
77:6cb4f478e7bc 78:c7528f8e288d
22 ;; Code 22 ;; Code
23 23
24 (require 'viper-util) 24 (require 'viper-util)
25 25
26 ;;; Variables 26 ;;; Variables
27
28 (defvar vip-toggle-key "\C-z"
29 "The key used to change states from emacs to Vi and back.
30 In insert mode, this key also functions as Meta.
31 Must be set in .vip file or prior to loading Viper.
32 This setting cannot be changed interactively.")
33
34 (defvar vip-ESC-key "\e"
35 "Key used to ESC.
36 Must be set in .vip file or prior to loading Viper.
37 This setting cannot be changed interactively.")
38
27 39
28 ;;; Keymaps 40 ;;; Keymaps
29 41
30 ;; Keymaps for vital things like \e and C-z. 42 ;; Keymaps for vital things like \e and C-z.
31 ;; Not for users 43 ;; Not for users
175 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent) 187 (define-key vip-insert-basic-map "\C-t" 'vip-forward-indent)
176 (define-key vip-insert-basic-map 188 (define-key vip-insert-basic-map
177 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab) 189 (if vip-xemacs-p [(shift tab)] [S-tab]) 'vip-insert-tab)
178 (define-key vip-insert-basic-map "\C-v" 'quoted-insert) 190 (define-key vip-insert-basic-map "\C-v" 'quoted-insert)
179 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert) 191 (define-key vip-insert-basic-map "\C-?" 'vip-del-backward-char-in-insert)
192 (define-key vip-insert-basic-map "\C-\\" 'vip-alternate-Meta-key)
193 (define-key vip-insert-basic-map vip-toggle-key 'vip-escape-to-vi)
180 (define-key vip-insert-basic-map "\C-c\M-p" 194 (define-key vip-insert-basic-map "\C-c\M-p"
181 'vip-insert-prev-from-insertion-ring) 195 'vip-insert-prev-from-insertion-ring)
182 (define-key vip-insert-basic-map "\C-c\M-n" 196 (define-key vip-insert-basic-map "\C-c\M-n"
183 'vip-insert-next-from-insertion-ring) 197 'vip-insert-next-from-insertion-ring)
184 198
193 207
194 ;; Vi keymaps 208 ;; Vi keymaps
195 209
196 (define-key vip-vi-basic-map "\C-^" 210 (define-key vip-vi-basic-map "\C-^"
197 (function (lambda () (interactive) (vip-ex "e#")))) 211 (function (lambda () (interactive) (vip-ex "e#"))))
198 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-back) 212 (define-key vip-vi-basic-map "\C-b" 'vip-scroll-screen-back)
199 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up) 213 (define-key vip-vi-basic-map "\C-d" 'vip-scroll-up)
200 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one) 214 (define-key vip-vi-basic-map "\C-e" 'vip-scroll-up-one)
201 (define-key vip-vi-basic-map "\C-f" 'vip-scroll) 215 (define-key vip-vi-basic-map "\C-f" 'vip-scroll-screen)
202 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol) 216 (define-key vip-vi-basic-map "\C-m" 'vip-next-line-at-bol)
203 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down) 217 (define-key vip-vi-basic-map "\C-u" 'vip-scroll-down)
204 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one) 218 (define-key vip-vi-basic-map "\C-y" 'vip-scroll-down-one)
205 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward) 219 (define-key vip-vi-basic-map "\C-s" 'vip-isearch-forward)
206 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward) 220 (define-key vip-vi-basic-map "\C-r" 'vip-isearch-backward)
207 ;(define-key vip-vi-basic-map "\C-\\" 'universal-argument)
208 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style) 221 (define-key vip-vi-basic-map "\C-c/" 'vip-toggle-search-style)
209 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file) 222 (define-key vip-vi-basic-map "\C-cg" 'vip-info-on-file)
210 223
211 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command) 224 (define-key vip-vi-basic-map "\C-c\M-p" 'vip-prev-destructive-command)
212 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command) 225 (define-key vip-vi-basic-map "\C-c\M-n" 'vip-next-destructive-command)
277 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer) 290 (define-key vip-vi-basic-map "ZZ" 'vip-save-kill-buffer)
278 291
279 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs) 292 (define-key vip-vi-basic-map "\\" 'vip-escape-to-emacs)
280 (define-key vip-vi-basic-map "[" 'vip-brac-function) 293 (define-key vip-vi-basic-map "[" 'vip-brac-function)
281 (define-key vip-vi-basic-map "]" 'vip-ket-function) 294 (define-key vip-vi-basic-map "]" 'vip-ket-function)
282 (define-key vip-vi-basic-map "_" 'vip-alternate-ESC) 295 (define-key vip-vi-basic-map "\C-\\" 'vip-alternate-Meta-key)
283 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white) 296 (define-key vip-vi-basic-map "^" 'vip-bol-and-skip-white)
284 (define-key vip-vi-basic-map "`" 'vip-goto-mark) 297 (define-key vip-vi-basic-map "`" 'vip-goto-mark)
285 298
286 (define-key vip-vi-basic-map "a" 'vip-append) 299 (define-key vip-vi-basic-map "a" 'vip-append)
287 (define-key vip-vi-basic-map "b" 'vip-backward-word) 300 (define-key vip-vi-basic-map "b" 'vip-backward-word)
319 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph) 332 (define-key vip-vi-basic-map "{" 'vip-backward-paragraph)
320 (define-key vip-vi-basic-map "|" 'vip-goto-col) 333 (define-key vip-vi-basic-map "|" 'vip-goto-col)
321 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph) 334 (define-key vip-vi-basic-map "}" 'vip-forward-paragraph)
322 (define-key vip-vi-basic-map "~" 'vip-toggle-case) 335 (define-key vip-vi-basic-map "~" 'vip-toggle-case)
323 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char) 336 (define-key vip-vi-basic-map "\C-?" 'vip-backward-char)
324 337 (define-key vip-vi-basic-map "_" 'vip-nil)
338
325 ;;; Escape from Emacs to Vi for one command 339 ;;; Escape from Emacs to Vi for one command
326 (global-set-key "\M-\C-z" 'vip-escape-to-vi) ;; in emacs-state 340 (global-set-key "\C-c\\" 'vip-escape-to-vi) ; everywhere
327 341
328 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on. 342 ;;; This is vip-vi-diehard-map. Used when vip-vi-diehard-minor-mode is on.
329 343
330 (define-key vip-vi-diehard-map "\C-a" 'vip-nil) 344 (define-key vip-vi-diehard-map "\C-a" 'vip-nil)
331 (define-key vip-vi-diehard-map "\C-c" 'vip-nil) 345 (define-key vip-vi-diehard-map "\C-c" 'vip-nil)
341 (define-key vip-vi-diehard-map "\C-s" 'vip-nil) 355 (define-key vip-vi-diehard-map "\C-s" 'vip-nil)
342 (define-key vip-vi-diehard-map "\C-t" 'vip-nil) 356 (define-key vip-vi-diehard-map "\C-t" 'vip-nil)
343 (define-key vip-vi-diehard-map "\C-v" 'vip-nil) 357 (define-key vip-vi-diehard-map "\C-v" 'vip-nil)
344 (define-key vip-vi-diehard-map "\C-w" 'vip-nil) 358 (define-key vip-vi-diehard-map "\C-w" 'vip-nil)
345 (define-key vip-vi-diehard-map "@" 'vip-nil) 359 (define-key vip-vi-diehard-map "@" 'vip-nil)
360 (define-key vip-vi-diehard-map "_" 'vip-nil)
346 (define-key vip-vi-diehard-map "*" 'vip-nil) 361 (define-key vip-vi-diehard-map "*" 'vip-nil)
347 (define-key vip-vi-diehard-map "#" 'vip-nil) 362 (define-key vip-vi-diehard-map "#" 'vip-nil)
348 (define-key vip-vi-diehard-map "\C-_" 'vip-nil) 363 (define-key vip-vi-diehard-map "\C-_" 'vip-nil)
349 (define-key vip-vi-diehard-map "\C-]" 'vip-nil);; This is actually tags. 364 (define-key vip-vi-diehard-map "\C-]" 'vip-nil) ; This is actually tags.
350 365
351 366
352 ;;; Minibuffer keymap 367 ;;; Minibuffer keymap
353 368
354 369
366 ;; Keymap for reading file names in Ex-style commands. 381 ;; Keymap for reading file names in Ex-style commands.
367 (defvar ex-read-filename-map (make-sparse-keymap)) 382 (defvar ex-read-filename-map (make-sparse-keymap))
368 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit) 383 (define-key ex-read-filename-map " " 'vip-complete-filename-or-exit)
369 (define-key ex-read-filename-map "!" 'vip-handle-!) 384 (define-key ex-read-filename-map "!" 'vip-handle-!)
370 385
371 386 ;; Some other maps
372 387 (defvar vip-slash-and-colon-map (make-sparse-keymap)
388 "This map redefines `/' and `:' to behave as in Vi.
389 Useful in some modes, such as Gnus, MH, etc.")
390 (define-key vip-slash-and-colon-map ":" 'vip-ex)
391 (define-key vip-slash-and-colon-map "/" 'vip-search-forward)
392
393 (defvar vip-comint-mode-modifier-map (make-sparse-keymap)
394 "This map modifies comint mode.")
395 (define-key vip-comint-mode-modifier-map "\C-m" 'comint-send-input)
396 (define-key vip-comint-mode-modifier-map "\C-d" 'comint-delchar-or-maybe-eof)
397
398 (defvar vip-dired-modifier-map (make-sparse-keymap)
399 "This map modifies Dired behavior.")
400 (define-key vip-dired-modifier-map ":" 'vip-ex)
401 (define-key vip-dired-modifier-map "/" 'vip-search-forward)
402
403
373 404
374 ;;; Code 405 ;;; Code
375 406
376 (defun vip-add-local-keys (state alist) 407 (defun vip-add-local-keys (state alist)
377 "Override some vi-state or insert-state bindings in the current buffer. 408 "Override some vi-state or insert-state bindings in the current buffer.
408 (vip-normalize-minor-mode-map-alist) 439 (vip-normalize-minor-mode-map-alist)
409 (vip-set-mode-vars-for vip-current-state))) 440 (vip-set-mode-vars-for vip-current-state)))
410 441
411 (defun vip-zap-local-keys () 442 (defun vip-zap-local-keys ()
412 "Unconditionally reset Viper vip-*-local-user-map's. 443 "Unconditionally reset Viper vip-*-local-user-map's.
413 Rarely useful, but if u made a mistake by switching to a mode that adds 444 Rarely useful, but if you made a mistake by switching to a mode that adds
414 undesirable local keys, e.g., comint-mode, then this function can return 445 undesirable local keys, e.g., comint-mode, then this function can restore
415 you to sanity." 446 sanity."
416 (interactive) 447 (interactive)
417 (setq vip-vi-local-user-map (make-sparse-keymap) 448 (setq vip-vi-local-user-map (make-sparse-keymap)
418 vip-need-new-vi-local-map nil 449 vip-need-new-vi-local-map nil
419 vip-insert-local-user-map (make-sparse-keymap) 450 vip-insert-local-user-map (make-sparse-keymap)
420 vip-need-new-insert-local-map nil 451 vip-need-new-insert-local-map nil