X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/a1506d2977a8c2eb982ad0b59416009cdfaa6f51..f76840f36cf60feecaf21d55d24ace948800fef7:/lisp/emulation/viper-keym.el diff --git a/lisp/emulation/viper-keym.el b/lisp/emulation/viper-keym.el index 2369346a3f..0e502720f5 100644 --- a/lisp/emulation/viper-keym.el +++ b/lisp/emulation/viper-keym.el @@ -1,6 +1,7 @@ ;;; viper-keym.el --- Viper keymaps -;; Copyright (C) 1994, 95, 96, 97, 2000, 01, 02 Free Software Foundation, Inc. +;; Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, +;; 2005, 2006, 2007 Free Software Foundation, Inc. ;; Author: Michael Kifer @@ -8,7 +9,7 @@ ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, @@ -18,8 +19,8 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Commentary: @@ -50,16 +51,6 @@ ;;; Variables -(defvar viper-toggle-key "\C-z" - "The key used to change states from emacs to Vi and back. -In insert mode, this key also functions as Meta. -Must be set in .viper file or prior to loading Viper. -This setting cannot be changed interactively.") - -(defvar viper-ESC-key "\e" - "Key used to ESC. -Must be set in .viper file or prior to loading Viper. -This setting cannot be changed interactively.") ;;; Emacs keys in other states. @@ -153,7 +144,7 @@ viper-insert-basic-map. Not recommended, except for novice users.") "Auxiliary map for global user-defined bindings in Emacs state.") (defvar viper-emacs-kbd-map (make-sparse-keymap) - "This keymap keeps Vi-style kbd macros for emacs mode.") + "This keymap keeps Vi-style kbd macros for Emacs mode.") (viper-deflocalvar viper-emacs-local-user-map (make-sparse-keymap) "Auxiliary map for local user-defined bindings in Emacs state.") @@ -167,6 +158,79 @@ viper-insert-basic-map. Not recommended, except for novice users.") ;; and, after .viper is loaded, we add this keymap to viper-vi-basic-map. (defvar viper-mode-map (make-sparse-keymap)) +;; Some important keys used in viper +(defcustom viper-toggle-key [(control ?z)] ; "\C-z" + "The key used to change states from Emacs to Vi and back. +In insert mode, this key also functions as Meta. + +Enter as a sexp. Examples: \"\\C-z\", [(control ?z)]." + :type 'sexp + :group 'viper + :set (lambda (symbol value) + (let ((old-value (if (boundp 'viper-toggle-key) + viper-toggle-key + [(control ?z)]))) + (mapc + (lambda (buf) + (save-excursion + (set-buffer buf) + (when (and (boundp 'viper-insert-basic-map) + (keymapp viper-insert-basic-map)) + (when old-value + (define-key viper-insert-basic-map old-value nil)) + (define-key viper-insert-basic-map value 'viper-escape-to-vi)) + (when (and (boundp 'viper-vi-intercept-map) + (keymapp viper-vi-intercept-map)) + (when old-value + (define-key viper-vi-intercept-map old-value nil)) + (define-key + viper-vi-intercept-map value 'viper-toggle-key-action)) + (when (and (boundp 'viper-emacs-intercept-map) + (keymapp viper-emacs-intercept-map)) + (define-key viper-emacs-intercept-map old-value nil) + (define-key + viper-emacs-intercept-map value 'viper-change-state-to-vi)) + )) + (buffer-list)) + (set-default symbol value) + ))) + +(defcustom viper-quoted-insert-key "\C-v" + "The key used to quote special characters when inserting them in Insert state." + :type 'string + :group 'viper) + +(defcustom viper-ESC-key (if (viper-window-display-p) [(escape)] "\e") + "Key used to ESC. +Enter as a sexp. Examples: \"\\e\", [(escape)]. +If running in a terminal, [(escape)] is not understood, so must use \"\\e\"." + :type 'sexp + :group 'viper + :set (lambda (symbol value) + (let ((old-value (if (boundp 'viper-ESC-key) + viper-ESC-key + [(escape)]))) + (mapc + (lambda (buf) + (save-excursion + (set-buffer buf) + (when (and (boundp 'viper-insert-intercept-map) + (keymapp viper-insert-intercept-map)) + (when old-value + (define-key viper-insert-intercept-map old-value nil)) + (define-key + viper-insert-intercept-map value 'viper-intercept-ESC-key)) + (when (and (boundp 'viper-vi-intercept-map) + (keymapp viper-vi-intercept-map)) + (when old-value + (define-key viper-vi-intercept-map old-value nil)) + (define-key + viper-vi-intercept-map value 'viper-intercept-ESC-key)) + )) + (buffer-list)) + (set-default symbol value) + ))) + ;;; Variables used by minor modes @@ -188,6 +252,10 @@ viper-insert-basic-map. Not recommended, except for novice users.") ;; to its Emacs state in various major modes. (defvar viper-emacs-state-modifier-alist nil) +;; The list of viper keymaps. Set by viper-normalize-minor-mode-map-alist +(viper-deflocalvar viper--key-maps nil) +(viper-deflocalvar viper--intercept-key-maps nil) + ;; Tells viper-add-local-keys to create a new viper-vi-local-user-map for new ;; buffers. Not a user option. (viper-deflocalvar viper-need-new-vi-local-map t "") @@ -240,9 +308,7 @@ viper-insert-basic-map. Not recommended, except for novice users.") (define-key viper-insert-basic-map "\C-d" 'viper-backward-indent) (define-key viper-insert-basic-map "\C-w" 'viper-delete-backward-word) (define-key viper-insert-basic-map "\C-t" 'viper-forward-indent) -(define-key viper-insert-basic-map - (if viper-xemacs-p [(shift tab)] [S-tab]) 'viper-insert-tab) -(define-key viper-insert-basic-map "\C-v" 'quoted-insert) +(define-key viper-insert-basic-map viper-quoted-insert-key 'quoted-insert) (define-key viper-insert-basic-map "\C-?" 'viper-del-backward-char-in-insert) (define-key viper-insert-basic-map [backspace] 'viper-del-backward-char-in-insert) (define-key viper-insert-basic-map "\C-\\" 'viper-alternate-Meta-key) @@ -273,8 +339,8 @@ viper-insert-basic-map. Not recommended, except for novice users.") (define-key viper-vi-basic-map "\C-m" 'viper-next-line-at-bol) (define-key viper-vi-basic-map "\C-u" 'viper-scroll-down) (define-key viper-vi-basic-map "\C-y" 'viper-scroll-down-one) -(define-key viper-vi-basic-map "\C-s" 'viper-isearch-forward) -(define-key viper-vi-basic-map "\C-r" 'viper-isearch-backward) +;;(define-key viper-vi-basic-map "\C-s" 'viper-isearch-forward) +;;(define-key viper-vi-basic-map "\C-r" 'viper-isearch-backward) (define-key viper-vi-basic-map "\C-c/" 'viper-toggle-search-style) (define-key viper-vi-basic-map "\C-c\C-g" 'viper-info-on-file) @@ -455,6 +521,10 @@ Useful in some modes, such as Gnus, MH, etc.") (define-key viper-dired-modifier-map ":" 'viper-ex) (define-key viper-dired-modifier-map "/" 'viper-search-forward) +(defvar viper-gnus-modifier-map (make-sparse-keymap) + "This map modifies Gnus behavior.") +(define-key viper-gnus-modifier-map ":" 'viper-ex) + ;;; Code @@ -496,7 +566,7 @@ Usage: (defun viper-zap-local-keys () "Unconditionally reset Viper viper-*-local-user-map's. -Rarely useful, but if u made a mistake by switching to a mode that adds +Rarely useful, but if you made a mistake by switching to a mode that adds undesirable local keys, e.g., comint-mode, then this function can restore sanity." (interactive) @@ -637,4 +707,5 @@ form ((key . function) (key . function) ... )." ;;; End: +;;; arch-tag: 43af4b2f-0bea-400b-889e-221ebc00acb1 ;;; viper-keym.el ends here