Function: viper-escape-to-state

viper-escape-to-state is a byte-compiled function defined in viper-cmd.el.gz.

Signature

(viper-escape-to-state ARG EVENTS STATE)

Source Code

;; Defined in /usr/src/emacs/lisp/emulation/viper-cmd.el.gz
;; Escape to STATE mode for one Emacs command.
(defun viper-escape-to-state (arg events state)
  ;;(let (com key prefix-arg)
  (let (com key)
    ;; this temporarily turns off Viper's minor mode keymaps
    (viper-set-mode-vars-for state)
    (viper-normalize-minor-mode-map-alist)
    (if events (viper-set-unread-command-events events))

    ;; protect against keyboard quit and other errors
    (condition-case nil
	(let (viper-vi-kbd-minor-mode
	      viper-insert-kbd-minor-mode
	      viper-emacs-kbd-minor-mode)
	  (setq com (key-binding (setq key (read-key-sequence nil))))
	  ;; In case of binding indirection--chase definitions.
	  ;; Have to do it here because we execute this command under
	  ;; different keymaps, so command-execute may not do the
	  ;; right thing there
	  (while (vectorp com) (setq com (key-binding com)))
	  ;; Execute command com in the original Viper state, not in state
	  ;; `state'.  Otherwise, if we switch buffers while executing the
	  ;; escaped to command, Viper's mode vars will remain those of
	  ;; `state'.  When we return to the orig buffer, the bindings will be
	  ;; screwed up.
	  (viper-set-mode-vars-for viper-current-state)

	  ;; this-command, last-command-char, last-command-event
	  (setq this-command com)
	  ;; Emacs represents key sequences as sequences (str or vec)
	  (setq last-command-event (viper-seq-last-elt key))

	  (if (commandp com)
	      ;; pretend that current state is the state we escaped to
	      (let ((viper-current-state state))
		(setq prefix-arg (or prefix-arg arg))
		(command-execute com))))
      (quit (ding))
      (error (beep 1))))
  ;; set state in the new buffer
  (viper-set-mode-vars-for viper-current-state))