diff lisp/emulation/viper-keym.el @ 90201:fbb2bea03df9

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-69 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 474-484) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 88-91) - Merge from emacs--cvs-trunk--0 - Update FSF's address in GPL notices - Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 14 Jul 2005 08:02:00 +0000
parents f9a65d7ebd29 a4c59075cac8
children edf295560b5a
line wrap: on
line diff
--- a/lisp/emulation/viper-keym.el	Thu Jul 07 12:43:14 2005 +0000
+++ b/lisp/emulation/viper-keym.el	Thu Jul 14 08:02:00 2005 +0000
@@ -50,25 +50,6 @@
 
 ;;; Variables
 
-(defcustom 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."
-  :type 'string
-  :group 'viper)
-
-(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 "\e"
-  "Key used to ESC.
-Must be set in .viper file or prior to loading Viper.
-This setting cannot be changed interactively."
-  :type 'string
-  :group 'viper)
 
 ;;; Emacs keys in other states.
 
@@ -176,6 +157,78 @@
 ;; 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)])))
+	   (mapcar
+	    (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 [(escape)]  ; "\e"
+  "Key used to ESC.
+Enter as a sexp. Examples: \"\\e\", [(escape)]."
+  :type 'sexp
+  :group 'viper
+  :set (lambda (symbol value)
+	 (let ((old-value (if (boundp 'viper-ESC-key)
+			      viper-ESC-key
+			    [(escape)])))
+	   (mapcar
+	    (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
 
@@ -197,6 +250,10 @@
 ;; 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 "")
@@ -509,7 +566,7 @@
 
 (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)