Commits

Anonymous committed 5c131d9

New version from Michael Kifer

  • Participants
  • Parent commits a35f247

Comments (0)

Files changed (5)

 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-VERSION = 1.06
+VERSION = 1.07
 AUTHOR_VERSION = 3.02
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = viper
 
 ;; Compute numeric prefix arg value. 
 ;; Invoked by EVENT. COM is the command part obtained so far.
-(defun viper-prefix-arg-value (event com)
+(defun viper-prefix-arg-value (event-char com)
   (let ((viper-intermediate-command 'viper-digit-argument)
 	value func)
     ;; read while number
-    (while (and (viper-characterp event) (>= event ?0) (<= event ?9))
-      (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
-      (setq event (viper-read-event-convert-to-char)))
+    (while (and (viper-characterp event-char)
+		(>= event-char ?0) (<= event-char ?9))
+      (setq value (+ (* (if (integerp value) value 0) 10) (- event-char ?0)))
+      (setq event-char (viper-read-event-convert-to-char)))
     
     (setq prefix-arg value)
     (if com (setq prefix-arg (cons prefix-arg com)))
-    (while (eq event ?U)
+    (while (eq event-char ?U)
       (viper-describe-arg prefix-arg)
-      (setq event (viper-read-event-convert-to-char)))
+      (setq event-char (viper-read-event-convert-to-char)))
     
     (if (or com (and (not (eq viper-current-state 'vi-state))
 		     ;; make sure it is a Vi command
-		     (viper-characterp event) (viper-vi-command-p event)
+		     (viper-characterp event-char)
+		     (viper-vi-command-p event-char)
 		     ))
 	;; If appears to be one of the vi commands,
 	;; then execute it with funcall and clear prefix-arg in order to not
 	  ;; etc., i.e., the user typed, say, d2. In this case, `com' would be
 	  ;; `d', `w', etc.  If viper-digit-argument was invoked by
 	  ;; viper-escape-to-vi (which is indicated by the fact that the
-	  ;; current state is not vi-state), then `event' represents the vi
-	  ;; command to be executed (e.g., `d', `w', etc). Again,
+	  ;; current state is not vi-state), then `event-char' represents the
+	  ;; vi command to be executed (e.g., `d', `w', etc). Again,
 	  ;; last-command-char must make emacs believe that this is the command
 	  ;; we typed.
-	  (cond ((eq event 'return) (setq event ?\C-m))
-		((eq event 'delete) (setq event ?\C-?))
-		((eq event 'backspace) (setq event ?\C-h))
-		((eq event 'space) (setq event ?\ )))
-	  (setq last-command-char (or com event))
+	  (cond ((eq event-char 'return) (setq event-char ?\C-m))
+		((eq event-char 'delete) (setq event-char ?\C-?))
+		((eq event-char 'backspace) (setq event-char ?\C-h))
+		((eq event-char 'space) (setq event-char ?\ )))
+	  (setq last-command-char (or com event-char))
 	  (setq func (viper-exec-form-in-vi 
-		      (` (key-binding (char-to-string (, event))))))
+		      (` (key-binding (char-to-string (, event-char))))))
 	  (funcall func prefix-arg)
 	  (setq prefix-arg nil))
       ;; some other command -- let emacs do it in its own way
-      (viper-set-unread-command-events event))
+      (viper-set-unread-command-events event-char))
     ))
 		     
 
 	(setq viper-use-register nil)))
   (setq last-command
 	(if (eq last-command 'd-command) 'kill-region nil))
+  (message "Deleted %d characters" (abs (- (point) viper-com-point)))
   (kill-region viper-com-point (point))
   (setq this-command 'd-command)
   (if viper-ex-style-motion
 	  (setq viper-use-register nil)))
     (setq last-command
 	  (if (eq last-command 'D-command) 'kill-region nil))
+    (message "Deleted %d lines" (count-lines (point) viper-com-point))
     (kill-region (mark t) (point))
     (if (eq m-com 'viper-line) (setq this-command 'D-command)))
   (back-to-indentation))
 
+;; save region
 (defun viper-exec-yank (m-com com)
   (or (and (markerp viper-com-point) (marker-position viper-com-point))
       (set-marker viper-com-point (point) (current-buffer)))
 	(setq viper-use-register nil)))
   (setq last-command nil)
   (copy-region-as-kill viper-com-point (point))
+  (message "Saved %d characters" (abs (- (point) viper-com-point)))
   (goto-char viper-com-point))
 
+;; save lines
 (defun viper-exec-Yank (m-com com)
   (save-excursion
     (set-mark viper-com-point)
 		   (error viper-InvalidRegister  viper-use-register)))
 	  (setq viper-use-register nil)))
     (setq last-command nil)
-    (copy-region-as-kill (mark t) (point)))
+    (copy-region-as-kill (mark t) (point))
+    (message "Saved %d lines" (count-lines (mark t) (point))))
   (viper-deactivate-mark)
   (goto-char viper-com-point))
 
 	  (if viper-parse-sexp-ignore-comments "" "NOT "))))
 
 
-;; sentence ,paragraph and heading
+;; sentence, paragraph and heading
 
 (defun viper-forward-sentence (arg)
   "Forward sentence."
   (or (eq last-command this-command)
       (push-mark nil t))
   (let ((val (viper-p-val arg))
-	(com (viper-getCom arg)))
+	;; if you want d} operate on whole lines, change viper-getcom to
+	;; viper-getCom below
+	(com (viper-getcom arg)))
     (if com (viper-move-marker-locally 'viper-com-point (point)))
     (forward-paragraph val)
     (if com
   (or (eq last-command this-command)
       (push-mark nil t))
   (let ((val (viper-p-val arg))
-	(com (viper-getCom arg)))
+	;; if you want d{ operate on whole lines, change viper-getcom to
+	;; viper-getCom below
+	(com (viper-getcom arg)))
     (if com (viper-move-marker-locally 'viper-com-point (point)))
     (backward-paragraph val)
     (if com
 			((viper-valid-register viper-use-register)
 			 (get-register (downcase viper-use-register)))
 			(t (error viper-InvalidRegister viper-use-register)))
-		(current-kill 0))))
+		(current-kill 0)))
+	sv-point)
     (if (null text)
 	(if viper-use-register
 	    (let ((reg viper-use-register))
     (set-marker (viper-mark-marker) (point) (current-buffer))
     (viper-set-destructive-command
      (list 'viper-put-back val nil viper-use-register nil nil))
-    (viper-loop val (viper-yank text)))
+    (setq sv-point (point))
+    (viper-loop val (viper-yank text))
+    (message "Inserted %d character(s), %d line(s)"
+	     (abs (- (point) sv-point)) 
+	     (abs (count-lines (point) sv-point))))
   ;; Vi puts cursor on the last char when the yanked text doesn't contain a
   ;; newline; it leaves the cursor at the beginning when the text contains 
   ;; a newline
 
 ;;; Face-saving tricks
 
-;;(defcustom viper-replace-overlay-pixmap "gray3"
-;;  "Pixmap to use for search face on non-color displays."
-;;  :type 'string
-;;  :group 'viper)
-;;(defcustom viper-search-face-pixmap "gray3"
-;;  "Pixmap to use for search face on non-color displays."
-;;  :type 'string
-;;  :group 'viper)
-
 (defun viper-hide-face (face)
   (if (and (viper-has-face-support-p) viper-emacs-p)
       (add-to-list 'facemenu-unlisted-faces face)))
   :prefix "viper-"
   :group 'viper)
 
-;;(defvar viper-search-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;	(make-face 'viper-search-face)
-;;	(or (face-differs-from-default-p 'viper-search-face)
-;;	    ;; face wasn't set in .viper or .Xdefaults
-;;	    (if (viper-can-use-colors "Black" "khaki")
-;;		(progn
-;;		  (set-face-background 'viper-search-face "khaki")
-;;		  (set-face-foreground 'viper-search-face "Black"))
-;;	      (set-face-underline-p 'viper-search-face t)
-;;	      (viper-set-face-pixmap 'viper-search-face
-;;				     viper-search-face-pixmap))) 
-;;	'viper-search-face))
-;;  "*Face used to flash out the search pattern.")
 
 (defface viper-search-face
   '((((class color)) (:foreground "Black" :background "khaki"))
 this variable represents.")
 (viper-hide-face 'viper-search-face)
   
-;;(defvar viper-replace-overlay-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;	(make-face 'viper-replace-overlay-face)
-;;	(or (face-differs-from-default-p 'viper-replace-overlay-face)
-;;	    (progn
-;;	      (if (viper-can-use-colors "darkseagreen2" "Black")
-;;		  (progn
-;;		    (set-face-background
-;;		     'viper-replace-overlay-face "darkseagreen2")
-;;		    (set-face-foreground 'viper-replace-overlay-face "Black")))
-;;	      (set-face-underline-p 'viper-replace-overlay-face t)
-;;	      (viper-set-face-pixmap
-;;	       'viper-replace-overlay-face viper-replace-overlay-pixmap)))
-;;	'viper-replace-overlay-face))
-;;  "*Face for highlighting replace regions on a window display.")
 
 (defface viper-replace-overlay-face
   '((((class color)) (:foreground "Black" :background "darkseagreen2"))
 this variable represents.")
 (viper-hide-face 'viper-replace-overlay-face)
 
-;;(defvar viper-minibuffer-emacs-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;	(make-face 'viper-minibuffer-emacs-face)
-;;	(or (face-differs-from-default-p 'viper-minibuffer-emacs-face)
-;;	    ;; face wasn't set in .viper or .Xdefaults
-;;	    (if viper-vi-style-in-minibuffer
-;;		;; emacs state is an exception in the minibuffer
-;;		(if (viper-can-use-colors "darkseagreen2" "Black")
-;;		    (progn
-;;		      (set-face-background
-;;		       'viper-minibuffer-emacs-face "darkseagreen2")
-;;		      (set-face-foreground
-;;		       'viper-minibuffer-emacs-face "Black"))
-;;		  (copy-face 'modeline 'viper-minibuffer-emacs-face))
-;;	      ;; emacs state is the main state in the minibuffer
-;;	      (if (viper-can-use-colors "Black" "pink")
-;;		  (progn
-;;		    (set-face-background 'viper-minibuffer-emacs-face "pink") 
-;;		    (set-face-foreground
-;;		     'viper-minibuffer-emacs-face "Black"))
-;;		(copy-face 'italic 'viper-minibuffer-emacs-face))
-;;	      ))
-;;	'viper-minibuffer-emacs-face))
-;;  "Face used in the Minibuffer when it is in Emacs state.")
 
 (defface viper-minibuffer-emacs-face
   '((((class color)) (:foreground "Black" :background "darkseagreen2"))
 this variable represents.")
 (viper-hide-face 'viper-minibuffer-emacs-face)
     
-;;(defvar viper-minibuffer-insert-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;	(make-face 'viper-minibuffer-insert-face)
-;;	(or (face-differs-from-default-p 'viper-minibuffer-insert-face)
-;;	    (if viper-vi-style-in-minibuffer
-;;		(if (viper-can-use-colors "Black" "pink")
-;;		    (progn
-;;		      (set-face-background 'viper-minibuffer-insert-face "pink") 
-;;		      (set-face-foreground
-;;		       'viper-minibuffer-insert-face "Black"))
-;;		  (copy-face 'italic 'viper-minibuffer-insert-face))
-;;	      ;; If Insert state is an exception
-;;	      (if (viper-can-use-colors "darkseagreen2" "Black")
-;;		  (progn
-;;		    (set-face-background
-;;		     'viper-minibuffer-insert-face "darkseagreen2")
-;;		    (set-face-foreground
-;;		     'viper-minibuffer-insert-face "Black"))
-;;		(copy-face 'modeline 'viper-minibuffer-insert-face))
-;;	      (viper-italicize-face 'viper-minibuffer-insert-face)))
-;;	'viper-minibuffer-insert-face))
-;;  "Face used in the Minibuffer when it is in Insert state.")
 
 (defface viper-minibuffer-insert-face
   '((((class color)) (:foreground "Black" :background "pink"))
 this variable represents.")
 (viper-hide-face 'viper-minibuffer-insert-face)
     
-;;(defvar viper-minibuffer-vi-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;	(make-face 'viper-minibuffer-vi-face)
-;;	(or (face-differs-from-default-p 'viper-minibuffer-vi-face)
-;;	    (if viper-vi-style-in-minibuffer
-;;		(if (viper-can-use-colors "Black" "grey")
-;;		    (progn
-;;		      (set-face-background 'viper-minibuffer-vi-face "grey")
-;;		      (set-face-foreground 'viper-minibuffer-vi-face "Black"))
-;;		  (copy-face 'bold 'viper-minibuffer-vi-face))
-;;	      (copy-face 'bold 'viper-minibuffer-vi-face)
-;;	      (invert-face 'viper-minibuffer-vi-face)))
-;;	'viper-minibuffer-vi-face))
-;;  "Face used in the Minibuffer when it is in Vi state.")
 
 (defface viper-minibuffer-vi-face
   '((((class color)) (:foreground "DarkGreen" :background "grey"))
       (cdr (assoc 'cursor-color (frame-parameters)))
     (color-instance-name (frame-property (selected-frame) 'cursor-color))))
   
-;;(defun viper-set-face-pixmap (face pixmap)
-;;  "Set face pixmap on a monochrome display."
-;;  (if (and (viper-window-display-p) (not (viper-color-display-p)))
-;;      (condition-case nil
-;;	  (set-face-background-pixmap face pixmap)
-;;	(error
-;;	 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
-;;	 (sit-for 1)))))
 
-  
 ;; OS/2
 (cond ((eq (viper-device-type) 'pm)
        (fset 'viper-color-defined-p
 	     (function (lambda (color) (assoc color pm-color-alist))))))
     
-;; needed to smooth out the difference between Emacs and XEmacs
-;;(defsubst viper-italicize-face (face)
-;;  (if viper-xemacs-p
-;;      (make-face-italic face)
-;;    (make-face-italic face nil 'noerror)))
-    
-;; test if display is color and the colors are defined
-;;(defsubst viper-can-use-colors (&rest colors)
-;;  (if (viper-color-display-p)
-;;      (not (memq nil (mapcar 'viper-color-defined-p colors)))
-;;    ))
 
 ;; cursor colors
 (defun viper-change-cursor-color (new-color)
     html-mode html-helper-mode
     emacs-lisp-mode lisp-mode lisp-interaction-mode
 				  
-    java-mode cc-mode c-mode c++-mode-hook
+    java-mode cc-mode c-mode c++-mode
     fortran-mode f90-mode
     basic-mode
     bat-mode
       (setq default-major-mode 'viper-mode))
   
   (add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
+  (add-hook 'find-file-hooks 'set-viper-state-in-major-mode)
 
   ;; keep this because many modes we don't know about use this hook
   (defvar text-mode-hook)
 (if (and viper-mode (memq major-mode viper-vi-state-mode-list))
     (viper-mode))
 
+
 (run-hooks 'viper-load-hook) ; the last chance to change something
 
 (provide 'viper)