;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
-;; Code
+;;; Commentary:
+
+;;; Code:
(provide 'viper-macs)
(defcustom viper-repeat-from-history-key 'f12
"Prefix key for accessing previously typed Vi commands.
-The previous command is accessible, as usual, via `.'. The command before this
+The previous command is accessible, as usual, via `.'. The command before this
can be invoked as `<this key> 1', and the command before that, and the command
before that one is accessible as `<this key> 2'.
-The notation for these keys is borrowed from XEmacs. Basically,
+The notation for these keys is borrowed from XEmacs. Basically,
a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g.,
`(meta control f1)'."
- :type 'key
+ :type 'sexp
:group 'viper)
(define-key viper-vi-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
(define-key viper-insert-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
(define-key viper-emacs-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
- (message "Mapping %S in %s state. Hit `C-x )' to complete the mapping"
+ (message "Mapping %S in %s state. Hit `C-x )' to complete the mapping"
(viper-display-macro macro-name)
(if ins "Insert" "Vi")))
))
;; We expect macro-name to be a vector, a string, or a quoted string.
;; In the second case, it will emerge as a symbol when read from
- ;; the above read-from-string. So we need to convert it into a string
+ ;; the above read-from-string. So we need to convert it into a string
(if macro-name
(cond ((vectorp macro-name) nil)
((stringp macro-name)
\f
;;; Recording, unrecording, executing
-;; accepts as macro names: strings and vectors.
+;; Accepts as macro names: strings and vectors.
;; strings must be strings of characters; vectors must be vectors of keys
-;; in canonic form. the canonic form is essentially the form used in XEmacs
+;; in canonic form. The canonic form is essentially the form used in XEmacs
(defun viper-record-kbd-macro (macro-name state macro-body &optional scope)
- "Record a Vi macro. Can be used in `.viper' file to define permanent macros.
-MACRO-NAME is a string of characters or a vector of keys. STATE is
-either `vi-state' or `insert-state'. It specifies the Viper state in which to
-define the macro. MACRO-BODY is a string that represents the keyboard macro.
+ "Record a Vi macro. Can be used in `.viper' file to define permanent macros.
+MACRO-NAME is a string of characters or a vector of keys. STATE is
+either `vi-state' or `insert-state'. It specifies the Viper state in which to
+define the macro. MACRO-BODY is a string that represents the keyboard macro.
Optional SCOPE says whether the macro should be global \(t\), mode-specific
\(a major-mode symbol\), or buffer-specific \(buffer name, a string\).
If SCOPE is nil, the user is asked to specify the scope."
(if (= (length macro-name) 0)
(error "Can't map an empty macro name"))
- ;; Macro-name is usually a vector. However, command history or macros
- ;; recorded in ~/.viper may be recorded as strings. So, convert to vectors.
+ ;; Macro-name is usually a vector. However, command history or macros
+ ;; recorded in ~/.viper may be recorded 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)))
;; macro name must be a vector of viper-style keys
(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
+MACRO-NAME must be a vector of viper-style keys. This command is used by Viper
internally, but the user can also use it in ~/.viper 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."
+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)
buf-mapping mode-mapping global-mapping
macro-pair macro-entry)
- ;; Macro-name is usually a vector. However, command history or macros
- ;; recorded in ~/.viper may appear as strings. So, convert to vectors.
+ ;; Macro-name is usually a vector. However, command history or macros
+ ;; recorded in ~/.viper 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)))
))
;; Check if MACRO-ALIST has an entry for a macro name starting with
-;; CHAR. If not, this indicates that the binding for this char
+;; CHAR. If not, this indicates that the binding for this char
;; in viper-vi/insert-kbd-map can be released.
(defun viper-can-release-key (char macro-alist)
(let ((lis macro-alist)
(viper-set-unread-command-events event-seq)
;; if the user typed arg, then use it if prefix arg is not set by
;; some other command (setting prefix arg can happen if we do, say,
- ;; 2dw and there is a macro starting with 2. Then control will go to
+ ;; 2dw and there is a macro starting with 2. Then control will go to
;; this routine
(or prefix-arg (setq prefix-arg count))
(setq command (key-binding (read-key-sequence nil)))
(let ((converted-seq (viper-events-to-macro seq)))
(eval (cons 'or
(mapcar
- (function (lambda (elt)
- (viper-prefix-subseq-p converted-seq elt)))
+ (lambda (elt) (viper-prefix-subseq-p converted-seq elt))
(viper-this-buffer-macros alist))))))
;; whether SEQ1 is a prefix of SEQ2
(setq len (apply 'min (mapcar 'length seqs))))
(while (< idx len)
(if (eval (cons 'and
- (mapcar (function (lambda (s)
- (equal (elt first idx)
- (elt s idx))))
+ (mapcar (lambda (s) (equal (elt first idx) (elt s idx)))
rest)))
(setq pref (vconcat pref (vector (elt first idx)))))
(setq idx (1+ idx)))
;; get all sequences that match PREFIX from a given A-LIST
(defun viper-extract-matching-alist-members (pref alist)
- (delq nil (mapcar (function (lambda (elt)
- (if (viper-prefix-subseq-p pref elt)
- elt)))
+ (delq nil (mapcar (lambda (elt) (if (viper-prefix-subseq-p pref elt) elt))
(viper-this-buffer-macros alist))))
(defun viper-do-sequence-completion (seq alist compl-message)
(defun viper-this-buffer-macros (macro-alist)
(let (candidates)
(setq candidates
- (mapcar (function
- (lambda (elt)
- (if (or (viper-kbd-buf-definition elt)
- (viper-kbd-mode-definition elt)
- (viper-kbd-global-definition elt))
- (car elt))))
+ (mapcar (lambda (elt)
+ (if (or (viper-kbd-buf-definition elt)
+ (viper-kbd-mode-definition elt)
+ (viper-kbd-global-definition elt))
+ (car elt)))
macro-alist))
(setq candidates (delq nil candidates))))
;; if seq of Viper key symbols (representing a macro) can be converted to a
-;; string--do so. Otherwise, do nothing.
+;; string--do so. Otherwise, do nothing.
(defun viper-display-macro (macro-name-or-body)
(cond ((viper-char-symbol-sequence-p macro-name-or-body)
(mapconcat 'symbol-name macro-name-or-body ""))
;; Viper's macro, which is a vector of the form
;; [ desc desc ... ]
;; Each desc is either a symbol of (meta symb), (shift symb), etc.
-;; Here we purge events that happen to be lists. In most cases, these events
+;; Here we purge events that happen to be lists. In most cases, these events
;; got into a macro definition unintentionally; say, when the user moves mouse
;; during a macro definition, then something like (switch-frame ...) might get
-;; in. Another reason for purging lists-events is that we can't store them in
+;; in. Another reason for purging lists-events is that we can't store them in
;; textual form (say, in .emacs) and then read them back.
(defun viper-events-to-macro (event-seq)
- (vconcat (delq nil (mapcar (function (lambda (elt)
- (if (consp elt)
- nil
- (viper-event-key elt))))
+ (vconcat (delq nil (mapcar (lambda (elt) (if (consp elt)
+ nil
+ (viper-event-key elt)))
event-seq))))
;; convert strings or arrays of characters to Viper macro form
(sequencep vec)
(eval
(cons 'and
- (mapcar
- (function (lambda (elt)
- (and (symbolp elt) (= (length (symbol-name elt)) 1))))
- vec)))))
+ (mapcar (lambda (elt)
+ (and (symbolp elt) (= (length (symbol-name elt)) 1)))
+ vec)))))
;; Check if vec is a vector of key-press events representing characters
;;; Reading fast key sequences
;; Assuming that CHAR was the first character in a fast succession of key
-;; strokes, read the rest. Return the vector of keys that was entered in
+;; strokes, read the rest. Return the vector of keys that was entered in
;; this fast succession of key strokes.
;; A fast keysequence is one that is terminated by a pause longer than
;; viper-fast-keyseq-timeout.
;; sets register to last-kbd-macro carefully.
(defun viper-set-register-macro (reg)
(if (get-register reg)
- (if (y-or-n-p "Register contains data. Overwrite? ")
+ (if (y-or-n-p "Register contains data. Overwrite? ")
()
(error
- "Macro not saved in register. Can still be invoked via `C-x e'")))
+ "Macro not saved in register. Can still be invoked via `C-x e'")))
(set-register reg last-kbd-macro))
(defun viper-register-macro (count)
(call-last-kbd-macro)))
-;;; viper-macs.el ends here
+;;; viper-macs.el ends here