;;; viper-keym.el --- Viper keymaps
-;; Copyright (C) 1994, 95, 96, 97, 2000, 01, 02, 2005 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 <kifer@cs.stonybrook.edu>
;; 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,
;; 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:
;;; 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.
"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.")
;; 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 (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)])))
+ (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
;; 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 "")
(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)
(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)