diff options
Diffstat (limited to 'lisp/emulation/viper-keym.el')
-rw-r--r-- | lisp/emulation/viper-keym.el | 97 |
1 files changed, 77 insertions, 20 deletions
diff --git a/lisp/emulation/viper-keym.el b/lisp/emulation/viper-keym.el index e83cf14776f..1bbf3dce2c2 100644 --- a/lisp/emulation/viper-keym.el +++ b/lisp/emulation/viper-keym.el @@ -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 @@ 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)]))) + (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 @@ 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 "") @@ -509,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) |