diff options
| author | Michael Kifer | 1996-01-26 23:34:09 +0000 |
|---|---|---|
| committer | Michael Kifer | 1996-01-26 23:34:09 +0000 |
| commit | 95d70c422a71985e67522cc54159c9b4a623ed79 (patch) | |
| tree | fcc25937b8d71102bd367ee9e9f1f7bff7b81291 | |
| parent | 6da9bbd6b23135ce70b75a486ef941d04fa403db (diff) | |
| download | emacs-95d70c422a71985e67522cc54159c9b4a623ed79.tar.gz emacs-95d70c422a71985e67522cc54159c9b4a623ed79.zip | |
Moved code around to minimize compiler warnings.
| -rw-r--r-- | lisp/emulation/viper-ex.el | 12 | ||||
| -rw-r--r-- | lisp/emulation/viper-macs.el | 6 | ||||
| -rw-r--r-- | lisp/emulation/viper-mous.el | 48 | ||||
| -rw-r--r-- | lisp/emulation/viper-util.el | 2 | ||||
| -rw-r--r-- | lisp/emulation/viper.el | 331 |
5 files changed, 203 insertions, 196 deletions
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el index 4ce8f1453d6..57a813f6c19 100644 --- a/lisp/emulation/viper-ex.el +++ b/lisp/emulation/viper-ex.el | |||
| @@ -1412,7 +1412,7 @@ reversed.") | |||
| 1412 | 1412 | ||
| 1413 | ;; Ex print working directory | 1413 | ;; Ex print working directory |
| 1414 | (defun ex-pwd () | 1414 | (defun ex-pwd () |
| 1415 | (message "%s" default-directory)) | 1415 | (message default-directory)) |
| 1416 | 1416 | ||
| 1417 | ;; Ex quit command | 1417 | ;; Ex quit command |
| 1418 | (defun ex-quit () | 1418 | (defun ex-quit () |
| @@ -1560,7 +1560,7 @@ reversed.") | |||
| 1560 | val "nil"))) | 1560 | val "nil"))) |
| 1561 | (if (eq val 0) ; value must be set by the user | 1561 | (if (eq val 0) ; value must be set by the user |
| 1562 | (let ((cursor-in-echo-area t)) | 1562 | (let ((cursor-in-echo-area t)) |
| 1563 | (message ":set %s = <Value>" var) | 1563 | (message (format ":set %s = <Value>" var)) |
| 1564 | ;; if there are unread events, don't wait | 1564 | ;; if there are unread events, don't wait |
| 1565 | (or (vip-set-unread-command-events "") (sit-for 2)) | 1565 | (or (vip-set-unread-command-events "") (sit-for 2)) |
| 1566 | (setq val (read-string (format ":set %s = " var))) | 1566 | (setq val (read-string (format ":set %s = " var))) |
| @@ -1632,9 +1632,9 @@ reversed.") | |||
| 1632 | )) | 1632 | )) |
| 1633 | )) | 1633 | )) |
| 1634 | 1634 | ||
| 1635 | (message "%s %s %s" set-cmd var (if (string-match "^[ \t]*$" val) | 1635 | (message (format "%s %s %s" set-cmd var (if (string-match "^[ \t]*$" val) |
| 1636 | (format "%S" val) | 1636 | (format "%S" val) |
| 1637 | val)) | 1637 | val))) |
| 1638 | (eval (car (read-from-string actual-lisp-cmd))) | 1638 | (eval (car (read-from-string actual-lisp-cmd))) |
| 1639 | (if (string= var "fill-column") | 1639 | (if (string= var "fill-column") |
| 1640 | (if (> val2 0) | 1640 | (if (> val2 0) |
| @@ -1962,7 +1962,7 @@ Please contact your system administrator. " | |||
| 1962 | (if (buffer-modified-p) "[Modified]" "[Unchanged]"))) | 1962 | (if (buffer-modified-p) "[Modified]" "[Unchanged]"))) |
| 1963 | (if (< (+ 1 (length info) (length file)) | 1963 | (if (< (+ 1 (length info) (length file)) |
| 1964 | (window-width (minibuffer-window))) | 1964 | (window-width (minibuffer-window))) |
| 1965 | (message "%s %s" file info) | 1965 | (message (concat file " " info)) |
| 1966 | (save-window-excursion | 1966 | (save-window-excursion |
| 1967 | (with-output-to-temp-buffer " *vip-info*" | 1967 | (with-output-to-temp-buffer " *vip-info*" |
| 1968 | (princ (concat "\n" | 1968 | (princ (concat "\n" |
diff --git a/lisp/emulation/viper-macs.el b/lisp/emulation/viper-macs.el index a32ee12c6fb..3554aba8666 100644 --- a/lisp/emulation/viper-macs.el +++ b/lisp/emulation/viper-macs.el | |||
| @@ -154,7 +154,7 @@ a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g., | |||
| 154 | variant (if (> (length key-seq) 0) | 154 | variant (if (> (length key-seq) 0) |
| 155 | (prin1-to-string (vip-display-macro key-seq)) | 155 | (prin1-to-string (vip-display-macro key-seq)) |
| 156 | ""))) | 156 | ""))) |
| 157 | (message "%s" message) | 157 | (message message) |
| 158 | (setq event (vip-read-key)) | 158 | (setq event (vip-read-key)) |
| 159 | ;;(setq event (vip-read-event)) | 159 | ;;(setq event (vip-read-event)) |
| 160 | (setq key | 160 | (setq key |
| @@ -229,7 +229,7 @@ a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g., | |||
| 229 | (prin1-to-string | 229 | (prin1-to-string |
| 230 | (vip-display-macro key-seq)) | 230 | (vip-display-macro key-seq)) |
| 231 | ""))) | 231 | ""))) |
| 232 | (message "%s" message) | 232 | (message message) |
| 233 | (setq event (vip-read-key)) | 233 | (setq event (vip-read-key)) |
| 234 | ;;(setq event (vip-read-event)) | 234 | ;;(setq event (vip-read-event)) |
| 235 | (setq key | 235 | (setq key |
| @@ -409,7 +409,7 @@ If SCOPE is nil, the user is asked to specify the scope." | |||
| 409 | scope) | 409 | scope) |
| 410 | vip-custom-file-name)) | 410 | vip-custom-file-name)) |
| 411 | 411 | ||
| 412 | (message "%s" msg) | 412 | (message msg) |
| 413 | )) | 413 | )) |
| 414 | 414 | ||
| 415 | (setq new-elt | 415 | (setq new-elt |
diff --git a/lisp/emulation/viper-mous.el b/lisp/emulation/viper-mous.el index d9b8d252514..95db8b6e27b 100644 --- a/lisp/emulation/viper-mous.el +++ b/lisp/emulation/viper-mous.el | |||
| @@ -69,7 +69,32 @@ considered related.") | |||
| 69 | 69 | ||
| 70 | (defsubst vip-multiclick-p () | 70 | (defsubst vip-multiclick-p () |
| 71 | (not (vip-sit-for-short vip-multiclick-timeout t))) | 71 | (not (vip-sit-for-short vip-multiclick-timeout t))) |
| 72 | |||
| 73 | ;; Returns window where click occurs | ||
| 74 | (defsubst vip-mouse-click-window (click) | ||
| 75 | (if vip-xemacs-p | ||
| 76 | (event-window click) | ||
| 77 | (posn-window (event-start click)))) | ||
| 78 | |||
| 79 | ;; Returns window where click occurs | ||
| 80 | (defsubst vip-mouse-click-frame (click) | ||
| 81 | (window-frame (vip-mouse-click-window click))) | ||
| 82 | |||
| 83 | ;; Returns the buffer of the window where click occurs | ||
| 84 | (defsubst vip-mouse-click-window-buffer (click) | ||
| 85 | (window-buffer (vip-mouse-click-window click))) | ||
| 86 | |||
| 87 | ;; Returns the name of the buffer in the window where click occurs | ||
| 88 | (defsubst vip-mouse-click-window-buffer-name (click) | ||
| 89 | (buffer-name (vip-mouse-click-window-buffer click))) | ||
| 90 | |||
| 91 | ;; Returns position of a click | ||
| 92 | (defsubst vip-mouse-click-posn (click) | ||
| 93 | (if vip-xemacs-p | ||
| 94 | (event-point click) | ||
| 95 | (posn-point (event-start click)))) | ||
| 72 | 96 | ||
| 97 | |||
| 73 | (defun vip-surrounding-word (count click-count) | 98 | (defun vip-surrounding-word (count click-count) |
| 74 | "Returns word surrounding point according to a heuristic. | 99 | "Returns word surrounding point according to a heuristic. |
| 75 | COUNT indicates how many regions to return. | 100 | COUNT indicates how many regions to return. |
| @@ -175,29 +200,6 @@ On single or double click, returns the word as determined by | |||
| 175 | (error "Click must be over a window.")) | 200 | (error "Click must be over a window.")) |
| 176 | click-word)))) | 201 | click-word)))) |
| 177 | 202 | ||
| 178 | ;; Returns window where click occurs | ||
| 179 | (defsubst vip-mouse-click-frame (click) | ||
| 180 | (window-frame (vip-mouse-click-window click))) | ||
| 181 | |||
| 182 | ;; Returns window where click occurs | ||
| 183 | (defsubst vip-mouse-click-window (click) | ||
| 184 | (if vip-xemacs-p | ||
| 185 | (event-window click) | ||
| 186 | (posn-window (event-start click)))) | ||
| 187 | |||
| 188 | ;; Returns the buffer of the window where click occurs | ||
| 189 | (defsubst vip-mouse-click-window-buffer (click) | ||
| 190 | (window-buffer (vip-mouse-click-window click))) | ||
| 191 | |||
| 192 | ;; Returns the name of the buffer in the window where click occurs | ||
| 193 | (defsubst vip-mouse-click-window-buffer-name (click) | ||
| 194 | (buffer-name (vip-mouse-click-window-buffer click))) | ||
| 195 | |||
| 196 | ;; Returns position of a click | ||
| 197 | (defsubst vip-mouse-click-posn (click) | ||
| 198 | (if vip-xemacs-p | ||
| 199 | (event-point click) | ||
| 200 | (posn-point (event-start click)))) | ||
| 201 | 203 | ||
| 202 | (defun vip-mouse-click-insert-word (click arg) | 204 | (defun vip-mouse-click-insert-word (click arg) |
| 203 | "Insert word clicked or double-clicked on. | 205 | "Insert word clicked or double-clicked on. |
diff --git a/lisp/emulation/viper-util.el b/lisp/emulation/viper-util.el index f509a681f2f..062ada3f88d 100644 --- a/lisp/emulation/viper-util.el +++ b/lisp/emulation/viper-util.el | |||
| @@ -507,7 +507,7 @@ | |||
| 507 | (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name)) | 507 | (regexp (format "^[^;]*%s[ \t\n]*[a-zA-Z---_']*[ \t\n)]" var-name)) |
| 508 | (buf (find-file-noselect (substitute-in-file-name custom-file))) | 508 | (buf (find-file-noselect (substitute-in-file-name custom-file))) |
| 509 | ) | 509 | ) |
| 510 | (message "%s" message) | 510 | (message message) |
| 511 | (save-excursion | 511 | (save-excursion |
| 512 | (set-buffer buf) | 512 | (set-buffer buf) |
| 513 | (goto-char (point-min)) | 513 | (goto-char (point-min)) |
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el index 8fe2936e9d7..a0384aa72dc 100644 --- a/lisp/emulation/viper.el +++ b/lisp/emulation/viper.el | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;; Keywords: emulations | 6 | ;; Keywords: emulations |
| 7 | ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | 7 | ;; Author: Michael Kifer <kifer@cs.sunysb.edu> |
| 8 | 8 | ||
| 9 | (defconst viper-version "2.85 of January 15, 1996" | 9 | (defconst viper-version "2.85 of January 24, 1996" |
| 10 | "The current version of Viper") | 10 | "The current version of Viper") |
| 11 | 11 | ||
| 12 | ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | 12 | ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
| @@ -939,7 +939,110 @@ Should be set in `~/.vip' file.") | |||
| 939 | (require 'viper-keym) | 939 | (require 'viper-keym) |
| 940 | 940 | ||
| 941 | 941 | ||
| 942 | ;;;; CODE | 942 | ;;; CODE |
| 943 | |||
| 944 | ;; sentinels | ||
| 945 | |||
| 946 | ;; Runs vip-after-change-functions inside after-change-functions | ||
| 947 | (defun vip-after-change-sentinel (beg end len) | ||
| 948 | (let ((list vip-after-change-functions)) | ||
| 949 | (while list | ||
| 950 | (funcall (car list) beg end len) | ||
| 951 | (setq list (cdr list))))) | ||
| 952 | |||
| 953 | ;; Runs vip-before-change-functions inside before-change-functions | ||
| 954 | (defun vip-before-change-sentinel (beg end) | ||
| 955 | (let ((list vip-before-change-functions)) | ||
| 956 | (while list | ||
| 957 | (funcall (car list) beg end) | ||
| 958 | (setq list (cdr list))))) | ||
| 959 | |||
| 960 | (defsubst vip-post-command-sentinel () | ||
| 961 | (run-hooks 'vip-post-command-hooks)) | ||
| 962 | |||
| 963 | (defsubst vip-pre-command-sentinel () | ||
| 964 | (run-hooks 'vip-pre-command-hooks)) | ||
| 965 | |||
| 966 | ;; Needed so that Viper will be able to figure the last inserted | ||
| 967 | ;; chunk of text with reasonable accuracy. | ||
| 968 | (defsubst vip-insert-state-post-command-sentinel () | ||
| 969 | (if (and (memq vip-current-state '(insert-state replace-state)) | ||
| 970 | vip-insert-point | ||
| 971 | (>= (point) vip-insert-point)) | ||
| 972 | (setq vip-last-posn-while-in-insert-state (point-marker))) | ||
| 973 | (if (and (eq this-command 'dabbrev-expand) | ||
| 974 | (integerp vip-pre-command-point) | ||
| 975 | (> vip-insert-point vip-pre-command-point)) | ||
| 976 | (move-marker vip-insert-point vip-pre-command-point)) | ||
| 977 | ) | ||
| 978 | |||
| 979 | (defsubst vip-insert-state-pre-command-sentinel () | ||
| 980 | (if (and (eq this-command 'dabbrev-expand) | ||
| 981 | (markerp vip-insert-point) | ||
| 982 | (marker-position vip-insert-point)) | ||
| 983 | (setq vip-pre-command-point (marker-position vip-insert-point)))) | ||
| 984 | |||
| 985 | (defsubst vip-R-state-post-command-sentinel () | ||
| 986 | ;; Restoring cursor color is needed despite | ||
| 987 | ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in | ||
| 988 | ;; another frame, the pre-command hook won't change cursor color to default | ||
| 989 | ;; in that other frame. So, if the second frame cursor was red and we set | ||
| 990 | ;; the point outside the replacement region, then the cursor color will | ||
| 991 | ;; remain red. Restoring the default, below, prevents this. | ||
| 992 | (if (and (<= (vip-replace-start) (point)) | ||
| 993 | (<= (point) (vip-replace-end))) | ||
| 994 | (vip-change-cursor-color vip-replace-overlay-cursor-color) | ||
| 995 | (vip-restore-cursor-color) | ||
| 996 | )) | ||
| 997 | |||
| 998 | ;; to speed up, don't change cursor color before self-insert | ||
| 999 | ;; and common move commands | ||
| 1000 | (defsubst vip-replace-state-pre-command-sentinel () | ||
| 1001 | (or (memq this-command '(self-insert-command)) | ||
| 1002 | (memq (vip-event-key last-command-event) | ||
| 1003 | '(up down left right (meta f) (meta b) | ||
| 1004 | (control n) (control p) (control f) (control b))) | ||
| 1005 | (vip-restore-cursor-color))) | ||
| 1006 | |||
| 1007 | (defun vip-replace-state-post-command-sentinel () | ||
| 1008 | ;; Restoring cursor color is needed despite | ||
| 1009 | ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer | ||
| 1010 | ;; in another frame, the pre-command hook won't change cursor color to | ||
| 1011 | ;; default in that other frame. So, if the second frame cursor was red and | ||
| 1012 | ;; we set the point outside the replacement region, then the cursor color | ||
| 1013 | ;; will remain red. Restoring the default, below, fixes this problem. | ||
| 1014 | ;; | ||
| 1015 | ;; We optimize for self-insert-command's here, since they either don't change | ||
| 1016 | ;; cursor color or, if they terminate replace mode, the color will be changed | ||
| 1017 | ;; in vip-finish-change | ||
| 1018 | (or (memq this-command '(self-insert-command)) | ||
| 1019 | (vip-restore-cursor-color)) | ||
| 1020 | (cond | ||
| 1021 | ((eq vip-current-state 'replace-state) | ||
| 1022 | ;; delete characters to compensate for inserted chars. | ||
| 1023 | (let ((replace-boundary (vip-replace-end))) | ||
| 1024 | (save-excursion | ||
| 1025 | (goto-char vip-last-posn-in-replace-region) | ||
| 1026 | (delete-char vip-replace-chars-to-delete) | ||
| 1027 | (setq vip-replace-chars-to-delete 0 | ||
| 1028 | vip-replace-chars-deleted 0) | ||
| 1029 | ;; terminate replace mode if reached replace limit | ||
| 1030 | (if (= vip-last-posn-in-replace-region | ||
| 1031 | (vip-replace-end)) | ||
| 1032 | (vip-finish-change vip-last-posn-in-replace-region))) | ||
| 1033 | |||
| 1034 | (if (and (<= (vip-replace-start) (point)) | ||
| 1035 | (<= (point) replace-boundary)) | ||
| 1036 | (progn | ||
| 1037 | ;; the state may have changed in vip-finish-change above | ||
| 1038 | (if (eq vip-current-state 'replace-state) | ||
| 1039 | (vip-change-cursor-color vip-replace-overlay-cursor-color)) | ||
| 1040 | (setq vip-last-posn-in-replace-region (point-marker)))) | ||
| 1041 | )) | ||
| 1042 | |||
| 1043 | (t ;; terminate replace mode if changed Viper states. | ||
| 1044 | (vip-finish-change vip-last-posn-in-replace-region)))) | ||
| 1045 | |||
| 943 | 1046 | ||
| 944 | ;; changing mode | 1047 | ;; changing mode |
| 945 | 1048 | ||
| @@ -947,16 +1050,17 @@ Should be set in `~/.vip' file.") | |||
| 947 | (defun vip-change-state (new-state) | 1050 | (defun vip-change-state (new-state) |
| 948 | ;; Keep vip-post/pre-command-hooks fresh. | 1051 | ;; Keep vip-post/pre-command-hooks fresh. |
| 949 | ;; We remove then add vip-post/pre-command-sentinel since it is very | 1052 | ;; We remove then add vip-post/pre-command-sentinel since it is very |
| 950 | ;; desirable that noone gets in-between | 1053 | ;; desirable that vip-pre-command-sentinel is the last hook and |
| 1054 | ;; vip-post-command-sentinel is the first hook. | ||
| 951 | (remove-hook 'post-command-hook 'vip-post-command-sentinel) | 1055 | (remove-hook 'post-command-hook 'vip-post-command-sentinel) |
| 952 | (add-hook 'post-command-hook 'vip-post-command-sentinel) | 1056 | (add-hook 'post-command-hook 'vip-post-command-sentinel) |
| 953 | (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) | 1057 | (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) |
| 954 | (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) | 1058 | (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) |
| 955 | ;; These hooks will be added back if switching to insert/replace mode | 1059 | ;; These hooks will be added back if switching to insert/replace mode |
| 956 | (vip-remove-hook 'vip-post-command-hooks | 1060 | (vip-remove-hook 'vip-post-command-hooks |
| 957 | 'vip-insert-state-post-command-sentinel) | 1061 | 'vip-insert-state-post-command-sentinel) |
| 958 | (vip-remove-hook 'vip-pre-command-hooks | 1062 | (vip-remove-hook 'vip-pre-command-hooks |
| 959 | 'vip-insert-state-pre-command-sentinel) | 1063 | 'vip-insert-state-pre-command-sentinel) |
| 960 | (cond ((eq new-state 'vi-state) | 1064 | (cond ((eq new-state 'vi-state) |
| 961 | (cond ((member vip-current-state '(insert-state replace-state)) | 1065 | (cond ((member vip-current-state '(insert-state replace-state)) |
| 962 | 1066 | ||
| @@ -997,9 +1101,9 @@ Should be set in `~/.vip' file.") | |||
| 997 | (vip-move-marker-locally 'vip-insert-point (point))) | 1101 | (vip-move-marker-locally 'vip-insert-point (point))) |
| 998 | (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point)) | 1102 | (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point)) |
| 999 | (vip-add-hook 'vip-post-command-hooks | 1103 | (vip-add-hook 'vip-post-command-hooks |
| 1000 | 'vip-insert-state-post-command-sentinel t) | 1104 | 'vip-insert-state-post-command-sentinel t) |
| 1001 | (vip-add-hook 'vip-pre-command-hooks | 1105 | (vip-add-hook 'vip-pre-command-hooks |
| 1002 | 'vip-insert-state-pre-command-sentinel t)) | 1106 | 'vip-insert-state-pre-command-sentinel t)) |
| 1003 | ) ; outermost cond | 1107 | ) ; outermost cond |
| 1004 | 1108 | ||
| 1005 | ;; Nothing needs to be done to switch to emacs mode! Just set some | 1109 | ;; Nothing needs to be done to switch to emacs mode! Just set some |
| @@ -1644,6 +1748,34 @@ behaves as in Emacs, any number of multiple escapes is allowed." | |||
| 1644 | ;; represents the numeric value of the prefix argument and COM represents | 1748 | ;; represents the numeric value of the prefix argument and COM represents |
| 1645 | ;; command prefix such as "c", "d", "m" and "y". | 1749 | ;; command prefix such as "c", "d", "m" and "y". |
| 1646 | 1750 | ||
| 1751 | ;; Get value part of prefix-argument ARG. | ||
| 1752 | (defsubst vip-p-val (arg) | ||
| 1753 | (cond ((null arg) 1) | ||
| 1754 | ((consp arg) | ||
| 1755 | (if (or (null (car arg)) (equal (car arg) '(nil))) | ||
| 1756 | 1 (car arg))) | ||
| 1757 | (t arg))) | ||
| 1758 | |||
| 1759 | ;; Get raw value part of prefix-argument ARG. | ||
| 1760 | (defsubst vip-P-val (arg) | ||
| 1761 | (cond ((consp arg) (car arg)) | ||
| 1762 | (t arg))) | ||
| 1763 | |||
| 1764 | ;; Get com part of prefix-argument ARG. | ||
| 1765 | (defsubst vip-getcom (arg) | ||
| 1766 | (cond ((null arg) nil) | ||
| 1767 | ((consp arg) (cdr arg)) | ||
| 1768 | (t nil))) | ||
| 1769 | |||
| 1770 | ;; Get com part of prefix-argument ARG and modify it. | ||
| 1771 | (defun vip-getCom (arg) | ||
| 1772 | (let ((com (vip-getcom arg))) | ||
| 1773 | (cond ((equal com ?c) ?C) | ||
| 1774 | ((equal com ?d) ?D) | ||
| 1775 | ((equal com ?y) ?Y) | ||
| 1776 | (t com)))) | ||
| 1777 | |||
| 1778 | |||
| 1647 | ;; Compute numeric prefix arg value. | 1779 | ;; Compute numeric prefix arg value. |
| 1648 | ;; Invoked by CHAR. COM is the command part obtained so far. | 1780 | ;; Invoked by CHAR. COM is the command part obtained so far. |
| 1649 | (defun vip-prefix-arg-value (event com) | 1781 | (defun vip-prefix-arg-value (event com) |
| @@ -1767,33 +1899,6 @@ behaves as in Emacs, any number of multiple escapes is allowed." | |||
| 1767 | (signal 'quit nil))) | 1899 | (signal 'quit nil))) |
| 1768 | (vip-deactivate-mark)) | 1900 | (vip-deactivate-mark)) |
| 1769 | 1901 | ||
| 1770 | ;; Get value part of prefix-argument ARG. | ||
| 1771 | (defsubst vip-p-val (arg) | ||
| 1772 | (cond ((null arg) 1) | ||
| 1773 | ((consp arg) | ||
| 1774 | (if (or (null (car arg)) (equal (car arg) '(nil))) | ||
| 1775 | 1 (car arg))) | ||
| 1776 | (t arg))) | ||
| 1777 | |||
| 1778 | ;; Get raw value part of prefix-argument ARG. | ||
| 1779 | (defsubst vip-P-val (arg) | ||
| 1780 | (cond ((consp arg) (car arg)) | ||
| 1781 | (t arg))) | ||
| 1782 | |||
| 1783 | ;; Get com part of prefix-argument ARG. | ||
| 1784 | (defsubst vip-getcom (arg) | ||
| 1785 | (cond ((null arg) nil) | ||
| 1786 | ((consp arg) (cdr arg)) | ||
| 1787 | (t nil))) | ||
| 1788 | |||
| 1789 | ;; Get com part of prefix-argument ARG and modify it. | ||
| 1790 | (defun vip-getCom (arg) | ||
| 1791 | (let ((com (vip-getcom arg))) | ||
| 1792 | (cond ((equal com ?c) ?C) | ||
| 1793 | ((equal com ?d) ?D) | ||
| 1794 | ((equal com ?y) ?Y) | ||
| 1795 | (t com)))) | ||
| 1796 | |||
| 1797 | 1902 | ||
| 1798 | ;; repeat last destructive command | 1903 | ;; repeat last destructive command |
| 1799 | 1904 | ||
| @@ -1803,10 +1908,31 @@ behaves as in Emacs, any number of multiple escapes is allowed." | |||
| 1803 | (set-register reg (concat (if (stringp (get-register reg)) | 1908 | (set-register reg (concat (if (stringp (get-register reg)) |
| 1804 | (get-register reg) "") | 1909 | (get-register reg) "") |
| 1805 | (buffer-substring start end)))) | 1910 | (buffer-substring start end)))) |
| 1911 | |||
| 1912 | ;; Saves last inserted text for possible use by vip-repeat command. | ||
| 1913 | (defun vip-save-last-insertion (beg end) | ||
| 1914 | (setq vip-last-insertion (buffer-substring beg end)) | ||
| 1915 | (or (< (length vip-d-com) 5) | ||
| 1916 | (setcar (nthcdr 4 vip-d-com) vip-last-insertion)) | ||
| 1917 | (or (null vip-command-ring) | ||
| 1918 | (ring-empty-p vip-command-ring) | ||
| 1919 | (progn | ||
| 1920 | (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring)) | ||
| 1921 | vip-last-insertion) | ||
| 1922 | ;; del most recent elt, if identical to the second most-recent | ||
| 1923 | (vip-cleanup-ring vip-command-ring))) | ||
| 1924 | ) | ||
| 1925 | |||
| 1926 | (defsubst vip-yank-last-insertion () | ||
| 1927 | "Inserts the text saved by the previous vip-save-last-insertion command." | ||
| 1928 | (condition-case nil | ||
| 1929 | (insert vip-last-insertion) | ||
| 1930 | (error nil))) | ||
| 1931 | |||
| 1806 | 1932 | ||
| 1807 | ;; define functions to be executed | 1933 | ;; define functions to be executed |
| 1808 | 1934 | ||
| 1809 | ;; invoked by C command | 1935 | ;; invoked by the `C' command |
| 1810 | (defun vip-exec-change (m-com com) | 1936 | (defun vip-exec-change (m-com com) |
| 1811 | ;; handle C cmd at the eol and at eob. | 1937 | ;; handle C cmd at the eol and at eob. |
| 1812 | (if (or (and (eolp) (= vip-com-point (point))) | 1938 | (if (or (and (eolp) (= vip-com-point (point))) |
| @@ -2730,106 +2856,6 @@ Undo previous insertion and inserts new." | |||
| 2730 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2856 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
| 2731 | ) | 2857 | ) |
| 2732 | 2858 | ||
| 2733 | ;; Runs vip-after-change-functions inside after-change-functions | ||
| 2734 | (defun vip-after-change-sentinel (beg end len) | ||
| 2735 | (let ((list vip-after-change-functions)) | ||
| 2736 | (while list | ||
| 2737 | (funcall (car list) beg end len) | ||
| 2738 | (setq list (cdr list))))) | ||
| 2739 | |||
| 2740 | ;; Runs vip-before-change-functions inside before-change-functions | ||
| 2741 | (defun vip-before-change-sentinel (beg end) | ||
| 2742 | (let ((list vip-before-change-functions)) | ||
| 2743 | (while list | ||
| 2744 | (funcall (car list) beg end) | ||
| 2745 | (setq list (cdr list))))) | ||
| 2746 | |||
| 2747 | (defsubst vip-post-command-sentinel () | ||
| 2748 | (run-hooks 'vip-post-command-hooks)) | ||
| 2749 | |||
| 2750 | (defsubst vip-pre-command-sentinel () | ||
| 2751 | (run-hooks 'vip-pre-command-hooks)) | ||
| 2752 | |||
| 2753 | ;; Needed so that Viper will be able to figure the last inserted | ||
| 2754 | ;; chunk of text with reasonable accuracy. | ||
| 2755 | (defsubst vip-insert-state-post-command-sentinel () | ||
| 2756 | (if (and (memq vip-current-state '(insert-state replace-state)) | ||
| 2757 | vip-insert-point | ||
| 2758 | (>= (point) vip-insert-point)) | ||
| 2759 | (setq vip-last-posn-while-in-insert-state (point-marker))) | ||
| 2760 | (if (and (eq this-command 'dabbrev-expand) | ||
| 2761 | (integerp vip-pre-command-point) | ||
| 2762 | (> vip-insert-point vip-pre-command-point)) | ||
| 2763 | (move-marker vip-insert-point vip-pre-command-point)) | ||
| 2764 | ) | ||
| 2765 | |||
| 2766 | (defsubst vip-insert-state-pre-command-sentinel () | ||
| 2767 | (if (and (eq this-command 'dabbrev-expand) | ||
| 2768 | (markerp vip-insert-point) | ||
| 2769 | (marker-position vip-insert-point)) | ||
| 2770 | (setq vip-pre-command-point (marker-position vip-insert-point)))) | ||
| 2771 | |||
| 2772 | (defsubst vip-R-state-post-command-sentinel () | ||
| 2773 | ;; Restoring cursor color is needed despite | ||
| 2774 | ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in | ||
| 2775 | ;; another frame, the pre-command hook won't change cursor color to default | ||
| 2776 | ;; in that other frame. So, if the second frame cursor was red and we set | ||
| 2777 | ;; the point outside the replacement region, then the cursor color will | ||
| 2778 | ;; remain red. Restoring the default, below, prevents this. | ||
| 2779 | (if (and (<= (vip-replace-start) (point)) | ||
| 2780 | (<= (point) (vip-replace-end))) | ||
| 2781 | (vip-change-cursor-color vip-replace-overlay-cursor-color) | ||
| 2782 | (vip-restore-cursor-color) | ||
| 2783 | )) | ||
| 2784 | |||
| 2785 | ;; to speed up, don't change cursor color before self-insert | ||
| 2786 | ;; and common move commands | ||
| 2787 | (defsubst vip-replace-state-pre-command-sentinel () | ||
| 2788 | (or (memq this-command '(self-insert-command)) | ||
| 2789 | (memq (vip-event-key last-command-event) | ||
| 2790 | '(up down left right (meta f) (meta b) | ||
| 2791 | (control n) (control p) (control f) (control b))) | ||
| 2792 | (vip-restore-cursor-color))) | ||
| 2793 | |||
| 2794 | (defun vip-replace-state-post-command-sentinel () | ||
| 2795 | ;; Restoring cursor color is needed despite | ||
| 2796 | ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer | ||
| 2797 | ;; in another frame, the pre-command hook won't change cursor color to | ||
| 2798 | ;; default in that other frame. So, if the second frame cursor was red and | ||
| 2799 | ;; we set the point outside the replacement region, then the cursor color | ||
| 2800 | ;; will remain red. Restoring the default, below, fixes this problem. | ||
| 2801 | ;; | ||
| 2802 | ;; We optimize for self-insert-command's here, since they either don't change | ||
| 2803 | ;; cursor color or, if they terminate replace mode, the color will be changed | ||
| 2804 | ;; in vip-finish-change | ||
| 2805 | (or (memq this-command '(self-insert-command)) | ||
| 2806 | (vip-restore-cursor-color)) | ||
| 2807 | (cond | ||
| 2808 | ((eq vip-current-state 'replace-state) | ||
| 2809 | ;; delete characters to compensate for inserted chars. | ||
| 2810 | (let ((replace-boundary (vip-replace-end))) | ||
| 2811 | (save-excursion | ||
| 2812 | (goto-char vip-last-posn-in-replace-region) | ||
| 2813 | (delete-char vip-replace-chars-to-delete) | ||
| 2814 | (setq vip-replace-chars-to-delete 0 | ||
| 2815 | vip-replace-chars-deleted 0) | ||
| 2816 | ;; terminate replace mode if reached replace limit | ||
| 2817 | (if (= vip-last-posn-in-replace-region | ||
| 2818 | (vip-replace-end)) | ||
| 2819 | (vip-finish-change vip-last-posn-in-replace-region))) | ||
| 2820 | |||
| 2821 | (if (and (<= (vip-replace-start) (point)) | ||
| 2822 | (<= (point) replace-boundary)) | ||
| 2823 | (progn | ||
| 2824 | ;; the state may have changed in vip-finish-change above | ||
| 2825 | (if (eq vip-current-state 'replace-state) | ||
| 2826 | (vip-change-cursor-color vip-replace-overlay-cursor-color)) | ||
| 2827 | (setq vip-last-posn-in-replace-region (point-marker)))) | ||
| 2828 | )) | ||
| 2829 | |||
| 2830 | (t ;; terminate replace mode if changed Viper states. | ||
| 2831 | (vip-finish-change vip-last-posn-in-replace-region)))) | ||
| 2832 | |||
| 2833 | 2859 | ||
| 2834 | ;; checks how many chars were deleted by the last change | 2860 | ;; checks how many chars were deleted by the last change |
| 2835 | (defun vip-replace-mode-spy-before (beg end) | 2861 | (defun vip-replace-mode-spy-before (beg end) |
| @@ -4331,26 +4357,6 @@ To turn this feature off, set this variable to nil.") | |||
| 4331 | (copy-region-as-kill beg end) | 4357 | (copy-region-as-kill beg end) |
| 4332 | (error (copy-region-as-kill beg beg)))) | 4358 | (error (copy-region-as-kill beg beg)))) |
| 4333 | 4359 | ||
| 4334 | ;; Saves last inserted text for possible use by vip-repeat command. | ||
| 4335 | (defun vip-save-last-insertion (beg end) | ||
| 4336 | (setq vip-last-insertion (buffer-substring beg end)) | ||
| 4337 | (or (< (length vip-d-com) 5) | ||
| 4338 | (setcar (nthcdr 4 vip-d-com) vip-last-insertion)) | ||
| 4339 | (or (null vip-command-ring) | ||
| 4340 | (ring-empty-p vip-command-ring) | ||
| 4341 | (progn | ||
| 4342 | (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring)) | ||
| 4343 | vip-last-insertion) | ||
| 4344 | ;; del most recent elt, if identical to the second most-recent | ||
| 4345 | (vip-cleanup-ring vip-command-ring))) | ||
| 4346 | ) | ||
| 4347 | |||
| 4348 | (defsubst vip-yank-last-insertion () | ||
| 4349 | "Inserts the text saved by the previous vip-save-last-insertion command." | ||
| 4350 | (condition-case nil | ||
| 4351 | (insert vip-last-insertion) | ||
| 4352 | (error nil))) | ||
| 4353 | |||
| 4354 | 4360 | ||
| 4355 | (defun vip-delete-char (arg) | 4361 | (defun vip-delete-char (arg) |
| 4356 | "Delete character." | 4362 | "Delete character." |
| @@ -4734,6 +4740,12 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 4734 | 4740 | ||
| 4735 | ;; Input Mode Indentation | 4741 | ;; Input Mode Indentation |
| 4736 | 4742 | ||
| 4743 | ;; Returns t, if the string before point matches the regexp STR. | ||
| 4744 | (defsubst vip-looking-back (str) | ||
| 4745 | (and (save-excursion (re-search-backward str nil t)) | ||
| 4746 | (= (point) (match-end 0)))) | ||
| 4747 | |||
| 4748 | |||
| 4737 | (defun vip-forward-indent () | 4749 | (defun vip-forward-indent () |
| 4738 | "Indent forward -- `C-t' in Vi." | 4750 | "Indent forward -- `C-t' in Vi." |
| 4739 | (interactive) | 4751 | (interactive) |
| @@ -5033,7 +5045,7 @@ Type any key to continue... ") | |||
| 5033 | level-changed t) | 5045 | level-changed t) |
| 5034 | (insert " | 5046 | (insert " |
| 5035 | Please specify your level of familiarity with the venomous VI PERil | 5047 | Please specify your level of familiarity with the venomous VI PERil |
| 5036 | \(and the VI Plan for Emacs Rescue). | 5048 | (and the VI Plan for Emacs Rescue). |
| 5037 | You can change it at any time by typing `M-x vip-set-expert-level RET' | 5049 | You can change it at any time by typing `M-x vip-set-expert-level RET' |
| 5038 | 5050 | ||
| 5039 | 1 -- BEGINNER: Almost all Emacs features are suppressed. | 5051 | 1 -- BEGINNER: Almost all Emacs features are suppressed. |
| @@ -5085,13 +5097,6 @@ Please, specify your level now: ") | |||
| 5085 | (interactive) | 5097 | (interactive) |
| 5086 | (beep 1)) | 5098 | (beep 1)) |
| 5087 | 5099 | ||
| 5088 | |||
| 5089 | ;; Returns t, if the string before point matches the regexp STR. | ||
| 5090 | (defsubst vip-looking-back (str) | ||
| 5091 | (and (save-excursion (re-search-backward str nil t)) | ||
| 5092 | (= (point) (match-end 0)))) | ||
| 5093 | |||
| 5094 | |||
| 5095 | 5100 | ||
| 5096 | ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer | 5101 | ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer |
| 5097 | (defun vip-register-to-point (char &optional enforce-buffer) | 5102 | (defun vip-register-to-point (char &optional enforce-buffer) |