Function: viper-unrecord-kbd-macro

viper-unrecord-kbd-macro is a byte-compiled function defined in viper-macs.el.gz.

Signature

(viper-unrecord-kbd-macro MACRO-NAME STATE)

Documentation

Delete macro MACRO-NAME from Viper STATE.

MACRO-NAME must be a vector of viper-style keys. This command is used by Viper internally, but you can also use it in viper-custom-file-name to delete pre-defined macros supplied with Viper. The best way to avoid mistakes in macro names to be passed to this function is to use viper-describe-kbd-macros and copy the name from there.

Source Code

;; Defined in /usr/src/emacs/lisp/emulation/viper-macs.el.gz
;; macro name must be a vector of viper-style keys
;; viper-unrecord-kbd-macro doesn't have scope. Macro definitions are inherited
;; from global -> major mode -> buffer
;; More specific definition overrides more general
;; Can't unrecord definition for more specific, if a more general definition is
;; in effect
(defun viper-unrecord-kbd-macro (macro-name state)
  "Delete macro MACRO-NAME from Viper STATE.
MACRO-NAME must be a vector of viper-style keys.  This command is used
by Viper internally, but you can also use it in `viper-custom-file-name'
to delete pre-defined macros supplied with Viper.  The best way to avoid
mistakes in macro names to be passed to this function is to use
`viper-describe-kbd-macros' and copy the name from there."
  (let* (state-name keymap
	 (macro-alist-var
	  (cond ((eq state 'vi-state)
		 (setq state-name "Vi state"
		       keymap viper-vi-kbd-map)
		 'viper-vi-kbd-macro-alist)
		((memq state '(insert-state replace-state))
		 (setq state-name "Insert state"
		       keymap viper-insert-kbd-map)
		 'viper-insert-kbd-macro-alist)
		(t
		 (setq state-name "Emacs state"
		       keymap viper-emacs-kbd-map)
		 'viper-emacs-kbd-macro-alist)
		))
	 buf-mapping mode-mapping global-mapping
	 macro-pair macro-entry)

    ;; Macro-name is usually a vector.  However, command history or macros
    ;; recorded in viper-custom-file-name may appear as strings.
    ;; So, convert to vectors.
    (setq macro-name (viper-fixup-macro macro-name))
    (if (viper-char-array-p macro-name)
	(setq macro-name (viper-char-array-to-macro macro-name)))

    (setq macro-entry (assoc macro-name (symbol-value macro-alist-var)))
    (if (= (length macro-name) 0)
	(error "Can't unmap an empty macro name"))
    (if (null macro-entry)
	(error "%S is not mapped to a macro for %s in `%s'"
	       (viper-display-macro macro-name)
	       state-name (buffer-name)))

    (setq buf-mapping (viper-kbd-buf-pair macro-entry)
	  mode-mapping (viper-kbd-mode-pair macro-entry)
	  global-mapping (viper-kbd-global-pair macro-entry))

    (cond ((and (cdr buf-mapping)
		(or (and (not (cdr mode-mapping)) (not (cdr global-mapping)))
		    (y-or-n-p
		     (format-message "Unmap %S for `%s' only? "
				     (viper-display-macro macro-name)
				     (buffer-name)))))
	   (setq macro-pair buf-mapping)
	   (message "%S is unmapped for %s in `%s'"
		    (viper-display-macro macro-name)
		    state-name (buffer-name)))
	  ((and (cdr mode-mapping)
		(or (not (cdr global-mapping))
		    (y-or-n-p
		     (format-message "Unmap %S for the major mode `%S' only? "
				     (viper-display-macro macro-name)
				     major-mode))))
	   (setq macro-pair mode-mapping)
	   (message "%S is unmapped for %s in %S"
		    (viper-display-macro macro-name) state-name major-mode))
	  ((cdr (setq macro-pair global-mapping))
	   (message
	    "Global mapping for %S in %s is removed"
	    (viper-display-macro macro-name) state-name))
	  (t (error "%S is not mapped to a macro for %s in `%s'"
		    (viper-display-macro macro-name)
		    state-name (buffer-name))))
    (setcdr macro-pair nil)
    (or (cdr buf-mapping)
	(cdr mode-mapping)
	(cdr global-mapping)
	(progn
	  (set macro-alist-var (delq macro-entry
                                     (symbol-value macro-alist-var)))
	  (if (viper-can-release-key (aref macro-name 0)
				     (symbol-value macro-alist-var))
	      (define-key
		keymap
		(vector (viper-key-to-emacs-key (aref macro-name 0)))
		nil))
	  ))
    ))