diff lisp/emulation/viper-macs.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents 633233bf2bbf
children 695cf19ef79e d7ddb3e565de
line wrap: on
line diff
--- a/lisp/emulation/viper-macs.el	Tue Feb 04 12:29:42 2003 +0000
+++ b/lisp/emulation/viper-macs.el	Tue Feb 04 13:24:35 2003 +0000
@@ -58,7 +58,7 @@
 ;; Register holding last macro.
 (defvar viper-last-macro-reg nil)
 
-;; format of the elements of kbd alists: 
+;; format of the elements of kbd alists:
 ;; (name ((buf . macr)...(buf . macr)) ((maj-mode . macr)...) (t . macr))
 ;; kbd macro alist for Vi state
 (defvar viper-vi-kbd-macro-alist nil)
@@ -121,7 +121,7 @@
 	       (viper-display-macro macro-name)
 	       (if ins "Insert" "Vi")))
     ))
-    
+
 
 ;; Ex unmap
 (defun ex-unmap ()
@@ -141,7 +141,7 @@
 			      (viper-display-macro temp)))
     (viper-unrecord-kbd-macro macro-name (if ins 'insert-state 'vi-state))
     ))
-    
+
 
 ;; read arguments for ex-map
 (defun ex-map-read-args (variant)
@@ -149,7 +149,7 @@
 	(key-seq [])
 	temp key event message
 	macro-name macro-body args)
-	
+
     (condition-case nil
 	(setq args (concat (ex-get-inline-cmd-args ".*map[!]*[ \t]?" "\n\C-m")
 			   " nil nil ")
@@ -158,15 +158,15 @@
 	      macro-body (car (read-from-string args (cdr temp))))
       (error
        (signal
-	'error 
+	'error
 	'("map: Macro name and body must be a quoted string or a vector"))))
-    
+
     ;; 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
     (if macro-name
         (cond ((vectorp macro-name) nil)
-	      ((stringp macro-name) 
+	      ((stringp macro-name)
 	       (setq macro-name (vconcat macro-name)))
 	      (t (setq macro-name (vconcat (prin1-to-string macro-name)))))
       (message ":map%s <Name>" variant)(sit-for 2)
@@ -198,13 +198,13 @@
 		(viper-event-key event)))
 	)
       (setq macro-name key-seq))
-    
+
     (if (= (length macro-name) 0)
 	(error "Can't map an empty macro name"))
     (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)))
-    
+
     (if macro-body
 	(cond ((viper-char-array-p macro-body)
 	       (setq macro-body (viper-char-array-to-macro macro-body)))
@@ -212,7 +212,7 @@
 	      (t (error "map: Invalid syntax in macro definition"))))
     (setq cursor-in-echo-area nil)(sit-for 0) ; this overcomes xemacs tty bug
     (cons macro-name macro-body)))
-    
+
 
 
 ;; read arguments for ex-unmap
@@ -230,7 +230,7 @@
 	event message
 	key key-seq macro-name)
     (setq macro-name (ex-get-inline-cmd-args ".*unma?p?[!]*[ \t]*"))
-	  
+
     (if (> (length macro-name) 0)
 	()
       (message ":unmap%s <Name>" variant) (sit-for 2)
@@ -245,7 +245,7 @@
 	       (setq key-seq (subseq key-seq 0 (- (length key-seq) 2))))
 	      ((member key '(tab (control i) ?\t))
 	       (setq key-seq (subseq key-seq 0 (1- (length key-seq))))
-	       (setq message 
+	       (setq message
 		     (format
 		      ":unmap%s %s"
 		      variant (if (> (length key-seq) 0)
@@ -255,7 +255,7 @@
 	       (setq key-seq
 		     (viper-do-sequence-completion key-seq macro-alist message))
 	       ))
-	(setq message 
+	(setq message
 	      (format
 	       ":unmap%s %s"
 	       variant (if (> (length key-seq) 0)
@@ -278,14 +278,14 @@
 
     (if (= (length macro-name) 0)
 	(error "Can't unmap an empty macro name"))
-				  
+
     ;; convert macro names into vector, if starts with a `['
     (if (memq (elt macro-name 0) '(?\[ ?\"))
 	(car (read-from-string macro-name))
       (vconcat macro-name))
     ))
-    
-    
+
+
 ;; Terminate a Vi kbd macro.
 ;; optional argument IGNORE, if t, indicates that we are dealing with an
 ;; existing macro that needs to be registered, but there is no need to
@@ -311,11 +311,11 @@
 	  ;; always go back to Vi, since this is where we started
 	  ;; defining macro
 	  (viper-change-state-to-vi)))
-    
+
     (viper-record-kbd-macro macro-name
 			  (if ins 'insert-state 'vi-state)
 			  (viper-display-macro macro-body))
-    
+
     (ex-fixup-history (format "map%s %S %S" mod-char
 			      (viper-display-macro macro-name)
 			      (viper-display-macro macro-body)))
@@ -337,7 +337,7 @@
 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."
-  (let* (state-name keymap 
+  (let* (state-name keymap
 	 (macro-alist-var
 	  (cond ((eq state 'vi-state)
 		 (setq state-name "Vi state"
@@ -354,20 +354,20 @@
 		 ))
 	 new-elt old-elt old-sub-elt msg
 	 temp lis lis2)
-	 
+
     (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. 
+    ;; 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-body (viper-fixup-macro macro-body))
     (if (viper-char-array-p macro-body)
 	(setq macro-body (viper-char-array-to-macro macro-body)))
-	
+
     ;; don't ask if scope is given and is of the right type
     (or (eq scope t)
 	(stringp scope)
@@ -423,7 +423,7 @@
 	  (if (y-or-n-p
 	       (format "Save this macro in %s? "
 		       (viper-abbreviate-file-name viper-custom-file-name)))
-	      (viper-save-string-in-file 
+	      (viper-save-string-in-file
 	       (format "\n(viper-record-kbd-macro %S '%S %s '%S)"
 		       (viper-display-macro macro-name)
 		       state
@@ -436,12 +436,12 @@
 		       (if (vectorp macro-body)
 			   (format "%S" macro-body)
 			 macro-body)
-		       scope) 
+		       scope)
 	       viper-custom-file-name))
-	  
+
 	  (message msg)
 	  ))
-	
+
     (setq new-elt
 	  (cons macro-name
 		(cond ((eq scope t) (list nil nil (cons t nil)))
@@ -463,7 +463,7 @@
 				     (viper-array-to-string macro-name)))
 	      (setq lis2 (cons (car lis) lis2))
 	      (setq lis (cdr lis)))
-	    
+
 	    (setq lis2 (reverse lis2))
 	    (set macro-alist-var (append lis2 (cons new-elt lis)))
 	    (setq old-elt new-elt)))
@@ -471,7 +471,7 @@
 	  (cond ((eq scope t) (viper-kbd-global-pair old-elt))
 		((symbolp scope) (assoc scope (viper-kbd-mode-alist old-elt)))
 		((stringp scope) (assoc scope (viper-kbd-buf-alist old-elt)))))
-    (if old-sub-elt 
+    (if old-sub-elt
 	(setcdr old-sub-elt macro-body)
       (cond ((symbolp scope) (setcar (cdr (cdr old-elt))
 				     (cons (cons scope macro-body)
@@ -480,9 +480,9 @@
 				     (cons (cons scope macro-body)
 					   (viper-kbd-buf-alist old-elt))))))
     ))
-  
+
 
-    
+
 ;; 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.
@@ -491,7 +491,7 @@
 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 
+  (let* (state-name keymap
 	 (macro-alist-var
 	  (cond ((eq state 'vi-state)
 		 (setq state-name "Vi state"
@@ -508,7 +508,7 @@
 		))
 	 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.
     (setq macro-name (viper-fixup-macro macro-name))
@@ -522,11 +522,11 @@
 	(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
@@ -534,7 +534,7 @@
 			     (viper-display-macro macro-name)
 			     (buffer-name)))))
 	   (setq macro-pair buf-mapping)
-	   (message "%S is unmapped for %s in `%s'" 
+	   (message "%S is unmapped for %s in `%s'"
 		    (viper-display-macro macro-name)
 		    state-name (buffer-name)))
 	  ((and (cdr mode-mapping)
@@ -559,7 +559,7 @@
 	(cdr global-mapping)
 	(progn
 	  (set macro-alist-var (delq macro-entry (eval macro-alist-var)))
-	  (if (viper-can-release-key (aref macro-name 0) 
+	  (if (viper-can-release-key (aref macro-name 0)
 				   (eval macro-alist-var))
 	      (define-key
 		keymap
@@ -567,7 +567,7 @@
 		nil))
 	  ))
     ))
-    
+
 ;; Check if MACRO-ALIST has an entry for a macro name starting with
 ;; CHAR.  If not, this indicates that the binding for this char
 ;; in viper-vi/insert-kbd-map can be released.
@@ -575,7 +575,7 @@
   (let ((lis macro-alist)
 	(can-release t)
 	macro-name)
-    
+
     (while (and lis can-release)
       (setq macro-name (car (car lis)))
       (if (eq char (aref macro-name 0))
@@ -602,13 +602,13 @@
 	next-best-match keyseq event-seq
 	macro-first-char macro-alist-elt macro-body
 	command)
-    
+
     (setq macro-first-char last-command-event
 	  event-seq (viper-read-fast-keysequence macro-first-char macro-alist)
 	  keyseq (viper-events-to-macro event-seq)
 	  macro-alist-elt (assoc keyseq macro-alist)
 	  next-best-match (viper-find-best-matching-macro macro-alist keyseq))
-	  
+
     (if (null macro-alist-elt)
 	(setq macro-alist-elt (car next-best-match)
 	      unmatched-suffix (subseq event-seq (cdr next-best-match))))
@@ -617,7 +617,7 @@
 	  ((setq macro-body (viper-kbd-buf-definition macro-alist-elt)))
 	  ((setq macro-body (viper-kbd-mode-definition macro-alist-elt)))
 	  ((setq macro-body (viper-kbd-global-definition macro-alist-elt))))
-				 
+
     ;; when defining keyboard macro, don't use the macro mappings
     (if (and macro-body (not defining-kbd-macro))
 	;; block cmd executed as part of a macro from entering command history
@@ -634,7 +634,7 @@
       ;; 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
       ;; this routine
-      (or prefix-arg (setq  prefix-arg count)) 
+      (or prefix-arg (setq  prefix-arg count))
       (setq command (key-binding (read-key-sequence nil)))
       (if (commandp command)
 	  (command-execute command)
@@ -644,7 +644,7 @@
 
 
 ;;; Displaying and completing macros
-    
+
 (defun viper-describe-kbd-macros ()
   "Show currently defined keyboard macros."
   (interactive)
@@ -656,7 +656,7 @@
     (princ "\n\nMacros in Emacs state:\n======================\n")
     (mapcar 'viper-describe-one-macro viper-emacs-kbd-macro-alist)
     ))
-    
+
 (defun viper-describe-one-macro (macro)
   (princ (format "\n  *** Mappings for %S:\n      ------------\n"
 		 (viper-display-macro (car macro))))
@@ -673,29 +673,29 @@
       (princ (format "\n           %S" (cdr (viper-kbd-global-pair macro))))
     (princ "  none"))
   (princ "\n"))
-  
+
 (defun viper-describe-one-macro-elt (elt)
   (let ((name (car elt))
 	(defn (cdr elt)))
     (princ (format "\n       * %S:\n           %S\n" name defn))))
-    
-    
-    
+
+
+
 ;; check if SEQ is a prefix of some car of an element in ALIST
 (defun viper-keyseq-is-a-possible-macro (seq alist)
   (let ((converted-seq (viper-events-to-macro seq)))
-    (eval (cons 'or 
+    (eval (cons 'or
 		(mapcar
 		 (lambda (elt) (viper-prefix-subseq-p converted-seq elt))
 		 (viper-this-buffer-macros alist))))))
-		 
+
 ;; whether SEQ1 is a prefix of SEQ2
 (defun viper-prefix-subseq-p (seq1 seq2)
   (let ((len1 (length seq1))
 	(len2 (length seq2)))
     (if (<= len1 len2)
 	(equal seq1 (subseq seq2 0 len1)))))
-	
+
 ;; find the longest common prefix
 (defun viper-common-seq-prefix (&rest seqs)
   (let* ((first (car seqs))
@@ -707,18 +707,18 @@
 	(setq len 0)
       (setq len (apply 'min (mapcar 'length seqs))))
     (while (< idx len)
-      (if (eval (cons 'and 
+      (if (eval (cons 'and
 		      (mapcar (lambda (s) (equal (elt first idx) (elt s idx)))
 			      rest)))
 	  (setq pref (vconcat pref (vector (elt first idx)))))
       (setq idx (1+ idx)))
     pref))
-    
+
 ;; get all sequences that match PREFIX from a given A-LIST
 (defun viper-extract-matching-alist-members (pref alist)
   (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)
   (let* ((matches (viper-extract-matching-alist-members seq alist))
 	 (new-seq (apply 'viper-common-seq-prefix matches))
@@ -726,27 +726,27 @@
     (cond ((and (equal seq new-seq) (= (length matches) 1))
 	   (message "%s (Sole completion)" compl-message)
 	   (sit-for 2))
-	  ((null matches) 
+	  ((null matches)
 	   (message "%s (No match)" compl-message)
 	   (sit-for 2)
 	   (setq new-seq seq))
-	  ((member seq matches) 
+	  ((member seq matches)
 	   (message "%s (Complete, but not unique)" compl-message)
 	   (sit-for 2)
 	   (viper-display-vector-completions matches))
 	  ((equal seq new-seq)
 	   (viper-display-vector-completions matches)))
     new-seq))
-	
-	 
+
+
 (defun viper-display-vector-completions (list)
   (with-output-to-temp-buffer "*Completions*"
-    (display-completion-list 
+    (display-completion-list
      (mapcar 'prin1-to-string
 	     (mapcar 'viper-display-macro list)))))
-  
-				  
-    
+
+
+
 ;; alist is the alist of macros
 ;; str is the fast key sequence entered
 ;; returns: (matching-macro-def . unmatched-suffix-start-index)
@@ -766,17 +766,17 @@
 	      (setq found t))
 	)
       (setq lis (cdr lis)))
-    
+
     (if found
 	(setq match macro-def
 	      unmatched-start-idx def-len)
       (setq match nil
 	    unmatched-start-idx 0))
-    
+
     (cons match unmatched-start-idx)))
-  
-    
-    
+
+
+
 ;; returns a list of names of macros defined for the current buffer
 (defun viper-this-buffer-macros (macro-alist)
   (let (candidates)
@@ -788,8 +788,8 @@
 			(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.
 (defun viper-display-macro (macro-name-or-body)
@@ -798,7 +798,7 @@
 	((viper-char-array-p macro-name-or-body)
 	 (mapconcat 'char-to-string macro-name-or-body ""))
 	(t macro-name-or-body)))
-    
+
 ;; convert sequence of events (that came presumably from emacs kbd macro) into
 ;; Viper's macro, which is a vector of the form
 ;; [ desc desc ... ]
@@ -813,7 +813,7 @@
 					       nil
 					     (viper-event-key elt)))
 			     event-seq))))
-  
+
 ;; convert strings or arrays of characters to Viper macro form
 (defun viper-char-array-to-macro (array)
   (let ((vec (vconcat array))
@@ -822,7 +822,7 @@
 	(setq macro (mapcar 'character-to-event vec))
       (setq macro vec))
     (vconcat (mapcar 'viper-event-key macro))))
-    
+
 ;; For macros bodies and names, goes over MACRO and checks if all members are
 ;; names of keys (actually, it only checks if they are symbols or lists
 ;; if a digit is found, it is converted into a symbol (e.g., 0 -> \0, etc).
@@ -850,18 +850,18 @@
 		((symbolp elt) nil)
 		(t (setq break t)))
 	  (setq idx (1+ idx))))
-      
+
       (if break
 	  (error "Wrong type macro component, symbol-or-listp, %S" elt)
 	macro)))
-  
+
 (defun viper-macro-to-events (macro-body)
   (vconcat (mapcar 'viper-key-to-emacs-key macro-body)))
-	    
-	       
+
+
 
 ;;; 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
 ;; this fast succession of key strokes.
@@ -902,7 +902,7 @@
 		 (viper-set-register-macro reg))
 	     (execute-kbd-macro (get-register reg) count)))
 	  ((or (= ?@ reg) (= ?\^j reg) (= ?\^m reg))
-	   (if viper-last-macro-reg 
+	   (if viper-last-macro-reg
 	       nil
 	       (error "No previous kbd macro"))
 	   (execute-kbd-macro (get-register viper-last-macro-reg) count))
@@ -916,7 +916,7 @@
 	       (viper-set-register-macro reg))))
 	  (t
 	   (error "`%c': Unknown register" reg)))))
-	   
+
 
 (defun viper-global-execute ()
   "Call last keyboad macro for each line in the region."