diff options
| author | Michael Kifer | 1997-08-02 06:56:24 +0000 |
|---|---|---|
| committer | Michael Kifer | 1997-08-02 06:56:24 +0000 |
| commit | 2f3eb3b625b8ab6745a0ea43206099865f41d802 (patch) | |
| tree | a871b388be55ef49dae34b99b36f75d1af3edc9d /lisp | |
| parent | 01a314694499b7245c21b05a0a48bc22ae8ab575 (diff) | |
| download | emacs-2f3eb3b625b8ab6745a0ea43206099865f41d802.tar.gz emacs-2f3eb3b625b8ab6745a0ea43206099865f41d802.zip | |
new version
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emulation/viper-cmd.el | 3679 |
1 files changed, 1873 insertions, 1806 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index ca27e860415..3ffed0cae88 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el | |||
| @@ -8,13 +8,13 @@ | |||
| 8 | (require 'advice) | 8 | (require 'advice) |
| 9 | 9 | ||
| 10 | ;; Compiler pacifier | 10 | ;; Compiler pacifier |
| 11 | (defvar vip-minibuffer-current-face) | 11 | (defvar viper-minibuffer-current-face) |
| 12 | (defvar vip-minibuffer-insert-face) | 12 | (defvar viper-minibuffer-insert-face) |
| 13 | (defvar vip-minibuffer-vi-face) | 13 | (defvar viper-minibuffer-vi-face) |
| 14 | (defvar vip-minibuffer-emacs-face) | 14 | (defvar viper-minibuffer-emacs-face) |
| 15 | (defvar viper-always) | 15 | (defvar viper-always) |
| 16 | (defvar vip-mode-string) | 16 | (defvar viper-mode-string) |
| 17 | (defvar vip-custom-file-name) | 17 | (defvar viper-custom-file-name) |
| 18 | (defvar iso-accents-mode) | 18 | (defvar iso-accents-mode) |
| 19 | (defvar zmacs-region-stays) | 19 | (defvar zmacs-region-stays) |
| 20 | (defvar mark-even-if-inactive) | 20 | (defvar mark-even-if-inactive) |
| @@ -53,151 +53,154 @@ | |||
| 53 | ;; generate test functions | 53 | ;; generate test functions |
| 54 | ;; given symbol foo, foo-p is the test function, foos is the set of | 54 | ;; given symbol foo, foo-p is the test function, foos is the set of |
| 55 | ;; Viper command keys | 55 | ;; Viper command keys |
| 56 | ;; (macroexpand '(vip-test-com-defun foo)) | 56 | ;; (macroexpand '(viper-test-com-defun foo)) |
| 57 | ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos))) | 57 | ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos))) |
| 58 | 58 | ||
| 59 | (defmacro vip-test-com-defun (name) | 59 | (defmacro viper-test-com-defun (name) |
| 60 | (let* ((snm (symbol-name name)) | 60 | (let* ((snm (symbol-name name)) |
| 61 | (nm-p (intern (concat snm "-p"))) | 61 | (nm-p (intern (concat snm "-p"))) |
| 62 | (nms (intern (concat snm "s")))) | 62 | (nms (intern (concat snm "s")))) |
| 63 | (` (defun (, nm-p) (com) | 63 | (` (defun (, nm-p) (com) |
| 64 | (consp (memq (if (< com 0) (- com) com) (, nms))))))) | 64 | (consp (memq (if (and (viper-characterp com) (< com 0)) |
| 65 | (- com) com) (, nms))))))) | ||
| 65 | 66 | ||
| 66 | ;; Variables for defining VI commands | 67 | ;; Variables for defining VI commands |
| 67 | 68 | ||
| 68 | ;; Modifying commands that can be prefixes to movement commands | 69 | ;; Modifying commands that can be prefixes to movement commands |
| 69 | (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) | 70 | (defconst viper-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) |
| 70 | ;; define vip-prefix-command-p | 71 | ;; define viper-prefix-command-p |
| 71 | (vip-test-com-defun vip-prefix-command) | 72 | (viper-test-com-defun viper-prefix-command) |
| 72 | 73 | ||
| 73 | ;; Commands that are pairs eg. dd. r and R here are a hack | 74 | ;; Commands that are pairs eg. dd. r and R here are a hack |
| 74 | (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) | 75 | (defconst viper-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) |
| 75 | ;; define vip-charpair-command-p | 76 | ;; define viper-charpair-command-p |
| 76 | (vip-test-com-defun vip-charpair-command) | 77 | (viper-test-com-defun viper-charpair-command) |
| 77 | 78 | ||
| 78 | (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l | 79 | (defconst viper-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l |
| 79 | ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?% | 80 | ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?% |
| 80 | ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` | 81 | ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` |
| 81 | ?; ?, ?0 ?? ?/ ?\C-m ?\ | 82 | ?; ?, ?0 ?? ?/ ?\C-m ?\ |
| 83 | space return | ||
| 84 | delete backspace | ||
| 82 | ) | 85 | ) |
| 83 | "Movement commands") | 86 | "Movement commands") |
| 84 | ;; define vip-movement-command-p | 87 | ;; define viper-movement-command-p |
| 85 | (vip-test-com-defun vip-movement-command) | 88 | (viper-test-com-defun viper-movement-command) |
| 86 | 89 | ||
| 87 | ;; Vi digit commands | 90 | ;; Vi digit commands |
| 88 | (defconst vip-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) | 91 | (defconst viper-digit-commands '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) |
| 89 | 92 | ||
| 90 | ;; define vip-digit-command-p | 93 | ;; define viper-digit-command-p |
| 91 | (vip-test-com-defun vip-digit-command) | 94 | (viper-test-com-defun viper-digit-command) |
| 92 | 95 | ||
| 93 | ;; Commands that can be repeated by . (dotted) | 96 | ;; Commands that can be repeated by . (dotted) |
| 94 | (defconst vip-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) | 97 | (defconst viper-dotable-commands '(?c ?d ?C ?s ?S ?D ?> ?<)) |
| 95 | ;; define vip-dotable-command-p | 98 | ;; define viper-dotable-command-p |
| 96 | (vip-test-com-defun vip-dotable-command) | 99 | (viper-test-com-defun viper-dotable-command) |
| 97 | 100 | ||
| 98 | ;; Commands that can follow a # | 101 | ;; Commands that can follow a # |
| 99 | (defconst vip-hash-commands '(?c ?C ?g ?q ?s)) | 102 | (defconst viper-hash-commands '(?c ?C ?g ?q ?s)) |
| 100 | ;; define vip-hash-command-p | 103 | ;; define viper-hash-command-p |
| 101 | (vip-test-com-defun vip-hash-command) | 104 | (viper-test-com-defun viper-hash-command) |
| 102 | 105 | ||
| 103 | ;; Commands that may have registers as prefix | 106 | ;; Commands that may have registers as prefix |
| 104 | (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) | 107 | (defconst viper-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) |
| 105 | ;; define vip-regsuffix-command-p | 108 | ;; define viper-regsuffix-command-p |
| 106 | (vip-test-com-defun vip-regsuffix-command) | 109 | (viper-test-com-defun viper-regsuffix-command) |
| 107 | 110 | ||
| 108 | (defconst vip-vi-commands (append vip-movement-commands | 111 | (defconst viper-vi-commands (append viper-movement-commands |
| 109 | vip-digit-commands | 112 | viper-digit-commands |
| 110 | vip-dotable-commands | 113 | viper-dotable-commands |
| 111 | vip-charpair-commands | 114 | viper-charpair-commands |
| 112 | vip-hash-commands | 115 | viper-hash-commands |
| 113 | vip-prefix-commands | 116 | viper-prefix-commands |
| 114 | vip-regsuffix-commands) | 117 | viper-regsuffix-commands) |
| 115 | "The list of all commands in Vi-state.") | 118 | "The list of all commands in Vi-state.") |
| 116 | ;; define vip-vi-command-p | 119 | ;; define viper-vi-command-p |
| 117 | (vip-test-com-defun vip-vi-command) | 120 | (viper-test-com-defun viper-vi-command) |
| 118 | 121 | ||
| 119 | 122 | ||
| 120 | ;;; CODE | 123 | ;;; CODE |
| 121 | 124 | ||
| 122 | ;; sentinels | 125 | ;; sentinels |
| 123 | 126 | ||
| 124 | ;; Runs vip-after-change-functions inside after-change-functions | 127 | ;; Runs viper-after-change-functions inside after-change-functions |
| 125 | (defun vip-after-change-sentinel (beg end len) | 128 | (defun viper-after-change-sentinel (beg end len) |
| 126 | (let ((list vip-after-change-functions)) | 129 | (let ((list viper-after-change-functions)) |
| 127 | (while list | 130 | (while list |
| 128 | (funcall (car list) beg end len) | 131 | (funcall (car list) beg end len) |
| 129 | (setq list (cdr list))))) | 132 | (setq list (cdr list))))) |
| 130 | 133 | ||
| 131 | ;; Runs vip-before-change-functions inside before-change-functions | 134 | ;; Runs viper-before-change-functions inside before-change-functions |
| 132 | (defun vip-before-change-sentinel (beg end) | 135 | (defun viper-before-change-sentinel (beg end) |
| 133 | (let ((list vip-before-change-functions)) | 136 | (let ((list viper-before-change-functions)) |
| 134 | (while list | 137 | (while list |
| 135 | (funcall (car list) beg end) | 138 | (funcall (car list) beg end) |
| 136 | (setq list (cdr list))))) | 139 | (setq list (cdr list))))) |
| 137 | 140 | ||
| 138 | (defsubst vip-post-command-sentinel () | 141 | (defsubst viper-post-command-sentinel () |
| 139 | (run-hooks 'vip-post-command-hooks)) | 142 | (run-hooks 'viper-post-command-hooks)) |
| 140 | 143 | ||
| 141 | (defsubst vip-pre-command-sentinel () | 144 | (defsubst viper-pre-command-sentinel () |
| 142 | (run-hooks 'vip-pre-command-hooks)) | 145 | (run-hooks 'viper-pre-command-hooks)) |
| 143 | 146 | ||
| 144 | ;; Needed so that Viper will be able to figure the last inserted | 147 | ;; Needed so that Viper will be able to figure the last inserted |
| 145 | ;; chunk of text with reasonable accuracy. | 148 | ;; chunk of text with reasonable accuracy. |
| 146 | (defsubst vip-insert-state-post-command-sentinel () | 149 | (defsubst viper-insert-state-post-command-sentinel () |
| 147 | (if (and (memq vip-current-state '(insert-state replace-state)) | 150 | (if (and (memq viper-current-state '(insert-state replace-state)) |
| 148 | vip-insert-point | 151 | viper-insert-point |
| 149 | (>= (point) vip-insert-point)) | 152 | (>= (point) viper-insert-point)) |
| 150 | (setq vip-last-posn-while-in-insert-state (point-marker))) | 153 | (setq viper-last-posn-while-in-insert-state (point-marker))) |
| 151 | (if (eq vip-current-state 'insert-state) | 154 | (if (eq viper-current-state 'insert-state) |
| 152 | (progn | 155 | (progn |
| 153 | (or (stringp vip-saved-cursor-color) | 156 | (or (stringp viper-saved-cursor-color) |
| 154 | (string= (vip-get-cursor-color) vip-insert-state-cursor-color) | 157 | (string= (viper-get-cursor-color) viper-insert-state-cursor-color) |
| 155 | (setq vip-saved-cursor-color (vip-get-cursor-color))) | 158 | (setq viper-saved-cursor-color (viper-get-cursor-color))) |
| 156 | (if (stringp vip-saved-cursor-color) | 159 | (if (stringp viper-saved-cursor-color) |
| 157 | (vip-change-cursor-color vip-insert-state-cursor-color)) | 160 | (viper-change-cursor-color viper-insert-state-cursor-color)) |
| 158 | )) | 161 | )) |
| 159 | (if (and (eq this-command 'dabbrev-expand) | 162 | (if (and (eq this-command 'dabbrev-expand) |
| 160 | (integerp vip-pre-command-point) | 163 | (integerp viper-pre-command-point) |
| 161 | (> vip-insert-point vip-pre-command-point)) | 164 | (> viper-insert-point viper-pre-command-point)) |
| 162 | (move-marker vip-insert-point vip-pre-command-point)) | 165 | (move-marker viper-insert-point viper-pre-command-point)) |
| 163 | ) | 166 | ) |
| 164 | 167 | ||
| 165 | (defsubst vip-insert-state-pre-command-sentinel () | 168 | (defsubst viper-insert-state-pre-command-sentinel () |
| 166 | (or (memq this-command '(self-insert-command)) | 169 | (or (memq this-command '(self-insert-command)) |
| 167 | (memq (vip-event-key last-command-event) | 170 | (memq (viper-event-key last-command-event) |
| 168 | '(up down left right (meta f) (meta b) | 171 | '(up down left right (meta f) (meta b) |
| 169 | (control n) (control p) (control f) (control b))) | 172 | (control n) (control p) (control f) (control b))) |
| 170 | (vip-restore-cursor-color-after-insert)) | 173 | (viper-restore-cursor-color-after-insert)) |
| 171 | (if (and (eq this-command 'dabbrev-expand) | 174 | (if (and (eq this-command 'dabbrev-expand) |
| 172 | (markerp vip-insert-point) | 175 | (markerp viper-insert-point) |
| 173 | (marker-position vip-insert-point)) | 176 | (marker-position viper-insert-point)) |
| 174 | (setq vip-pre-command-point (marker-position vip-insert-point)))) | 177 | (setq viper-pre-command-point (marker-position viper-insert-point)))) |
| 175 | 178 | ||
| 176 | (defsubst vip-R-state-post-command-sentinel () | 179 | (defsubst viper-R-state-post-command-sentinel () |
| 177 | ;; Restoring cursor color is needed despite | 180 | ;; Restoring cursor color is needed despite |
| 178 | ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in | 181 | ;; viper-replace-state-pre-command-sentinel: When you jump to another buffer |
| 179 | ;; another frame, the pre-command hook won't change cursor color to default | 182 | ;; in another frame, the pre-command hook won't change cursor color to |
| 180 | ;; in that other frame. So, if the second frame cursor was red and we set | 183 | ;; default in that other frame. So, if the second frame cursor was red and |
| 181 | ;; the point outside the replacement region, then the cursor color will | 184 | ;; we set the point outside the replacement region, then the cursor color |
| 182 | ;; remain red. Restoring the default, below, prevents this. | 185 | ;; will remain red. Restoring the default, below, prevents this. |
| 183 | (if (and (<= (vip-replace-start) (point)) | 186 | (if (and (<= (viper-replace-start) (point)) |
| 184 | (<= (point) (vip-replace-end))) | 187 | (<= (point) (viper-replace-end))) |
| 185 | (vip-change-cursor-color vip-replace-overlay-cursor-color) | 188 | (viper-change-cursor-color viper-replace-overlay-cursor-color) |
| 186 | (vip-restore-cursor-color-after-replace) | 189 | (viper-restore-cursor-color-after-replace) |
| 187 | )) | 190 | )) |
| 188 | 191 | ||
| 189 | ;; to speed up, don't change cursor color before self-insert | 192 | ;; to speed up, don't change cursor color before self-insert |
| 190 | ;; and common move commands | 193 | ;; and common move commands |
| 191 | (defsubst vip-replace-state-pre-command-sentinel () | 194 | (defsubst viper-replace-state-pre-command-sentinel () |
| 192 | (or (memq this-command '(self-insert-command)) | 195 | (or (memq this-command '(self-insert-command)) |
| 193 | (memq (vip-event-key last-command-event) | 196 | (memq (viper-event-key last-command-event) |
| 194 | '(up down left right (meta f) (meta b) | 197 | '(up down left right (meta f) (meta b) |
| 195 | (control n) (control p) (control f) (control b))) | 198 | (control n) (control p) (control f) (control b))) |
| 196 | (vip-restore-cursor-color-after-replace))) | 199 | (viper-restore-cursor-color-after-replace))) |
| 197 | 200 | ||
| 198 | (defun vip-replace-state-post-command-sentinel () | 201 | (defun viper-replace-state-post-command-sentinel () |
| 199 | ;; Restoring cursor color is needed despite | 202 | ;; Restoring cursor color is needed despite |
| 200 | ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer | 203 | ;; viper-replace-state-pre-command-sentinel: When one jumps to another buffer |
| 201 | ;; in another frame, the pre-command hook won't change cursor color to | 204 | ;; in another frame, the pre-command hook won't change cursor color to |
| 202 | ;; default in that other frame. So, if the second frame cursor was red and | 205 | ;; default in that other frame. So, if the second frame cursor was red and |
| 203 | ;; we set the point outside the replacement region, then the cursor color | 206 | ;; we set the point outside the replacement region, then the cursor color |
| @@ -205,57 +208,58 @@ | |||
| 205 | ;; | 208 | ;; |
| 206 | ;; We optimize for self-insert-command's here, since they either don't change | 209 | ;; We optimize for self-insert-command's here, since they either don't change |
| 207 | ;; cursor color or, if they terminate replace mode, the color will be changed | 210 | ;; cursor color or, if they terminate replace mode, the color will be changed |
| 208 | ;; in vip-finish-change | 211 | ;; in viper-finish-change |
| 209 | (or (memq this-command '(self-insert-command)) | 212 | (or (memq this-command '(self-insert-command)) |
| 210 | (vip-restore-cursor-color-after-replace)) | 213 | (viper-restore-cursor-color-after-replace)) |
| 211 | (cond | 214 | (cond |
| 212 | ((eq vip-current-state 'replace-state) | 215 | ((eq viper-current-state 'replace-state) |
| 213 | ;; delete characters to compensate for inserted chars. | 216 | ;; delete characters to compensate for inserted chars. |
| 214 | (let ((replace-boundary (vip-replace-end))) | 217 | (let ((replace-boundary (viper-replace-end))) |
| 215 | (save-excursion | 218 | (save-excursion |
| 216 | (goto-char vip-last-posn-in-replace-region) | 219 | (goto-char viper-last-posn-in-replace-region) |
| 217 | (delete-char vip-replace-chars-to-delete) | 220 | (delete-char viper-replace-chars-to-delete) |
| 218 | (setq vip-replace-chars-to-delete 0 | 221 | (setq viper-replace-chars-to-delete 0 |
| 219 | vip-replace-chars-deleted 0) | 222 | viper-replace-chars-deleted 0) |
| 220 | ;; terminate replace mode if reached replace limit | 223 | ;; terminate replace mode if reached replace limit |
| 221 | (if (= vip-last-posn-in-replace-region | 224 | (if (= viper-last-posn-in-replace-region |
| 222 | (vip-replace-end)) | 225 | (viper-replace-end)) |
| 223 | (vip-finish-change vip-last-posn-in-replace-region))) | 226 | (viper-finish-change viper-last-posn-in-replace-region))) |
| 224 | 227 | ||
| 225 | (if (and (<= (vip-replace-start) (point)) | 228 | (if (and (<= (viper-replace-start) (point)) |
| 226 | (<= (point) replace-boundary)) | 229 | (<= (point) replace-boundary)) |
| 227 | (progn | 230 | (progn |
| 228 | ;; the state may have changed in vip-finish-change above | 231 | ;; the state may have changed in viper-finish-change above |
| 229 | (if (eq vip-current-state 'replace-state) | 232 | (if (eq viper-current-state 'replace-state) |
| 230 | (vip-change-cursor-color vip-replace-overlay-cursor-color)) | 233 | (viper-change-cursor-color viper-replace-overlay-cursor-color)) |
| 231 | (setq vip-last-posn-in-replace-region (point-marker)))) | 234 | (setq viper-last-posn-in-replace-region (point-marker)))) |
| 232 | )) | 235 | )) |
| 233 | 236 | ||
| 234 | (t ;; terminate replace mode if changed Viper states. | 237 | (t ;; terminate replace mode if changed Viper states. |
| 235 | (vip-finish-change vip-last-posn-in-replace-region)))) | 238 | (viper-finish-change viper-last-posn-in-replace-region)))) |
| 236 | 239 | ||
| 237 | 240 | ||
| 238 | ;; changing mode | 241 | ;; changing mode |
| 239 | 242 | ||
| 240 | ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | 243 | ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. |
| 241 | (defun vip-change-state (new-state) | 244 | (defun viper-change-state (new-state) |
| 242 | ;; Keep vip-post/pre-command-hooks fresh. | 245 | ;; Keep viper-post/pre-command-hooks fresh. |
| 243 | ;; We remove then add vip-post/pre-command-sentinel since it is very | 246 | ;; We remove then add viper-post/pre-command-sentinel since it is very |
| 244 | ;; desirable that vip-pre-command-sentinel is the last hook and | 247 | ;; desirable that viper-pre-command-sentinel is the last hook and |
| 245 | ;; vip-post-command-sentinel is the first hook. | 248 | ;; viper-post-command-sentinel is the first hook. |
| 246 | (remove-hook 'post-command-hook 'vip-post-command-sentinel) | 249 | (remove-hook 'post-command-hook 'viper-post-command-sentinel) |
| 247 | (add-hook 'post-command-hook 'vip-post-command-sentinel) | 250 | (add-hook 'post-command-hook 'viper-post-command-sentinel) |
| 248 | (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) | 251 | (remove-hook 'pre-command-hook 'viper-pre-command-sentinel) |
| 249 | (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) | 252 | (add-hook 'pre-command-hook 'viper-pre-command-sentinel t) |
| 250 | ;; These hooks will be added back if switching to insert/replace mode | 253 | ;; These hooks will be added back if switching to insert/replace mode |
| 251 | (vip-remove-hook 'vip-post-command-hooks | 254 | (viper-remove-hook 'viper-post-command-hooks |
| 252 | 'vip-insert-state-post-command-sentinel) | 255 | 'viper-insert-state-post-command-sentinel) |
| 253 | (vip-remove-hook 'vip-pre-command-hooks | 256 | (viper-remove-hook 'viper-pre-command-hooks |
| 254 | 'vip-insert-state-pre-command-sentinel) | 257 | 'viper-insert-state-pre-command-sentinel) |
| 258 | (setq viper-intermediate-command nil) | ||
| 255 | (cond ((eq new-state 'vi-state) | 259 | (cond ((eq new-state 'vi-state) |
| 256 | (cond ((member vip-current-state '(insert-state replace-state)) | 260 | (cond ((member viper-current-state '(insert-state replace-state)) |
| 257 | 261 | ||
| 258 | ;; move vip-last-posn-while-in-insert-state | 262 | ;; move viper-last-posn-while-in-insert-state |
| 259 | ;; This is a normal hook that is executed in insert/replace | 263 | ;; This is a normal hook that is executed in insert/replace |
| 260 | ;; states after each command. In Vi/Emacs state, it does | 264 | ;; states after each command. In Vi/Emacs state, it does |
| 261 | ;; nothing. We need to execute it here to make sure that | 265 | ;; nothing. We need to execute it here to make sure that |
| @@ -263,139 +267,140 @@ | |||
| 263 | ;; It may be left unrecorded if the last thing done in | 267 | ;; It may be left unrecorded if the last thing done in |
| 264 | ;; insert/repl state was dabbrev-expansion or abbrev | 268 | ;; insert/repl state was dabbrev-expansion or abbrev |
| 265 | ;; expansion caused by hitting ESC | 269 | ;; expansion caused by hitting ESC |
| 266 | (vip-insert-state-post-command-sentinel) | 270 | (viper-insert-state-post-command-sentinel) |
| 267 | 271 | ||
| 268 | (condition-case conds | 272 | (condition-case conds |
| 269 | (progn | 273 | (progn |
| 270 | (vip-save-last-insertion | 274 | (viper-save-last-insertion |
| 271 | vip-insert-point | 275 | viper-insert-point |
| 272 | vip-last-posn-while-in-insert-state) | 276 | viper-last-posn-while-in-insert-state) |
| 273 | (if vip-began-as-replace | 277 | (if viper-began-as-replace |
| 274 | (setq vip-began-as-replace nil) | 278 | (setq viper-began-as-replace nil) |
| 275 | ;; repeat insert commands if numerical arg > 1 | 279 | ;; repeat insert commands if numerical arg > 1 |
| 276 | (save-excursion | 280 | (save-excursion |
| 277 | (vip-repeat-insert-command)))) | 281 | (viper-repeat-insert-command)))) |
| 278 | (error | 282 | (error |
| 279 | (vip-message-conditions conds))) | 283 | (viper-message-conditions conds))) |
| 280 | 284 | ||
| 281 | (if (> (length vip-last-insertion) 0) | 285 | (if (> (length viper-last-insertion) 0) |
| 282 | (vip-push-onto-ring vip-last-insertion | 286 | (viper-push-onto-ring viper-last-insertion |
| 283 | 'vip-insertion-ring)) | 287 | 'viper-insertion-ring)) |
| 284 | 288 | ||
| 285 | (if vip-ex-style-editing-in-insert | 289 | (if viper-ex-style-editing-in-insert |
| 286 | (or (bolp) (backward-char 1)))) | 290 | (or (bolp) (backward-char 1)))) |
| 287 | )) | 291 | )) |
| 288 | 292 | ||
| 289 | ;; insert or replace | 293 | ;; insert or replace |
| 290 | ((memq new-state '(insert-state replace-state)) | 294 | ((memq new-state '(insert-state replace-state)) |
| 291 | (if (memq vip-current-state '(emacs-state vi-state)) | 295 | (if (memq viper-current-state '(emacs-state vi-state)) |
| 292 | (vip-move-marker-locally 'vip-insert-point (point))) | 296 | (viper-move-marker-locally 'viper-insert-point (point))) |
| 293 | (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point)) | 297 | (viper-move-marker-locally |
| 294 | (vip-add-hook 'vip-post-command-hooks | 298 | 'viper-last-posn-while-in-insert-state (point)) |
| 295 | 'vip-insert-state-post-command-sentinel t) | 299 | (viper-add-hook 'viper-post-command-hooks |
| 296 | (vip-add-hook 'vip-pre-command-hooks | 300 | 'viper-insert-state-post-command-sentinel t) |
| 297 | 'vip-insert-state-pre-command-sentinel t)) | 301 | (viper-add-hook 'viper-pre-command-hooks |
| 302 | 'viper-insert-state-pre-command-sentinel t)) | ||
| 298 | ) ; outermost cond | 303 | ) ; outermost cond |
| 299 | 304 | ||
| 300 | ;; Nothing needs to be done to switch to emacs mode! Just set some | 305 | ;; Nothing needs to be done to switch to emacs mode! Just set some |
| 301 | ;; variables, which is already done in vip-change-state-to-emacs! | 306 | ;; variables, which is already done in viper-change-state-to-emacs! |
| 302 | 307 | ||
| 303 | (setq vip-current-state new-state) | 308 | (setq viper-current-state new-state) |
| 304 | (vip-normalize-minor-mode-map-alist) | 309 | (viper-normalize-minor-mode-map-alist) |
| 305 | (vip-adjust-keys-for new-state) | 310 | (viper-adjust-keys-for new-state) |
| 306 | (vip-set-mode-vars-for new-state) | 311 | (viper-set-mode-vars-for new-state) |
| 307 | (vip-refresh-mode-line) | 312 | (viper-refresh-mode-line) |
| 308 | ) | 313 | ) |
| 309 | 314 | ||
| 310 | 315 | ||
| 311 | 316 | ||
| 312 | (defun vip-adjust-keys-for (state) | 317 | (defun viper-adjust-keys-for (state) |
| 313 | "Make necessary adjustments to keymaps before entering STATE." | 318 | "Make necessary adjustments to keymaps before entering STATE." |
| 314 | (cond ((memq state '(insert-state replace-state)) | 319 | (cond ((memq state '(insert-state replace-state)) |
| 315 | (if vip-auto-indent | 320 | (if viper-auto-indent |
| 316 | (progn | 321 | (progn |
| 317 | (define-key vip-insert-basic-map "\C-m" 'vip-autoindent) | 322 | (define-key viper-insert-basic-map "\C-m" 'viper-autoindent) |
| 318 | (if vip-want-emacs-keys-in-insert | 323 | (if viper-want-emacs-keys-in-insert |
| 319 | ;; expert | 324 | ;; expert |
| 320 | (define-key vip-insert-basic-map "\C-j" nil) | 325 | (define-key viper-insert-basic-map "\C-j" nil) |
| 321 | ;; novice | 326 | ;; novice |
| 322 | (define-key vip-insert-basic-map "\C-j" 'vip-autoindent))) | 327 | (define-key viper-insert-basic-map "\C-j" 'viper-autoindent))) |
| 323 | (define-key vip-insert-basic-map "\C-m" nil) | 328 | (define-key viper-insert-basic-map "\C-m" nil) |
| 324 | (define-key vip-insert-basic-map "\C-j" nil)) | 329 | (define-key viper-insert-basic-map "\C-j" nil)) |
| 325 | 330 | ||
| 326 | (setq vip-insert-diehard-minor-mode | 331 | (setq viper-insert-diehard-minor-mode |
| 327 | (not vip-want-emacs-keys-in-insert)) | 332 | (not viper-want-emacs-keys-in-insert)) |
| 328 | 333 | ||
| 329 | (if vip-want-ctl-h-help | 334 | (if viper-want-ctl-h-help |
| 330 | (progn | 335 | (progn |
| 331 | (define-key vip-insert-basic-map [(control h)] 'help-command) | 336 | (define-key viper-insert-basic-map [(control h)] 'help-command) |
| 332 | (define-key vip-replace-map [(control h)] 'help-command)) | 337 | (define-key viper-replace-map [(control h)] 'help-command)) |
| 333 | (define-key vip-insert-basic-map | 338 | (define-key viper-insert-basic-map |
| 334 | [(control h)] 'vip-del-backward-char-in-insert) | 339 | [(control h)] 'viper-del-backward-char-in-insert) |
| 335 | (define-key vip-replace-map | 340 | (define-key viper-replace-map |
| 336 | [(control h)] 'vip-del-backward-char-in-replace))) | 341 | [(control h)] 'viper-del-backward-char-in-replace))) |
| 337 | 342 | ||
| 338 | (t ; Vi state | 343 | (t ; Vi state |
| 339 | (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi)) | 344 | (setq viper-vi-diehard-minor-mode (not viper-want-emacs-keys-in-vi)) |
| 340 | (if vip-want-ctl-h-help | 345 | (if viper-want-ctl-h-help |
| 341 | (define-key vip-vi-basic-map [(control h)] 'help-command) | 346 | (define-key viper-vi-basic-map [(control h)] 'help-command) |
| 342 | (define-key vip-vi-basic-map [(control h)] 'vip-backward-char))) | 347 | (define-key viper-vi-basic-map [(control h)] 'viper-backward-char))) |
| 343 | )) | 348 | )) |
| 344 | 349 | ||
| 345 | 350 | ||
| 346 | ;; Normalizes minor-mode-map-alist by putting Viper keymaps first. | 351 | ;; Normalizes minor-mode-map-alist by putting Viper keymaps first. |
| 347 | ;; This ensures that Viper bindings are in effect, regardless of which minor | 352 | ;; This ensures that Viper bindings are in effect, regardless of which minor |
| 348 | ;; modes were turned on by the user or by other packages. | 353 | ;; modes were turned on by the user or by other packages. |
| 349 | (defun vip-normalize-minor-mode-map-alist () | 354 | (defun viper-normalize-minor-mode-map-alist () |
| 350 | (setq minor-mode-map-alist | 355 | (setq minor-mode-map-alist |
| 351 | (vip-append-filter-alist | 356 | (viper-append-filter-alist |
| 352 | (list | 357 | (list |
| 353 | (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map) | 358 | (cons 'viper-vi-intercept-minor-mode viper-vi-intercept-map) |
| 354 | (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map) | 359 | (cons 'viper-vi-minibuffer-minor-mode viper-minibuffer-map) |
| 355 | (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map) | 360 | (cons 'viper-vi-local-user-minor-mode viper-vi-local-user-map) |
| 356 | (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map) | 361 | (cons 'viper-vi-kbd-minor-mode viper-vi-kbd-map) |
| 357 | (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map) | 362 | (cons 'viper-vi-global-user-minor-mode viper-vi-global-user-map) |
| 358 | (cons 'vip-vi-state-modifier-minor-mode | 363 | (cons 'viper-vi-state-modifier-minor-mode |
| 359 | (if (keymapp | 364 | (if (keymapp |
| 360 | (cdr (assoc major-mode vip-vi-state-modifier-alist))) | 365 | (cdr (assoc major-mode viper-vi-state-modifier-alist))) |
| 361 | (cdr (assoc major-mode vip-vi-state-modifier-alist)) | 366 | (cdr (assoc major-mode viper-vi-state-modifier-alist)) |
| 362 | vip-empty-keymap)) | 367 | viper-empty-keymap)) |
| 363 | (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map) | 368 | (cons 'viper-vi-diehard-minor-mode viper-vi-diehard-map) |
| 364 | (cons 'vip-vi-basic-minor-mode vip-vi-basic-map) | 369 | (cons 'viper-vi-basic-minor-mode viper-vi-basic-map) |
| 365 | (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map) | 370 | (cons 'viper-insert-intercept-minor-mode viper-insert-intercept-map) |
| 366 | (cons 'vip-replace-minor-mode vip-replace-map) | 371 | (cons 'viper-replace-minor-mode viper-replace-map) |
| 367 | ;; vip-insert-minibuffer-minor-mode must come after | 372 | ;; viper-insert-minibuffer-minor-mode must come after |
| 368 | ;; vip-replace-minor-mode | 373 | ;; viper-replace-minor-mode |
| 369 | (cons 'vip-insert-minibuffer-minor-mode | 374 | (cons 'viper-insert-minibuffer-minor-mode |
| 370 | vip-minibuffer-map) | 375 | viper-minibuffer-map) |
| 371 | (cons 'vip-insert-local-user-minor-mode | 376 | (cons 'viper-insert-local-user-minor-mode |
| 372 | vip-insert-local-user-map) | 377 | viper-insert-local-user-map) |
| 373 | (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map) | 378 | (cons 'viper-insert-kbd-minor-mode viper-insert-kbd-map) |
| 374 | (cons 'vip-insert-global-user-minor-mode | 379 | (cons 'viper-insert-global-user-minor-mode |
| 375 | vip-insert-global-user-map) | 380 | viper-insert-global-user-map) |
| 376 | (cons 'vip-insert-state-modifier-minor-mode | 381 | (cons 'viper-insert-state-modifier-minor-mode |
| 377 | (if (keymapp | 382 | (if (keymapp |
| 378 | (cdr | 383 | (cdr |
| 379 | (assoc major-mode vip-insert-state-modifier-alist))) | 384 | (assoc major-mode viper-insert-state-modifier-alist))) |
| 380 | (cdr | 385 | (cdr |
| 381 | (assoc major-mode vip-insert-state-modifier-alist)) | 386 | (assoc major-mode viper-insert-state-modifier-alist)) |
| 382 | vip-empty-keymap)) | 387 | viper-empty-keymap)) |
| 383 | (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map) | 388 | (cons 'viper-insert-diehard-minor-mode viper-insert-diehard-map) |
| 384 | (cons 'vip-insert-basic-minor-mode vip-insert-basic-map) | 389 | (cons 'viper-insert-basic-minor-mode viper-insert-basic-map) |
| 385 | (cons 'vip-emacs-intercept-minor-mode | 390 | (cons 'viper-emacs-intercept-minor-mode |
| 386 | vip-emacs-intercept-map) | 391 | viper-emacs-intercept-map) |
| 387 | (cons 'vip-emacs-local-user-minor-mode | 392 | (cons 'viper-emacs-local-user-minor-mode |
| 388 | vip-emacs-local-user-map) | 393 | viper-emacs-local-user-map) |
| 389 | (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map) | 394 | (cons 'viper-emacs-kbd-minor-mode viper-emacs-kbd-map) |
| 390 | (cons 'vip-emacs-global-user-minor-mode | 395 | (cons 'viper-emacs-global-user-minor-mode |
| 391 | vip-emacs-global-user-map) | 396 | viper-emacs-global-user-map) |
| 392 | (cons 'vip-emacs-state-modifier-minor-mode | 397 | (cons 'viper-emacs-state-modifier-minor-mode |
| 393 | (if (keymapp | 398 | (if (keymapp |
| 394 | (cdr | 399 | (cdr |
| 395 | (assoc major-mode vip-emacs-state-modifier-alist))) | 400 | (assoc major-mode viper-emacs-state-modifier-alist))) |
| 396 | (cdr | 401 | (cdr |
| 397 | (assoc major-mode vip-emacs-state-modifier-alist)) | 402 | (assoc major-mode viper-emacs-state-modifier-alist)) |
| 398 | vip-empty-keymap)) | 403 | viper-empty-keymap)) |
| 399 | ) | 404 | ) |
| 400 | minor-mode-map-alist))) | 405 | minor-mode-map-alist))) |
| 401 | 406 | ||
| @@ -406,116 +411,117 @@ | |||
| 406 | ;; Viper mode-changing commands and utilities | 411 | ;; Viper mode-changing commands and utilities |
| 407 | 412 | ||
| 408 | ;; Modifies mode-line-buffer-identification. | 413 | ;; Modifies mode-line-buffer-identification. |
| 409 | (defun vip-refresh-mode-line () | 414 | (defun viper-refresh-mode-line () |
| 410 | (setq vip-mode-string | 415 | (setq viper-mode-string |
| 411 | (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id) | 416 | (cond ((eq viper-current-state 'emacs-state) viper-emacs-state-id) |
| 412 | ((eq vip-current-state 'vi-state) vip-vi-state-id) | 417 | ((eq viper-current-state 'vi-state) viper-vi-state-id) |
| 413 | ((eq vip-current-state 'replace-state) vip-replace-state-id) | 418 | ((eq viper-current-state 'replace-state) viper-replace-state-id) |
| 414 | ((eq vip-current-state 'insert-state) vip-insert-state-id))) | 419 | ((eq viper-current-state 'insert-state) viper-insert-state-id))) |
| 415 | 420 | ||
| 416 | ;; Sets Viper mode string in global-mode-string | 421 | ;; Sets Viper mode string in global-mode-string |
| 417 | (force-mode-line-update)) | 422 | (force-mode-line-update)) |
| 418 | 423 | ||
| 419 | 424 | ||
| 420 | ;; Switch from Insert state to Vi state. | 425 | ;; Switch from Insert state to Vi state. |
| 421 | (defun vip-exit-insert-state () | 426 | (defun viper-exit-insert-state () |
| 422 | (interactive) | 427 | (interactive) |
| 423 | (vip-change-state-to-vi)) | 428 | (viper-change-state-to-vi)) |
| 424 | 429 | ||
| 425 | (defun vip-set-mode-vars-for (state) | 430 | (defun viper-set-mode-vars-for (state) |
| 426 | "Sets Viper minor mode variables to put Viper's state STATE in effect." | 431 | "Sets Viper minor mode variables to put Viper's state STATE in effect." |
| 427 | 432 | ||
| 428 | ;; Emacs state | 433 | ;; Emacs state |
| 429 | (setq vip-vi-minibuffer-minor-mode nil | 434 | (setq viper-vi-minibuffer-minor-mode nil |
| 430 | vip-insert-minibuffer-minor-mode nil | 435 | viper-insert-minibuffer-minor-mode nil |
| 431 | vip-vi-intercept-minor-mode nil | 436 | viper-vi-intercept-minor-mode nil |
| 432 | vip-insert-intercept-minor-mode nil | 437 | viper-insert-intercept-minor-mode nil |
| 433 | 438 | ||
| 434 | vip-vi-local-user-minor-mode nil | 439 | viper-vi-local-user-minor-mode nil |
| 435 | vip-vi-kbd-minor-mode nil | 440 | viper-vi-kbd-minor-mode nil |
| 436 | vip-vi-global-user-minor-mode nil | 441 | viper-vi-global-user-minor-mode nil |
| 437 | vip-vi-state-modifier-minor-mode nil | 442 | viper-vi-state-modifier-minor-mode nil |
| 438 | vip-vi-diehard-minor-mode nil | 443 | viper-vi-diehard-minor-mode nil |
| 439 | vip-vi-basic-minor-mode nil | 444 | viper-vi-basic-minor-mode nil |
| 440 | 445 | ||
| 441 | vip-replace-minor-mode nil | 446 | viper-replace-minor-mode nil |
| 442 | 447 | ||
| 443 | vip-insert-local-user-minor-mode nil | 448 | viper-insert-local-user-minor-mode nil |
| 444 | vip-insert-kbd-minor-mode nil | 449 | viper-insert-kbd-minor-mode nil |
| 445 | vip-insert-global-user-minor-mode nil | 450 | viper-insert-global-user-minor-mode nil |
| 446 | vip-insert-state-modifier-minor-mode nil | 451 | viper-insert-state-modifier-minor-mode nil |
| 447 | vip-insert-diehard-minor-mode nil | 452 | viper-insert-diehard-minor-mode nil |
| 448 | vip-insert-basic-minor-mode nil | 453 | viper-insert-basic-minor-mode nil |
| 449 | vip-emacs-intercept-minor-mode t | 454 | viper-emacs-intercept-minor-mode t |
| 450 | vip-emacs-local-user-minor-mode t | 455 | viper-emacs-local-user-minor-mode t |
| 451 | vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer)) | 456 | viper-emacs-kbd-minor-mode (not (viper-is-in-minibuffer)) |
| 452 | vip-emacs-global-user-minor-mode t | 457 | viper-emacs-global-user-minor-mode t |
| 453 | vip-emacs-state-modifier-minor-mode t | 458 | viper-emacs-state-modifier-minor-mode t |
| 454 | ) | 459 | ) |
| 455 | 460 | ||
| 456 | ;; Vi state | 461 | ;; Vi state |
| 457 | (if (eq state 'vi-state) ; adjust for vi-state | 462 | (if (eq state 'vi-state) ; adjust for vi-state |
| 458 | (setq | 463 | (setq |
| 459 | vip-vi-intercept-minor-mode t | 464 | viper-vi-intercept-minor-mode t |
| 460 | vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer) | 465 | viper-vi-minibuffer-minor-mode (viper-is-in-minibuffer) |
| 461 | vip-vi-local-user-minor-mode t | 466 | viper-vi-local-user-minor-mode t |
| 462 | vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer)) | 467 | viper-vi-kbd-minor-mode (not (viper-is-in-minibuffer)) |
| 463 | vip-vi-global-user-minor-mode t | 468 | viper-vi-global-user-minor-mode t |
| 464 | vip-vi-state-modifier-minor-mode t | 469 | viper-vi-state-modifier-minor-mode t |
| 465 | ;; don't let the diehard keymap block command completion | 470 | ;; don't let the diehard keymap block command completion |
| 466 | ;; and other things in the minibuffer | 471 | ;; and other things in the minibuffer |
| 467 | vip-vi-diehard-minor-mode (not | 472 | viper-vi-diehard-minor-mode (not |
| 468 | (or vip-want-emacs-keys-in-vi | 473 | (or viper-want-emacs-keys-in-vi |
| 469 | (vip-is-in-minibuffer))) | 474 | (viper-is-in-minibuffer))) |
| 470 | vip-vi-basic-minor-mode t | 475 | viper-vi-basic-minor-mode t |
| 471 | vip-emacs-intercept-minor-mode nil | 476 | viper-emacs-intercept-minor-mode nil |
| 472 | vip-emacs-local-user-minor-mode nil | 477 | viper-emacs-local-user-minor-mode nil |
| 473 | vip-emacs-kbd-minor-mode nil | 478 | viper-emacs-kbd-minor-mode nil |
| 474 | vip-emacs-global-user-minor-mode nil | 479 | viper-emacs-global-user-minor-mode nil |
| 475 | vip-emacs-state-modifier-minor-mode nil | 480 | viper-emacs-state-modifier-minor-mode nil |
| 476 | )) | 481 | )) |
| 477 | 482 | ||
| 478 | ;; Insert and Replace states | 483 | ;; Insert and Replace states |
| 479 | (if (member state '(insert-state replace-state)) | 484 | (if (member state '(insert-state replace-state)) |
| 480 | (setq | 485 | (setq |
| 481 | vip-insert-intercept-minor-mode t | 486 | viper-insert-intercept-minor-mode t |
| 482 | vip-replace-minor-mode (eq state 'replace-state) | 487 | viper-replace-minor-mode (eq state 'replace-state) |
| 483 | vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer) | 488 | viper-insert-minibuffer-minor-mode (viper-is-in-minibuffer) |
| 484 | vip-insert-local-user-minor-mode t | 489 | viper-insert-local-user-minor-mode t |
| 485 | vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer)) | 490 | viper-insert-kbd-minor-mode (not (viper-is-in-minibuffer)) |
| 486 | vip-insert-global-user-minor-mode t | 491 | viper-insert-global-user-minor-mode t |
| 487 | vip-insert-state-modifier-minor-mode t | 492 | viper-insert-state-modifier-minor-mode t |
| 488 | ;; don't let the diehard keymap block command completion | 493 | ;; don't let the diehard keymap block command completion |
| 489 | ;; and other things in the minibuffer | 494 | ;; and other things in the minibuffer |
| 490 | vip-insert-diehard-minor-mode (not | 495 | viper-insert-diehard-minor-mode (not |
| 491 | (or vip-want-emacs-keys-in-insert | 496 | (or |
| 492 | (vip-is-in-minibuffer))) | 497 | viper-want-emacs-keys-in-insert |
| 493 | vip-insert-basic-minor-mode t | 498 | (viper-is-in-minibuffer))) |
| 494 | vip-emacs-intercept-minor-mode nil | 499 | viper-insert-basic-minor-mode t |
| 495 | vip-emacs-local-user-minor-mode nil | 500 | viper-emacs-intercept-minor-mode nil |
| 496 | vip-emacs-kbd-minor-mode nil | 501 | viper-emacs-local-user-minor-mode nil |
| 497 | vip-emacs-global-user-minor-mode nil | 502 | viper-emacs-kbd-minor-mode nil |
| 498 | vip-emacs-state-modifier-minor-mode nil | 503 | viper-emacs-global-user-minor-mode nil |
| 504 | viper-emacs-state-modifier-minor-mode nil | ||
| 499 | )) | 505 | )) |
| 500 | 506 | ||
| 501 | ;; minibuffer faces | 507 | ;; minibuffer faces |
| 502 | (if (vip-has-face-support-p) | 508 | (if (viper-has-face-support-p) |
| 503 | (setq vip-minibuffer-current-face | 509 | (setq viper-minibuffer-current-face |
| 504 | (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face) | 510 | (cond ((eq state 'emacs-state) viper-minibuffer-emacs-face) |
| 505 | ((eq state 'vi-state) vip-minibuffer-vi-face) | 511 | ((eq state 'vi-state) viper-minibuffer-vi-face) |
| 506 | ((memq state '(insert-state replace-state)) | 512 | ((memq state '(insert-state replace-state)) |
| 507 | vip-minibuffer-insert-face)))) | 513 | viper-minibuffer-insert-face)))) |
| 508 | 514 | ||
| 509 | (if (vip-is-in-minibuffer) | 515 | (if (viper-is-in-minibuffer) |
| 510 | (vip-set-minibuffer-overlay)) | 516 | (viper-set-minibuffer-overlay)) |
| 511 | ) | 517 | ) |
| 512 | 518 | ||
| 513 | ;; This also takes care of the annoying incomplete lines in files. | 519 | ;; This also takes care of the annoying incomplete lines in files. |
| 514 | ;; Also, this fixes `undo' to work vi-style for complex commands. | 520 | ;; Also, this fixes `undo' to work vi-style for complex commands. |
| 515 | (defun vip-change-state-to-vi () | 521 | (defun viper-change-state-to-vi () |
| 516 | "Change Viper state to Vi." | 522 | "Change Viper state to Vi." |
| 517 | (interactive) | 523 | (interactive) |
| 518 | (if (and vip-first-time (not (vip-is-in-minibuffer))) | 524 | (if (and viper-first-time (not (viper-is-in-minibuffer))) |
| 519 | (viper-mode) | 525 | (viper-mode) |
| 520 | (if overwrite-mode (overwrite-mode nil)) | 526 | (if overwrite-mode (overwrite-mode nil)) |
| 521 | (if abbrev-mode (expand-abbrev)) | 527 | (if abbrev-mode (expand-abbrev)) |
| @@ -523,126 +529,126 @@ | |||
| 523 | (funcall auto-fill-function)) | 529 | (funcall auto-fill-function)) |
| 524 | ;; don't leave whitespace lines around | 530 | ;; don't leave whitespace lines around |
| 525 | (if (and (memq last-command | 531 | (if (and (memq last-command |
| 526 | '(vip-autoindent | 532 | '(viper-autoindent |
| 527 | vip-open-line vip-Open-line | 533 | viper-open-line viper-Open-line |
| 528 | vip-replace-state-exit-cmd)) | 534 | viper-replace-state-exit-cmd)) |
| 529 | (vip-over-whitespace-line)) | 535 | (viper-over-whitespace-line)) |
| 530 | (indent-to-left-margin)) | 536 | (indent-to-left-margin)) |
| 531 | (vip-add-newline-at-eob-if-necessary) | 537 | (viper-add-newline-at-eob-if-necessary) |
| 532 | (if vip-undo-needs-adjustment (vip-adjust-undo)) | 538 | (if viper-undo-needs-adjustment (viper-adjust-undo)) |
| 533 | (vip-change-state 'vi-state) | 539 | (viper-change-state 'vi-state) |
| 534 | 540 | ||
| 535 | ;; always turn off iso-accents-mode, or else we won't be able to use the | 541 | ;; always turn off iso-accents-mode, or else we won't be able to use the |
| 536 | ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions. | 542 | ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions. |
| 537 | (if (and (boundp 'iso-accents-mode) iso-accents-mode) | 543 | (if (and (boundp 'iso-accents-mode) iso-accents-mode) |
| 538 | (iso-accents-mode -1)) | 544 | (iso-accents-mode -1)) |
| 539 | 545 | ||
| 540 | (vip-restore-cursor-color-after-insert) | 546 | (viper-restore-cursor-color-after-insert) |
| 541 | 547 | ||
| 542 | ;; Protection against user errors in hooks | 548 | ;; Protection against user errors in hooks |
| 543 | (condition-case conds | 549 | (condition-case conds |
| 544 | (run-hooks 'vip-vi-state-hook) | 550 | (run-hooks 'viper-vi-state-hook) |
| 545 | (error | 551 | (error |
| 546 | (vip-message-conditions conds))))) | 552 | (viper-message-conditions conds))))) |
| 547 | 553 | ||
| 548 | (defun vip-change-state-to-insert () | 554 | (defun viper-change-state-to-insert () |
| 549 | "Change Viper state to Insert." | 555 | "Change Viper state to Insert." |
| 550 | (interactive) | 556 | (interactive) |
| 551 | (vip-change-state 'insert-state) | 557 | (viper-change-state 'insert-state) |
| 552 | (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | 558 | (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode)) |
| 553 | (iso-accents-mode 1)) ; turn iso accents on | 559 | (iso-accents-mode 1)) ; turn iso accents on |
| 554 | 560 | ||
| 555 | (or (stringp vip-saved-cursor-color) | 561 | (or (stringp viper-saved-cursor-color) |
| 556 | (string= (vip-get-cursor-color) vip-insert-state-cursor-color) | 562 | (string= (viper-get-cursor-color) viper-insert-state-cursor-color) |
| 557 | (setq vip-saved-cursor-color (vip-get-cursor-color))) | 563 | (setq viper-saved-cursor-color (viper-get-cursor-color))) |
| 558 | ;; Commented out, because if vip-change-state-to-insert is executed | 564 | ;; Commented out, because if viper-change-state-to-insert is executed |
| 559 | ;; non-interactively then the old cursor color may get lost. Same old Emacs | 565 | ;; non-interactively then the old cursor color may get lost. Same old Emacs |
| 560 | ;; bug related to local variables? | 566 | ;; bug related to local variables? |
| 561 | ;;;(if (stringp vip-saved-cursor-color) | 567 | ;;;(if (stringp viper-saved-cursor-color) |
| 562 | ;;; (vip-change-cursor-color vip-insert-state-cursor-color)) | 568 | ;;; (viper-change-cursor-color viper-insert-state-cursor-color)) |
| 563 | ;; Protection against user errors in hooks | 569 | ;; Protection against user errors in hooks |
| 564 | (condition-case conds | 570 | (condition-case conds |
| 565 | (run-hooks 'vip-insert-state-hook) | 571 | (run-hooks 'viper-insert-state-hook) |
| 566 | (error | 572 | (error |
| 567 | (vip-message-conditions conds)))) | 573 | (viper-message-conditions conds)))) |
| 568 | 574 | ||
| 569 | (defsubst vip-downgrade-to-insert () | 575 | (defsubst viper-downgrade-to-insert () |
| 570 | (setq vip-current-state 'insert-state | 576 | (setq viper-current-state 'insert-state |
| 571 | vip-replace-minor-mode nil) | 577 | viper-replace-minor-mode nil) |
| 572 | ) | 578 | ) |
| 573 | 579 | ||
| 574 | 580 | ||
| 575 | 581 | ||
| 576 | ;; Change to replace state. When the end of replacement region is reached, | 582 | ;; Change to replace state. When the end of replacement region is reached, |
| 577 | ;; replace state changes to insert state. | 583 | ;; replace state changes to insert state. |
| 578 | (defun vip-change-state-to-replace (&optional non-R-cmd) | 584 | (defun viper-change-state-to-replace (&optional non-R-cmd) |
| 579 | (vip-change-state 'replace-state) | 585 | (viper-change-state 'replace-state) |
| 580 | (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | 586 | (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode)) |
| 581 | (iso-accents-mode 1)) ; turn iso accents on | 587 | (iso-accents-mode 1)) ; turn iso accents on |
| 582 | ;; Run insert-state-hook | 588 | ;; Run insert-state-hook |
| 583 | (condition-case conds | 589 | (condition-case conds |
| 584 | (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook) | 590 | (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook) |
| 585 | (error | 591 | (error |
| 586 | (vip-message-conditions conds))) | 592 | (viper-message-conditions conds))) |
| 587 | 593 | ||
| 588 | (if non-R-cmd | 594 | (if non-R-cmd |
| 589 | (vip-start-replace) | 595 | (viper-start-replace) |
| 590 | ;; 'R' is implemented using Emacs's overwrite-mode | 596 | ;; 'R' is implemented using Emacs's overwrite-mode |
| 591 | (vip-start-R-mode)) | 597 | (viper-start-R-mode)) |
| 592 | ) | 598 | ) |
| 593 | 599 | ||
| 594 | 600 | ||
| 595 | (defun vip-change-state-to-emacs () | 601 | (defun viper-change-state-to-emacs () |
| 596 | "Change Viper state to Emacs." | 602 | "Change Viper state to Emacs." |
| 597 | (interactive) | 603 | (interactive) |
| 598 | (vip-change-state 'emacs-state) | 604 | (viper-change-state 'emacs-state) |
| 599 | (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | 605 | (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode)) |
| 600 | (iso-accents-mode 1)) ; turn iso accents on | 606 | (iso-accents-mode 1)) ; turn iso accents on |
| 601 | 607 | ||
| 602 | ;; Protection agains user errors in hooks | 608 | ;; Protection agains user errors in hooks |
| 603 | (condition-case conds | 609 | (condition-case conds |
| 604 | (run-hooks 'vip-emacs-state-hook) | 610 | (run-hooks 'viper-emacs-state-hook) |
| 605 | (error | 611 | (error |
| 606 | (vip-message-conditions conds)))) | 612 | (viper-message-conditions conds)))) |
| 607 | 613 | ||
| 608 | ;; escape to emacs mode termporarily | 614 | ;; escape to emacs mode termporarily |
| 609 | (defun vip-escape-to-emacs (arg &optional events) | 615 | (defun viper-escape-to-emacs (arg &optional events) |
| 610 | "Escape to Emacs state from Vi state for one Emacs command. | 616 | "Escape to Emacs state from Vi state for one Emacs command. |
| 611 | ARG is used as the prefix value for the executed command. If | 617 | ARG is used as the prefix value for the executed command. If |
| 612 | EVENTS is a list of events, which become the beginning of the command." | 618 | EVENTS is a list of events, which become the beginning of the command." |
| 613 | (interactive "P") | 619 | (interactive "P") |
| 614 | (if (= last-command-char ?\\) | 620 | (if (= last-command-char ?\\) |
| 615 | (message "Switched to EMACS state for the next command...")) | 621 | (message "Switched to EMACS state for the next command...")) |
| 616 | (vip-escape-to-state arg events 'emacs-state)) | 622 | (viper-escape-to-state arg events 'emacs-state)) |
| 617 | 623 | ||
| 618 | ;; escape to Vi mode termporarily | 624 | ;; escape to Vi mode termporarily |
| 619 | (defun vip-escape-to-vi (arg) | 625 | (defun viper-escape-to-vi (arg) |
| 620 | "Escape from Emacs state to Vi state for one Vi 1-character command. | 626 | "Escape from Emacs state to Vi state for one Vi 1-character command. |
| 621 | If the Vi command that the user types has a prefix argument, e.g., `d2w', then | 627 | If the Vi command that the user types has a prefix argument, e.g., `d2w', then |
| 622 | Vi's prefix argument will be used. Otherwise, the prefix argument passed to | 628 | Vi's prefix argument will be used. Otherwise, the prefix argument passed to |
| 623 | `vip-escape-to-vi' is used." | 629 | `viper-escape-to-vi' is used." |
| 624 | (interactive "P") | 630 | (interactive "P") |
| 625 | (message "Switched to VI state for the next command...") | 631 | (message "Switched to VI state for the next command...") |
| 626 | (vip-escape-to-state arg nil 'vi-state)) | 632 | (viper-escape-to-state arg nil 'vi-state)) |
| 627 | 633 | ||
| 628 | ;; Escape to STATE mode for one Emacs command. | 634 | ;; Escape to STATE mode for one Emacs command. |
| 629 | (defun vip-escape-to-state (arg events state) | 635 | (defun viper-escape-to-state (arg events state) |
| 630 | ;;(let (com key prefix-arg) | 636 | ;;(let (com key prefix-arg) |
| 631 | (let (com key) | 637 | (let (com key) |
| 632 | ;; this temporarily turns off Viper's minor mode keymaps | 638 | ;; this temporarily turns off Viper's minor mode keymaps |
| 633 | (vip-set-mode-vars-for state) | 639 | (viper-set-mode-vars-for state) |
| 634 | (vip-normalize-minor-mode-map-alist) | 640 | (viper-normalize-minor-mode-map-alist) |
| 635 | (if events (vip-set-unread-command-events events)) | 641 | (if events (viper-set-unread-command-events events)) |
| 636 | 642 | ||
| 637 | ;; protect against keyboard quit and other errors | 643 | ;; protect against keyboard quit and other errors |
| 638 | (condition-case nil | 644 | (condition-case nil |
| 639 | (let (vip-vi-kbd-minor-mode | 645 | (let (viper-vi-kbd-minor-mode |
| 640 | vip-insert-kbd-minor-mode | 646 | viper-insert-kbd-minor-mode |
| 641 | vip-emacs-kbd-minor-mode) | 647 | viper-emacs-kbd-minor-mode) |
| 642 | (unwind-protect | 648 | (unwind-protect |
| 643 | (progn | 649 | (progn |
| 644 | (setq com (key-binding (setq key | 650 | (setq com (key-binding (setq key |
| 645 | (if vip-xemacs-p | 651 | (if viper-xemacs-p |
| 646 | (read-key-sequence nil) | 652 | (read-key-sequence nil) |
| 647 | (read-key-sequence nil t))))) | 653 | (read-key-sequence nil t))))) |
| 648 | ;; In case of binding indirection--chase definitions. | 654 | ;; In case of binding indirection--chase definitions. |
| @@ -656,15 +662,17 @@ Vi's prefix argument will be used. Otherwise, the prefix argument passed to | |||
| 656 | ;; escaped to command, Viper's mode vars will remain those of | 662 | ;; escaped to command, Viper's mode vars will remain those of |
| 657 | ;; `state'. When we return to the orig buffer, the bindings will be | 663 | ;; `state'. When we return to the orig buffer, the bindings will be |
| 658 | ;; screwed up. | 664 | ;; screwed up. |
| 659 | (vip-set-mode-vars-for vip-current-state) | 665 | (viper-set-mode-vars-for viper-current-state) |
| 660 | 666 | ||
| 661 | ;; this-command, last-command-char, last-command-event | 667 | ;; this-command, last-command-char, last-command-event |
| 662 | (setq this-command com) | 668 | (setq this-command com) |
| 663 | (if vip-xemacs-p ; XEmacs represents key sequences as vectors | 669 | (if viper-xemacs-p ; XEmacs represents key sequences as vectors |
| 664 | (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) | 670 | (setq last-command-event |
| 671 | (viper-copy-event (viper-seq-last-elt key)) | ||
| 665 | last-command-char (event-to-character last-command-event)) | 672 | last-command-char (event-to-character last-command-event)) |
| 666 | ;; Emacs represents them as sequences (str or vec) | 673 | ;; Emacs represents them as sequences (str or vec) |
| 667 | (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) | 674 | (setq last-command-event |
| 675 | (viper-copy-event (viper-seq-last-elt key)) | ||
| 668 | last-command-char last-command-event)) | 676 | last-command-char last-command-event)) |
| 669 | 677 | ||
| 670 | (if (commandp com) | 678 | (if (commandp com) |
| @@ -675,103 +683,105 @@ Vi's prefix argument will be used. Otherwise, the prefix argument passed to | |||
| 675 | (quit (ding)) | 683 | (quit (ding)) |
| 676 | (error (beep 1)))) | 684 | (error (beep 1)))) |
| 677 | ;; set state in the new buffer | 685 | ;; set state in the new buffer |
| 678 | (vip-set-mode-vars-for vip-current-state)) | 686 | (viper-set-mode-vars-for viper-current-state)) |
| 679 | 687 | ||
| 680 | (defun vip-exec-form-in-vi (form) | 688 | (defun viper-exec-form-in-vi (form) |
| 681 | "Execute FORM in Vi state, regardless of the Ccurrent Vi state." | 689 | "Execute FORM in Vi state, regardless of the Ccurrent Vi state." |
| 682 | (let ((buff (current-buffer)) | 690 | (let ((buff (current-buffer)) |
| 683 | result) | 691 | result) |
| 684 | (vip-set-mode-vars-for 'vi-state) | 692 | (viper-set-mode-vars-for 'vi-state) |
| 685 | 693 | ||
| 686 | (condition-case nil | 694 | (condition-case nil |
| 687 | (setq result (eval form)) | 695 | (let (viper-vi-kbd-minor-mode) ; execute without kbd macros |
| 696 | (setq result (eval form)) | ||
| 697 | ) | ||
| 688 | (error | 698 | (error |
| 689 | (signal 'quit nil))) | 699 | (signal 'quit nil))) |
| 690 | 700 | ||
| 691 | (if (not (equal buff (current-buffer))) ; cmd switched buffer | 701 | (if (not (equal buff (current-buffer))) ; cmd switched buffer |
| 692 | (save-excursion | 702 | (save-excursion |
| 693 | (set-buffer buff) | 703 | (set-buffer buff) |
| 694 | (vip-set-mode-vars-for vip-current-state))) | 704 | (viper-set-mode-vars-for viper-current-state))) |
| 695 | (vip-set-mode-vars-for vip-current-state) | 705 | (viper-set-mode-vars-for viper-current-state) |
| 696 | result)) | 706 | result)) |
| 697 | 707 | ||
| 698 | (defun vip-exec-form-in-emacs (form) | 708 | (defun viper-exec-form-in-emacs (form) |
| 699 | "Execute FORM in Emacs, temporarily disabling Viper's minor modes. | 709 | "Execute FORM in Emacs, temporarily disabling Viper's minor modes. |
| 700 | Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes." | 710 | Similar to viper-escape-to-emacs, but accepts forms rather than keystrokes." |
| 701 | (let ((buff (current-buffer)) | 711 | (let ((buff (current-buffer)) |
| 702 | result) | 712 | result) |
| 703 | (vip-set-mode-vars-for 'emacs-state) | 713 | (viper-set-mode-vars-for 'emacs-state) |
| 704 | (setq result (eval form)) | 714 | (setq result (eval form)) |
| 705 | (if (not (equal buff (current-buffer))) ; cmd switched buffer | 715 | (if (not (equal buff (current-buffer))) ; cmd switched buffer |
| 706 | (save-excursion | 716 | (save-excursion |
| 707 | (set-buffer buff) | 717 | (set-buffer buff) |
| 708 | (vip-set-mode-vars-for vip-current-state))) | 718 | (viper-set-mode-vars-for viper-current-state))) |
| 709 | (vip-set-mode-vars-for vip-current-state) | 719 | (viper-set-mode-vars-for viper-current-state) |
| 710 | result)) | 720 | result)) |
| 711 | 721 | ||
| 712 | 722 | ||
| 713 | ;; This is needed because minor modes sometimes override essential Viper | 723 | ;; This is needed because minor modes sometimes override essential Viper |
| 714 | ;; bindings. By letting Viper know which files these modes are in, it will | 724 | ;; bindings. By letting Viper know which files these modes are in, it will |
| 715 | ;; arrange to reorganize minor-mode-map-alist so that things will work right. | 725 | ;; arrange to reorganize minor-mode-map-alist so that things will work right. |
| 716 | (defun vip-harness-minor-mode (load-file) | 726 | (defun viper-harness-minor-mode (load-file) |
| 717 | "Familiarize Viper with a minor mode defined in LOAD_FILE. | 727 | "Familiarize Viper with a minor mode defined in LOAD_FILE. |
| 718 | Minor modes that have their own keymaps may overshadow Viper keymaps. | 728 | Minor modes that have their own keymaps may overshadow Viper keymaps. |
| 719 | This function is designed to make Viper aware of the packages that define | 729 | This function is designed to make Viper aware of the packages that define |
| 720 | such minor modes. | 730 | such minor modes. |
| 721 | Usage: | 731 | Usage: |
| 722 | (vip-harness-minor-mode load-file) | 732 | (viper-harness-minor-mode load-file) |
| 723 | 733 | ||
| 724 | LOAD-FILE is a name of the file where the specific minor mode is defined. | 734 | LOAD-FILE is a name of the file where the specific minor mode is defined. |
| 725 | Suffixes such as .el or .elc should be stripped." | 735 | Suffixes such as .el or .elc should be stripped." |
| 726 | 736 | ||
| 727 | (interactive "sEnter name of the load file: ") | 737 | (interactive "sEnter name of the load file: ") |
| 728 | 738 | ||
| 729 | (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist)) | 739 | (eval-after-load load-file '(viper-normalize-minor-mode-map-alist)) |
| 730 | 740 | ||
| 731 | ;; Change the default for minor-mode-map-alist each time a harnessed minor | 741 | ;; Change the default for minor-mode-map-alist each time a harnessed minor |
| 732 | ;; mode adds its own keymap to the a-list. | 742 | ;; mode adds its own keymap to the a-list. |
| 733 | (vip-eval-after-load | 743 | (eval-after-load |
| 734 | load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) | 744 | load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) |
| 735 | ) | 745 | ) |
| 736 | 746 | ||
| 737 | 747 | ||
| 738 | (defun vip-ESC (arg) | 748 | (defun viper-ESC (arg) |
| 739 | "Emulate ESC key in Emacs. | 749 | "Emulate ESC key in Emacs. |
| 740 | Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. | 750 | Prevents multiple escape keystrokes if viper-no-multiple-ESC is true. |
| 741 | If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state. | 751 | If viper-no-multiple-ESC is 'twice double ESC would ding in vi-state. |
| 742 | Other ESC sequences are emulated via the current Emacs's major mode | 752 | Other ESC sequences are emulated via the current Emacs's major mode |
| 743 | keymap. This is more convenient on TTYs, since this won't block | 753 | keymap. This is more convenient on TTYs, since this won't block |
| 744 | function keys such as up,down, etc. ESC will also will also work as | 754 | function keys such as up,down, etc. ESC will also will also work as |
| 745 | a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions | 755 | a Meta key in this case. When viper-no-multiple-ESC is nil, ESC functions |
| 746 | as a Meta key and any number of multiple escapes is allowed." | 756 | as a Meta key and any number of multiple escapes is allowed." |
| 747 | (interactive "P") | 757 | (interactive "P") |
| 748 | (let (char) | 758 | (let (char) |
| 749 | (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state)) | 759 | (cond ((and (not viper-no-multiple-ESC) (eq viper-current-state 'vi-state)) |
| 750 | (setq char (vip-read-char-exclusive)) | 760 | (setq char (viper-read-char-exclusive)) |
| 751 | (vip-escape-to-emacs arg (list ?\e char) )) | 761 | (viper-escape-to-emacs arg (list ?\e char) )) |
| 752 | ((and (eq vip-no-multiple-ESC 'twice) | 762 | ((and (eq viper-no-multiple-ESC 'twice) |
| 753 | (eq vip-current-state 'vi-state)) | 763 | (eq viper-current-state 'vi-state)) |
| 754 | (setq char (vip-read-char-exclusive)) | 764 | (setq char (viper-read-char-exclusive)) |
| 755 | (if (= char (string-to-char vip-ESC-key)) | 765 | (if (= char (string-to-char viper-ESC-key)) |
| 756 | (ding) | 766 | (ding) |
| 757 | (vip-escape-to-emacs arg (list ?\e char) ))) | 767 | (viper-escape-to-emacs arg (list ?\e char) ))) |
| 758 | (t (ding))) | 768 | (t (ding))) |
| 759 | )) | 769 | )) |
| 760 | 770 | ||
| 761 | (defun vip-alternate-Meta-key (arg) | 771 | (defun viper-alternate-Meta-key (arg) |
| 762 | "Simulate Emacs Meta key." | 772 | "Simulate Emacs Meta key." |
| 763 | (interactive "P") | 773 | (interactive "P") |
| 764 | (sit-for 1) (message "ESC-") | 774 | (sit-for 1) (message "ESC-") |
| 765 | (vip-escape-to-emacs arg '(?\e))) | 775 | (viper-escape-to-emacs arg '(?\e))) |
| 766 | 776 | ||
| 767 | (defun vip-toggle-key-action () | 777 | (defun viper-toggle-key-action () |
| 768 | "Action bound to `vip-toggle-key'." | 778 | "Action bound to `viper-toggle-key'." |
| 769 | (interactive) | 779 | (interactive) |
| 770 | (if (and (< viper-expert-level 2) (equal vip-toggle-key "\C-z")) | 780 | (if (and (< viper-expert-level 2) (equal viper-toggle-key "\C-z")) |
| 771 | (if (vip-window-display-p) | 781 | (if (viper-window-display-p) |
| 772 | (vip-iconify) | 782 | (viper-iconify) |
| 773 | (suspend-emacs)) | 783 | (suspend-emacs)) |
| 774 | (vip-change-state-to-emacs))) | 784 | (viper-change-state-to-emacs))) |
| 775 | 785 | ||
| 776 | 786 | ||
| 777 | ;; Intercept ESC sequences on dumb terminals. | 787 | ;; Intercept ESC sequences on dumb terminals. |
| @@ -780,16 +790,16 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 780 | ;; Check if last key was ESC and if so try to reread it as a function key. | 790 | ;; Check if last key was ESC and if so try to reread it as a function key. |
| 781 | ;; But only if there are characters to read during a very short time. | 791 | ;; But only if there are characters to read during a very short time. |
| 782 | ;; Returns the last event, if any. | 792 | ;; Returns the last event, if any. |
| 783 | (defun vip-envelop-ESC-key () | 793 | (defun viper-envelop-ESC-key () |
| 784 | (let ((event last-input-event) | 794 | (let ((event last-input-event) |
| 785 | (keyseq [nil]) | 795 | (keyseq [nil]) |
| 786 | inhibit-quit) | 796 | inhibit-quit) |
| 787 | (if (vip-ESC-event-p event) | 797 | (if (viper-ESC-event-p event) |
| 788 | (progn | 798 | (progn |
| 789 | (if (vip-fast-keysequence-p) | 799 | (if (viper-fast-keysequence-p) |
| 790 | (progn | 800 | (progn |
| 791 | (let (minor-mode-map-alist) | 801 | (let (minor-mode-map-alist) |
| 792 | (vip-set-unread-command-events event) | 802 | (viper-set-unread-command-events event) |
| 793 | (setq keyseq | 803 | (setq keyseq |
| 794 | (funcall | 804 | (funcall |
| 795 | (ad-get-orig-definition 'read-key-sequence) nil)) | 805 | (ad-get-orig-definition 'read-key-sequence) nil)) |
| @@ -812,37 +822,38 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 812 | ;; If `first-key' is not an ESC event, we make it into the | 822 | ;; If `first-key' is not an ESC event, we make it into the |
| 813 | ;; last-command-event in order to pretend that this key was | 823 | ;; last-command-event in order to pretend that this key was |
| 814 | ;; pressed. This is needed to allow arrow keys to be bound to | 824 | ;; pressed. This is needed to allow arrow keys to be bound to |
| 815 | ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that | 825 | ;; macros. Otherwise, viper-exec-mapped-kbd-macro will think |
| 816 | ;; the last event was ESC and so it'll execute whatever is | 826 | ;; that the last event was ESC and so it'll execute whatever is |
| 817 | ;; bound to ESC. (Viper macros can't be bound to | 827 | ;; bound to ESC. (Viper macros can't be bound to |
| 818 | ;; ESC-sequences). | 828 | ;; ESC-sequences). |
| 819 | (let* ((first-key (elt keyseq 0)) | 829 | (let* ((first-key (elt keyseq 0)) |
| 820 | (key-mod (event-modifiers first-key))) | 830 | (key-mod (event-modifiers first-key))) |
| 821 | (cond ((vip-ESC-event-p first-key) | 831 | (cond ((viper-ESC-event-p first-key) |
| 822 | ;; put keys following ESC on the unread list | 832 | ;; put keys following ESC on the unread list |
| 823 | ;; and return ESC as the key-sequence | 833 | ;; and return ESC as the key-sequence |
| 824 | (vip-set-unread-command-events (subseq keyseq 1)) | 834 | (viper-set-unread-command-events (subseq keyseq 1)) |
| 825 | (setq last-input-event event | 835 | (setq last-input-event event |
| 826 | keyseq (if vip-emacs-p | 836 | keyseq (if viper-emacs-p |
| 827 | "\e" | 837 | "\e" |
| 828 | (vector (character-to-event ?\e))))) | 838 | (vector (character-to-event ?\e))))) |
| 829 | ((and vip-xemacs-p | 839 | ((and viper-xemacs-p |
| 830 | (key-press-event-p first-key) | 840 | (key-press-event-p first-key) |
| 831 | (equal '(meta) key-mod)) | 841 | (equal '(meta) key-mod)) |
| 832 | (vip-set-unread-command-events | 842 | (viper-set-unread-command-events |
| 833 | (vconcat (vector | 843 | (vconcat (vector |
| 834 | (character-to-event (event-key first-key))) | 844 | (character-to-event (event-key first-key))) |
| 835 | (subseq keyseq 1))) | 845 | (subseq keyseq 1))) |
| 836 | (setq last-input-event event | 846 | (setq last-input-event event |
| 837 | keyseq (vector (character-to-event ?\e)))) | 847 | keyseq (vector (character-to-event ?\e)))) |
| 838 | ((eventp first-key) | 848 | ((eventp first-key) |
| 839 | (setq last-command-event (vip-copy-event first-key))) | 849 | (setq last-command-event |
| 850 | (viper-copy-event first-key))) | ||
| 840 | )) | 851 | )) |
| 841 | ) ; end progn | 852 | ) ; end progn |
| 842 | 853 | ||
| 843 | ;; this is escape event with nothing after it | 854 | ;; this is escape event with nothing after it |
| 844 | ;; put in unread-command-event and then re-read | 855 | ;; put in unread-command-event and then re-read |
| 845 | (vip-set-unread-command-events event) | 856 | (viper-set-unread-command-events event) |
| 846 | (setq keyseq | 857 | (setq keyseq |
| 847 | (funcall (ad-get-orig-definition 'read-key-sequence) nil)) | 858 | (funcall (ad-get-orig-definition 'read-key-sequence) nil)) |
| 848 | )) | 859 | )) |
| @@ -855,24 +866,24 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 855 | ;; Listen to ESC key. | 866 | ;; Listen to ESC key. |
| 856 | ;; If a sequence of keys starting with ESC is issued with very short delays, | 867 | ;; If a sequence of keys starting with ESC is issued with very short delays, |
| 857 | ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. | 868 | ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. |
| 858 | (defun vip-intercept-ESC-key () | 869 | (defun viper-intercept-ESC-key () |
| 859 | "Function that implements ESC key in Viper emulation of Vi." | 870 | "Function that implements ESC key in Viper emulation of Vi." |
| 860 | (interactive) | 871 | (interactive) |
| 861 | (let ((cmd (or (key-binding (vip-envelop-ESC-key)) | 872 | (let ((cmd (or (key-binding (viper-envelop-ESC-key)) |
| 862 | '(lambda () (interactive) (error ""))))) | 873 | '(lambda () (interactive) (error ""))))) |
| 863 | 874 | ||
| 864 | ;; call the actual function to execute ESC (if no other symbols followed) | 875 | ;; call the actual function to execute ESC (if no other symbols followed) |
| 865 | ;; or the key bound to the ESC sequence (if the sequence was issued | 876 | ;; or the key bound to the ESC sequence (if the sequence was issued |
| 866 | ;; with very short delay between characters. | 877 | ;; with very short delay between characters. |
| 867 | (if (eq cmd 'vip-intercept-ESC-key) | 878 | (if (eq cmd 'viper-intercept-ESC-key) |
| 868 | (setq cmd | 879 | (setq cmd |
| 869 | (cond ((eq vip-current-state 'vi-state) | 880 | (cond ((eq viper-current-state 'vi-state) |
| 870 | 'vip-ESC) | 881 | 'viper-ESC) |
| 871 | ((eq vip-current-state 'insert-state) | 882 | ((eq viper-current-state 'insert-state) |
| 872 | 'vip-exit-insert-state) | 883 | 'viper-exit-insert-state) |
| 873 | ((eq vip-current-state 'replace-state) | 884 | ((eq viper-current-state 'replace-state) |
| 874 | 'vip-replace-state-exit-cmd) | 885 | 'viper-replace-state-exit-cmd) |
| 875 | (t 'vip-change-state-to-vi) | 886 | (t 'viper-change-state-to-vi) |
| 876 | ))) | 887 | ))) |
| 877 | (call-interactively cmd))) | 888 | (call-interactively cmd))) |
| 878 | 889 | ||
| @@ -886,7 +897,7 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 886 | ;; command prefix such as "c", "d", "m" and "y". | 897 | ;; command prefix such as "c", "d", "m" and "y". |
| 887 | 898 | ||
| 888 | ;; Get value part of prefix-argument ARG. | 899 | ;; Get value part of prefix-argument ARG. |
| 889 | (defsubst vip-p-val (arg) | 900 | (defsubst viper-p-val (arg) |
| 890 | (cond ((null arg) 1) | 901 | (cond ((null arg) 1) |
| 891 | ((consp arg) | 902 | ((consp arg) |
| 892 | (if (or (null (car arg)) (equal (car arg) '(nil))) | 903 | (if (or (null (car arg)) (equal (car arg) '(nil))) |
| @@ -894,20 +905,23 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 894 | (t arg))) | 905 | (t arg))) |
| 895 | 906 | ||
| 896 | ;; Get raw value part of prefix-argument ARG. | 907 | ;; Get raw value part of prefix-argument ARG. |
| 897 | (defsubst vip-P-val (arg) | 908 | (defsubst viper-P-val (arg) |
| 898 | (cond ((consp arg) (car arg)) | 909 | (cond ((consp arg) (car arg)) |
| 899 | (t arg))) | 910 | (t arg))) |
| 900 | 911 | ||
| 901 | ;; Get com part of prefix-argument ARG. | 912 | ;; Get com part of prefix-argument ARG. |
| 902 | (defsubst vip-getcom (arg) | 913 | (defsubst viper-getcom (arg) |
| 903 | (cond ((null arg) nil) | 914 | (cond ((null arg) nil) |
| 904 | ((consp arg) (cdr arg)) | 915 | ((consp arg) (cdr arg)) |
| 905 | (t nil))) | 916 | (t nil))) |
| 906 | 917 | ||
| 907 | ;; Get com part of prefix-argument ARG and modify it. | 918 | ;; Get com part of prefix-argument ARG and modify it. |
| 908 | (defun vip-getCom (arg) | 919 | (defun viper-getCom (arg) |
| 909 | (let ((com (vip-getcom arg))) | 920 | (let ((com (viper-getcom arg))) |
| 910 | (cond ((equal com ?c) ?C) | 921 | (cond ((equal com ?c) ?c) |
| 922 | ;; Previously, ?c was being converted to ?C, but this prevented | ||
| 923 | ;; multiline replace regions. | ||
| 924 | ;;((equal com ?c) ?C) | ||
| 911 | ((equal com ?d) ?D) | 925 | ((equal com ?d) ?D) |
| 912 | ((equal com ?y) ?Y) | 926 | ((equal com ?y) ?Y) |
| 913 | (t com)))) | 927 | (t com)))) |
| @@ -915,56 +929,61 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 915 | 929 | ||
| 916 | ;; Compute numeric prefix arg value. | 930 | ;; Compute numeric prefix arg value. |
| 917 | ;; Invoked by EVENT. COM is the command part obtained so far. | 931 | ;; Invoked by EVENT. COM is the command part obtained so far. |
| 918 | (defun vip-prefix-arg-value (event com) | 932 | (defun viper-prefix-arg-value (event com) |
| 919 | (let (value func) | 933 | (let ((viper-intermediate-command 'viper-digit-argument) |
| 934 | value func) | ||
| 920 | ;; read while number | 935 | ;; read while number |
| 921 | (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) | 936 | (while (and (viper-characterp event) (>= event ?0) (<= event ?9)) |
| 922 | (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0))) | 937 | (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0))) |
| 923 | (setq event (vip-read-event-convert-to-char))) | 938 | (setq event (viper-read-event-convert-to-char))) |
| 924 | 939 | ||
| 925 | (setq prefix-arg value) | 940 | (setq prefix-arg value) |
| 926 | (if com (setq prefix-arg (cons prefix-arg com))) | 941 | (if com (setq prefix-arg (cons prefix-arg com))) |
| 927 | (while (eq event ?U) | 942 | (while (eq event ?U) |
| 928 | (vip-describe-arg prefix-arg) | 943 | (viper-describe-arg prefix-arg) |
| 929 | (setq event (vip-read-event-convert-to-char))) | 944 | (setq event (viper-read-event-convert-to-char))) |
| 930 | 945 | ||
| 931 | (if (or com (and (not (eq vip-current-state 'vi-state)) | 946 | (if (or com (and (not (eq viper-current-state 'vi-state)) |
| 932 | ;; make sure it is a Vi command | 947 | ;; make sure it is a Vi command |
| 933 | (vip-characterp event) (vip-vi-command-p event) | 948 | (viper-characterp event) (viper-vi-command-p event) |
| 934 | )) | 949 | )) |
| 935 | ;; If appears to be one of the vi commands, | 950 | ;; If appears to be one of the vi commands, |
| 936 | ;; then execute it with funcall and clear prefix-arg in order to not | 951 | ;; then execute it with funcall and clear prefix-arg in order to not |
| 937 | ;; confuse subsequent commands | 952 | ;; confuse subsequent commands |
| 938 | (progn | 953 | (progn |
| 939 | ;; last-command-char is the char we want emacs to think was typed | 954 | ;; last-command-char is the char we want emacs to think was typed |
| 940 | ;; last. If com is not nil, the vip-digit-argument command was called | 955 | ;; last. If com is not nil, the viper-digit-argument command was |
| 941 | ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e., | 956 | ;; called from within viper-prefix-arg command, such as `d', `w', |
| 942 | ;; the user typed, say, d2. In this case, `com' would be `d', `w', | 957 | ;; etc., i.e., the user typed, say, d2. In this case, `com' would be |
| 943 | ;; etc. | 958 | ;; `d', `w', etc. If viper-digit-argument was invoked by |
| 944 | ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is | 959 | ;; viper-escape-to-vi (which is indicated by the fact that the |
| 945 | ;; indicated by the fact that the current state is not vi-state), | 960 | ;; current state is not vi-state), then `event' represents the vi |
| 946 | ;; then `event' represents the vi command to be executed (e.g., `d', | 961 | ;; command to be executed (e.g., `d', `w', etc). Again, |
| 947 | ;; `w', etc). Again, last-command-char must make emacs believe that | 962 | ;; last-command-char must make emacs believe that this is the command |
| 948 | ;; this is the command we typed. | 963 | ;; we typed. |
| 964 | (cond ((eq event 'return) (setq event ?\C-m)) | ||
| 965 | ((eq event 'delete) (setq event ?\C-?)) | ||
| 966 | ((eq event 'backspace) (setq event ?\C-h)) | ||
| 967 | ((eq event 'space) (setq event ?\ ))) | ||
| 949 | (setq last-command-char (or com event)) | 968 | (setq last-command-char (or com event)) |
| 950 | (setq func (vip-exec-form-in-vi | 969 | (setq func (viper-exec-form-in-vi |
| 951 | (` (key-binding (char-to-string (, event)))))) | 970 | (` (key-binding (char-to-string (, event)))))) |
| 952 | (funcall func prefix-arg) | 971 | (funcall func prefix-arg) |
| 953 | (setq prefix-arg nil)) | 972 | (setq prefix-arg nil)) |
| 954 | ;; some other command -- let emacs do it in its own way | 973 | ;; some other command -- let emacs do it in its own way |
| 955 | (vip-set-unread-command-events event)) | 974 | (viper-set-unread-command-events event)) |
| 956 | )) | 975 | )) |
| 957 | 976 | ||
| 958 | 977 | ||
| 959 | ;; Vi operator as prefix argument." | 978 | ;; Vi operator as prefix argument." |
| 960 | (defun vip-prefix-arg-com (char value com) | 979 | (defun viper-prefix-arg-com (char value com) |
| 961 | (let ((cont t) | 980 | (let ((cont t) |
| 962 | cmd-info | 981 | cmd-info |
| 963 | cmd-to-exec-at-end) | 982 | cmd-to-exec-at-end) |
| 964 | (while (and cont | 983 | (while (and cont |
| 965 | (memq char | 984 | (memq char |
| 966 | (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" | 985 | (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" |
| 967 | vip-buffer-search-char))) | 986 | viper-buffer-search-char))) |
| 968 | (if com | 987 | (if com |
| 969 | ;; this means that we already have a command character, so we | 988 | ;; this means that we already have a command character, so we |
| 970 | ;; construct a com list and exit while. however, if char is " | 989 | ;; construct a com list and exit while. however, if char is " |
| @@ -974,10 +993,10 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 974 | (if (memq char '(?# ?\")) (error "")) | 993 | (if (memq char '(?# ?\")) (error "")) |
| 975 | (setq com (cons char com)) | 994 | (setq com (cons char com)) |
| 976 | (setq cont nil)) | 995 | (setq cont nil)) |
| 977 | ;; If com is nil we set com as char, and read more. Again, if char | 996 | ;; If com is nil we set com as char, and read more. Again, if char is |
| 978 | ;; is ", we read the name of register and store it in vip-use-register. | 997 | ;; ", we read the name of register and store it in viper-use-register. |
| 979 | ;; if char is !, =, or #, a complete com is formed so we exit the | 998 | ;; if char is !, =, or #, a complete com is formed so we exit the while |
| 980 | ;; while loop. | 999 | ;; loop. |
| 981 | (cond ((memq char '(?! ?=)) | 1000 | (cond ((memq char '(?! ?=)) |
| 982 | (setq com char) | 1001 | (setq com char) |
| 983 | (setq char (read-char)) | 1002 | (setq char (read-char)) |
| @@ -988,8 +1007,8 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 988 | (setq char (read-char))) | 1007 | (setq char (read-char))) |
| 989 | ((= char ?\") | 1008 | ((= char ?\") |
| 990 | (let ((reg (read-char))) | 1009 | (let ((reg (read-char))) |
| 991 | (if (vip-valid-register reg) | 1010 | (if (viper-valid-register reg) |
| 992 | (setq vip-use-register reg) | 1011 | (setq viper-use-register reg) |
| 993 | (error "")) | 1012 | (error "")) |
| 994 | (setq char (read-char)))) | 1013 | (setq char (read-char)))) |
| 995 | (t | 1014 | (t |
| @@ -1003,17 +1022,17 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 1003 | (progn | 1022 | (progn |
| 1004 | (setq cmd-info (cons value com)) | 1023 | (setq cmd-info (cons value com)) |
| 1005 | (while (= char ?U) | 1024 | (while (= char ?U) |
| 1006 | (vip-describe-arg cmd-info) | 1025 | (viper-describe-arg cmd-info) |
| 1007 | (setq char (read-char))) | 1026 | (setq char (read-char))) |
| 1008 | ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we | 1027 | ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we |
| 1009 | ;; execute it at the very end | 1028 | ;; execute it at the very end |
| 1010 | (or (vip-movement-command-p char) | 1029 | (or (viper-movement-command-p char) |
| 1011 | (vip-digit-command-p char) | 1030 | (viper-digit-command-p char) |
| 1012 | (vip-regsuffix-command-p char) | 1031 | (viper-regsuffix-command-p char) |
| 1013 | (= char ?!) ; bang command | 1032 | (= char ?!) ; bang command |
| 1014 | (error "")) | 1033 | (error "")) |
| 1015 | (setq cmd-to-exec-at-end | 1034 | (setq cmd-to-exec-at-end |
| 1016 | (vip-exec-form-in-vi | 1035 | (viper-exec-form-in-vi |
| 1017 | (` (key-binding (char-to-string (, char))))))) | 1036 | (` (key-binding (char-to-string (, char))))))) |
| 1018 | 1037 | ||
| 1019 | ;; as com is non-nil, this means that we have a command to execute | 1038 | ;; as com is non-nil, this means that we have a command to execute |
| @@ -1021,39 +1040,44 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 1021 | ;; execute apropriate region command. | 1040 | ;; execute apropriate region command. |
| 1022 | (let ((char (car com)) (com (cdr com))) | 1041 | (let ((char (car com)) (com (cdr com))) |
| 1023 | (setq prefix-arg (cons value com)) | 1042 | (setq prefix-arg (cons value com)) |
| 1024 | (if (= char ?r) (vip-region prefix-arg) | 1043 | (if (= char ?r) (viper-region prefix-arg) |
| 1025 | (vip-Region prefix-arg)) | 1044 | (viper-Region prefix-arg)) |
| 1026 | ;; reset prefix-arg | 1045 | ;; reset prefix-arg |
| 1027 | (setq prefix-arg nil)) | 1046 | (setq prefix-arg nil)) |
| 1028 | ;; otherwise, reset prefix arg and call appropriate command | 1047 | ;; otherwise, reset prefix arg and call appropriate command |
| 1029 | (setq value (if (null value) 1 value)) | 1048 | (setq value (if (null value) 1 value)) |
| 1030 | (setq prefix-arg nil) | 1049 | (setq prefix-arg nil) |
| 1031 | (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C))) | 1050 | (cond |
| 1032 | ((equal com '(?d . ?d)) (vip-line (cons value ?D))) | 1051 | ;; If we change ?C to ?c here, then cc will enter replacement mode |
| 1033 | ((equal com '(?d . ?y)) (vip-yank-defun)) | 1052 | ;; rather than deleting lines. However, it will affect 1 less line than |
| 1034 | ((equal com '(?y . ?y)) (vip-line (cons value ?Y))) | 1053 | ;; normal. We decided to not use replacement mode here and follow Vi, |
| 1035 | ((equal com '(?< . ?<)) (vip-line (cons value ?<))) | 1054 | ;; since replacement mode on n full lines can be achieved with nC. |
| 1036 | ((equal com '(?> . ?>)) (vip-line (cons value ?>))) | 1055 | ((equal com '(?c . ?c)) (viper-line (cons value ?C))) |
| 1037 | ((equal com '(?! . ?!)) (vip-line (cons value ?!))) | 1056 | ((equal com '(?d . ?d)) (viper-line (cons value ?D))) |
| 1038 | ((equal com '(?= . ?=)) (vip-line (cons value ?=))) | 1057 | ((equal com '(?d . ?y)) (viper-yank-defun)) |
| 1039 | (t (error ""))))) | 1058 | ((equal com '(?y . ?y)) (viper-line (cons value ?Y))) |
| 1059 | ((equal com '(?< . ?<)) (viper-line (cons value ?<))) | ||
| 1060 | ((equal com '(?> . ?>)) (viper-line (cons value ?>))) | ||
| 1061 | ((equal com '(?! . ?!)) (viper-line (cons value ?!))) | ||
| 1062 | ((equal com '(?= . ?=)) (viper-line (cons value ?=))) | ||
| 1063 | (t (error ""))))) | ||
| 1040 | 1064 | ||
| 1041 | (if cmd-to-exec-at-end | 1065 | (if cmd-to-exec-at-end |
| 1042 | (progn | 1066 | (progn |
| 1043 | (setq last-command-char char) | 1067 | (setq last-command-char char) |
| 1044 | (setq last-command-event | 1068 | (setq last-command-event |
| 1045 | (vip-copy-event | 1069 | (viper-copy-event |
| 1046 | (if vip-xemacs-p (character-to-event char) char))) | 1070 | (if viper-xemacs-p (character-to-event char) char))) |
| 1047 | (condition-case nil | 1071 | (condition-case nil |
| 1048 | (funcall cmd-to-exec-at-end cmd-info) | 1072 | (funcall cmd-to-exec-at-end cmd-info) |
| 1049 | (error | 1073 | (error |
| 1050 | (error ""))))) | 1074 | (error ""))))) |
| 1051 | )) | 1075 | )) |
| 1052 | 1076 | ||
| 1053 | (defun vip-describe-arg (arg) | 1077 | (defun viper-describe-arg (arg) |
| 1054 | (let (val com) | 1078 | (let (val com) |
| 1055 | (setq val (vip-P-val arg) | 1079 | (setq val (viper-P-val arg) |
| 1056 | com (vip-getcom arg)) | 1080 | com (viper-getcom arg)) |
| 1057 | (if (null val) | 1081 | (if (null val) |
| 1058 | (if (null com) | 1082 | (if (null com) |
| 1059 | (message "Value is nil, and command is nil") | 1083 | (message "Value is nil, and command is nil") |
| @@ -1062,280 +1086,285 @@ as a Meta key and any number of multiple escapes is allowed." | |||
| 1062 | (message "Value is `%d', and command is nil" val) | 1086 | (message "Value is `%d', and command is nil" val) |
| 1063 | (message "Value is `%d', and command is `%c'" val com))))) | 1087 | (message "Value is `%d', and command is `%c'" val com))))) |
| 1064 | 1088 | ||
| 1065 | (defun vip-digit-argument (arg) | 1089 | (defun viper-digit-argument (arg) |
| 1066 | "Begin numeric argument for the next command." | 1090 | "Begin numeric argument for the next command." |
| 1067 | (interactive "P") | 1091 | (interactive "P") |
| 1068 | (vip-leave-region-active) | 1092 | (viper-leave-region-active) |
| 1069 | (vip-prefix-arg-value | 1093 | (viper-prefix-arg-value |
| 1070 | last-command-char (if (consp arg) (cdr arg) nil))) | 1094 | last-command-char (if (consp arg) (cdr arg) nil))) |
| 1071 | 1095 | ||
| 1072 | (defun vip-command-argument (arg) | 1096 | (defun viper-command-argument (arg) |
| 1073 | "Accept a motion command as an argument." | 1097 | "Accept a motion command as an argument." |
| 1074 | (interactive "P") | 1098 | (interactive "P") |
| 1075 | (let ((vip-inside-command-argument-action t)) | 1099 | (let ((viper-intermediate-command 'viper-command-argument)) |
| 1076 | (condition-case nil | 1100 | (condition-case nil |
| 1077 | (vip-prefix-arg-com | 1101 | (viper-prefix-arg-com |
| 1078 | last-command-char | 1102 | last-command-char |
| 1079 | (cond ((null arg) nil) | 1103 | (cond ((null arg) nil) |
| 1080 | ((consp arg) (car arg)) | 1104 | ((consp arg) (car arg)) |
| 1081 | ((integerp arg) arg) | 1105 | ((integerp arg) arg) |
| 1082 | (t (error vip-InvalidCommandArgument))) | 1106 | (t (error viper-InvalidCommandArgument))) |
| 1083 | (cond ((null arg) nil) | 1107 | (cond ((null arg) nil) |
| 1084 | ((consp arg) (cdr arg)) | 1108 | ((consp arg) (cdr arg)) |
| 1085 | ((integerp arg) nil) | 1109 | ((integerp arg) nil) |
| 1086 | (t (error vip-InvalidCommandArgument)))) | 1110 | (t (error viper-InvalidCommandArgument)))) |
| 1087 | (quit (setq vip-use-register nil) | 1111 | (quit (setq viper-use-register nil) |
| 1088 | (signal 'quit nil))) | 1112 | (signal 'quit nil))) |
| 1089 | (vip-deactivate-mark))) | 1113 | (viper-deactivate-mark))) |
| 1090 | 1114 | ||
| 1091 | 1115 | ||
| 1092 | ;; repeat last destructive command | 1116 | ;; repeat last destructive command |
| 1093 | 1117 | ||
| 1094 | ;; Append region to text in register REG. | 1118 | ;; Append region to text in register REG. |
| 1095 | ;; START and END are buffer positions indicating what to append. | 1119 | ;; START and END are buffer positions indicating what to append. |
| 1096 | (defsubst vip-append-to-register (reg start end) | 1120 | (defsubst viper-append-to-register (reg start end) |
| 1097 | (set-register reg (concat (if (stringp (get-register reg)) | 1121 | (set-register reg (concat (if (stringp (get-register reg)) |
| 1098 | (get-register reg) "") | 1122 | (get-register reg) "") |
| 1099 | (buffer-substring start end)))) | 1123 | (buffer-substring start end)))) |
| 1100 | 1124 | ||
| 1101 | ;; Saves last inserted text for possible use by vip-repeat command. | 1125 | ;; Saves last inserted text for possible use by viper-repeat command. |
| 1102 | (defun vip-save-last-insertion (beg end) | 1126 | (defun viper-save-last-insertion (beg end) |
| 1103 | (setq vip-last-insertion (buffer-substring beg end)) | 1127 | (setq viper-last-insertion (buffer-substring beg end)) |
| 1104 | (or (< (length vip-d-com) 5) | 1128 | (or (< (length viper-d-com) 5) |
| 1105 | (setcar (nthcdr 4 vip-d-com) vip-last-insertion)) | 1129 | (setcar (nthcdr 4 viper-d-com) viper-last-insertion)) |
| 1106 | (or (null vip-command-ring) | 1130 | (or (null viper-command-ring) |
| 1107 | (ring-empty-p vip-command-ring) | 1131 | (ring-empty-p viper-command-ring) |
| 1108 | (progn | 1132 | (progn |
| 1109 | (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring)) | 1133 | (setcar (nthcdr 4 (viper-current-ring-item viper-command-ring)) |
| 1110 | vip-last-insertion) | 1134 | viper-last-insertion) |
| 1111 | ;; del most recent elt, if identical to the second most-recent | 1135 | ;; del most recent elt, if identical to the second most-recent |
| 1112 | (vip-cleanup-ring vip-command-ring))) | 1136 | (viper-cleanup-ring viper-command-ring))) |
| 1113 | ) | 1137 | ) |
| 1114 | 1138 | ||
| 1115 | (defsubst vip-yank-last-insertion () | 1139 | (defsubst viper-yank-last-insertion () |
| 1116 | "Inserts the text saved by the previous vip-save-last-insertion command." | 1140 | "Inserts the text saved by the previous viper-save-last-insertion command." |
| 1117 | (condition-case nil | 1141 | (condition-case nil |
| 1118 | (insert vip-last-insertion) | 1142 | (insert viper-last-insertion) |
| 1119 | (error nil))) | 1143 | (error nil))) |
| 1120 | 1144 | ||
| 1121 | 1145 | ||
| 1122 | ;; define functions to be executed | 1146 | ;; define functions to be executed |
| 1123 | 1147 | ||
| 1124 | ;; invoked by the `C' command | 1148 | ;; invoked by the `C' command |
| 1125 | (defun vip-exec-change (m-com com) | 1149 | (defun viper-exec-change (m-com com) |
| 1126 | (or (and (markerp vip-com-point) (marker-position vip-com-point)) | 1150 | (or (and (markerp viper-com-point) (marker-position viper-com-point)) |
| 1127 | (set-marker vip-com-point (point) (current-buffer))) | 1151 | (set-marker viper-com-point (point) (current-buffer))) |
| 1128 | ;; handle C cmd at the eol and at eob. | 1152 | ;; handle C cmd at the eol and at eob. |
| 1129 | (if (or (and (eolp) (= vip-com-point (point))) | 1153 | (if (or (and (eolp) (= viper-com-point (point))) |
| 1130 | (= vip-com-point (point-max))) | 1154 | (= viper-com-point (point-max))) |
| 1131 | (progn | 1155 | (progn |
| 1132 | (insert " ")(backward-char 1))) | 1156 | (insert " ")(backward-char 1))) |
| 1133 | (if (= vip-com-point (point)) | 1157 | (if (= viper-com-point (point)) |
| 1134 | (vip-forward-char-carefully)) | 1158 | (viper-forward-char-carefully)) |
| 1159 | (set-mark viper-com-point) | ||
| 1160 | (if (eq m-com 'viper-next-line-at-bol) | ||
| 1161 | (viper-enlarge-region (mark t) (point))) | ||
| 1162 | (if (< (point) (mark t)) | ||
| 1163 | (exchange-point-and-mark)) | ||
| 1164 | (if (eq (preceding-char) ?\n) | ||
| 1165 | (viper-backward-char-carefully)) ; give back the newline | ||
| 1135 | (if (= com ?c) | 1166 | (if (= com ?c) |
| 1136 | (vip-change vip-com-point (point)) | 1167 | (viper-change (mark t) (point)) |
| 1137 | (vip-change-subr vip-com-point (point)))) | 1168 | (viper-change-subr (mark t) (point)))) |
| 1138 | 1169 | ||
| 1139 | ;; this is invoked by vip-substitute-line | 1170 | ;; this is invoked by viper-substitute-line |
| 1140 | (defun vip-exec-Change (m-com com) | 1171 | (defun viper-exec-Change (m-com com) |
| 1141 | (save-excursion | 1172 | (save-excursion |
| 1142 | (set-mark vip-com-point) | 1173 | (set-mark viper-com-point) |
| 1143 | (vip-enlarge-region (mark t) (point)) | 1174 | (viper-enlarge-region (mark t) (point)) |
| 1144 | (if vip-use-register | 1175 | (if viper-use-register |
| 1145 | (progn | 1176 | (progn |
| 1146 | (cond ((vip-valid-register vip-use-register '(letter digit)) | 1177 | (cond ((viper-valid-register viper-use-register '(letter digit)) |
| 1147 | ;;(vip-valid-register vip-use-register '(letter) | ||
| 1148 | (copy-to-register | 1178 | (copy-to-register |
| 1149 | vip-use-register (mark t) (point) nil)) | 1179 | viper-use-register (mark t) (point) nil)) |
| 1150 | ((vip-valid-register vip-use-register '(Letter)) | 1180 | ((viper-valid-register viper-use-register '(Letter)) |
| 1151 | (vip-append-to-register | 1181 | (viper-append-to-register |
| 1152 | (downcase vip-use-register) (mark t) (point))) | 1182 | (downcase viper-use-register) (mark t) (point))) |
| 1153 | (t (setq vip-use-register nil) | 1183 | (t (setq viper-use-register nil) |
| 1154 | (error vip-InvalidRegister vip-use-register))) | 1184 | (error viper-InvalidRegister viper-use-register))) |
| 1155 | (setq vip-use-register nil))) | 1185 | (setq viper-use-register nil))) |
| 1156 | (delete-region (mark t) (point))) | 1186 | (delete-region (mark t) (point))) |
| 1157 | (open-line 1) | 1187 | (open-line 1) |
| 1158 | (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) | 1188 | (if (= com ?C) |
| 1159 | 1189 | (viper-change-state-to-insert) | |
| 1160 | (defun vip-exec-delete (m-com com) | 1190 | (viper-yank-last-insertion))) |
| 1161 | (or (and (markerp vip-com-point) (marker-position vip-com-point)) | 1191 | |
| 1162 | (set-marker vip-com-point (point) (current-buffer))) | 1192 | (defun viper-exec-delete (m-com com) |
| 1163 | (if vip-use-register | 1193 | (or (and (markerp viper-com-point) (marker-position viper-com-point)) |
| 1194 | (set-marker viper-com-point (point) (current-buffer))) | ||
| 1195 | (if viper-use-register | ||
| 1164 | (progn | 1196 | (progn |
| 1165 | (cond ((vip-valid-register vip-use-register '(letter digit)) | 1197 | (cond ((viper-valid-register viper-use-register '(letter digit)) |
| 1166 | ;;(vip-valid-register vip-use-register '(letter)) | ||
| 1167 | (copy-to-register | 1198 | (copy-to-register |
| 1168 | vip-use-register vip-com-point (point) nil)) | 1199 | viper-use-register viper-com-point (point) nil)) |
| 1169 | ((vip-valid-register vip-use-register '(Letter)) | 1200 | ((viper-valid-register viper-use-register '(Letter)) |
| 1170 | (vip-append-to-register | 1201 | (viper-append-to-register |
| 1171 | (downcase vip-use-register) vip-com-point (point))) | 1202 | (downcase viper-use-register) viper-com-point (point))) |
| 1172 | (t (setq vip-use-register nil) | 1203 | (t (setq viper-use-register nil) |
| 1173 | (error vip-InvalidRegister vip-use-register))) | 1204 | (error viper-InvalidRegister viper-use-register))) |
| 1174 | (setq vip-use-register nil))) | 1205 | (setq viper-use-register nil))) |
| 1175 | (setq last-command | 1206 | (setq last-command |
| 1176 | (if (eq last-command 'd-command) 'kill-region nil)) | 1207 | (if (eq last-command 'd-command) 'kill-region nil)) |
| 1177 | (kill-region vip-com-point (point)) | 1208 | (kill-region viper-com-point (point)) |
| 1178 | (setq this-command 'd-command) | 1209 | (setq this-command 'd-command) |
| 1179 | (if vip-ex-style-motion | 1210 | (if viper-ex-style-motion |
| 1180 | (if (and (eolp) (not (bolp))) (backward-char 1)))) | 1211 | (if (and (eolp) (not (bolp))) (backward-char 1)))) |
| 1181 | 1212 | ||
| 1182 | (defun vip-exec-Delete (m-com com) | 1213 | (defun viper-exec-Delete (m-com com) |
| 1183 | (save-excursion | 1214 | (save-excursion |
| 1184 | (set-mark vip-com-point) | 1215 | (set-mark viper-com-point) |
| 1185 | (vip-enlarge-region (mark t) (point)) | 1216 | (viper-enlarge-region (mark t) (point)) |
| 1186 | (if vip-use-register | 1217 | (if viper-use-register |
| 1187 | (progn | 1218 | (progn |
| 1188 | (cond ((vip-valid-register vip-use-register '(letter digit)) | 1219 | (cond ((viper-valid-register viper-use-register '(letter digit)) |
| 1189 | ;;(vip-valid-register vip-use-register '(letter)) | ||
| 1190 | (copy-to-register | 1220 | (copy-to-register |
| 1191 | vip-use-register (mark t) (point) nil)) | 1221 | viper-use-register (mark t) (point) nil)) |
| 1192 | ((vip-valid-register vip-use-register '(Letter)) | 1222 | ((viper-valid-register viper-use-register '(Letter)) |
| 1193 | (vip-append-to-register | 1223 | (viper-append-to-register |
| 1194 | (downcase vip-use-register) (mark t) (point))) | 1224 | (downcase viper-use-register) (mark t) (point))) |
| 1195 | (t (setq vip-use-register nil) | 1225 | (t (setq viper-use-register nil) |
| 1196 | (error vip-InvalidRegister vip-use-register))) | 1226 | (error viper-InvalidRegister viper-use-register))) |
| 1197 | (setq vip-use-register nil))) | 1227 | (setq viper-use-register nil))) |
| 1198 | (setq last-command | 1228 | (setq last-command |
| 1199 | (if (eq last-command 'D-command) 'kill-region nil)) | 1229 | (if (eq last-command 'D-command) 'kill-region nil)) |
| 1200 | (kill-region (mark t) (point)) | 1230 | (kill-region (mark t) (point)) |
| 1201 | (if (eq m-com 'vip-line) (setq this-command 'D-command))) | 1231 | (if (eq m-com 'viper-line) (setq this-command 'D-command))) |
| 1202 | (back-to-indentation)) | 1232 | (back-to-indentation)) |
| 1203 | 1233 | ||
| 1204 | (defun vip-exec-yank (m-com com) | 1234 | (defun viper-exec-yank (m-com com) |
| 1205 | (or (and (markerp vip-com-point) (marker-position vip-com-point)) | 1235 | (or (and (markerp viper-com-point) (marker-position viper-com-point)) |
| 1206 | (set-marker vip-com-point (point) (current-buffer))) | 1236 | (set-marker viper-com-point (point) (current-buffer))) |
| 1207 | (if vip-use-register | 1237 | (if viper-use-register |
| 1208 | (progn | 1238 | (progn |
| 1209 | (cond ((vip-valid-register vip-use-register '(letter digit)) | 1239 | (cond ((viper-valid-register viper-use-register '(letter digit)) |
| 1210 | ;; (vip-valid-register vip-use-register '(letter)) | ||
| 1211 | (copy-to-register | 1240 | (copy-to-register |
| 1212 | vip-use-register vip-com-point (point) nil)) | 1241 | viper-use-register viper-com-point (point) nil)) |
| 1213 | ((vip-valid-register vip-use-register '(Letter)) | 1242 | ((viper-valid-register viper-use-register '(Letter)) |
| 1214 | (vip-append-to-register | 1243 | (viper-append-to-register |
| 1215 | (downcase vip-use-register) vip-com-point (point))) | 1244 | (downcase viper-use-register) viper-com-point (point))) |
| 1216 | (t (setq vip-use-register nil) | 1245 | (t (setq viper-use-register nil) |
| 1217 | (error vip-InvalidRegister vip-use-register))) | 1246 | (error viper-InvalidRegister viper-use-register))) |
| 1218 | (setq vip-use-register nil))) | 1247 | (setq viper-use-register nil))) |
| 1219 | (setq last-command nil) | 1248 | (setq last-command nil) |
| 1220 | (copy-region-as-kill vip-com-point (point)) | 1249 | (copy-region-as-kill viper-com-point (point)) |
| 1221 | (goto-char vip-com-point)) | 1250 | (goto-char viper-com-point)) |
| 1222 | 1251 | ||
| 1223 | (defun vip-exec-Yank (m-com com) | 1252 | (defun viper-exec-Yank (m-com com) |
| 1224 | (save-excursion | 1253 | (save-excursion |
| 1225 | (set-mark vip-com-point) | 1254 | (set-mark viper-com-point) |
| 1226 | (vip-enlarge-region (mark t) (point)) | 1255 | (viper-enlarge-region (mark t) (point)) |
| 1227 | (if vip-use-register | 1256 | (if viper-use-register |
| 1228 | (progn | 1257 | (progn |
| 1229 | (cond ((vip-valid-register vip-use-register '(letter digit)) | 1258 | (cond ((viper-valid-register viper-use-register '(letter digit)) |
| 1230 | (copy-to-register | 1259 | (copy-to-register |
| 1231 | vip-use-register (mark t) (point) nil)) | 1260 | viper-use-register (mark t) (point) nil)) |
| 1232 | ((vip-valid-register vip-use-register '(Letter)) | 1261 | ((viper-valid-register viper-use-register '(Letter)) |
| 1233 | (vip-append-to-register | 1262 | (viper-append-to-register |
| 1234 | (downcase vip-use-register) (mark t) (point))) | 1263 | (downcase viper-use-register) (mark t) (point))) |
| 1235 | (t (setq vip-use-register nil) | 1264 | (t (setq viper-use-register nil) |
| 1236 | (error vip-InvalidRegister vip-use-register))) | 1265 | (error viper-InvalidRegister viper-use-register))) |
| 1237 | (setq vip-use-register nil))) | 1266 | (setq viper-use-register nil))) |
| 1238 | (setq last-command nil) | 1267 | (setq last-command nil) |
| 1239 | (copy-region-as-kill (mark t) (point))) | 1268 | (copy-region-as-kill (mark t) (point))) |
| 1240 | (vip-deactivate-mark) | 1269 | (viper-deactivate-mark) |
| 1241 | (goto-char vip-com-point)) | 1270 | (goto-char viper-com-point)) |
| 1242 | 1271 | ||
| 1243 | (defun vip-exec-bang (m-com com) | 1272 | (defun viper-exec-bang (m-com com) |
| 1244 | (save-excursion | 1273 | (save-excursion |
| 1245 | (set-mark vip-com-point) | 1274 | (set-mark viper-com-point) |
| 1246 | (vip-enlarge-region (mark t) (point)) | 1275 | (viper-enlarge-region (mark t) (point)) |
| 1247 | (exchange-point-and-mark) | 1276 | (exchange-point-and-mark) |
| 1248 | (shell-command-on-region | 1277 | (shell-command-on-region |
| 1249 | (mark t) (point) | 1278 | (mark t) (point) |
| 1250 | (if (= com ?!) | 1279 | (if (= com ?!) |
| 1251 | (setq vip-last-shell-com | 1280 | (setq viper-last-shell-com |
| 1252 | (vip-read-string-with-history | 1281 | (viper-read-string-with-history |
| 1253 | "!" | 1282 | "!" |
| 1254 | nil | 1283 | nil |
| 1255 | 'vip-shell-history | 1284 | 'viper-shell-history |
| 1256 | (car vip-shell-history) | 1285 | (car viper-shell-history) |
| 1257 | )) | 1286 | )) |
| 1258 | vip-last-shell-com) | 1287 | viper-last-shell-com) |
| 1259 | t))) | 1288 | t))) |
| 1260 | 1289 | ||
| 1261 | (defun vip-exec-equals (m-com com) | 1290 | (defun viper-exec-equals (m-com com) |
| 1262 | (save-excursion | 1291 | (save-excursion |
| 1263 | (set-mark vip-com-point) | 1292 | (set-mark viper-com-point) |
| 1264 | (vip-enlarge-region (mark t) (point)) | 1293 | (viper-enlarge-region (mark t) (point)) |
| 1265 | (if (> (mark t) (point)) (exchange-point-and-mark)) | 1294 | (if (> (mark t) (point)) (exchange-point-and-mark)) |
| 1266 | (indent-region (mark t) (point) nil))) | 1295 | (indent-region (mark t) (point) nil))) |
| 1267 | 1296 | ||
| 1268 | (defun vip-exec-shift (m-com com) | 1297 | (defun viper-exec-shift (m-com com) |
| 1269 | (save-excursion | 1298 | (save-excursion |
| 1270 | (set-mark vip-com-point) | 1299 | (set-mark viper-com-point) |
| 1271 | (vip-enlarge-region (mark t) (point)) | 1300 | (viper-enlarge-region (mark t) (point)) |
| 1272 | (if (> (mark t) (point)) (exchange-point-and-mark)) | 1301 | (if (> (mark t) (point)) (exchange-point-and-mark)) |
| 1273 | (indent-rigidly (mark t) (point) | 1302 | (indent-rigidly (mark t) (point) |
| 1274 | (if (= com ?>) | 1303 | (if (= com ?>) |
| 1275 | vip-shift-width | 1304 | viper-shift-width |
| 1276 | (- vip-shift-width)))) | 1305 | (- viper-shift-width)))) |
| 1277 | ;; return point to where it was before shift | 1306 | ;; return point to where it was before shift |
| 1278 | (goto-char vip-com-point)) | 1307 | (goto-char viper-com-point)) |
| 1279 | 1308 | ||
| 1280 | ;; this is needed because some commands fake com by setting it to ?r, which | 1309 | ;; this is needed because some commands fake com by setting it to ?r, which |
| 1281 | ;; denotes repeated insert command. | 1310 | ;; denotes repeated insert command. |
| 1282 | (defsubst vip-exec-dummy (m-com com) | 1311 | (defsubst viper-exec-dummy (m-com com) |
| 1283 | nil) | 1312 | nil) |
| 1284 | 1313 | ||
| 1285 | (defun vip-exec-buffer-search (m-com com) | 1314 | (defun viper-exec-buffer-search (m-com com) |
| 1286 | (setq vip-s-string (buffer-substring (point) vip-com-point)) | 1315 | (setq viper-s-string (buffer-substring (point) viper-com-point)) |
| 1287 | (setq vip-s-forward t) | 1316 | (setq viper-s-forward t) |
| 1288 | (setq vip-search-history (cons vip-s-string vip-search-history)) | 1317 | (setq viper-search-history (cons viper-s-string viper-search-history)) |
| 1289 | (vip-search vip-s-string vip-s-forward 1)) | 1318 | (viper-search viper-s-string viper-s-forward 1)) |
| 1290 | 1319 | ||
| 1291 | (defvar vip-exec-array (make-vector 128 nil)) | 1320 | (defvar viper-exec-array (make-vector 128 nil)) |
| 1292 | 1321 | ||
| 1293 | ;; Using a dispatch array allows adding functions like buffer search | 1322 | ;; Using a dispatch array allows adding functions like buffer search |
| 1294 | ;; without affecting other functions. Buffer search can now be bound | 1323 | ;; without affecting other functions. Buffer search can now be bound |
| 1295 | ;; to any character. | 1324 | ;; to any character. |
| 1296 | 1325 | ||
| 1297 | (aset vip-exec-array ?c 'vip-exec-change) | 1326 | (aset viper-exec-array ?c 'viper-exec-change) |
| 1298 | (aset vip-exec-array ?C 'vip-exec-Change) | 1327 | (aset viper-exec-array ?C 'viper-exec-Change) |
| 1299 | (aset vip-exec-array ?d 'vip-exec-delete) | 1328 | (aset viper-exec-array ?d 'viper-exec-delete) |
| 1300 | (aset vip-exec-array ?D 'vip-exec-Delete) | 1329 | (aset viper-exec-array ?D 'viper-exec-Delete) |
| 1301 | (aset vip-exec-array ?y 'vip-exec-yank) | 1330 | (aset viper-exec-array ?y 'viper-exec-yank) |
| 1302 | (aset vip-exec-array ?Y 'vip-exec-Yank) | 1331 | (aset viper-exec-array ?Y 'viper-exec-Yank) |
| 1303 | (aset vip-exec-array ?r 'vip-exec-dummy) | 1332 | (aset viper-exec-array ?r 'viper-exec-dummy) |
| 1304 | (aset vip-exec-array ?! 'vip-exec-bang) | 1333 | (aset viper-exec-array ?! 'viper-exec-bang) |
| 1305 | (aset vip-exec-array ?< 'vip-exec-shift) | 1334 | (aset viper-exec-array ?< 'viper-exec-shift) |
| 1306 | (aset vip-exec-array ?> 'vip-exec-shift) | 1335 | (aset viper-exec-array ?> 'viper-exec-shift) |
| 1307 | (aset vip-exec-array ?= 'vip-exec-equals) | 1336 | (aset viper-exec-array ?= 'viper-exec-equals) |
| 1308 | 1337 | ||
| 1309 | 1338 | ||
| 1310 | 1339 | ||
| 1311 | ;; This function is called by various movement commands to execute a | 1340 | ;; This function is called by various movement commands to execute a |
| 1312 | ;; destructive command on the region specified by the movement command. For | 1341 | ;; destructive command on the region specified by the movement command. For |
| 1313 | ;; instance, if the user types cw, then the command vip-forward-word will | 1342 | ;; instance, if the user types cw, then the command viper-forward-word will |
| 1314 | ;; call vip-execute-com to execute vip-exec-change, which eventually will | 1343 | ;; call viper-execute-com to execute viper-exec-change, which eventually will |
| 1315 | ;; call vip-change to invoke the replace mode on the region. | 1344 | ;; call viper-change to invoke the replace mode on the region. |
| 1316 | ;; | 1345 | ;; |
| 1317 | ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to | 1346 | ;; The var viper-d-com is set to (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) |
| 1318 | ;; vip-d-com for later use by vip-repeat. | 1347 | ;; via a call to viper-set-destructive-command, for later use by viper-repeat. |
| 1319 | (defun vip-execute-com (m-com val com) | 1348 | (defun viper-execute-com (m-com val com) |
| 1320 | (let ((reg vip-use-register)) | 1349 | (let ((reg viper-use-register)) |
| 1321 | ;; this is the special command `#' | 1350 | ;; this is the special command `#' |
| 1322 | (if (> com 128) | 1351 | (if (> com 128) |
| 1323 | (vip-special-prefix-com (- com 128)) | 1352 | (viper-special-prefix-com (- com 128)) |
| 1324 | (let ((fn (aref vip-exec-array (if (< com 0) (- com) com)))) | 1353 | (let ((fn (aref viper-exec-array (if (< com 0) (- com) com)))) |
| 1325 | (if (null fn) | 1354 | (if (null fn) |
| 1326 | (error "%c: %s" com vip-InvalidViCommand) | 1355 | (error "%c: %s" com viper-InvalidViCommand) |
| 1327 | (funcall fn m-com com)))) | 1356 | (funcall fn m-com com)))) |
| 1328 | (if (vip-dotable-command-p com) | 1357 | (if (viper-dotable-command-p com) |
| 1329 | (vip-set-destructive-command | 1358 | (viper-set-destructive-command |
| 1330 | (list m-com val | 1359 | (list m-com val |
| 1331 | (if (memq com (list ?c ?C ?!)) (- com) com) | 1360 | (if (memq com (list ?c ?C ?!)) (- com) com) |
| 1332 | reg nil nil))) | 1361 | reg nil nil))) |
| 1333 | )) | 1362 | )) |
| 1334 | 1363 | ||
| 1335 | 1364 | ||
| 1336 | (defun vip-repeat (arg) | 1365 | (defun viper-repeat (arg) |
| 1337 | "Re-execute last destructive command. | 1366 | "Re-execute last destructive command. |
| 1338 | Use the info in vip-d-com, which has the form | 1367 | Use the info in viper-d-com, which has the form |
| 1339 | \(com val ch reg inserted-text command-keys\), | 1368 | \(com val ch reg inserted-text command-keys\), |
| 1340 | where `com' is the command to be re-executed, `val' is the | 1369 | where `com' is the command to be re-executed, `val' is the |
| 1341 | argument to `com', `ch' is a flag for repeat, and `reg' is optional; | 1370 | argument to `com', `ch' is a flag for repeat, and `reg' is optional; |
| @@ -1344,99 +1373,99 @@ If the prefix argument, ARG, is non-nil, it is used instead of `val'." | |||
| 1344 | (interactive "P") | 1373 | (interactive "P") |
| 1345 | (let ((save-point (point)) ; save point before repeating prev cmd | 1374 | (let ((save-point (point)) ; save point before repeating prev cmd |
| 1346 | ;; Pass along that we are repeating a destructive command | 1375 | ;; Pass along that we are repeating a destructive command |
| 1347 | ;; This tells vip-set-destructive-command not to update | 1376 | ;; This tells viper-set-destructive-command not to update |
| 1348 | ;; vip-command-ring | 1377 | ;; viper-command-ring |
| 1349 | (vip-intermediate-command 'vip-repeat)) | 1378 | (viper-intermediate-command 'viper-repeat)) |
| 1350 | (if (eq last-command 'vip-undo) | 1379 | (if (eq last-command 'viper-undo) |
| 1351 | ;; if the last command was vip-undo, then undo-more | 1380 | ;; if the last command was viper-undo, then undo-more |
| 1352 | (vip-undo-more) | 1381 | (viper-undo-more) |
| 1353 | ;; otherwise execute the command stored in vip-d-com. if arg is non-nil | 1382 | ;; otherwise execute the command stored in viper-d-com. if arg is |
| 1354 | ;; its prefix value is used as new prefix value for the command. | 1383 | ;; non-nil its prefix value is used as new prefix value for the command. |
| 1355 | (let ((m-com (car vip-d-com)) | 1384 | (let ((m-com (car viper-d-com)) |
| 1356 | (val (vip-P-val arg)) | 1385 | (val (viper-P-val arg)) |
| 1357 | (com (nth 2 vip-d-com)) | 1386 | (com (nth 2 viper-d-com)) |
| 1358 | (reg (nth 3 vip-d-com))) | 1387 | (reg (nth 3 viper-d-com))) |
| 1359 | (if (null val) (setq val (nth 1 vip-d-com))) | 1388 | (if (null val) (setq val (nth 1 viper-d-com))) |
| 1360 | (if (null m-com) (error "No previous command to repeat.")) | 1389 | (if (null m-com) (error "No previous command to repeat.")) |
| 1361 | (setq vip-use-register reg) | 1390 | (setq viper-use-register reg) |
| 1362 | (if (nth 4 vip-d-com) ; text inserted by command | 1391 | (if (nth 4 viper-d-com) ; text inserted by command |
| 1363 | (setq vip-last-insertion (nth 4 vip-d-com) | 1392 | (setq viper-last-insertion (nth 4 viper-d-com) |
| 1364 | vip-d-char (nth 4 vip-d-com))) | 1393 | viper-d-char (nth 4 viper-d-com))) |
| 1365 | (funcall m-com (cons val com)) | 1394 | (funcall m-com (cons val com)) |
| 1366 | (cond ((and (< save-point (point)) vip-keep-point-on-repeat) | 1395 | (cond ((and (< save-point (point)) viper-keep-point-on-repeat) |
| 1367 | (goto-char save-point)) ; go back to before repeat. | 1396 | (goto-char save-point)) ; go back to before repeat. |
| 1368 | ((and (< save-point (point)) vip-ex-style-editing-in-insert) | 1397 | ((and (< save-point (point)) viper-ex-style-editing-in-insert) |
| 1369 | (or (bolp) (backward-char 1)))) | 1398 | (or (bolp) (backward-char 1)))) |
| 1370 | (if (and (eolp) (not (bolp))) | 1399 | (if (and (eolp) (not (bolp))) |
| 1371 | (backward-char 1)) | 1400 | (backward-char 1)) |
| 1372 | )) | 1401 | )) |
| 1373 | (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo | 1402 | (if viper-undo-needs-adjustment (viper-adjust-undo)) ; take care of undo |
| 1374 | ;; If the prev cmd was rotating the command ring, this means that `.' has | 1403 | ;; If the prev cmd was rotating the command ring, this means that `.' has |
| 1375 | ;; just executed a command from that ring. So, push it on the ring again. | 1404 | ;; just executed a command from that ring. So, push it on the ring again. |
| 1376 | ;; If we are just executing previous command , then don't push vip-d-com | 1405 | ;; If we are just executing previous command , then don't push viper-d-com |
| 1377 | ;; because vip-d-com is not fully constructed in this case (its keys and | 1406 | ;; because viper-d-com is not fully constructed in this case (its keys and |
| 1378 | ;; the inserted text may be nil). Besides, in this case, the command | 1407 | ;; the inserted text may be nil). Besides, in this case, the command |
| 1379 | ;; executed by `.' is already on the ring. | 1408 | ;; executed by `.' is already on the ring. |
| 1380 | (if (eq last-command 'vip-display-current-destructive-command) | 1409 | (if (eq last-command 'viper-display-current-destructive-command) |
| 1381 | (vip-push-onto-ring vip-d-com 'vip-command-ring)) | 1410 | (viper-push-onto-ring viper-d-com 'viper-command-ring)) |
| 1382 | (vip-deactivate-mark) | 1411 | (viper-deactivate-mark) |
| 1383 | )) | 1412 | )) |
| 1384 | 1413 | ||
| 1385 | (defun vip-repeat-from-history () | 1414 | (defun viper-repeat-from-history () |
| 1386 | "Repeat a destructive command from history. | 1415 | "Repeat a destructive command from history. |
| 1387 | Doesn't change vip-command-ring in any way, so `.' will work as before | 1416 | Doesn't change viper-command-ring in any way, so `.' will work as before |
| 1388 | executing this command. | 1417 | executing this command. |
| 1389 | This command is supposed to be bound to a two-character Vi macro where | 1418 | This command is supposed to be bound to a two-character Vi macro where |
| 1390 | the second character is a digit 0 to 9. The digit indicates which | 1419 | the second character is a digit 0 to 9. The digit indicates which |
| 1391 | history command to execute. `<char>0' is equivalent to `.', `<char>1' | 1420 | history command to execute. `<char>0' is equivalent to `.', `<char>1' |
| 1392 | invokes the command before that, etc." | 1421 | invokes the command before that, etc." |
| 1393 | (interactive) | 1422 | (interactive) |
| 1394 | (let* ((vip-intermediate-command 'repeating-display-destructive-command) | 1423 | (let* ((viper-intermediate-command 'repeating-display-destructive-command) |
| 1395 | (idx (cond (vip-this-kbd-macro | 1424 | (idx (cond (viper-this-kbd-macro |
| 1396 | (string-to-number | 1425 | (string-to-number |
| 1397 | (symbol-name (elt vip-this-kbd-macro 1)))) | 1426 | (symbol-name (elt viper-this-kbd-macro 1)))) |
| 1398 | (t 0))) | 1427 | (t 0))) |
| 1399 | (num idx) | 1428 | (num idx) |
| 1400 | (vip-d-com vip-d-com)) | 1429 | (viper-d-com viper-d-com)) |
| 1401 | 1430 | ||
| 1402 | (or (and (numberp num) (<= 0 num) (<= num 9)) | 1431 | (or (and (numberp num) (<= 0 num) (<= num 9)) |
| 1403 | (progn | 1432 | (progn |
| 1404 | (setq idx 0 | 1433 | (setq idx 0 |
| 1405 | num 0) | 1434 | num 0) |
| 1406 | (message | 1435 | (message |
| 1407 | "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) | 1436 | "`viper-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) |
| 1408 | (while (< 0 num) | 1437 | (while (< 0 num) |
| 1409 | (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) | 1438 | (setq viper-d-com (viper-special-ring-rotate1 viper-command-ring -1)) |
| 1410 | (setq num (1- num))) | 1439 | (setq num (1- num))) |
| 1411 | (vip-repeat nil) | 1440 | (viper-repeat nil) |
| 1412 | (while (> idx num) | 1441 | (while (> idx num) |
| 1413 | (vip-special-ring-rotate1 vip-command-ring 1) | 1442 | (viper-special-ring-rotate1 viper-command-ring 1) |
| 1414 | (setq num (1+ num))) | 1443 | (setq num (1+ num))) |
| 1415 | )) | 1444 | )) |
| 1416 | 1445 | ||
| 1417 | 1446 | ||
| 1418 | ;; The hash-command. It is invoked interactively by the key sequence #<char>. | 1447 | ;; The hash-command. It is invoked interactively by the key sequence #<char>. |
| 1419 | ;; The chars that can follow `#' are determined by vip-hash-command-p | 1448 | ;; The chars that can follow `#' are determined by viper-hash-command-p |
| 1420 | (defun vip-special-prefix-com (char) | 1449 | (defun viper-special-prefix-com (char) |
| 1421 | (cond ((= char ?c) | 1450 | (cond ((= char ?c) |
| 1422 | (downcase-region (min vip-com-point (point)) | 1451 | (downcase-region (min viper-com-point (point)) |
| 1423 | (max vip-com-point (point)))) | 1452 | (max viper-com-point (point)))) |
| 1424 | ((= char ?C) | 1453 | ((= char ?C) |
| 1425 | (upcase-region (min vip-com-point (point)) | 1454 | (upcase-region (min viper-com-point (point)) |
| 1426 | (max vip-com-point (point)))) | 1455 | (max viper-com-point (point)))) |
| 1427 | ((= char ?g) | 1456 | ((= char ?g) |
| 1428 | (push-mark vip-com-point t) | 1457 | (push-mark viper-com-point t) |
| 1429 | (vip-global-execute)) | 1458 | (viper-global-execute)) |
| 1430 | ((= char ?q) | 1459 | ((= char ?q) |
| 1431 | (push-mark vip-com-point t) | 1460 | (push-mark viper-com-point t) |
| 1432 | (vip-quote-region)) | 1461 | (viper-quote-region)) |
| 1433 | ((= char ?s) (funcall vip-spell-function vip-com-point (point))) | 1462 | ((= char ?s) (funcall viper-spell-function viper-com-point (point))) |
| 1434 | (t (error "#%c: %s" char vip-InvalidViCommand)))) | 1463 | (t (error "#%c: %s" char viper-InvalidViCommand)))) |
| 1435 | 1464 | ||
| 1436 | 1465 | ||
| 1437 | ;; undoing | 1466 | ;; undoing |
| 1438 | 1467 | ||
| 1439 | (defun vip-undo () | 1468 | (defun viper-undo () |
| 1440 | "Undo previous change." | 1469 | "Undo previous change." |
| 1441 | (interactive) | 1470 | (interactive) |
| 1442 | (message "undo!") | 1471 | (message "undo!") |
| @@ -1458,13 +1487,13 @@ invokes the command before that, etc." | |||
| 1458 | 1487 | ||
| 1459 | (goto-char undo-beg-posn) | 1488 | (goto-char undo-beg-posn) |
| 1460 | (sit-for 0) | 1489 | (sit-for 0) |
| 1461 | (if (and vip-keep-point-on-undo | 1490 | (if (and viper-keep-point-on-undo |
| 1462 | (pos-visible-in-window-p before-undo-pt)) | 1491 | (pos-visible-in-window-p before-undo-pt)) |
| 1463 | (progn | 1492 | (progn |
| 1464 | (push-mark (point-marker) t) | 1493 | (push-mark (point-marker) t) |
| 1465 | (vip-sit-for-short 300) | 1494 | (viper-sit-for-short 300) |
| 1466 | (goto-char undo-end-posn) | 1495 | (goto-char undo-end-posn) |
| 1467 | (vip-sit-for-short 300) | 1496 | (viper-sit-for-short 300) |
| 1468 | (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) | 1497 | (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) |
| 1469 | (> (abs (- undo-end-posn before-undo-pt)) 1)) | 1498 | (> (abs (- undo-end-posn before-undo-pt)) 1)) |
| 1470 | (goto-char before-undo-pt) | 1499 | (goto-char before-undo-pt) |
| @@ -1472,27 +1501,27 @@ invokes the command before that, etc." | |||
| 1472 | (push-mark before-undo-pt t)) | 1501 | (push-mark before-undo-pt t)) |
| 1473 | (if (and (eolp) (not (bolp))) (backward-char 1)) | 1502 | (if (and (eolp) (not (bolp))) (backward-char 1)) |
| 1474 | (if (not modified) (set-buffer-modified-p t))) | 1503 | (if (not modified) (set-buffer-modified-p t))) |
| 1475 | (setq this-command 'vip-undo)) | 1504 | (setq this-command 'viper-undo)) |
| 1476 | 1505 | ||
| 1477 | ;; Continue undoing previous changes. | 1506 | ;; Continue undoing previous changes. |
| 1478 | (defun vip-undo-more () | 1507 | (defun viper-undo-more () |
| 1479 | (message "undo more!") | 1508 | (message "undo more!") |
| 1480 | (condition-case nil | 1509 | (condition-case nil |
| 1481 | (undo-more 1) | 1510 | (undo-more 1) |
| 1482 | (error (beep) | 1511 | (error (beep) |
| 1483 | (message "No further undo information in this buffer"))) | 1512 | (message "No further undo information in this buffer"))) |
| 1484 | (if (and (eolp) (not (bolp))) (backward-char 1)) | 1513 | (if (and (eolp) (not (bolp))) (backward-char 1)) |
| 1485 | (setq this-command 'vip-undo)) | 1514 | (setq this-command 'viper-undo)) |
| 1486 | 1515 | ||
| 1487 | ;; The following two functions are used to set up undo properly. | 1516 | ;; The following two functions are used to set up undo properly. |
| 1488 | ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, | 1517 | ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, |
| 1489 | ;; they are undone all at once. | 1518 | ;; they are undone all at once. |
| 1490 | (defun vip-adjust-undo () | 1519 | (defun viper-adjust-undo () |
| 1491 | (let ((inhibit-quit t) | 1520 | (let ((inhibit-quit t) |
| 1492 | tmp tmp2) | 1521 | tmp tmp2) |
| 1493 | (setq vip-undo-needs-adjustment nil) | 1522 | (setq viper-undo-needs-adjustment nil) |
| 1494 | (if (listp buffer-undo-list) | 1523 | (if (listp buffer-undo-list) |
| 1495 | (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list)) | 1524 | (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list)) |
| 1496 | (progn | 1525 | (progn |
| 1497 | (setq tmp2 (cdr tmp)) ; the part after mark | 1526 | (setq tmp2 (cdr tmp)) ; the part after mark |
| 1498 | 1527 | ||
| @@ -1502,114 +1531,118 @@ invokes the command before that, etc." | |||
| 1502 | 1531 | ||
| 1503 | (setq buffer-undo-list (delq nil buffer-undo-list)) | 1532 | (setq buffer-undo-list (delq nil buffer-undo-list)) |
| 1504 | (setq buffer-undo-list | 1533 | (setq buffer-undo-list |
| 1505 | (delq vip-buffer-undo-list-mark buffer-undo-list)) | 1534 | (delq viper-buffer-undo-list-mark buffer-undo-list)) |
| 1506 | ;; restore tail of buffer-undo-list | 1535 | ;; restore tail of buffer-undo-list |
| 1507 | (setq buffer-undo-list (nconc buffer-undo-list tmp2))) | 1536 | (setq buffer-undo-list (nconc buffer-undo-list tmp2))) |
| 1508 | (setq buffer-undo-list (delq nil buffer-undo-list)))))) | 1537 | (setq buffer-undo-list (delq nil buffer-undo-list)))))) |
| 1509 | 1538 | ||
| 1510 | 1539 | ||
| 1511 | (defun vip-set-complex-command-for-undo () | 1540 | (defun viper-set-complex-command-for-undo () |
| 1512 | (if (listp buffer-undo-list) | 1541 | (if (listp buffer-undo-list) |
| 1513 | (if (not vip-undo-needs-adjustment) | 1542 | (if (not viper-undo-needs-adjustment) |
| 1514 | (let ((inhibit-quit t)) | 1543 | (let ((inhibit-quit t)) |
| 1515 | (setq buffer-undo-list | 1544 | (setq buffer-undo-list |
| 1516 | (cons vip-buffer-undo-list-mark buffer-undo-list)) | 1545 | (cons viper-buffer-undo-list-mark buffer-undo-list)) |
| 1517 | (setq vip-undo-needs-adjustment t))))) | 1546 | (setq viper-undo-needs-adjustment t))))) |
| 1518 | 1547 | ||
| 1519 | 1548 | ||
| 1520 | 1549 | ||
| 1521 | 1550 | ||
| 1522 | (defun vip-display-current-destructive-command () | 1551 | (defun viper-display-current-destructive-command () |
| 1523 | (let ((text (nth 4 vip-d-com)) | 1552 | (let ((text (nth 4 viper-d-com)) |
| 1524 | (keys (nth 5 vip-d-com)) | 1553 | (keys (nth 5 viper-d-com)) |
| 1525 | (max-text-len 30)) | 1554 | (max-text-len 30)) |
| 1526 | 1555 | ||
| 1527 | (setq this-command 'vip-display-current-destructive-command) | 1556 | (setq this-command 'viper-display-current-destructive-command) |
| 1528 | 1557 | ||
| 1529 | (message " `.' runs %s%s" | 1558 | (message " `.' runs %s%s" |
| 1530 | (concat "`" (vip-array-to-string keys) "'") | 1559 | (concat "`" (viper-array-to-string keys) "'") |
| 1531 | (vip-abbreviate-string text max-text-len | 1560 | (viper-abbreviate-string text max-text-len |
| 1532 | " inserting `" "'" " .......")) | 1561 | " inserting `" "'" " .......")) |
| 1533 | )) | 1562 | )) |
| 1534 | 1563 | ||
| 1535 | 1564 | ||
| 1536 | ;; don't change vip-d-com if it was vip-repeat command invoked with `.' | 1565 | ;; don't change viper-d-com if it was viper-repeat command invoked with `.' |
| 1537 | ;; or in some other way (non-interactively). | 1566 | ;; or in some other way (non-interactively). |
| 1538 | (defun vip-set-destructive-command (list) | 1567 | (defun viper-set-destructive-command (list) |
| 1539 | (or (eq vip-intermediate-command 'vip-repeat) | 1568 | (or (eq viper-intermediate-command 'viper-repeat) |
| 1540 | (progn | 1569 | (progn |
| 1541 | (setq vip-d-com list) | 1570 | (setq viper-d-com list) |
| 1542 | (setcar (nthcdr 5 vip-d-com) | 1571 | (setcar (nthcdr 5 viper-d-com) |
| 1543 | (vip-array-to-string (this-command-keys))) | 1572 | (viper-array-to-string (if (arrayp viper-this-command-keys) |
| 1544 | (vip-push-onto-ring vip-d-com 'vip-command-ring)))) | 1573 | viper-this-command-keys |
| 1574 | (this-command-keys)))) | ||
| 1575 | (viper-push-onto-ring viper-d-com 'viper-command-ring))) | ||
| 1576 | (setq viper-this-command-keys nil)) | ||
| 1545 | 1577 | ||
| 1546 | (defun vip-prev-destructive-command (next) | 1578 | (defun viper-prev-destructive-command (next) |
| 1547 | "Find previous destructive command in the history of destructive commands. | 1579 | "Find previous destructive command in the history of destructive commands. |
| 1548 | With prefix argument, find next destructive command." | 1580 | With prefix argument, find next destructive command." |
| 1549 | (interactive "P") | 1581 | (interactive "P") |
| 1550 | (let (cmd vip-intermediate-command) | 1582 | (let (cmd viper-intermediate-command) |
| 1551 | (if (eq last-command 'vip-display-current-destructive-command) | 1583 | (if (eq last-command 'viper-display-current-destructive-command) |
| 1552 | ;; repeated search through command history | 1584 | ;; repeated search through command history |
| 1553 | (setq vip-intermediate-command 'repeating-display-destructive-command) | 1585 | (setq viper-intermediate-command |
| 1586 | 'repeating-display-destructive-command) | ||
| 1554 | ;; first search through command history--set temp ring | 1587 | ;; first search through command history--set temp ring |
| 1555 | (setq vip-temp-command-ring (copy-list vip-command-ring))) | 1588 | (setq viper-temp-command-ring (copy-list viper-command-ring))) |
| 1556 | (setq cmd (if next | 1589 | (setq cmd (if next |
| 1557 | (vip-special-ring-rotate1 vip-temp-command-ring 1) | 1590 | (viper-special-ring-rotate1 viper-temp-command-ring 1) |
| 1558 | (vip-special-ring-rotate1 vip-temp-command-ring -1))) | 1591 | (viper-special-ring-rotate1 viper-temp-command-ring -1))) |
| 1559 | (if (null cmd) | 1592 | (if (null cmd) |
| 1560 | () | 1593 | () |
| 1561 | (setq vip-d-com cmd)) | 1594 | (setq viper-d-com cmd)) |
| 1562 | (vip-display-current-destructive-command))) | 1595 | (viper-display-current-destructive-command))) |
| 1563 | 1596 | ||
| 1564 | (defun vip-next-destructive-command () | 1597 | (defun viper-next-destructive-command () |
| 1565 | "Find next destructive command in the history of destructive commands." | 1598 | "Find next destructive command in the history of destructive commands." |
| 1566 | (interactive) | 1599 | (interactive) |
| 1567 | (vip-prev-destructive-command 'next)) | 1600 | (viper-prev-destructive-command 'next)) |
| 1568 | 1601 | ||
| 1569 | (defun vip-insert-prev-from-insertion-ring (arg) | 1602 | (defun viper-insert-prev-from-insertion-ring (arg) |
| 1570 | "Cycle through insertion ring in the direction of older insertions. | 1603 | "Cycle through insertion ring in the direction of older insertions. |
| 1571 | Undoes previous insertion and inserts new. | 1604 | Undoes previous insertion and inserts new. |
| 1572 | With prefix argument, cycles in the direction of newer elements. | 1605 | With prefix argument, cycles in the direction of newer elements. |
| 1573 | In minibuffer, this command executes whatever the invocation key is bound | 1606 | In minibuffer, this command executes whatever the invocation key is bound |
| 1574 | to in the global map, instead of cycling through the insertion ring." | 1607 | to in the global map, instead of cycling through the insertion ring." |
| 1575 | (interactive "P") | 1608 | (interactive "P") |
| 1576 | (let (vip-intermediate-command) | 1609 | (let (viper-intermediate-command) |
| 1577 | (if (eq last-command 'vip-insert-from-insertion-ring) | 1610 | (if (eq last-command 'viper-insert-from-insertion-ring) |
| 1578 | (progn ; repeated search through insertion history | 1611 | (progn ; repeated search through insertion history |
| 1579 | (setq vip-intermediate-command 'repeating-insertion-from-ring) | 1612 | (setq viper-intermediate-command 'repeating-insertion-from-ring) |
| 1580 | (if (eq vip-current-state 'replace-state) | 1613 | (if (eq viper-current-state 'replace-state) |
| 1581 | (undo 1) | 1614 | (undo 1) |
| 1582 | (if vip-last-inserted-string-from-insertion-ring | 1615 | (if viper-last-inserted-string-from-insertion-ring |
| 1583 | (backward-delete-char | 1616 | (backward-delete-char |
| 1584 | (length vip-last-inserted-string-from-insertion-ring)))) | 1617 | (length viper-last-inserted-string-from-insertion-ring)))) |
| 1585 | ) | 1618 | ) |
| 1586 | ;;first search through insertion history | 1619 | ;;first search through insertion history |
| 1587 | (setq vip-temp-insertion-ring (copy-list vip-insertion-ring))) | 1620 | (setq viper-temp-insertion-ring (copy-list viper-insertion-ring))) |
| 1588 | (setq this-command 'vip-insert-from-insertion-ring) | 1621 | (setq this-command 'viper-insert-from-insertion-ring) |
| 1589 | ;; so that things will be undone properly | 1622 | ;; so that things will be undone properly |
| 1590 | (setq buffer-undo-list (cons nil buffer-undo-list)) | 1623 | (setq buffer-undo-list (cons nil buffer-undo-list)) |
| 1591 | (setq vip-last-inserted-string-from-insertion-ring | 1624 | (setq viper-last-inserted-string-from-insertion-ring |
| 1592 | (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1))) | 1625 | (viper-special-ring-rotate1 viper-temp-insertion-ring (if arg 1 -1))) |
| 1593 | 1626 | ||
| 1594 | ;; this change of vip-intermediate-command must come after | 1627 | ;; this change of viper-intermediate-command must come after |
| 1595 | ;; vip-special-ring-rotate1, so that the ring will rotate, but before the | 1628 | ;; viper-special-ring-rotate1, so that the ring will rotate, but before the |
| 1596 | ;; insertion. | 1629 | ;; insertion. |
| 1597 | (setq vip-intermediate-command nil) | 1630 | (setq viper-intermediate-command nil) |
| 1598 | (if vip-last-inserted-string-from-insertion-ring | 1631 | (if viper-last-inserted-string-from-insertion-ring |
| 1599 | (insert vip-last-inserted-string-from-insertion-ring)) | 1632 | (insert viper-last-inserted-string-from-insertion-ring)) |
| 1600 | )) | 1633 | )) |
| 1601 | 1634 | ||
| 1602 | (defun vip-insert-next-from-insertion-ring () | 1635 | (defun viper-insert-next-from-insertion-ring () |
| 1603 | "Cycle through insertion ring in the direction of older insertions. | 1636 | "Cycle through insertion ring in the direction of older insertions. |
| 1604 | Undo previous insertion and inserts new." | 1637 | Undo previous insertion and inserts new." |
| 1605 | (interactive) | 1638 | (interactive) |
| 1606 | (vip-insert-prev-from-insertion-ring 'next)) | 1639 | (viper-insert-prev-from-insertion-ring 'next)) |
| 1607 | 1640 | ||
| 1608 | 1641 | ||
| 1609 | ;; some region utilities | 1642 | ;; some region utilities |
| 1610 | 1643 | ||
| 1611 | ;; If at the last line of buffer, add \\n before eob, if newline is missing. | 1644 | ;; If at the last line of buffer, add \\n before eob, if newline is missing. |
| 1612 | (defun vip-add-newline-at-eob-if-necessary () | 1645 | (defun viper-add-newline-at-eob-if-necessary () |
| 1613 | (save-excursion | 1646 | (save-excursion |
| 1614 | (end-of-line) | 1647 | (end-of-line) |
| 1615 | ;; make sure all lines end with newline, unless in the minibuffer or | 1648 | ;; make sure all lines end with newline, unless in the minibuffer or |
| @@ -1617,16 +1650,16 @@ Undo previous insertion and inserts new." | |||
| 1617 | (if (and (eobp) | 1650 | (if (and (eobp) |
| 1618 | (not (bolp)) | 1651 | (not (bolp)) |
| 1619 | require-final-newline | 1652 | require-final-newline |
| 1620 | (not (vip-is-in-minibuffer)) | 1653 | (not (viper-is-in-minibuffer)) |
| 1621 | (not buffer-read-only)) | 1654 | (not buffer-read-only)) |
| 1622 | (insert "\n")))) | 1655 | (insert "\n")))) |
| 1623 | 1656 | ||
| 1624 | (defun vip-yank-defun () | 1657 | (defun viper-yank-defun () |
| 1625 | (mark-defun) | 1658 | (mark-defun) |
| 1626 | (copy-region-as-kill (point) (mark t))) | 1659 | (copy-region-as-kill (point) (mark t))) |
| 1627 | 1660 | ||
| 1628 | ;; Enlarge region between BEG and END. | 1661 | ;; Enlarge region between BEG and END. |
| 1629 | (defun vip-enlarge-region (beg end) | 1662 | (defun viper-enlarge-region (beg end) |
| 1630 | (or beg (setq beg end)) ; if beg is nil, set to end | 1663 | (or beg (setq beg end)) ; if beg is nil, set to end |
| 1631 | (or end (setq end beg)) ; if end is nil, set to beg | 1664 | (or end (setq end beg)) ; if end is nil, set to beg |
| 1632 | 1665 | ||
| @@ -1642,26 +1675,26 @@ Undo previous insertion and inserts new." | |||
| 1642 | 1675 | ||
| 1643 | 1676 | ||
| 1644 | ;; Quote region by each line with a user supplied string. | 1677 | ;; Quote region by each line with a user supplied string. |
| 1645 | (defun vip-quote-region () | 1678 | (defun viper-quote-region () |
| 1646 | (setq vip-quote-string | 1679 | (setq viper-quote-string |
| 1647 | (vip-read-string-with-history | 1680 | (viper-read-string-with-history |
| 1648 | "Quote string: " | 1681 | "Quote string: " |
| 1649 | nil | 1682 | nil |
| 1650 | 'vip-quote-region-history | 1683 | 'viper-quote-region-history |
| 1651 | vip-quote-string)) | 1684 | viper-quote-string)) |
| 1652 | (vip-enlarge-region (point) (mark t)) | 1685 | (viper-enlarge-region (point) (mark t)) |
| 1653 | (if (> (point) (mark t)) (exchange-point-and-mark)) | 1686 | (if (> (point) (mark t)) (exchange-point-and-mark)) |
| 1654 | (insert vip-quote-string) | 1687 | (insert viper-quote-string) |
| 1655 | (beginning-of-line) | 1688 | (beginning-of-line) |
| 1656 | (forward-line 1) | 1689 | (forward-line 1) |
| 1657 | (while (and (< (point) (mark t)) (bolp)) | 1690 | (while (and (< (point) (mark t)) (bolp)) |
| 1658 | (insert vip-quote-string) | 1691 | (insert viper-quote-string) |
| 1659 | (beginning-of-line) | 1692 | (beginning-of-line) |
| 1660 | (forward-line 1))) | 1693 | (forward-line 1))) |
| 1661 | 1694 | ||
| 1662 | ;; Tells whether BEG is on the same line as END. | 1695 | ;; Tells whether BEG is on the same line as END. |
| 1663 | ;; If one of the args is nil, it'll return nil. | 1696 | ;; If one of the args is nil, it'll return nil. |
| 1664 | (defun vip-same-line (beg end) | 1697 | (defun viper-same-line (beg end) |
| 1665 | (let ((selective-display nil) | 1698 | (let ((selective-display nil) |
| 1666 | (incr 0) | 1699 | (incr 0) |
| 1667 | temp) | 1700 | temp) |
| @@ -1675,18 +1708,18 @@ Undo previous insertion and inserts new." | |||
| 1675 | (t | 1708 | (t |
| 1676 | ;; This 'if' is needed because Emacs treats the next empty line | 1709 | ;; This 'if' is needed because Emacs treats the next empty line |
| 1677 | ;; as part of the previous line. | 1710 | ;; as part of the previous line. |
| 1678 | (if (= (vip-line-pos 'start) end) | 1711 | (if (= (viper-line-pos 'start) end) |
| 1679 | (setq incr 1)) | 1712 | (setq incr 1)) |
| 1680 | (<= (+ incr (count-lines beg end)) 1)))) | 1713 | (<= (+ incr (count-lines beg end)) 1)))) |
| 1681 | )) | 1714 | )) |
| 1682 | 1715 | ||
| 1683 | 1716 | ||
| 1684 | ;; Check if the string ends with a newline. | 1717 | ;; Check if the string ends with a newline. |
| 1685 | (defun vip-end-with-a-newline-p (string) | 1718 | (defun viper-end-with-a-newline-p (string) |
| 1686 | (or (string= string "") | 1719 | (or (string= string "") |
| 1687 | (= (vip-seq-last-elt string) ?\n))) | 1720 | (= (viper-seq-last-elt string) ?\n))) |
| 1688 | 1721 | ||
| 1689 | (defun vip-tmp-insert-at-eob (msg) | 1722 | (defun viper-tmp-insert-at-eob (msg) |
| 1690 | (let ((savemax (point-max))) | 1723 | (let ((savemax (point-max))) |
| 1691 | (goto-char savemax) | 1724 | (goto-char savemax) |
| 1692 | (insert msg) | 1725 | (insert msg) |
| @@ -1698,19 +1731,19 @@ Undo previous insertion and inserts new." | |||
| 1698 | 1731 | ||
| 1699 | ;;; Minibuffer business | 1732 | ;;; Minibuffer business |
| 1700 | 1733 | ||
| 1701 | (defsubst vip-set-minibuffer-style () | 1734 | (defsubst viper-set-minibuffer-style () |
| 1702 | (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel)) | 1735 | (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)) |
| 1703 | 1736 | ||
| 1704 | 1737 | ||
| 1705 | (defun vip-minibuffer-setup-sentinel () | 1738 | (defun viper-minibuffer-setup-sentinel () |
| 1706 | (let ((hook (if vip-vi-style-in-minibuffer | 1739 | (let ((hook (if viper-vi-style-in-minibuffer |
| 1707 | 'vip-change-state-to-insert | 1740 | 'viper-change-state-to-insert |
| 1708 | 'vip-change-state-to-emacs))) | 1741 | 'viper-change-state-to-emacs))) |
| 1709 | (funcall hook) | 1742 | (funcall hook) |
| 1710 | )) | 1743 | )) |
| 1711 | 1744 | ||
| 1712 | ;; Interpret last event in the local map | 1745 | ;; Interpret last event in the local map |
| 1713 | (defun vip-exit-minibuffer () | 1746 | (defun viper-exit-minibuffer () |
| 1714 | (interactive) | 1747 | (interactive) |
| 1715 | (let (command) | 1748 | (let (command) |
| 1716 | (setq command (local-key-binding (char-to-string last-command-char))) | 1749 | (setq command (local-key-binding (char-to-string last-command-char))) |
| @@ -1721,7 +1754,7 @@ Undo previous insertion and inserts new." | |||
| 1721 | 1754 | ||
| 1722 | ;;; Reading string with history | 1755 | ;;; Reading string with history |
| 1723 | 1756 | ||
| 1724 | (defun vip-read-string-with-history (prompt &optional initial | 1757 | (defun viper-read-string-with-history (prompt &optional initial |
| 1725 | history-var default keymap) | 1758 | history-var default keymap) |
| 1726 | ;; Read string, prompting with PROMPT and inserting the INITIAL | 1759 | ;; Read string, prompting with PROMPT and inserting the INITIAL |
| 1727 | ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the | 1760 | ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the |
| @@ -1739,7 +1772,7 @@ Undo previous insertion and inserts new." | |||
| 1739 | (sit-for 840)) | 1772 | (sit-for 840)) |
| 1740 | (erase-buffer) | 1773 | (erase-buffer) |
| 1741 | (insert initial))) | 1774 | (insert initial))) |
| 1742 | (vip-minibuffer-setup-sentinel))) | 1775 | (viper-minibuffer-setup-sentinel))) |
| 1743 | (val "") | 1776 | (val "") |
| 1744 | (padding "") | 1777 | (padding "") |
| 1745 | temp-msg) | 1778 | temp-msg) |
| @@ -1750,12 +1783,12 @@ Undo previous insertion and inserts new." | |||
| 1750 | (format "(default: %s) " default) | 1783 | (format "(default: %s) " default) |
| 1751 | "")) | 1784 | "")) |
| 1752 | 1785 | ||
| 1753 | (setq vip-incomplete-ex-cmd nil) | 1786 | (setq viper-incomplete-ex-cmd nil) |
| 1754 | (setq val (read-from-minibuffer prompt | 1787 | (setq val (read-from-minibuffer prompt |
| 1755 | (concat temp-msg initial val padding) | 1788 | (concat temp-msg initial val padding) |
| 1756 | keymap nil history-var)) | 1789 | keymap nil history-var)) |
| 1757 | (setq minibuffer-setup-hook nil | 1790 | (setq minibuffer-setup-hook nil |
| 1758 | padding (vip-array-to-string (this-command-keys)) | 1791 | padding (viper-array-to-string (this-command-keys)) |
| 1759 | temp-msg "") | 1792 | temp-msg "") |
| 1760 | ;; the following tries to be smart about what to put in history | 1793 | ;; the following tries to be smart about what to put in history |
| 1761 | (if (not (string= val (car (eval history-var)))) | 1794 | (if (not (string= val (car (eval history-var)))) |
| @@ -1763,15 +1796,15 @@ Undo previous insertion and inserts new." | |||
| 1763 | (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) | 1796 | (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) |
| 1764 | (string= (nth 0 (eval history-var)) "")) | 1797 | (string= (nth 0 (eval history-var)) "")) |
| 1765 | (set history-var (cdr (eval history-var)))) | 1798 | (set history-var (cdr (eval history-var)))) |
| 1766 | ;; If the user enters nothing but the prev cmd wasn't vip-ex, | 1799 | ;; If the user enters nothing but the prev cmd wasn't viper-ex, |
| 1767 | ;; vip-command-argument, or `! shell-command', this probably means | 1800 | ;; viper-command-argument, or `! shell-command', this probably means |
| 1768 | ;; that the user typed something then erased. Return "" in this case, not | 1801 | ;; that the user typed something then erased. Return "" in this case, not |
| 1769 | ;; the default---the default is too confusing in this case. | 1802 | ;; the default---the default is too confusing in this case. |
| 1770 | (cond ((and (string= val "") | 1803 | (cond ((and (string= val "") |
| 1771 | (not (string= prompt "!")) ; was a `! shell-command' | 1804 | (not (string= prompt "!")) ; was a `! shell-command' |
| 1772 | (not (memq last-command | 1805 | (not (memq last-command |
| 1773 | '(vip-ex | 1806 | '(viper-ex |
| 1774 | vip-command-argument | 1807 | viper-command-argument |
| 1775 | t) | 1808 | t) |
| 1776 | ))) | 1809 | ))) |
| 1777 | "") | 1810 | "") |
| @@ -1786,204 +1819,207 @@ Undo previous insertion and inserts new." | |||
| 1786 | ;; Called when state changes from Insert Vi command mode. | 1819 | ;; Called when state changes from Insert Vi command mode. |
| 1787 | ;; Repeats the insertion command if Insert state was entered with prefix | 1820 | ;; Repeats the insertion command if Insert state was entered with prefix |
| 1788 | ;; argument > 1. | 1821 | ;; argument > 1. |
| 1789 | (defun vip-repeat-insert-command () | 1822 | (defun viper-repeat-insert-command () |
| 1790 | (let ((i-com (car vip-d-com)) | 1823 | (let ((i-com (car viper-d-com)) |
| 1791 | (val (nth 1 vip-d-com)) | 1824 | (val (nth 1 viper-d-com)) |
| 1792 | (char (nth 2 vip-d-com))) | 1825 | (char (nth 2 viper-d-com))) |
| 1793 | (if (and val (> val 1)) ; first check that val is non-nil | 1826 | (if (and val (> val 1)) ; first check that val is non-nil |
| 1794 | (progn | 1827 | (progn |
| 1795 | (setq vip-d-com (list i-com (1- val) ?r nil nil nil)) | 1828 | (setq viper-d-com (list i-com (1- val) ?r nil nil nil)) |
| 1796 | (vip-repeat nil) | 1829 | (viper-repeat nil) |
| 1797 | (setq vip-d-com (list i-com val char nil nil nil)) | 1830 | (setq viper-d-com (list i-com val char nil nil nil)) |
| 1798 | )))) | 1831 | )))) |
| 1799 | 1832 | ||
| 1800 | (defun vip-insert (arg) | 1833 | (defun viper-insert (arg) |
| 1801 | "Insert before point." | 1834 | "Insert before point." |
| 1802 | (interactive "P") | 1835 | (interactive "P") |
| 1803 | (vip-set-complex-command-for-undo) | 1836 | (viper-set-complex-command-for-undo) |
| 1804 | (let ((val (vip-p-val arg)) | 1837 | (let ((val (viper-p-val arg)) |
| 1805 | (com (vip-getcom arg))) | 1838 | (com (viper-getcom arg))) |
| 1806 | (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil)) | 1839 | (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil)) |
| 1807 | (if com | 1840 | (if com |
| 1808 | (vip-loop val (vip-yank-last-insertion)) | 1841 | (viper-loop val (viper-yank-last-insertion)) |
| 1809 | (vip-change-state-to-insert)))) | 1842 | (viper-change-state-to-insert)))) |
| 1810 | 1843 | ||
| 1811 | (defun vip-append (arg) | 1844 | (defun viper-append (arg) |
| 1812 | "Append after point." | 1845 | "Append after point." |
| 1813 | (interactive "P") | 1846 | (interactive "P") |
| 1814 | (vip-set-complex-command-for-undo) | 1847 | (viper-set-complex-command-for-undo) |
| 1815 | (let ((val (vip-p-val arg)) | 1848 | (let ((val (viper-p-val arg)) |
| 1816 | (com (vip-getcom arg))) | 1849 | (com (viper-getcom arg))) |
| 1817 | (vip-set-destructive-command (list 'vip-append val ?r nil nil nil)) | 1850 | (viper-set-destructive-command (list 'viper-append val ?r nil nil nil)) |
| 1818 | (if (not (eolp)) (forward-char)) | 1851 | (if (not (eolp)) (forward-char)) |
| 1819 | (if (equal com ?r) | 1852 | (if (equal com ?r) |
| 1820 | (vip-loop val (vip-yank-last-insertion)) | 1853 | (viper-loop val (viper-yank-last-insertion)) |
| 1821 | (vip-change-state-to-insert)))) | 1854 | (viper-change-state-to-insert)))) |
| 1822 | 1855 | ||
| 1823 | (defun vip-Append (arg) | 1856 | (defun viper-Append (arg) |
| 1824 | "Append at end of line." | 1857 | "Append at end of line." |
| 1825 | (interactive "P") | 1858 | (interactive "P") |
| 1826 | (vip-set-complex-command-for-undo) | 1859 | (viper-set-complex-command-for-undo) |
| 1827 | (let ((val (vip-p-val arg)) | 1860 | (let ((val (viper-p-val arg)) |
| 1828 | (com (vip-getcom arg))) | 1861 | (com (viper-getcom arg))) |
| 1829 | (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil)) | 1862 | (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil)) |
| 1830 | (end-of-line) | 1863 | (end-of-line) |
| 1831 | (if (equal com ?r) | 1864 | (if (equal com ?r) |
| 1832 | (vip-loop val (vip-yank-last-insertion)) | 1865 | (viper-loop val (viper-yank-last-insertion)) |
| 1833 | (vip-change-state-to-insert)))) | 1866 | (viper-change-state-to-insert)))) |
| 1834 | 1867 | ||
| 1835 | (defun vip-Insert (arg) | 1868 | (defun viper-Insert (arg) |
| 1836 | "Insert before first non-white." | 1869 | "Insert before first non-white." |
| 1837 | (interactive "P") | 1870 | (interactive "P") |
| 1838 | (vip-set-complex-command-for-undo) | 1871 | (viper-set-complex-command-for-undo) |
| 1839 | (let ((val (vip-p-val arg)) | 1872 | (let ((val (viper-p-val arg)) |
| 1840 | (com (vip-getcom arg))) | 1873 | (com (viper-getcom arg))) |
| 1841 | (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil)) | 1874 | (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil)) |
| 1842 | (back-to-indentation) | 1875 | (back-to-indentation) |
| 1843 | (if (equal com ?r) | 1876 | (if (equal com ?r) |
| 1844 | (vip-loop val (vip-yank-last-insertion)) | 1877 | (viper-loop val (viper-yank-last-insertion)) |
| 1845 | (vip-change-state-to-insert)))) | 1878 | (viper-change-state-to-insert)))) |
| 1846 | 1879 | ||
| 1847 | (defun vip-open-line (arg) | 1880 | (defun viper-open-line (arg) |
| 1848 | "Open line below." | 1881 | "Open line below." |
| 1849 | (interactive "P") | 1882 | (interactive "P") |
| 1850 | (vip-set-complex-command-for-undo) | 1883 | (viper-set-complex-command-for-undo) |
| 1851 | (let ((val (vip-p-val arg)) | 1884 | (let ((val (viper-p-val arg)) |
| 1852 | (com (vip-getcom arg))) | 1885 | (com (viper-getcom arg))) |
| 1853 | (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil)) | 1886 | (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil)) |
| 1854 | (let ((col (current-indentation))) | 1887 | (let ((col (current-indentation))) |
| 1855 | (if (equal com ?r) | 1888 | (if (equal com ?r) |
| 1856 | (vip-loop val | 1889 | (viper-loop val |
| 1857 | (progn | 1890 | (progn |
| 1858 | (end-of-line) | 1891 | (end-of-line) |
| 1859 | (newline 1) | 1892 | (newline 1) |
| 1860 | (if vip-auto-indent | 1893 | (if viper-auto-indent |
| 1861 | (progn | 1894 | (progn |
| 1862 | (setq vip-cted t) | 1895 | (setq viper-cted t) |
| 1863 | (if vip-electric-mode | 1896 | (if viper-electric-mode |
| 1864 | (indent-according-to-mode) | 1897 | (indent-according-to-mode) |
| 1865 | (indent-to col)) | 1898 | (indent-to col)) |
| 1866 | )) | 1899 | )) |
| 1867 | (vip-yank-last-insertion))) | 1900 | (viper-yank-last-insertion))) |
| 1868 | (end-of-line) | 1901 | (end-of-line) |
| 1869 | (newline 1) | 1902 | (newline 1) |
| 1870 | (if vip-auto-indent | 1903 | (if viper-auto-indent |
| 1871 | (progn | 1904 | (progn |
| 1872 | (setq vip-cted t) | 1905 | (setq viper-cted t) |
| 1873 | (if vip-electric-mode | 1906 | (if viper-electric-mode |
| 1874 | (indent-according-to-mode) | 1907 | (indent-according-to-mode) |
| 1875 | (indent-to col)))) | 1908 | (indent-to col)))) |
| 1876 | (vip-change-state-to-insert))))) | 1909 | (viper-change-state-to-insert))))) |
| 1877 | 1910 | ||
| 1878 | (defun vip-Open-line (arg) | 1911 | (defun viper-Open-line (arg) |
| 1879 | "Open line above." | 1912 | "Open line above." |
| 1880 | (interactive "P") | 1913 | (interactive "P") |
| 1881 | (vip-set-complex-command-for-undo) | 1914 | (viper-set-complex-command-for-undo) |
| 1882 | (let ((val (vip-p-val arg)) | 1915 | (let ((val (viper-p-val arg)) |
| 1883 | (com (vip-getcom arg))) | 1916 | (com (viper-getcom arg))) |
| 1884 | (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil)) | 1917 | (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil)) |
| 1885 | (let ((col (current-indentation))) | 1918 | (let ((col (current-indentation))) |
| 1886 | (if (equal com ?r) | 1919 | (if (equal com ?r) |
| 1887 | (vip-loop val | 1920 | (viper-loop val |
| 1888 | (progn | 1921 | (progn |
| 1889 | (beginning-of-line) | 1922 | (beginning-of-line) |
| 1890 | (open-line 1) | 1923 | (open-line 1) |
| 1891 | (if vip-auto-indent | 1924 | (if viper-auto-indent |
| 1892 | (progn | 1925 | (progn |
| 1893 | (setq vip-cted t) | 1926 | (setq viper-cted t) |
| 1894 | (if vip-electric-mode | 1927 | (if viper-electric-mode |
| 1895 | (indent-according-to-mode) | 1928 | (indent-according-to-mode) |
| 1896 | (indent-to col)) | 1929 | (indent-to col)) |
| 1897 | )) | 1930 | )) |
| 1898 | (vip-yank-last-insertion))) | 1931 | (viper-yank-last-insertion))) |
| 1899 | (beginning-of-line) | 1932 | (beginning-of-line) |
| 1900 | (open-line 1) | 1933 | (open-line 1) |
| 1901 | (if vip-auto-indent | 1934 | (if viper-auto-indent |
| 1902 | (progn | 1935 | (progn |
| 1903 | (setq vip-cted t) | 1936 | (setq viper-cted t) |
| 1904 | (if vip-electric-mode | 1937 | (if viper-electric-mode |
| 1905 | (indent-according-to-mode) | 1938 | (indent-according-to-mode) |
| 1906 | (indent-to col)) | 1939 | (indent-to col)) |
| 1907 | )) | 1940 | )) |
| 1908 | (vip-change-state-to-insert))))) | 1941 | (viper-change-state-to-insert))))) |
| 1909 | 1942 | ||
| 1910 | (defun vip-open-line-at-point (arg) | 1943 | (defun viper-open-line-at-point (arg) |
| 1911 | "Open line at point." | 1944 | "Open line at point." |
| 1912 | (interactive "P") | 1945 | (interactive "P") |
| 1913 | (vip-set-complex-command-for-undo) | 1946 | (viper-set-complex-command-for-undo) |
| 1914 | (let ((val (vip-p-val arg)) | 1947 | (let ((val (viper-p-val arg)) |
| 1915 | (com (vip-getcom arg))) | 1948 | (com (viper-getcom arg))) |
| 1916 | (vip-set-destructive-command | 1949 | (viper-set-destructive-command |
| 1917 | (list 'vip-open-line-at-point val ?r nil nil nil)) | 1950 | (list 'viper-open-line-at-point val ?r nil nil nil)) |
| 1918 | (if (equal com ?r) | 1951 | (if (equal com ?r) |
| 1919 | (vip-loop val | 1952 | (viper-loop val |
| 1920 | (progn | 1953 | (progn |
| 1921 | (open-line 1) | 1954 | (open-line 1) |
| 1922 | (vip-yank-last-insertion))) | 1955 | (viper-yank-last-insertion))) |
| 1923 | (open-line 1) | 1956 | (open-line 1) |
| 1924 | (vip-change-state-to-insert)))) | 1957 | (viper-change-state-to-insert)))) |
| 1925 | 1958 | ||
| 1926 | (defun vip-substitute (arg) | 1959 | (defun viper-substitute (arg) |
| 1927 | "Substitute characters." | 1960 | "Substitute characters." |
| 1928 | (interactive "P") | 1961 | (interactive "P") |
| 1929 | (let ((val (vip-p-val arg)) | 1962 | (let ((val (viper-p-val arg)) |
| 1930 | (com (vip-getcom arg))) | 1963 | (com (viper-getcom arg))) |
| 1931 | (push-mark nil t) | 1964 | (push-mark nil t) |
| 1932 | (forward-char val) | 1965 | (forward-char val) |
| 1933 | (if (equal com ?r) | 1966 | (if (equal com ?r) |
| 1934 | (vip-change-subr (mark t) (point)) | 1967 | (viper-change-subr (mark t) (point)) |
| 1935 | (vip-change (mark t) (point))) | 1968 | (viper-change (mark t) (point))) |
| 1936 | (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil)) | 1969 | (viper-set-destructive-command (list 'viper-substitute val ?r nil nil nil)) |
| 1937 | )) | 1970 | )) |
| 1938 | 1971 | ||
| 1939 | (defun vip-substitute-line (arg) | 1972 | ;; Command bound to S |
| 1973 | (defun viper-substitute-line (arg) | ||
| 1940 | "Substitute lines." | 1974 | "Substitute lines." |
| 1941 | (interactive "p") | 1975 | (interactive "p") |
| 1942 | (vip-set-complex-command-for-undo) | 1976 | (viper-set-complex-command-for-undo) |
| 1943 | (vip-line (cons arg ?C))) | 1977 | (viper-line (cons arg ?C))) |
| 1944 | 1978 | ||
| 1945 | ;; Prepare for replace | 1979 | ;; Prepare for replace |
| 1946 | (defun vip-start-replace () | 1980 | (defun viper-start-replace () |
| 1947 | (setq vip-began-as-replace t | 1981 | (setq viper-began-as-replace t |
| 1948 | vip-sitting-in-replace t | 1982 | viper-sitting-in-replace t |
| 1949 | vip-replace-chars-to-delete 0 | 1983 | viper-replace-chars-to-delete 0 |
| 1950 | vip-replace-chars-deleted 0) | 1984 | viper-replace-chars-deleted 0) |
| 1951 | (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t) | 1985 | (viper-add-hook |
| 1952 | (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t) | 1986 | 'viper-after-change-functions 'viper-replace-mode-spy-after t) |
| 1987 | (viper-add-hook | ||
| 1988 | 'viper-before-change-functions 'viper-replace-mode-spy-before t) | ||
| 1953 | ;; this will get added repeatedly, but no harm | 1989 | ;; this will get added repeatedly, but no harm |
| 1954 | (add-hook 'after-change-functions 'vip-after-change-sentinel t) | 1990 | (add-hook 'after-change-functions 'viper-after-change-sentinel t) |
| 1955 | (add-hook 'before-change-functions 'vip-before-change-sentinel t) | 1991 | (add-hook 'before-change-functions 'viper-before-change-sentinel t) |
| 1956 | (vip-move-marker-locally 'vip-last-posn-in-replace-region | 1992 | (viper-move-marker-locally 'viper-last-posn-in-replace-region |
| 1957 | (vip-replace-start)) | 1993 | (viper-replace-start)) |
| 1958 | (vip-add-hook | 1994 | (viper-add-hook |
| 1959 | 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) | 1995 | 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel t) |
| 1960 | (vip-add-hook | 1996 | (viper-add-hook |
| 1961 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 1997 | 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t) |
| 1962 | ;; guard against a smartie who switched from R-replace to normal replace | 1998 | ;; guard against a smartie who switched from R-replace to normal replace |
| 1963 | (vip-remove-hook | 1999 | (viper-remove-hook |
| 1964 | 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) | 2000 | 'viper-post-command-hooks 'viper-R-state-post-command-sentinel) |
| 1965 | (if overwrite-mode (overwrite-mode nil)) | 2001 | (if overwrite-mode (overwrite-mode nil)) |
| 1966 | ) | 2002 | ) |
| 1967 | 2003 | ||
| 1968 | 2004 | ||
| 1969 | ;; checks how many chars were deleted by the last change | 2005 | ;; checks how many chars were deleted by the last change |
| 1970 | (defun vip-replace-mode-spy-before (beg end) | 2006 | (defun viper-replace-mode-spy-before (beg end) |
| 1971 | (setq vip-replace-chars-deleted | 2007 | (setq viper-replace-chars-deleted |
| 1972 | (- end beg | 2008 | (- end beg |
| 1973 | (max 0 (- end (vip-replace-end))) | 2009 | (max 0 (- end (viper-replace-end))) |
| 1974 | (max 0 (- (vip-replace-start) beg)) | 2010 | (max 0 (- (viper-replace-start) beg)) |
| 1975 | ))) | 2011 | ))) |
| 1976 | 2012 | ||
| 1977 | ;; Invoked as an after-change-function to set up parameters of the last change | 2013 | ;; Invoked as an after-change-function to set up parameters of the last change |
| 1978 | (defun vip-replace-mode-spy-after (beg end length) | 2014 | (defun viper-replace-mode-spy-after (beg end length) |
| 1979 | (if (memq vip-intermediate-command '(repeating-insertion-from-ring)) | 2015 | (if (memq viper-intermediate-command '(repeating-insertion-from-ring)) |
| 1980 | (progn | 2016 | (progn |
| 1981 | (setq vip-replace-chars-to-delete 0) | 2017 | (setq viper-replace-chars-to-delete 0) |
| 1982 | (vip-move-marker-locally | 2018 | (viper-move-marker-locally |
| 1983 | 'vip-last-posn-in-replace-region (point))) | 2019 | 'viper-last-posn-in-replace-region (point))) |
| 1984 | 2020 | ||
| 1985 | (let (beg-col end-col real-end chars-to-delete) | 2021 | (let (beg-col end-col real-end chars-to-delete) |
| 1986 | (setq real-end (min end (vip-replace-end))) | 2022 | (setq real-end (min end (viper-replace-end))) |
| 1987 | (save-excursion | 2023 | (save-excursion |
| 1988 | (goto-char beg) | 2024 | (goto-char beg) |
| 1989 | (setq beg-col (current-column)) | 2025 | (setq beg-col (current-column)) |
| @@ -2013,8 +2049,8 @@ Undo previous insertion and inserts new." | |||
| 2013 | ;; regions as well, since this will let us capture the situation when | 2049 | ;; regions as well, since this will let us capture the situation when |
| 2014 | ;; dabbrev-expand goes back past the insertion point to find the | 2050 | ;; dabbrev-expand goes back past the insertion point to find the |
| 2015 | ;; beginning of the word to be expanded. | 2051 | ;; beginning of the word to be expanded. |
| 2016 | (if (or (and (<= (vip-replace-start) beg) | 2052 | (if (or (and (<= (viper-replace-start) beg) |
| 2017 | (<= beg (vip-replace-end))) | 2053 | (<= beg (viper-replace-end))) |
| 2018 | (and (= length 0) (eq this-command 'dabbrev-expand))) | 2054 | (and (= length 0) (eq this-command 'dabbrev-expand))) |
| 2019 | (setq chars-to-delete | 2055 | (setq chars-to-delete |
| 2020 | (max (- end-col beg-col) (- real-end beg) 0)) | 2056 | (max (- end-col beg-col) (- real-end beg) 0)) |
| @@ -2024,277 +2060,289 @@ Undo previous insertion and inserts new." | |||
| 2024 | ;; same command that does multiple changes. Moreover, it means | 2060 | ;; same command that does multiple changes. Moreover, it means |
| 2025 | ;; that we have two subsequent changes (insert/delete) that | 2061 | ;; that we have two subsequent changes (insert/delete) that |
| 2026 | ;; complement each other. | 2062 | ;; complement each other. |
| 2027 | (if (= beg (marker-position vip-last-posn-in-replace-region)) | 2063 | (if (= beg (marker-position viper-last-posn-in-replace-region)) |
| 2028 | (setq vip-replace-chars-to-delete | 2064 | (setq viper-replace-chars-to-delete |
| 2029 | (- (+ chars-to-delete vip-replace-chars-to-delete) | 2065 | (- (+ chars-to-delete viper-replace-chars-to-delete) |
| 2030 | vip-replace-chars-deleted)) | 2066 | viper-replace-chars-deleted)) |
| 2031 | (setq vip-replace-chars-to-delete chars-to-delete)) | 2067 | (setq viper-replace-chars-to-delete chars-to-delete)) |
| 2032 | 2068 | ||
| 2033 | (vip-move-marker-locally | 2069 | (viper-move-marker-locally |
| 2034 | 'vip-last-posn-in-replace-region | 2070 | 'viper-last-posn-in-replace-region |
| 2035 | (max (if (> end (vip-replace-end)) (vip-replace-start) end) | 2071 | (max (if (> end (viper-replace-end)) (viper-replace-start) end) |
| 2036 | (or (marker-position vip-last-posn-in-replace-region) | 2072 | (or (marker-position viper-last-posn-in-replace-region) |
| 2037 | (vip-replace-start)) | 2073 | (viper-replace-start)) |
| 2038 | )) | 2074 | )) |
| 2039 | 2075 | ||
| 2040 | (setq vip-replace-chars-to-delete | 2076 | (setq viper-replace-chars-to-delete |
| 2041 | (max 0 | 2077 | (max 0 |
| 2042 | (min vip-replace-chars-to-delete | 2078 | (min viper-replace-chars-to-delete |
| 2043 | (- (vip-replace-end) vip-last-posn-in-replace-region) | 2079 | (- (viper-replace-end) viper-last-posn-in-replace-region) |
| 2044 | (- (vip-line-pos 'end) vip-last-posn-in-replace-region) | 2080 | (- (viper-line-pos 'end) |
| 2081 | viper-last-posn-in-replace-region) | ||
| 2045 | ))) | 2082 | ))) |
| 2046 | ))) | 2083 | ))) |
| 2047 | 2084 | ||
| 2048 | 2085 | ||
| 2049 | ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | 2086 | ;; Delete stuff between posn and the end of viper-replace-overlay-marker, if |
| 2050 | ;; posn is within the overlay. | 2087 | ;; posn is within the overlay. |
| 2051 | (defun vip-finish-change (posn) | 2088 | (defun viper-finish-change (posn) |
| 2052 | (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after) | 2089 | (viper-remove-hook |
| 2053 | (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before) | 2090 | 'viper-after-change-functions 'viper-replace-mode-spy-after) |
| 2054 | (vip-remove-hook 'vip-post-command-hooks | 2091 | (viper-remove-hook |
| 2055 | 'vip-replace-state-post-command-sentinel) | 2092 | 'viper-before-change-functions 'viper-replace-mode-spy-before) |
| 2056 | (vip-remove-hook | 2093 | (viper-remove-hook |
| 2057 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) | 2094 | 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel) |
| 2058 | (vip-restore-cursor-color-after-replace) | 2095 | (viper-remove-hook |
| 2059 | (setq vip-sitting-in-replace nil) ; just in case we'll need to know it | 2096 | 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel) |
| 2097 | (viper-restore-cursor-color-after-replace) | ||
| 2098 | (setq viper-sitting-in-replace nil) ; just in case we'll need to know it | ||
| 2060 | (save-excursion | 2099 | (save-excursion |
| 2061 | (if (and | 2100 | (if (and |
| 2062 | vip-replace-overlay | 2101 | viper-replace-overlay |
| 2063 | (>= posn (vip-replace-start)) | 2102 | (>= posn (viper-replace-start)) |
| 2064 | (< posn (vip-replace-end))) | 2103 | (< posn (viper-replace-end))) |
| 2065 | (delete-region posn (vip-replace-end))) | 2104 | (delete-region posn (viper-replace-end))) |
| 2066 | ) | 2105 | ) |
| 2067 | 2106 | ||
| 2068 | (if (eq vip-current-state 'replace-state) | 2107 | (if (eq viper-current-state 'replace-state) |
| 2069 | (vip-downgrade-to-insert)) | 2108 | (viper-downgrade-to-insert)) |
| 2070 | ;; replace mode ended => nullify vip-last-posn-in-replace-region | 2109 | ;; replace mode ended => nullify viper-last-posn-in-replace-region |
| 2071 | (vip-move-marker-locally 'vip-last-posn-in-replace-region nil) | 2110 | (viper-move-marker-locally 'viper-last-posn-in-replace-region nil) |
| 2072 | (vip-hide-replace-overlay) | 2111 | (viper-hide-replace-overlay) |
| 2073 | (vip-refresh-mode-line) | 2112 | (viper-refresh-mode-line) |
| 2074 | (vip-put-string-on-kill-ring vip-last-replace-region) | 2113 | (viper-put-string-on-kill-ring viper-last-replace-region) |
| 2075 | ) | 2114 | ) |
| 2076 | 2115 | ||
| 2077 | ;; Make STRING be the first element of the kill ring. | 2116 | ;; Make STRING be the first element of the kill ring. |
| 2078 | (defun vip-put-string-on-kill-ring (string) | 2117 | (defun viper-put-string-on-kill-ring (string) |
| 2079 | (setq kill-ring (cons string kill-ring)) | 2118 | (setq kill-ring (cons string kill-ring)) |
| 2080 | (if (> (length kill-ring) kill-ring-max) | 2119 | (if (> (length kill-ring) kill-ring-max) |
| 2081 | (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) | 2120 | (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) |
| 2082 | (setq kill-ring-yank-pointer kill-ring)) | 2121 | (setq kill-ring-yank-pointer kill-ring)) |
| 2083 | 2122 | ||
| 2084 | (defun vip-finish-R-mode () | 2123 | (defun viper-finish-R-mode () |
| 2085 | (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) | 2124 | (viper-remove-hook |
| 2086 | (vip-remove-hook | 2125 | 'viper-post-command-hooks 'viper-R-state-post-command-sentinel) |
| 2087 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) | 2126 | (viper-remove-hook |
| 2088 | (vip-downgrade-to-insert)) | 2127 | 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel) |
| 2128 | (viper-downgrade-to-insert)) | ||
| 2089 | 2129 | ||
| 2090 | (defun vip-start-R-mode () | 2130 | (defun viper-start-R-mode () |
| 2091 | ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number | 2131 | ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number |
| 2092 | (overwrite-mode 1) | 2132 | (overwrite-mode 1) |
| 2093 | (vip-add-hook | 2133 | (viper-add-hook |
| 2094 | 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) | 2134 | 'viper-post-command-hooks 'viper-R-state-post-command-sentinel t) |
| 2095 | (vip-add-hook | 2135 | (viper-add-hook |
| 2096 | 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) | 2136 | 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t) |
| 2097 | ;; guard against a smartie who switched from R-replace to normal replace | 2137 | ;; guard against a smartie who switched from R-replace to normal replace |
| 2098 | (vip-remove-hook | 2138 | (viper-remove-hook |
| 2099 | 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel) | 2139 | 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel) |
| 2100 | ) | 2140 | ) |
| 2101 | 2141 | ||
| 2102 | 2142 | ||
| 2103 | 2143 | ||
| 2104 | (defun vip-replace-state-exit-cmd () | 2144 | (defun viper-replace-state-exit-cmd () |
| 2105 | "Binding for keys that cause Replace state to switch to Vi or to Insert. | 2145 | "Binding for keys that cause Replace state to switch to Vi or to Insert. |
| 2106 | These keys are ESC, RET, and LineFeed" | 2146 | These keys are ESC, RET, and LineFeed" |
| 2107 | (interactive) | 2147 | (interactive) |
| 2108 | (if overwrite-mode ;; If you are in replace mode invoked via 'R' | 2148 | (if overwrite-mode ;; If you are in replace mode invoked via 'R' |
| 2109 | (vip-finish-R-mode) | 2149 | (viper-finish-R-mode) |
| 2110 | (vip-finish-change vip-last-posn-in-replace-region)) | 2150 | (viper-finish-change viper-last-posn-in-replace-region)) |
| 2111 | (let (com) | 2151 | (let (com) |
| 2112 | (if (eq this-command 'vip-intercept-ESC-key) | 2152 | (if (eq this-command 'viper-intercept-ESC-key) |
| 2113 | (setq com 'vip-exit-insert-state) | 2153 | (setq com 'viper-exit-insert-state) |
| 2114 | (vip-set-unread-command-events last-input-char) | 2154 | (viper-set-unread-command-events last-input-char) |
| 2115 | (setq com (key-binding (read-key-sequence nil)))) | 2155 | (setq com (key-binding (read-key-sequence nil)))) |
| 2116 | 2156 | ||
| 2117 | (condition-case conds | 2157 | (condition-case conds |
| 2118 | (command-execute com) | 2158 | (command-execute com) |
| 2119 | (error | 2159 | (error |
| 2120 | (vip-message-conditions conds))) | 2160 | (viper-message-conditions conds))) |
| 2121 | ) | 2161 | ) |
| 2122 | (vip-hide-replace-overlay)) | 2162 | (viper-hide-replace-overlay)) |
| 2163 | |||
| 2123 | 2164 | ||
| 2124 | (defun vip-replace-state-carriage-return () | 2165 | (defun viper-replace-state-carriage-return () |
| 2125 | "Implements carriage return in Viper replace state." | 2166 | "Carriage return in Viper replace state." |
| 2126 | (interactive) | 2167 | (interactive) |
| 2127 | ;; If Emacs start supporting overlay maps, as it currently supports | 2168 | ;; If Emacs start supporting overlay maps, as it currently supports |
| 2128 | ;; text-property maps, we could do away with vip-replace-minor-mode and | 2169 | ;; text-property maps, we could do away with viper-replace-minor-mode and |
| 2129 | ;; just have keymap attached to replace overlay. Then the "if part" of this | 2170 | ;; just have keymap attached to replace overlay. Then the "if part" of this |
| 2130 | ;; statement can be deleted. | 2171 | ;; statement can be deleted. |
| 2131 | (if (or (< (point) (vip-replace-start)) | 2172 | (if (or (< (point) (viper-replace-start)) |
| 2132 | (> (point) (vip-replace-end))) | 2173 | (> (point) (viper-replace-end))) |
| 2133 | (let (vip-replace-minor-mode com) | 2174 | (let (viper-replace-minor-mode com) |
| 2134 | (vip-set-unread-command-events last-input-char) | 2175 | (viper-set-unread-command-events last-input-char) |
| 2135 | (setq com (key-binding (read-key-sequence nil))) | 2176 | (setq com (key-binding (read-key-sequence nil))) |
| 2136 | (condition-case conds | 2177 | (condition-case conds |
| 2137 | (command-execute com) | 2178 | (command-execute com) |
| 2138 | (error | 2179 | (error |
| 2139 | (vip-message-conditions conds)))) | 2180 | (viper-message-conditions conds)))) |
| 2140 | (if (not vip-allow-multiline-replace-regions) | 2181 | (if (not viper-allow-multiline-replace-regions) |
| 2141 | (vip-replace-state-exit-cmd) | 2182 | (viper-replace-state-exit-cmd) |
| 2142 | (if (vip-same-line (point) (vip-replace-end)) | 2183 | (if (viper-same-line (point) (viper-replace-end)) |
| 2143 | (vip-replace-state-exit-cmd) | 2184 | (viper-replace-state-exit-cmd) |
| 2144 | (vip-kill-line nil) | 2185 | ;; delete the rest of line |
| 2145 | (vip-next-line-at-bol nil))))) | 2186 | (delete-region (point) (viper-line-pos 'end)) |
| 2187 | (save-excursion | ||
| 2188 | (end-of-line) | ||
| 2189 | (if (eobp) (error "Last line in buffer"))) | ||
| 2190 | ;; skip to the next line | ||
| 2191 | (forward-line 1) | ||
| 2192 | (back-to-indentation) | ||
| 2193 | )))) | ||
| 2146 | 2194 | ||
| 2147 | 2195 | ||
| 2148 | ;; This is the function bound to 'R'---unlimited replace. | 2196 | ;; This is the function bound to 'R'---unlimited replace. |
| 2149 | ;; Similar to Emacs's own overwrite-mode. | 2197 | ;; Similar to Emacs's own overwrite-mode. |
| 2150 | (defun vip-overwrite (arg) | 2198 | (defun viper-overwrite (arg) |
| 2151 | "Begin overwrite mode." | 2199 | "Begin overwrite mode." |
| 2152 | (interactive "P") | 2200 | (interactive "P") |
| 2153 | (let ((val (vip-p-val arg)) | 2201 | (let ((val (viper-p-val arg)) |
| 2154 | (com (vip-getcom arg)) (len)) | 2202 | (com (viper-getcom arg)) (len)) |
| 2155 | (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil)) | 2203 | (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil)) |
| 2156 | (if com | 2204 | (if com |
| 2157 | (progn | 2205 | (progn |
| 2158 | ;; Viper saves inserted text in vip-last-insertion | 2206 | ;; Viper saves inserted text in viper-last-insertion |
| 2159 | (setq len (length vip-last-insertion)) | 2207 | (setq len (length viper-last-insertion)) |
| 2160 | (delete-char len) | 2208 | (delete-char len) |
| 2161 | (vip-loop val (vip-yank-last-insertion))) | 2209 | (viper-loop val (viper-yank-last-insertion))) |
| 2162 | (setq last-command 'vip-overwrite) | 2210 | (setq last-command 'viper-overwrite) |
| 2163 | (vip-set-complex-command-for-undo) | 2211 | (viper-set-complex-command-for-undo) |
| 2164 | (vip-set-replace-overlay (point) (vip-line-pos 'end)) | 2212 | (viper-set-replace-overlay (point) (viper-line-pos 'end)) |
| 2165 | (vip-change-state-to-replace) | 2213 | (viper-change-state-to-replace) |
| 2166 | ))) | 2214 | ))) |
| 2167 | 2215 | ||
| 2168 | 2216 | ||
| 2169 | ;; line commands | 2217 | ;; line commands |
| 2170 | 2218 | ||
| 2171 | (defun vip-line (arg) | 2219 | (defun viper-line (arg) |
| 2172 | (let ((val (car arg)) | 2220 | (let ((val (car arg)) |
| 2173 | (com (cdr arg))) | 2221 | (com (cdr arg))) |
| 2174 | (vip-move-marker-locally 'vip-com-point (point)) | 2222 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2175 | (if (not (eobp)) | 2223 | (if (not (eobp)) |
| 2176 | (vip-next-line-carefully (1- val))) | 2224 | (viper-next-line-carefully (1- val))) |
| 2177 | ;; this ensures that dd, cc, D, yy will do the right thing on the last | 2225 | ;; this ensures that dd, cc, D, yy will do the right thing on the last |
| 2178 | ;; line of buffer when this line has no \n. | 2226 | ;; line of buffer when this line has no \n. |
| 2179 | (vip-add-newline-at-eob-if-necessary) | 2227 | (viper-add-newline-at-eob-if-necessary) |
| 2180 | (vip-execute-com 'vip-line val com)) | 2228 | (viper-execute-com 'viper-line val com)) |
| 2181 | (if (and (eobp) (not (bobp))) (forward-line -1)) | 2229 | (if (and (eobp) (not (bobp))) (forward-line -1)) |
| 2182 | ) | 2230 | ) |
| 2183 | 2231 | ||
| 2184 | (defun vip-yank-line (arg) | 2232 | (defun viper-yank-line (arg) |
| 2185 | "Yank ARG lines (in Vi's sense)." | 2233 | "Yank ARG lines (in Vi's sense)." |
| 2186 | (interactive "P") | 2234 | (interactive "P") |
| 2187 | (let ((val (vip-p-val arg))) | 2235 | (let ((val (viper-p-val arg))) |
| 2188 | (vip-line (cons val ?Y)))) | 2236 | (viper-line (cons val ?Y)))) |
| 2189 | 2237 | ||
| 2190 | 2238 | ||
| 2191 | ;; region commands | 2239 | ;; region commands |
| 2192 | 2240 | ||
| 2193 | (defun vip-region (arg) | 2241 | (defun viper-region (arg) |
| 2194 | "Execute command on a region." | 2242 | "Execute command on a region." |
| 2195 | (interactive "P") | 2243 | (interactive "P") |
| 2196 | (let ((val (vip-P-val arg)) | 2244 | (let ((val (viper-P-val arg)) |
| 2197 | (com (vip-getcom arg))) | 2245 | (com (viper-getcom arg))) |
| 2198 | (vip-move-marker-locally 'vip-com-point (point)) | 2246 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2199 | (exchange-point-and-mark) | 2247 | (exchange-point-and-mark) |
| 2200 | (vip-execute-com 'vip-region val com))) | 2248 | (viper-execute-com 'viper-region val com))) |
| 2201 | 2249 | ||
| 2202 | (defun vip-Region (arg) | 2250 | (defun viper-Region (arg) |
| 2203 | "Execute command on a Region." | 2251 | "Execute command on a Region." |
| 2204 | (interactive "P") | 2252 | (interactive "P") |
| 2205 | (let ((val (vip-P-val arg)) | 2253 | (let ((val (viper-P-val arg)) |
| 2206 | (com (vip-getCom arg))) | 2254 | (com (viper-getCom arg))) |
| 2207 | (vip-move-marker-locally 'vip-com-point (point)) | 2255 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2208 | (exchange-point-and-mark) | 2256 | (exchange-point-and-mark) |
| 2209 | (vip-execute-com 'vip-Region val com))) | 2257 | (viper-execute-com 'viper-Region val com))) |
| 2210 | 2258 | ||
| 2211 | (defun vip-replace-char (arg) | 2259 | (defun viper-replace-char (arg) |
| 2212 | "Replace the following ARG chars by the character read." | 2260 | "Replace the following ARG chars by the character read." |
| 2213 | (interactive "P") | 2261 | (interactive "P") |
| 2214 | (if (and (eolp) (bolp)) (error "No character to replace here")) | 2262 | (if (and (eolp) (bolp)) (error "No character to replace here")) |
| 2215 | (let ((val (vip-p-val arg)) | 2263 | (let ((val (viper-p-val arg)) |
| 2216 | (com (vip-getcom arg))) | 2264 | (com (viper-getcom arg))) |
| 2217 | (vip-replace-char-subr com val) | 2265 | (viper-replace-char-subr com val) |
| 2218 | (if (and (eolp) (not (bolp))) (forward-char 1)) | 2266 | (if (and (eolp) (not (bolp))) (forward-char 1)) |
| 2219 | (vip-set-destructive-command | 2267 | (viper-set-destructive-command |
| 2220 | (list 'vip-replace-char val ?r nil vip-d-char nil)) | 2268 | (list 'viper-replace-char val ?r nil viper-d-char nil)) |
| 2221 | )) | 2269 | )) |
| 2222 | 2270 | ||
| 2223 | (defun vip-replace-char-subr (com arg) | 2271 | (defun viper-replace-char-subr (com arg) |
| 2224 | (let ((take-care-of-iso-accents | 2272 | (let ((take-care-of-iso-accents |
| 2225 | (and (boundp 'iso-accents-mode) vip-automatic-iso-accents)) | 2273 | (and (boundp 'iso-accents-mode) viper-automatic-iso-accents)) |
| 2226 | char) | 2274 | char) |
| 2227 | (setq char (if (equal com ?r) | 2275 | (setq char (if (equal com ?r) |
| 2228 | vip-d-char | 2276 | viper-d-char |
| 2229 | (read-char))) | 2277 | (read-char))) |
| 2230 | (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~))) | 2278 | (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~))) |
| 2231 | ;; get European characters | 2279 | ;; get European characters |
| 2232 | (progn | 2280 | (progn |
| 2233 | (iso-accents-mode 1) | 2281 | (iso-accents-mode 1) |
| 2234 | (vip-set-unread-command-events char) | 2282 | (viper-set-unread-command-events char) |
| 2235 | (setq char (aref (read-key-sequence nil) 0)) | 2283 | (setq char (aref (read-key-sequence nil) 0)) |
| 2236 | (iso-accents-mode -1))) | 2284 | (iso-accents-mode -1))) |
| 2237 | (delete-char arg t) | 2285 | (delete-char arg t) |
| 2238 | (setq vip-d-char char) | 2286 | (setq viper-d-char char) |
| 2239 | (vip-loop (if (> arg 0) arg (- arg)) | 2287 | (viper-loop (if (> arg 0) arg (- arg)) |
| 2240 | (if (eq char ?\C-m) (insert "\n") (insert char))) | 2288 | (if (eq char ?\C-m) (insert "\n") (insert char))) |
| 2241 | (backward-char arg))) | 2289 | (backward-char arg))) |
| 2242 | 2290 | ||
| 2243 | 2291 | ||
| 2244 | ;; basic cursor movement. j, k, l, h commands. | 2292 | ;; basic cursor movement. j, k, l, h commands. |
| 2245 | 2293 | ||
| 2246 | (defun vip-forward-char (arg) | 2294 | (defun viper-forward-char (arg) |
| 2247 | "Move point right ARG characters (left if ARG negative). | 2295 | "Move point right ARG characters (left if ARG negative). |
| 2248 | On reaching end of line, stop and signal error." | 2296 | On reaching end of line, stop and signal error." |
| 2249 | (interactive "P") | 2297 | (interactive "P") |
| 2250 | (vip-leave-region-active) | 2298 | (viper-leave-region-active) |
| 2251 | (let ((val (vip-p-val arg)) | 2299 | (let ((val (viper-p-val arg)) |
| 2252 | (com (vip-getcom arg))) | 2300 | (com (viper-getcom arg))) |
| 2253 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2301 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2254 | (if vip-ex-style-motion | 2302 | (if viper-ex-style-motion |
| 2255 | (progn | 2303 | (progn |
| 2256 | ;; the boundary condition check gets weird here because | 2304 | ;; the boundary condition check gets weird here because |
| 2257 | ;; forward-char may be the parameter of a delete, and 'dl' works | 2305 | ;; forward-char may be the parameter of a delete, and 'dl' works |
| 2258 | ;; just like 'x' for the last char on a line, so we have to allow | 2306 | ;; just like 'x' for the last char on a line, so we have to allow |
| 2259 | ;; the forward motion before the 'vip-execute-com', but, of | 2307 | ;; the forward motion before the 'viper-execute-com', but, of |
| 2260 | ;; course, 'dl' doesn't work on an empty line, so we have to | 2308 | ;; course, 'dl' doesn't work on an empty line, so we have to |
| 2261 | ;; catch that condition before 'vip-execute-com' | 2309 | ;; catch that condition before 'viper-execute-com' |
| 2262 | (if (and (eolp) (bolp)) (error "") (forward-char val)) | 2310 | (if (and (eolp) (bolp)) (error "") (forward-char val)) |
| 2263 | (if com (vip-execute-com 'vip-forward-char val com)) | 2311 | (if com (viper-execute-com 'viper-forward-char val com)) |
| 2264 | (if (eolp) (progn (backward-char 1) (error "")))) | 2312 | (if (eolp) (progn (backward-char 1) (error "")))) |
| 2265 | (forward-char val) | 2313 | (forward-char val) |
| 2266 | (if com (vip-execute-com 'vip-forward-char val com))))) | 2314 | (if com (viper-execute-com 'viper-forward-char val com))))) |
| 2267 | 2315 | ||
| 2268 | (defun vip-backward-char (arg) | 2316 | (defun viper-backward-char (arg) |
| 2269 | "Move point left ARG characters (right if ARG negative). | 2317 | "Move point left ARG characters (right if ARG negative). |
| 2270 | On reaching beginning of line, stop and signal error." | 2318 | On reaching beginning of line, stop and signal error." |
| 2271 | (interactive "P") | 2319 | (interactive "P") |
| 2272 | (vip-leave-region-active) | 2320 | (viper-leave-region-active) |
| 2273 | (let ((val (vip-p-val arg)) | 2321 | (let ((val (viper-p-val arg)) |
| 2274 | (com (vip-getcom arg))) | 2322 | (com (viper-getcom arg))) |
| 2275 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2323 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2276 | (if vip-ex-style-motion | 2324 | (if viper-ex-style-motion |
| 2277 | (progn | 2325 | (progn |
| 2278 | (if (bolp) (error "") (backward-char val)) | 2326 | (if (bolp) (error "") (backward-char val)) |
| 2279 | (if com (vip-execute-com 'vip-backward-char val com))) | 2327 | (if com (viper-execute-com 'viper-backward-char val com))) |
| 2280 | (backward-char val) | 2328 | (backward-char val) |
| 2281 | (if com (vip-execute-com 'vip-backward-char val com))))) | 2329 | (if com (viper-execute-com 'viper-backward-char val com))))) |
| 2282 | 2330 | ||
| 2283 | ;; Like forward-char, but doesn't move at end of buffer. | 2331 | ;; Like forward-char, but doesn't move at end of buffer. |
| 2284 | (defun vip-forward-char-carefully (&optional arg) | 2332 | (defun viper-forward-char-carefully (&optional arg) |
| 2285 | (setq arg (or arg 1)) | 2333 | (setq arg (or arg 1)) |
| 2286 | (if (>= (point-max) (+ (point) arg)) | 2334 | (if (>= (point-max) (+ (point) arg)) |
| 2287 | (forward-char arg) | 2335 | (forward-char arg) |
| 2288 | (goto-char (point-max)))) | 2336 | (goto-char (point-max)))) |
| 2289 | 2337 | ||
| 2290 | ;; Like backward-char, but doesn't move at end of buffer. | 2338 | ;; Like backward-char, but doesn't move at end of buffer. |
| 2291 | (defun vip-backward-char-carefully (&optional arg) | 2339 | (defun viper-backward-char-carefully (&optional arg) |
| 2292 | (setq arg (or arg 1)) | 2340 | (setq arg (or arg 1)) |
| 2293 | (if (<= (point-min) (- (point) arg)) | 2341 | (if (<= (point-min) (- (point) arg)) |
| 2294 | (backward-char arg) | 2342 | (backward-char arg) |
| 2295 | (goto-char (point-min)))) | 2343 | (goto-char (point-min)))) |
| 2296 | 2344 | ||
| 2297 | (defun vip-next-line-carefully (arg) | 2345 | (defun viper-next-line-carefully (arg) |
| 2298 | (condition-case nil | 2346 | (condition-case nil |
| 2299 | (next-line arg) | 2347 | (next-line arg) |
| 2300 | (error nil))) | 2348 | (error nil))) |
| @@ -2303,337 +2351,336 @@ On reaching beginning of line, stop and signal error." | |||
| 2303 | 2351 | ||
| 2304 | ;;; Word command | 2352 | ;;; Word command |
| 2305 | 2353 | ||
| 2306 | ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators | 2354 | ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for |
| 2307 | ;; for word movement. When executed with a destructive command, \n is | 2355 | ;; word movement. When executed with a destructive command, \n is usually left |
| 2308 | ;; usually left untouched for the last word. | 2356 | ;; untouched for the last word. Viper uses syntax table to determine what is a |
| 2309 | ;; Viper uses syntax table to determine what is a word and what is a | 2357 | ;; word and what is a separator. However, \n is always a separator. Also, if |
| 2310 | ;; separator. However, \n is always a separator. Also, if vip-syntax-preference | 2358 | ;; viper-syntax-preference is 'vi, then `_' is part of the word. |
| 2311 | ;; is 'vi, then `_' is part of the word. | ||
| 2312 | 2359 | ||
| 2313 | ;; skip only one \n | 2360 | ;; skip only one \n |
| 2314 | (defun vip-skip-separators (forward) | 2361 | (defun viper-skip-separators (forward) |
| 2315 | (if forward | 2362 | (if forward |
| 2316 | (progn | 2363 | (progn |
| 2317 | (vip-skip-all-separators-forward 'within-line) | 2364 | (viper-skip-all-separators-forward 'within-line) |
| 2318 | (if (looking-at "\n") | 2365 | (if (looking-at "\n") |
| 2319 | (progn | 2366 | (progn |
| 2320 | (forward-char) | 2367 | (forward-char) |
| 2321 | (vip-skip-all-separators-forward 'within-line)))) | 2368 | (viper-skip-all-separators-forward 'within-line)))) |
| 2322 | (vip-skip-all-separators-backward 'within-line) | 2369 | (viper-skip-all-separators-backward 'within-line) |
| 2323 | (backward-char) | 2370 | (backward-char) |
| 2324 | (if (looking-at "\n") | 2371 | (if (looking-at "\n") |
| 2325 | (vip-skip-all-separators-backward 'within-line) | 2372 | (viper-skip-all-separators-backward 'within-line) |
| 2326 | (forward-char)))) | 2373 | (forward-char)))) |
| 2327 | 2374 | ||
| 2328 | (defun vip-forward-word-kernel (val) | 2375 | (defun viper-forward-word-kernel (val) |
| 2329 | (while (> val 0) | 2376 | (while (> val 0) |
| 2330 | (cond ((vip-looking-at-alpha) | 2377 | (cond ((viper-looking-at-alpha) |
| 2331 | (vip-skip-alpha-forward "_") | 2378 | (viper-skip-alpha-forward "_") |
| 2332 | (vip-skip-separators t)) | 2379 | (viper-skip-separators t)) |
| 2333 | ((vip-looking-at-separator) | 2380 | ((viper-looking-at-separator) |
| 2334 | (vip-skip-separators t)) | 2381 | (viper-skip-separators t)) |
| 2335 | ((not (vip-looking-at-alphasep)) | 2382 | ((not (viper-looking-at-alphasep)) |
| 2336 | (vip-skip-nonalphasep-forward) | 2383 | (viper-skip-nonalphasep-forward) |
| 2337 | (vip-skip-separators t))) | 2384 | (viper-skip-separators t))) |
| 2338 | (setq val (1- val)))) | 2385 | (setq val (1- val)))) |
| 2339 | 2386 | ||
| 2340 | ;; first search backward for pat. Then skip chars backwards using aux-pat | 2387 | ;; first search backward for pat. Then skip chars backwards using aux-pat |
| 2341 | (defun vip-fwd-skip (pat aux-pat lim) | 2388 | (defun viper-fwd-skip (pat aux-pat lim) |
| 2342 | (if (and (save-excursion | 2389 | (if (and (save-excursion |
| 2343 | (re-search-backward pat lim t)) | 2390 | (re-search-backward pat lim t)) |
| 2344 | (= (point) (match-end 0))) | 2391 | (= (point) (match-end 0))) |
| 2345 | (goto-char (match-beginning 0))) | 2392 | (goto-char (match-beginning 0))) |
| 2346 | (skip-chars-backward aux-pat lim) | 2393 | (skip-chars-backward aux-pat lim) |
| 2347 | (if (= (point) lim) | 2394 | (if (= (point) lim) |
| 2348 | (vip-forward-char-carefully)) | 2395 | (viper-forward-char-carefully)) |
| 2349 | ) | 2396 | ) |
| 2350 | 2397 | ||
| 2351 | 2398 | ||
| 2352 | (defun vip-forward-word (arg) | 2399 | (defun viper-forward-word (arg) |
| 2353 | "Forward word." | 2400 | "Forward word." |
| 2354 | (interactive "P") | 2401 | (interactive "P") |
| 2355 | (vip-leave-region-active) | 2402 | (viper-leave-region-active) |
| 2356 | (let ((val (vip-p-val arg)) | 2403 | (let ((val (viper-p-val arg)) |
| 2357 | (com (vip-getcom arg))) | 2404 | (com (viper-getcom arg))) |
| 2358 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2405 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2359 | (vip-forward-word-kernel val) | 2406 | (viper-forward-word-kernel val) |
| 2360 | (if com (progn | 2407 | (if com (progn |
| 2361 | (cond ((memq com (list ?c (- ?c))) | 2408 | (cond ((memq com (list ?c (- ?c))) |
| 2362 | (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) | 2409 | (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point)) |
| 2363 | ;; Yank words including the whitespace, but not newline | 2410 | ;; Yank words including the whitespace, but not newline |
| 2364 | ((memq com (list ?y (- ?y))) | 2411 | ((memq com (list ?y (- ?y))) |
| 2365 | (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) | 2412 | (viper-fwd-skip "\n[ \t]*" "" viper-com-point)) |
| 2366 | ((vip-dotable-command-p com) | 2413 | ((viper-dotable-command-p com) |
| 2367 | (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | 2414 | (viper-fwd-skip "\n[ \t]*" "" viper-com-point))) |
| 2368 | (vip-execute-com 'vip-forward-word val com))))) | 2415 | (viper-execute-com 'viper-forward-word val com))))) |
| 2369 | 2416 | ||
| 2370 | 2417 | ||
| 2371 | (defun vip-forward-Word (arg) | 2418 | (defun viper-forward-Word (arg) |
| 2372 | "Forward word delimited by white characters." | 2419 | "Forward word delimited by white characters." |
| 2373 | (interactive "P") | 2420 | (interactive "P") |
| 2374 | (vip-leave-region-active) | 2421 | (viper-leave-region-active) |
| 2375 | (let ((val (vip-p-val arg)) | 2422 | (let ((val (viper-p-val arg)) |
| 2376 | (com (vip-getcom arg))) | 2423 | (com (viper-getcom arg))) |
| 2377 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2424 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2378 | (vip-loop val | 2425 | (viper-loop val |
| 2379 | (progn | 2426 | (progn |
| 2380 | (vip-skip-nonseparators 'forward) | 2427 | (viper-skip-nonseparators 'forward) |
| 2381 | (vip-skip-separators t))) | 2428 | (viper-skip-separators t))) |
| 2382 | (if com (progn | 2429 | (if com (progn |
| 2383 | (cond ((memq com (list ?c (- ?c))) | 2430 | (cond ((memq com (list ?c (- ?c))) |
| 2384 | (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) | 2431 | (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point)) |
| 2385 | ;; Yank words including the whitespace, but not newline | 2432 | ;; Yank words including the whitespace, but not newline |
| 2386 | ((memq com (list ?y (- ?y))) | 2433 | ((memq com (list ?y (- ?y))) |
| 2387 | (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) | 2434 | (viper-fwd-skip "\n[ \t]*" "" viper-com-point)) |
| 2388 | ((vip-dotable-command-p com) | 2435 | ((viper-dotable-command-p com) |
| 2389 | (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | 2436 | (viper-fwd-skip "\n[ \t]*" "" viper-com-point))) |
| 2390 | (vip-execute-com 'vip-forward-Word val com))))) | 2437 | (viper-execute-com 'viper-forward-Word val com))))) |
| 2391 | 2438 | ||
| 2392 | 2439 | ||
| 2393 | ;; this is a bit different from Vi, but Vi's end of word | 2440 | ;; this is a bit different from Vi, but Vi's end of word |
| 2394 | ;; makes no sense whatsoever | 2441 | ;; makes no sense whatsoever |
| 2395 | (defun vip-end-of-word-kernel () | 2442 | (defun viper-end-of-word-kernel () |
| 2396 | (if (vip-end-of-word-p) (forward-char)) | 2443 | (if (viper-end-of-word-p) (forward-char)) |
| 2397 | (if (vip-looking-at-separator) | 2444 | (if (viper-looking-at-separator) |
| 2398 | (vip-skip-all-separators-forward)) | 2445 | (viper-skip-all-separators-forward)) |
| 2399 | 2446 | ||
| 2400 | (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_")) | 2447 | (cond ((viper-looking-at-alpha) (viper-skip-alpha-forward "_")) |
| 2401 | ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward))) | 2448 | ((not (viper-looking-at-alphasep)) (viper-skip-nonalphasep-forward))) |
| 2402 | (vip-backward-char-carefully)) | 2449 | (viper-backward-char-carefully)) |
| 2403 | 2450 | ||
| 2404 | (defun vip-end-of-word-p () | 2451 | (defun viper-end-of-word-p () |
| 2405 | (or (eobp) | 2452 | (or (eobp) |
| 2406 | (save-excursion | 2453 | (save-excursion |
| 2407 | (cond ((vip-looking-at-alpha) | 2454 | (cond ((viper-looking-at-alpha) |
| 2408 | (forward-char) | 2455 | (forward-char) |
| 2409 | (not (vip-looking-at-alpha))) | 2456 | (not (viper-looking-at-alpha))) |
| 2410 | ((not (vip-looking-at-alphasep)) | 2457 | ((not (viper-looking-at-alphasep)) |
| 2411 | (forward-char) | 2458 | (forward-char) |
| 2412 | (vip-looking-at-alphasep)))))) | 2459 | (viper-looking-at-alphasep)))))) |
| 2413 | 2460 | ||
| 2414 | 2461 | ||
| 2415 | (defun vip-end-of-word (arg &optional careful) | 2462 | (defun viper-end-of-word (arg &optional careful) |
| 2416 | "Move point to end of current word." | 2463 | "Move point to end of current word." |
| 2417 | (interactive "P") | 2464 | (interactive "P") |
| 2418 | (vip-leave-region-active) | 2465 | (viper-leave-region-active) |
| 2419 | (let ((val (vip-p-val arg)) | 2466 | (let ((val (viper-p-val arg)) |
| 2420 | (com (vip-getcom arg))) | 2467 | (com (viper-getcom arg))) |
| 2421 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2468 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2422 | (vip-loop val (vip-end-of-word-kernel)) | 2469 | (viper-loop val (viper-end-of-word-kernel)) |
| 2423 | (if com | 2470 | (if com |
| 2424 | (progn | 2471 | (progn |
| 2425 | (forward-char) | 2472 | (forward-char) |
| 2426 | (vip-execute-com 'vip-end-of-word val com))))) | 2473 | (viper-execute-com 'viper-end-of-word val com))))) |
| 2427 | 2474 | ||
| 2428 | (defun vip-end-of-Word (arg) | 2475 | (defun viper-end-of-Word (arg) |
| 2429 | "Forward to end of word delimited by white character." | 2476 | "Forward to end of word delimited by white character." |
| 2430 | (interactive "P") | 2477 | (interactive "P") |
| 2431 | (vip-leave-region-active) | 2478 | (viper-leave-region-active) |
| 2432 | (let ((val (vip-p-val arg)) | 2479 | (let ((val (viper-p-val arg)) |
| 2433 | (com (vip-getcom arg))) | 2480 | (com (viper-getcom arg))) |
| 2434 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2481 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2435 | (vip-loop val | 2482 | (viper-loop val |
| 2436 | (progn | 2483 | (progn |
| 2437 | (vip-end-of-word-kernel) | 2484 | (viper-end-of-word-kernel) |
| 2438 | (vip-skip-nonseparators 'forward) | 2485 | (viper-skip-nonseparators 'forward) |
| 2439 | (backward-char))) | 2486 | (backward-char))) |
| 2440 | (if com | 2487 | (if com |
| 2441 | (progn | 2488 | (progn |
| 2442 | (forward-char) | 2489 | (forward-char) |
| 2443 | (vip-execute-com 'vip-end-of-Word val com))))) | 2490 | (viper-execute-com 'viper-end-of-Word val com))))) |
| 2444 | 2491 | ||
| 2445 | (defun vip-backward-word-kernel (val) | 2492 | (defun viper-backward-word-kernel (val) |
| 2446 | (while (> val 0) | 2493 | (while (> val 0) |
| 2447 | (backward-char) | 2494 | (backward-char) |
| 2448 | (cond ((vip-looking-at-alpha) | 2495 | (cond ((viper-looking-at-alpha) |
| 2449 | (vip-skip-alpha-backward "_")) | 2496 | (viper-skip-alpha-backward "_")) |
| 2450 | ((vip-looking-at-separator) | 2497 | ((viper-looking-at-separator) |
| 2451 | (forward-char) | 2498 | (forward-char) |
| 2452 | (vip-skip-separators nil) | 2499 | (viper-skip-separators nil) |
| 2453 | (backward-char) | 2500 | (backward-char) |
| 2454 | (cond ((vip-looking-at-alpha) | 2501 | (cond ((viper-looking-at-alpha) |
| 2455 | (vip-skip-alpha-backward "_")) | 2502 | (viper-skip-alpha-backward "_")) |
| 2456 | ((not (vip-looking-at-alphasep)) | 2503 | ((not (viper-looking-at-alphasep)) |
| 2457 | (vip-skip-nonalphasep-backward)) | 2504 | (viper-skip-nonalphasep-backward)) |
| 2458 | (t (forward-char)))) | 2505 | (t (forward-char)))) |
| 2459 | ((not (vip-looking-at-alphasep)) | 2506 | ((not (viper-looking-at-alphasep)) |
| 2460 | (vip-skip-nonalphasep-backward))) | 2507 | (viper-skip-nonalphasep-backward))) |
| 2461 | (setq val (1- val)))) | 2508 | (setq val (1- val)))) |
| 2462 | 2509 | ||
| 2463 | (defun vip-backward-word (arg) | 2510 | (defun viper-backward-word (arg) |
| 2464 | "Backward word." | 2511 | "Backward word." |
| 2465 | (interactive "P") | 2512 | (interactive "P") |
| 2466 | (vip-leave-region-active) | 2513 | (viper-leave-region-active) |
| 2467 | (let ((val (vip-p-val arg)) | 2514 | (let ((val (viper-p-val arg)) |
| 2468 | (com (vip-getcom arg))) | 2515 | (com (viper-getcom arg))) |
| 2469 | (if com | 2516 | (if com |
| 2470 | (let (i) | 2517 | (let (i) |
| 2471 | (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | 2518 | (if (setq i (save-excursion (backward-char) (looking-at "\n"))) |
| 2472 | (backward-char)) | 2519 | (backward-char)) |
| 2473 | (vip-move-marker-locally 'vip-com-point (point)) | 2520 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2474 | (if i (forward-char)))) | 2521 | (if i (forward-char)))) |
| 2475 | (vip-backward-word-kernel val) | 2522 | (viper-backward-word-kernel val) |
| 2476 | (if com (vip-execute-com 'vip-backward-word val com)))) | 2523 | (if com (viper-execute-com 'viper-backward-word val com)))) |
| 2477 | 2524 | ||
| 2478 | (defun vip-backward-Word (arg) | 2525 | (defun viper-backward-Word (arg) |
| 2479 | "Backward word delimited by white character." | 2526 | "Backward word delimited by white character." |
| 2480 | (interactive "P") | 2527 | (interactive "P") |
| 2481 | (vip-leave-region-active) | 2528 | (viper-leave-region-active) |
| 2482 | (let ((val (vip-p-val arg)) | 2529 | (let ((val (viper-p-val arg)) |
| 2483 | (com (vip-getcom arg))) | 2530 | (com (viper-getcom arg))) |
| 2484 | (if com | 2531 | (if com |
| 2485 | (let (i) | 2532 | (let (i) |
| 2486 | (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | 2533 | (if (setq i (save-excursion (backward-char) (looking-at "\n"))) |
| 2487 | (backward-char)) | 2534 | (backward-char)) |
| 2488 | (vip-move-marker-locally 'vip-com-point (point)) | 2535 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2489 | (if i (forward-char)))) | 2536 | (if i (forward-char)))) |
| 2490 | (vip-loop val | 2537 | (viper-loop val |
| 2491 | (progn | 2538 | (progn |
| 2492 | (vip-skip-separators nil) | 2539 | (viper-skip-separators nil) |
| 2493 | (vip-skip-nonseparators 'backward))) | 2540 | (viper-skip-nonseparators 'backward))) |
| 2494 | (if com (vip-execute-com 'vip-backward-Word val com)))) | 2541 | (if com (viper-execute-com 'viper-backward-Word val com)))) |
| 2495 | 2542 | ||
| 2496 | 2543 | ||
| 2497 | 2544 | ||
| 2498 | ;; line commands | 2545 | ;; line commands |
| 2499 | 2546 | ||
| 2500 | (defun vip-beginning-of-line (arg) | 2547 | (defun viper-beginning-of-line (arg) |
| 2501 | "Go to beginning of line." | 2548 | "Go to beginning of line." |
| 2502 | (interactive "P") | 2549 | (interactive "P") |
| 2503 | (vip-leave-region-active) | 2550 | (viper-leave-region-active) |
| 2504 | (let ((val (vip-p-val arg)) | 2551 | (let ((val (viper-p-val arg)) |
| 2505 | (com (vip-getcom arg))) | 2552 | (com (viper-getcom arg))) |
| 2506 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2553 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2507 | (beginning-of-line val) | 2554 | (beginning-of-line val) |
| 2508 | (if com (vip-execute-com 'vip-beginning-of-line val com)))) | 2555 | (if com (viper-execute-com 'viper-beginning-of-line val com)))) |
| 2509 | 2556 | ||
| 2510 | (defun vip-bol-and-skip-white (arg) | 2557 | (defun viper-bol-and-skip-white (arg) |
| 2511 | "Beginning of line at first non-white character." | 2558 | "Beginning of line at first non-white character." |
| 2512 | (interactive "P") | 2559 | (interactive "P") |
| 2513 | (vip-leave-region-active) | 2560 | (viper-leave-region-active) |
| 2514 | (let ((val (vip-p-val arg)) | 2561 | (let ((val (viper-p-val arg)) |
| 2515 | (com (vip-getcom arg))) | 2562 | (com (viper-getcom arg))) |
| 2516 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2563 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2517 | (forward-to-indentation (1- val)) | 2564 | (forward-to-indentation (1- val)) |
| 2518 | (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) | 2565 | (if com (viper-execute-com 'viper-bol-and-skip-white val com)))) |
| 2519 | 2566 | ||
| 2520 | (defun vip-goto-eol (arg) | 2567 | (defun viper-goto-eol (arg) |
| 2521 | "Go to end of line." | 2568 | "Go to end of line." |
| 2522 | (interactive "P") | 2569 | (interactive "P") |
| 2523 | (vip-leave-region-active) | 2570 | (viper-leave-region-active) |
| 2524 | (let ((val (vip-p-val arg)) | 2571 | (let ((val (viper-p-val arg)) |
| 2525 | (com (vip-getcom arg))) | 2572 | (com (viper-getcom arg))) |
| 2526 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2573 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2527 | (end-of-line val) | 2574 | (end-of-line val) |
| 2528 | (if com (vip-execute-com 'vip-goto-eol val com)) | 2575 | (if com (viper-execute-com 'viper-goto-eol val com)) |
| 2529 | (if vip-ex-style-motion | 2576 | (if viper-ex-style-motion |
| 2530 | (if (and (eolp) (not (bolp)) | 2577 | (if (and (eolp) (not (bolp)) |
| 2531 | ;; a fix for vip-change-to-eol | 2578 | ;; a fix for viper-change-to-eol |
| 2532 | (not (equal vip-current-state 'insert-state))) | 2579 | (not (equal viper-current-state 'insert-state))) |
| 2533 | (backward-char 1) | 2580 | (backward-char 1) |
| 2534 | )))) | 2581 | )))) |
| 2535 | 2582 | ||
| 2536 | 2583 | ||
| 2537 | (defun vip-goto-col (arg) | 2584 | (defun viper-goto-col (arg) |
| 2538 | "Go to ARG's column." | 2585 | "Go to ARG's column." |
| 2539 | (interactive "P") | 2586 | (interactive "P") |
| 2540 | (vip-leave-region-active) | 2587 | (viper-leave-region-active) |
| 2541 | (let ((val (vip-p-val arg)) | 2588 | (let ((val (viper-p-val arg)) |
| 2542 | (com (vip-getcom arg)) | 2589 | (com (viper-getcom arg)) |
| 2543 | line-len) | 2590 | line-len) |
| 2544 | (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start))) | 2591 | (setq line-len (- (viper-line-pos 'end) (viper-line-pos 'start))) |
| 2545 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2592 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2546 | (beginning-of-line) | 2593 | (beginning-of-line) |
| 2547 | (forward-char (1- (min line-len val))) | 2594 | (forward-char (1- (min line-len val))) |
| 2548 | (while (> (current-column) (1- val)) | 2595 | (while (> (current-column) (1- val)) |
| 2549 | (backward-char 1)) | 2596 | (backward-char 1)) |
| 2550 | (if com (vip-execute-com 'vip-goto-col val com)) | 2597 | (if com (viper-execute-com 'viper-goto-col val com)) |
| 2551 | (save-excursion | 2598 | (save-excursion |
| 2552 | (end-of-line) | 2599 | (end-of-line) |
| 2553 | (if (> val (current-column)) (error ""))) | 2600 | (if (> val (current-column)) (error ""))) |
| 2554 | )) | 2601 | )) |
| 2555 | 2602 | ||
| 2556 | 2603 | ||
| 2557 | (defun vip-next-line (arg) | 2604 | (defun viper-next-line (arg) |
| 2558 | "Go to next line." | 2605 | "Go to next line." |
| 2559 | (interactive "P") | 2606 | (interactive "P") |
| 2560 | (vip-leave-region-active) | 2607 | (viper-leave-region-active) |
| 2561 | (let ((val (vip-p-val arg)) | 2608 | (let ((val (viper-p-val arg)) |
| 2562 | (com (vip-getCom arg))) | 2609 | (com (viper-getCom arg))) |
| 2563 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2610 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2564 | (next-line val) | 2611 | (next-line val) |
| 2565 | (if vip-ex-style-motion | 2612 | (if viper-ex-style-motion |
| 2566 | (if (and (eolp) (not (bolp))) (backward-char 1))) | 2613 | (if (and (eolp) (not (bolp))) (backward-char 1))) |
| 2567 | (setq this-command 'next-line) | 2614 | (setq this-command 'next-line) |
| 2568 | (if com (vip-execute-com 'vip-next-line val com)))) | 2615 | (if com (viper-execute-com 'viper-next-line val com)))) |
| 2569 | 2616 | ||
| 2570 | (defun vip-next-line-at-bol (arg) | 2617 | (defun viper-next-line-at-bol (arg) |
| 2571 | "Next line at beginning of line." | 2618 | "Next line at beginning of line." |
| 2572 | (interactive "P") | 2619 | (interactive "P") |
| 2573 | (vip-leave-region-active) | 2620 | (viper-leave-region-active) |
| 2574 | (save-excursion | 2621 | (save-excursion |
| 2575 | (end-of-line) | 2622 | (end-of-line) |
| 2576 | (if (eobp) (error "Last line in buffer"))) | 2623 | (if (eobp) (error "Last line in buffer"))) |
| 2577 | (let ((val (vip-p-val arg)) | 2624 | (let ((val (viper-p-val arg)) |
| 2578 | (com (vip-getCom arg))) | 2625 | (com (viper-getCom arg))) |
| 2579 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2626 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2580 | (forward-line val) | 2627 | (forward-line val) |
| 2581 | (back-to-indentation) | 2628 | (back-to-indentation) |
| 2582 | (if com (vip-execute-com 'vip-next-line-at-bol val com)))) | 2629 | (if com (viper-execute-com 'viper-next-line-at-bol val com)))) |
| 2583 | 2630 | ||
| 2584 | (defun vip-previous-line (arg) | 2631 | (defun viper-previous-line (arg) |
| 2585 | "Go to previous line." | 2632 | "Go to previous line." |
| 2586 | (interactive "P") | 2633 | (interactive "P") |
| 2587 | (vip-leave-region-active) | 2634 | (viper-leave-region-active) |
| 2588 | (let ((val (vip-p-val arg)) | 2635 | (let ((val (viper-p-val arg)) |
| 2589 | (com (vip-getCom arg))) | 2636 | (com (viper-getCom arg))) |
| 2590 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2637 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2591 | (previous-line val) | 2638 | (previous-line val) |
| 2592 | (if vip-ex-style-motion | 2639 | (if viper-ex-style-motion |
| 2593 | (if (and (eolp) (not (bolp))) (backward-char 1))) | 2640 | (if (and (eolp) (not (bolp))) (backward-char 1))) |
| 2594 | (setq this-command 'previous-line) | 2641 | (setq this-command 'previous-line) |
| 2595 | (if com (vip-execute-com 'vip-previous-line val com)))) | 2642 | (if com (viper-execute-com 'viper-previous-line val com)))) |
| 2596 | 2643 | ||
| 2597 | 2644 | ||
| 2598 | (defun vip-previous-line-at-bol (arg) | 2645 | (defun viper-previous-line-at-bol (arg) |
| 2599 | "Previous line at beginning of line." | 2646 | "Previous line at beginning of line." |
| 2600 | (interactive "P") | 2647 | (interactive "P") |
| 2601 | (vip-leave-region-active) | 2648 | (viper-leave-region-active) |
| 2602 | (save-excursion | 2649 | (save-excursion |
| 2603 | (beginning-of-line) | 2650 | (beginning-of-line) |
| 2604 | (if (bobp) (error "First line in buffer"))) | 2651 | (if (bobp) (error "First line in buffer"))) |
| 2605 | (let ((val (vip-p-val arg)) | 2652 | (let ((val (viper-p-val arg)) |
| 2606 | (com (vip-getCom arg))) | 2653 | (com (viper-getCom arg))) |
| 2607 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2654 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2608 | (forward-line (- val)) | 2655 | (forward-line (- val)) |
| 2609 | (back-to-indentation) | 2656 | (back-to-indentation) |
| 2610 | (if com (vip-execute-com 'vip-previous-line val com)))) | 2657 | (if com (viper-execute-com 'viper-previous-line val com)))) |
| 2611 | 2658 | ||
| 2612 | (defun vip-change-to-eol (arg) | 2659 | (defun viper-change-to-eol (arg) |
| 2613 | "Change to end of line." | 2660 | "Change to end of line." |
| 2614 | (interactive "P") | 2661 | (interactive "P") |
| 2615 | (vip-goto-eol (cons arg ?c))) | 2662 | (viper-goto-eol (cons arg ?c))) |
| 2616 | 2663 | ||
| 2617 | (defun vip-kill-line (arg) | 2664 | (defun viper-kill-line (arg) |
| 2618 | "Delete line." | 2665 | "Delete line." |
| 2619 | (interactive "P") | 2666 | (interactive "P") |
| 2620 | (vip-goto-eol (cons arg ?d))) | 2667 | (viper-goto-eol (cons arg ?d))) |
| 2621 | 2668 | ||
| 2622 | (defun vip-erase-line (arg) | 2669 | (defun viper-erase-line (arg) |
| 2623 | "Erase line." | 2670 | "Erase line." |
| 2624 | (interactive "P") | 2671 | (interactive "P") |
| 2625 | (vip-beginning-of-line (cons arg ?d))) | 2672 | (viper-beginning-of-line (cons arg ?d))) |
| 2626 | 2673 | ||
| 2627 | 2674 | ||
| 2628 | ;;; Moving around | 2675 | ;;; Moving around |
| 2629 | 2676 | ||
| 2630 | (defun vip-goto-line (arg) | 2677 | (defun viper-goto-line (arg) |
| 2631 | "Go to ARG's line. Without ARG go to end of buffer." | 2678 | "Go to ARG's line. Without ARG go to end of buffer." |
| 2632 | (interactive "P") | 2679 | (interactive "P") |
| 2633 | (let ((val (vip-P-val arg)) | 2680 | (let ((val (viper-P-val arg)) |
| 2634 | (com (vip-getCom arg))) | 2681 | (com (viper-getCom arg))) |
| 2635 | (vip-move-marker-locally 'vip-com-point (point)) | 2682 | (viper-move-marker-locally 'viper-com-point (point)) |
| 2636 | (vip-deactivate-mark) | 2683 | (viper-deactivate-mark) |
| 2637 | (push-mark nil t) | 2684 | (push-mark nil t) |
| 2638 | (if (null val) | 2685 | (if (null val) |
| 2639 | (goto-char (point-max)) | 2686 | (goto-char (point-max)) |
| @@ -2644,7 +2691,7 @@ On reaching beginning of line, stop and signal error." | |||
| 2644 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2691 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2645 | (back-to-indentation) | 2692 | (back-to-indentation) |
| 2646 | 2693 | ||
| 2647 | (if com (vip-execute-com 'vip-goto-line val com)) | 2694 | (if com (viper-execute-com 'viper-goto-line val com)) |
| 2648 | 2695 | ||
| 2649 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2696 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2650 | (back-to-indentation) | 2697 | (back-to-indentation) |
| @@ -2653,12 +2700,12 @@ On reaching beginning of line, stop and signal error." | |||
| 2653 | ;; Find ARG's occurrence of CHAR on the current line. | 2700 | ;; Find ARG's occurrence of CHAR on the current line. |
| 2654 | ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to | 2701 | ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to |
| 2655 | ;; adjust point after search. | 2702 | ;; adjust point after search. |
| 2656 | (defun vip-find-char (arg char forward offset) | 2703 | (defun viper-find-char (arg char forward offset) |
| 2657 | (or (char-or-string-p char) (error "")) | 2704 | (or (char-or-string-p char) (error "")) |
| 2658 | (let ((arg (if forward arg (- arg))) | 2705 | (let ((arg (if forward arg (- arg))) |
| 2659 | (cmd (if (eq vip-intermediate-command 'vip-repeat) | 2706 | (cmd (if (eq viper-intermediate-command 'viper-repeat) |
| 2660 | (nth 5 vip-d-com) | 2707 | (nth 5 viper-d-com) |
| 2661 | (vip-array-to-string (this-command-keys)))) | 2708 | (viper-array-to-string (this-command-keys)))) |
| 2662 | point) | 2709 | point) |
| 2663 | (save-excursion | 2710 | (save-excursion |
| 2664 | (save-restriction | 2711 | (save-restriction |
| @@ -2683,155 +2730,150 @@ On reaching beginning of line, stop and signal error." | |||
| 2683 | (error "Command `%s': `%c' not found" cmd char)))) | 2730 | (error "Command `%s': `%c' not found" cmd char)))) |
| 2684 | (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) | 2731 | (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) |
| 2685 | 2732 | ||
| 2686 | (defun vip-find-char-forward (arg) | 2733 | (defun viper-find-char-forward (arg) |
| 2687 | "Find char on the line. | 2734 | "Find char on the line. |
| 2688 | If called interactively read the char to find from the terminal, and if | 2735 | If called interactively read the char to find from the terminal, and if |
| 2689 | called from vip-repeat, the char last used is used. This behaviour is | 2736 | called from viper-repeat, the char last used is used. This behaviour is |
| 2690 | controlled by the sign of prefix numeric value." | 2737 | controlled by the sign of prefix numeric value." |
| 2691 | (interactive "P") | 2738 | (interactive "P") |
| 2692 | (let ((val (vip-p-val arg)) | 2739 | (let ((val (viper-p-val arg)) |
| 2693 | (com (vip-getcom arg)) | 2740 | (com (viper-getcom arg)) |
| 2694 | (cmd-representation (nth 5 vip-d-com))) | 2741 | (cmd-representation (nth 5 viper-d-com))) |
| 2695 | (if (> val 0) | 2742 | (if (> val 0) |
| 2696 | ;; this means that the function was called interactively | 2743 | ;; this means that the function was called interactively |
| 2697 | (setq vip-f-char (read-char) | 2744 | (setq viper-f-char (read-char) |
| 2698 | vip-f-forward t | 2745 | viper-f-forward t |
| 2699 | vip-f-offset nil) | 2746 | viper-f-offset nil) |
| 2700 | ;; vip-repeat --- set vip-F-char from command-keys | 2747 | ;; viper-repeat --- set viper-F-char from command-keys |
| 2701 | (setq vip-F-char (if (stringp cmd-representation) | 2748 | (setq viper-F-char (if (stringp cmd-representation) |
| 2702 | (vip-seq-last-elt cmd-representation) | 2749 | (viper-seq-last-elt cmd-representation) |
| 2703 | vip-F-char) | 2750 | viper-F-char) |
| 2704 | vip-f-char vip-F-char) | 2751 | viper-f-char viper-F-char) |
| 2705 | (setq val (- val))) | 2752 | (setq val (- val))) |
| 2706 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2753 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2707 | (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) | 2754 | (viper-find-char |
| 2755 | val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t nil) | ||
| 2708 | (setq val (- val)) | 2756 | (setq val (- val)) |
| 2709 | (if com | 2757 | (if com |
| 2710 | (progn | 2758 | (progn |
| 2711 | (setq vip-F-char vip-f-char) ; set new vip-F-char | 2759 | (setq viper-F-char viper-f-char) ; set new viper-F-char |
| 2712 | (forward-char) | 2760 | (forward-char) |
| 2713 | (vip-execute-com 'vip-find-char-forward val com))))) | 2761 | (viper-execute-com 'viper-find-char-forward val com))))) |
| 2714 | 2762 | ||
| 2715 | (defun vip-goto-char-forward (arg) | 2763 | (defun viper-goto-char-forward (arg) |
| 2716 | "Go up to char ARG forward on line." | 2764 | "Go up to char ARG forward on line." |
| 2717 | (interactive "P") | 2765 | (interactive "P") |
| 2718 | (let ((val (vip-p-val arg)) | 2766 | (let ((val (viper-p-val arg)) |
| 2719 | (com (vip-getcom arg)) | 2767 | (com (viper-getcom arg)) |
| 2720 | (cmd-representation (nth 5 vip-d-com))) | 2768 | (cmd-representation (nth 5 viper-d-com))) |
| 2721 | (if (> val 0) | 2769 | (if (> val 0) |
| 2722 | ;; this means that the function was called interactively | 2770 | ;; this means that the function was called interactively |
| 2723 | (setq vip-f-char (read-char) | 2771 | (setq viper-f-char (read-char) |
| 2724 | vip-f-forward t | 2772 | viper-f-forward t |
| 2725 | vip-f-offset t) | 2773 | viper-f-offset t) |
| 2726 | ;; vip-repeat --- set vip-F-char from command-keys | 2774 | ;; viper-repeat --- set viper-F-char from command-keys |
| 2727 | (setq vip-F-char (if (stringp cmd-representation) | 2775 | (setq viper-F-char (if (stringp cmd-representation) |
| 2728 | (vip-seq-last-elt cmd-representation) | 2776 | (viper-seq-last-elt cmd-representation) |
| 2729 | vip-F-char) | 2777 | viper-F-char) |
| 2730 | vip-f-char vip-F-char) | 2778 | viper-f-char viper-F-char) |
| 2731 | (setq val (- val))) | 2779 | (setq val (- val))) |
| 2732 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2780 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2733 | (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) | 2781 | (viper-find-char |
| 2782 | val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t t) | ||
| 2734 | (setq val (- val)) | 2783 | (setq val (- val)) |
| 2735 | (if com | 2784 | (if com |
| 2736 | (progn | 2785 | (progn |
| 2737 | (setq vip-F-char vip-f-char) ; set new vip-F-char | 2786 | (setq viper-F-char viper-f-char) ; set new viper-F-char |
| 2738 | (forward-char) | 2787 | (forward-char) |
| 2739 | (vip-execute-com 'vip-goto-char-forward val com))))) | 2788 | (viper-execute-com 'viper-goto-char-forward val com))))) |
| 2740 | 2789 | ||
| 2741 | (defun vip-find-char-backward (arg) | 2790 | (defun viper-find-char-backward (arg) |
| 2742 | "Find char ARG on line backward." | 2791 | "Find char ARG on line backward." |
| 2743 | (interactive "P") | 2792 | (interactive "P") |
| 2744 | (let ((val (vip-p-val arg)) | 2793 | (let ((val (viper-p-val arg)) |
| 2745 | (com (vip-getcom arg)) | 2794 | (com (viper-getcom arg)) |
| 2746 | (cmd-representation (nth 5 vip-d-com))) | 2795 | (cmd-representation (nth 5 viper-d-com))) |
| 2747 | (if (> val 0) | 2796 | (if (> val 0) |
| 2748 | ;; this means that the function was called interactively | 2797 | ;; this means that the function was called interactively |
| 2749 | (setq vip-f-char (read-char) | 2798 | (setq viper-f-char (read-char) |
| 2750 | vip-f-forward nil | 2799 | viper-f-forward nil |
| 2751 | vip-f-offset nil) | 2800 | viper-f-offset nil) |
| 2752 | ;; vip-repeat --- set vip-F-char from command-keys | 2801 | ;; viper-repeat --- set viper-F-char from command-keys |
| 2753 | (setq vip-F-char (if (stringp cmd-representation) | 2802 | (setq viper-F-char (if (stringp cmd-representation) |
| 2754 | (vip-seq-last-elt cmd-representation) | 2803 | (viper-seq-last-elt cmd-representation) |
| 2755 | vip-F-char) | 2804 | viper-F-char) |
| 2756 | vip-f-char vip-F-char) | 2805 | viper-f-char viper-F-char) |
| 2757 | (setq val (- val))) | 2806 | (setq val (- val))) |
| 2758 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2807 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2759 | (vip-find-char | 2808 | (viper-find-char |
| 2760 | val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) | 2809 | val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil nil) |
| 2761 | (setq val (- val)) | 2810 | (setq val (- val)) |
| 2762 | (if com | 2811 | (if com |
| 2763 | (progn | 2812 | (progn |
| 2764 | (setq vip-F-char vip-f-char) ; set new vip-F-char | 2813 | (setq viper-F-char viper-f-char) ; set new viper-F-char |
| 2765 | (vip-execute-com 'vip-find-char-backward val com))))) | 2814 | (viper-execute-com 'viper-find-char-backward val com))))) |
| 2766 | 2815 | ||
| 2767 | (defun vip-goto-char-backward (arg) | 2816 | (defun viper-goto-char-backward (arg) |
| 2768 | "Go up to char ARG backward on line." | 2817 | "Go up to char ARG backward on line." |
| 2769 | (interactive "P") | 2818 | (interactive "P") |
| 2770 | (let ((val (vip-p-val arg)) | 2819 | (let ((val (viper-p-val arg)) |
| 2771 | (com (vip-getcom arg)) | 2820 | (com (viper-getcom arg)) |
| 2772 | (cmd-representation (nth 5 vip-d-com))) | 2821 | (cmd-representation (nth 5 viper-d-com))) |
| 2773 | (if (> val 0) | 2822 | (if (> val 0) |
| 2774 | ;; this means that the function was called interactively | 2823 | ;; this means that the function was called interactively |
| 2775 | (setq vip-f-char (read-char) | 2824 | (setq viper-f-char (read-char) |
| 2776 | vip-f-forward nil | 2825 | viper-f-forward nil |
| 2777 | vip-f-offset t) | 2826 | viper-f-offset t) |
| 2778 | ;; vip-repeat --- set vip-F-char from command-keys | 2827 | ;; viper-repeat --- set viper-F-char from command-keys |
| 2779 | (setq vip-F-char (if (stringp cmd-representation) | 2828 | (setq viper-F-char (if (stringp cmd-representation) |
| 2780 | (vip-seq-last-elt cmd-representation) | 2829 | (viper-seq-last-elt cmd-representation) |
| 2781 | vip-F-char) | 2830 | viper-F-char) |
| 2782 | vip-f-char vip-F-char) | 2831 | viper-f-char viper-F-char) |
| 2783 | (setq val (- val))) | 2832 | (setq val (- val))) |
| 2784 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2833 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2785 | (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) | 2834 | (viper-find-char |
| 2835 | val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil t) | ||
| 2786 | (setq val (- val)) | 2836 | (setq val (- val)) |
| 2787 | (if com | 2837 | (if com |
| 2788 | (progn | 2838 | (progn |
| 2789 | (setq vip-F-char vip-f-char) ; set new vip-F-char | 2839 | (setq viper-F-char viper-f-char) ; set new viper-F-char |
| 2790 | (vip-execute-com 'vip-goto-char-backward val com))))) | 2840 | (viper-execute-com 'viper-goto-char-backward val com))))) |
| 2791 | 2841 | ||
| 2792 | (defun vip-repeat-find (arg) | 2842 | (defun viper-repeat-find (arg) |
| 2793 | "Repeat previous find command." | 2843 | "Repeat previous find command." |
| 2794 | (interactive "P") | 2844 | (interactive "P") |
| 2795 | (let ((val (vip-p-val arg)) | 2845 | (let ((val (viper-p-val arg)) |
| 2796 | (com (vip-getcom arg))) | 2846 | (com (viper-getcom arg))) |
| 2797 | (vip-deactivate-mark) | 2847 | (viper-deactivate-mark) |
| 2798 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2848 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2799 | (vip-find-char val vip-f-char vip-f-forward vip-f-offset) | 2849 | (viper-find-char val viper-f-char viper-f-forward viper-f-offset) |
| 2800 | (if com | 2850 | (if com |
| 2801 | (progn | 2851 | (progn |
| 2802 | (if vip-f-forward (forward-char)) | 2852 | (if viper-f-forward (forward-char)) |
| 2803 | (vip-execute-com 'vip-repeat-find val com))))) | 2853 | (viper-execute-com 'viper-repeat-find val com))))) |
| 2804 | 2854 | ||
| 2805 | (defun vip-repeat-find-opposite (arg) | 2855 | (defun viper-repeat-find-opposite (arg) |
| 2806 | "Repeat previous find command in the opposite direction." | 2856 | "Repeat previous find command in the opposite direction." |
| 2807 | (interactive "P") | 2857 | (interactive "P") |
| 2808 | (let ((val (vip-p-val arg)) | 2858 | (let ((val (viper-p-val arg)) |
| 2809 | (com (vip-getcom arg))) | 2859 | (com (viper-getcom arg))) |
| 2810 | (vip-deactivate-mark) | 2860 | (viper-deactivate-mark) |
| 2811 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2861 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2812 | (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) | 2862 | (viper-find-char val viper-f-char (not viper-f-forward) viper-f-offset) |
| 2813 | (if com | 2863 | (if com |
| 2814 | (progn | 2864 | (progn |
| 2815 | (if vip-f-forward (forward-char)) | 2865 | (if viper-f-forward (forward-char)) |
| 2816 | (vip-execute-com 'vip-repeat-find-opposite val com))))) | 2866 | (viper-execute-com 'viper-repeat-find-opposite val com))))) |
| 2817 | 2867 | ||
| 2818 | 2868 | ||
| 2819 | ;; window scrolling etc. | 2869 | ;; window scrolling etc. |
| 2820 | 2870 | ||
| 2821 | (defun vip-other-window (arg) | 2871 | (defun viper-window-top (arg) |
| 2822 | "Switch to other window." | ||
| 2823 | (interactive "p") | ||
| 2824 | (other-window arg) | ||
| 2825 | (or (not (eq vip-current-state 'emacs-state)) | ||
| 2826 | (string= (buffer-name (current-buffer)) " *Minibuf-1*") | ||
| 2827 | (vip-change-state-to-vi))) | ||
| 2828 | |||
| 2829 | (defun vip-window-top (arg) | ||
| 2830 | "Go to home window line." | 2872 | "Go to home window line." |
| 2831 | (interactive "P") | 2873 | (interactive "P") |
| 2832 | (let ((val (vip-p-val arg)) | 2874 | (let ((val (viper-p-val arg)) |
| 2833 | (com (vip-getCom arg))) | 2875 | (com (viper-getCom arg))) |
| 2834 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2876 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2835 | (push-mark nil t) | 2877 | (push-mark nil t) |
| 2836 | (move-to-window-line (1- val)) | 2878 | (move-to-window-line (1- val)) |
| 2837 | 2879 | ||
| @@ -2839,19 +2881,19 @@ controlled by the sign of prefix numeric value." | |||
| 2839 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2881 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2840 | (back-to-indentation) | 2882 | (back-to-indentation) |
| 2841 | 2883 | ||
| 2842 | (if com (vip-execute-com 'vip-window-top val com)) | 2884 | (if com (viper-execute-com 'viper-window-top val com)) |
| 2843 | 2885 | ||
| 2844 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2886 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2845 | (back-to-indentation) | 2887 | (back-to-indentation) |
| 2846 | )) | 2888 | )) |
| 2847 | 2889 | ||
| 2848 | (defun vip-window-middle (arg) | 2890 | (defun viper-window-middle (arg) |
| 2849 | "Go to middle window line." | 2891 | "Go to middle window line." |
| 2850 | (interactive "P") | 2892 | (interactive "P") |
| 2851 | (let ((val (vip-p-val arg)) | 2893 | (let ((val (viper-p-val arg)) |
| 2852 | (com (vip-getCom arg)) | 2894 | (com (viper-getCom arg)) |
| 2853 | lines) | 2895 | lines) |
| 2854 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2896 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2855 | (push-mark nil t) | 2897 | (push-mark nil t) |
| 2856 | (if (not (pos-visible-in-window-p (point-max))) | 2898 | (if (not (pos-visible-in-window-p (point-max))) |
| 2857 | (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) | 2899 | (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) |
| @@ -2862,18 +2904,18 @@ controlled by the sign of prefix numeric value." | |||
| 2862 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2904 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2863 | (back-to-indentation) | 2905 | (back-to-indentation) |
| 2864 | 2906 | ||
| 2865 | (if com (vip-execute-com 'vip-window-middle val com)) | 2907 | (if com (viper-execute-com 'viper-window-middle val com)) |
| 2866 | 2908 | ||
| 2867 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2909 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2868 | (back-to-indentation) | 2910 | (back-to-indentation) |
| 2869 | )) | 2911 | )) |
| 2870 | 2912 | ||
| 2871 | (defun vip-window-bottom (arg) | 2913 | (defun viper-window-bottom (arg) |
| 2872 | "Go to last window line." | 2914 | "Go to last window line." |
| 2873 | (interactive "P") | 2915 | (interactive "P") |
| 2874 | (let ((val (vip-p-val arg)) | 2916 | (let ((val (viper-p-val arg)) |
| 2875 | (com (vip-getCom arg))) | 2917 | (com (viper-getCom arg))) |
| 2876 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 2918 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2877 | (push-mark nil t) | 2919 | (push-mark nil t) |
| 2878 | (move-to-window-line (- val)) | 2920 | (move-to-window-line (- val)) |
| 2879 | 2921 | ||
| @@ -2881,34 +2923,34 @@ controlled by the sign of prefix numeric value." | |||
| 2881 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2923 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2882 | (back-to-indentation) | 2924 | (back-to-indentation) |
| 2883 | 2925 | ||
| 2884 | (if com (vip-execute-com 'vip-window-bottom val com)) | 2926 | (if com (viper-execute-com 'viper-window-bottom val com)) |
| 2885 | 2927 | ||
| 2886 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) | 2928 | (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
| 2887 | (back-to-indentation) | 2929 | (back-to-indentation) |
| 2888 | )) | 2930 | )) |
| 2889 | 2931 | ||
| 2890 | (defun vip-line-to-top (arg) | 2932 | (defun viper-line-to-top (arg) |
| 2891 | "Put current line on the home line." | 2933 | "Put current line on the home line." |
| 2892 | (interactive "p") | 2934 | (interactive "p") |
| 2893 | (recenter (1- arg))) | 2935 | (recenter (1- arg))) |
| 2894 | 2936 | ||
| 2895 | (defun vip-line-to-middle (arg) | 2937 | (defun viper-line-to-middle (arg) |
| 2896 | "Put current line on the middle line." | 2938 | "Put current line on the middle line." |
| 2897 | (interactive "p") | 2939 | (interactive "p") |
| 2898 | (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | 2940 | (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) |
| 2899 | 2941 | ||
| 2900 | (defun vip-line-to-bottom (arg) | 2942 | (defun viper-line-to-bottom (arg) |
| 2901 | "Put current line on the last line." | 2943 | "Put current line on the last line." |
| 2902 | (interactive "p") | 2944 | (interactive "p") |
| 2903 | (recenter (- (window-height) (1+ arg)))) | 2945 | (recenter (- (window-height) (1+ arg)))) |
| 2904 | 2946 | ||
| 2905 | ;; If point is within vip-search-scroll-threshold of window top or bottom, | 2947 | ;; If point is within viper-search-scroll-threshold of window top or bottom, |
| 2906 | ;; scroll up or down 1/7 of window height, depending on whether we are at the | 2948 | ;; scroll up or down 1/7 of window height, depending on whether we are at the |
| 2907 | ;; bottom or at the top of the window. This function is called by vip-search | 2949 | ;; bottom or at the top of the window. This function is called by viper-search |
| 2908 | ;; (which is called from vip-search-forward/backward/next). If the value of | 2950 | ;; (which is called from viper-search-forward/backward/next). If the value of |
| 2909 | ;; vip-search-scroll-threshold is negative - don't scroll. | 2951 | ;; viper-search-scroll-threshold is negative - don't scroll. |
| 2910 | (defun vip-adjust-window () | 2952 | (defun viper-adjust-window () |
| 2911 | (let ((win-height (if vip-emacs-p | 2953 | (let ((win-height (if viper-emacs-p |
| 2912 | (1- (window-height)) ; adjust for modeline | 2954 | (1- (window-height)) ; adjust for modeline |
| 2913 | (window-displayed-height))) | 2955 | (window-displayed-height))) |
| 2914 | (pt (point)) | 2956 | (pt (point)) |
| @@ -2918,14 +2960,14 @@ controlled by the sign of prefix numeric value." | |||
| 2918 | (move-to-window-line 0) ; top | 2960 | (move-to-window-line 0) ; top |
| 2919 | (setq at-top-p | 2961 | (setq at-top-p |
| 2920 | (<= (count-lines pt (point)) | 2962 | (<= (count-lines pt (point)) |
| 2921 | vip-search-scroll-threshold)) | 2963 | viper-search-scroll-threshold)) |
| 2922 | (move-to-window-line -1) ; bottom | 2964 | (move-to-window-line -1) ; bottom |
| 2923 | (setq at-bottom-p | 2965 | (setq at-bottom-p |
| 2924 | (<= (count-lines pt (point)) vip-search-scroll-threshold)) | 2966 | (<= (count-lines pt (point)) viper-search-scroll-threshold)) |
| 2925 | ) | 2967 | ) |
| 2926 | (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold) | 2968 | (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold) |
| 2927 | direction 1)) | 2969 | direction 1)) |
| 2928 | (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold) | 2970 | (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold) |
| 2929 | direction -1))) | 2971 | direction -1))) |
| 2930 | (if min-scroll | 2972 | (if min-scroll |
| 2931 | (recenter | 2973 | (recenter |
| @@ -2938,12 +2980,12 @@ controlled by the sign of prefix numeric value." | |||
| 2938 | ;; it is good that paren match gets confused, because that way you | 2980 | ;; it is good that paren match gets confused, because that way you |
| 2939 | ;; catch _all_ imbalances. | 2981 | ;; catch _all_ imbalances. |
| 2940 | 2982 | ||
| 2941 | (defun vip-paren-match (arg) | 2983 | (defun viper-paren-match (arg) |
| 2942 | "Go to the matching parenthesis." | 2984 | "Go to the matching parenthesis." |
| 2943 | (interactive "P") | 2985 | (interactive "P") |
| 2944 | (vip-leave-region-active) | 2986 | (viper-leave-region-active) |
| 2945 | (let ((com (vip-getcom arg)) | 2987 | (let ((com (viper-getcom arg)) |
| 2946 | (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments) | 2988 | (parse-sexp-ignore-comments viper-parse-sexp-ignore-comments) |
| 2947 | anchor-point) | 2989 | anchor-point) |
| 2948 | (if (integerp arg) | 2990 | (if (integerp arg) |
| 2949 | (if (or (> arg 99) (< arg 1)) | 2991 | (if (or (> arg 99) (< arg 1)) |
| @@ -2968,116 +3010,117 @@ controlled by the sign of prefix numeric value." | |||
| 2968 | (t | 3010 | (t |
| 2969 | (error "No matching character on line")))) | 3011 | (error "No matching character on line")))) |
| 2970 | (cond ((looking-at "[\(\[{]") | 3012 | (cond ((looking-at "[\(\[{]") |
| 2971 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3013 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2972 | (forward-sexp 1) | 3014 | (forward-sexp 1) |
| 2973 | (if com | 3015 | (if com |
| 2974 | (vip-execute-com 'vip-paren-match nil com) | 3016 | (viper-execute-com 'viper-paren-match nil com) |
| 2975 | (backward-char))) | 3017 | (backward-char))) |
| 2976 | (anchor-point | 3018 | (anchor-point |
| 2977 | (if com | 3019 | (if com |
| 2978 | (progn | 3020 | (progn |
| 2979 | (vip-move-marker-locally 'vip-com-point anchor-point) | 3021 | (viper-move-marker-locally 'viper-com-point anchor-point) |
| 2980 | (forward-char 1) | 3022 | (forward-char 1) |
| 2981 | (vip-execute-com 'vip-paren-match nil com) | 3023 | (viper-execute-com 'viper-paren-match nil com) |
| 2982 | ))) | 3024 | ))) |
| 2983 | ((looking-at "[])}]") | 3025 | ((looking-at "[])}]") |
| 2984 | (forward-char) | 3026 | (forward-char) |
| 2985 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3027 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 2986 | (backward-sexp 1) | 3028 | (backward-sexp 1) |
| 2987 | (if com (vip-execute-com 'vip-paren-match nil com))) | 3029 | (if com (viper-execute-com 'viper-paren-match nil com))) |
| 2988 | (t (error "")))))) | 3030 | (t (error "")))))) |
| 2989 | 3031 | ||
| 2990 | (defun vip-toggle-parse-sexp-ignore-comments () | 3032 | (defun viper-toggle-parse-sexp-ignore-comments () |
| 2991 | (interactive) | 3033 | (interactive) |
| 2992 | (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments)) | 3034 | (setq viper-parse-sexp-ignore-comments |
| 3035 | (not viper-parse-sexp-ignore-comments)) | ||
| 2993 | (princ (format | 3036 | (princ (format |
| 2994 | "From now on, `%%' will %signore parentheses inside comment fields" | 3037 | "From now on, `%%' will %signore parentheses inside comment fields" |
| 2995 | (if vip-parse-sexp-ignore-comments "" "NOT ")))) | 3038 | (if viper-parse-sexp-ignore-comments "" "NOT ")))) |
| 2996 | 3039 | ||
| 2997 | 3040 | ||
| 2998 | ;; sentence ,paragraph and heading | 3041 | ;; sentence ,paragraph and heading |
| 2999 | 3042 | ||
| 3000 | (defun vip-forward-sentence (arg) | 3043 | (defun viper-forward-sentence (arg) |
| 3001 | "Forward sentence." | 3044 | "Forward sentence." |
| 3002 | (interactive "P") | 3045 | (interactive "P") |
| 3003 | (push-mark nil t) | 3046 | (push-mark nil t) |
| 3004 | (let ((val (vip-p-val arg)) | 3047 | (let ((val (viper-p-val arg)) |
| 3005 | (com (vip-getcom arg))) | 3048 | (com (viper-getcom arg))) |
| 3006 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3049 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3007 | (forward-sentence val) | 3050 | (forward-sentence val) |
| 3008 | (if com (vip-execute-com 'vip-forward-sentence nil com)))) | 3051 | (if com (viper-execute-com 'viper-forward-sentence nil com)))) |
| 3009 | 3052 | ||
| 3010 | (defun vip-backward-sentence (arg) | 3053 | (defun viper-backward-sentence (arg) |
| 3011 | "Backward sentence." | 3054 | "Backward sentence." |
| 3012 | (interactive "P") | 3055 | (interactive "P") |
| 3013 | (push-mark nil t) | 3056 | (push-mark nil t) |
| 3014 | (let ((val (vip-p-val arg)) | 3057 | (let ((val (viper-p-val arg)) |
| 3015 | (com (vip-getcom arg))) | 3058 | (com (viper-getcom arg))) |
| 3016 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3059 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3017 | (backward-sentence val) | 3060 | (backward-sentence val) |
| 3018 | (if com (vip-execute-com 'vip-backward-sentence nil com)))) | 3061 | (if com (viper-execute-com 'viper-backward-sentence nil com)))) |
| 3019 | 3062 | ||
| 3020 | (defun vip-forward-paragraph (arg) | 3063 | (defun viper-forward-paragraph (arg) |
| 3021 | "Forward paragraph." | 3064 | "Forward paragraph." |
| 3022 | (interactive "P") | 3065 | (interactive "P") |
| 3023 | (push-mark nil t) | 3066 | (push-mark nil t) |
| 3024 | (let ((val (vip-p-val arg)) | 3067 | (let ((val (viper-p-val arg)) |
| 3025 | (com (vip-getCom arg))) | 3068 | (com (viper-getCom arg))) |
| 3026 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3069 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3027 | (forward-paragraph val) | 3070 | (forward-paragraph val) |
| 3028 | (if com | 3071 | (if com |
| 3029 | (progn | 3072 | (progn |
| 3030 | (backward-char 1) | 3073 | (backward-char 1) |
| 3031 | (vip-execute-com 'vip-forward-paragraph nil com))))) | 3074 | (viper-execute-com 'viper-forward-paragraph nil com))))) |
| 3032 | 3075 | ||
| 3033 | (defun vip-backward-paragraph (arg) | 3076 | (defun viper-backward-paragraph (arg) |
| 3034 | "Backward paragraph." | 3077 | "Backward paragraph." |
| 3035 | (interactive "P") | 3078 | (interactive "P") |
| 3036 | (push-mark nil t) | 3079 | (push-mark nil t) |
| 3037 | (let ((val (vip-p-val arg)) | 3080 | (let ((val (viper-p-val arg)) |
| 3038 | (com (vip-getCom arg))) | 3081 | (com (viper-getCom arg))) |
| 3039 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3082 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3040 | (backward-paragraph val) | 3083 | (backward-paragraph val) |
| 3041 | (if com | 3084 | (if com |
| 3042 | (progn | 3085 | (progn |
| 3043 | (forward-char 1) | 3086 | (forward-char 1) |
| 3044 | (vip-execute-com 'vip-backward-paragraph nil com) | 3087 | (viper-execute-com 'viper-backward-paragraph nil com) |
| 3045 | (backward-char 1))))) | 3088 | (backward-char 1))))) |
| 3046 | 3089 | ||
| 3047 | ;; should be mode-specific etc. | 3090 | ;; should be mode-specific etc. |
| 3048 | 3091 | ||
| 3049 | (defun vip-prev-heading (arg) | 3092 | (defun viper-prev-heading (arg) |
| 3050 | (interactive "P") | 3093 | (interactive "P") |
| 3051 | (let ((val (vip-p-val arg)) | 3094 | (let ((val (viper-p-val arg)) |
| 3052 | (com (vip-getCom arg))) | 3095 | (com (viper-getCom arg))) |
| 3053 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3096 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3054 | (re-search-backward vip-heading-start nil t val) | 3097 | (re-search-backward viper-heading-start nil t val) |
| 3055 | (goto-char (match-beginning 0)) | 3098 | (goto-char (match-beginning 0)) |
| 3056 | (if com (vip-execute-com 'vip-prev-heading nil com)))) | 3099 | (if com (viper-execute-com 'viper-prev-heading nil com)))) |
| 3057 | 3100 | ||
| 3058 | (defun vip-heading-end (arg) | 3101 | (defun viper-heading-end (arg) |
| 3059 | (interactive "P") | 3102 | (interactive "P") |
| 3060 | (let ((val (vip-p-val arg)) | 3103 | (let ((val (viper-p-val arg)) |
| 3061 | (com (vip-getCom arg))) | 3104 | (com (viper-getCom arg))) |
| 3062 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3105 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3063 | (re-search-forward vip-heading-end nil t val) | 3106 | (re-search-forward viper-heading-end nil t val) |
| 3064 | (goto-char (match-beginning 0)) | 3107 | (goto-char (match-beginning 0)) |
| 3065 | (if com (vip-execute-com 'vip-heading-end nil com)))) | 3108 | (if com (viper-execute-com 'viper-heading-end nil com)))) |
| 3066 | 3109 | ||
| 3067 | (defun vip-next-heading (arg) | 3110 | (defun viper-next-heading (arg) |
| 3068 | (interactive "P") | 3111 | (interactive "P") |
| 3069 | (let ((val (vip-p-val arg)) | 3112 | (let ((val (viper-p-val arg)) |
| 3070 | (com (vip-getCom arg))) | 3113 | (com (viper-getCom arg))) |
| 3071 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 3114 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3072 | (end-of-line) | 3115 | (end-of-line) |
| 3073 | (re-search-forward vip-heading-start nil t val) | 3116 | (re-search-forward viper-heading-start nil t val) |
| 3074 | (goto-char (match-beginning 0)) | 3117 | (goto-char (match-beginning 0)) |
| 3075 | (if com (vip-execute-com 'vip-next-heading nil com)))) | 3118 | (if com (viper-execute-com 'viper-next-heading nil com)))) |
| 3076 | 3119 | ||
| 3077 | 3120 | ||
| 3078 | ;; scrolling | 3121 | ;; scrolling |
| 3079 | 3122 | ||
| 3080 | (defun vip-scroll-screen (arg) | 3123 | (defun viper-scroll-screen (arg) |
| 3081 | "Scroll to next screen." | 3124 | "Scroll to next screen." |
| 3082 | (interactive "p") | 3125 | (interactive "p") |
| 3083 | (condition-case nil | 3126 | (condition-case nil |
| @@ -3097,12 +3140,12 @@ controlled by the sign of prefix numeric value." | |||
| 3097 | (goto-char (point-min)))) | 3140 | (goto-char (point-min)))) |
| 3098 | )) | 3141 | )) |
| 3099 | 3142 | ||
| 3100 | (defun vip-scroll-screen-back (arg) | 3143 | (defun viper-scroll-screen-back (arg) |
| 3101 | "Scroll to previous screen." | 3144 | "Scroll to previous screen." |
| 3102 | (interactive "p") | 3145 | (interactive "p") |
| 3103 | (vip-scroll-screen (- arg))) | 3146 | (viper-scroll-screen (- arg))) |
| 3104 | 3147 | ||
| 3105 | (defun vip-scroll-down (arg) | 3148 | (defun viper-scroll-down (arg) |
| 3106 | "Pull down half screen." | 3149 | "Pull down half screen." |
| 3107 | (interactive "P") | 3150 | (interactive "P") |
| 3108 | (condition-case nil | 3151 | (condition-case nil |
| @@ -3113,12 +3156,12 @@ controlled by the sign of prefix numeric value." | |||
| 3113 | (message "Beginning of buffer") | 3156 | (message "Beginning of buffer") |
| 3114 | (goto-char (point-min))))) | 3157 | (goto-char (point-min))))) |
| 3115 | 3158 | ||
| 3116 | (defun vip-scroll-down-one (arg) | 3159 | (defun viper-scroll-down-one (arg) |
| 3117 | "Scroll up one line." | 3160 | "Scroll up one line." |
| 3118 | (interactive "p") | 3161 | (interactive "p") |
| 3119 | (scroll-down arg)) | 3162 | (scroll-down arg)) |
| 3120 | 3163 | ||
| 3121 | (defun vip-scroll-up (arg) | 3164 | (defun viper-scroll-up (arg) |
| 3122 | "Pull up half screen." | 3165 | "Pull up half screen." |
| 3123 | (interactive "P") | 3166 | (interactive "P") |
| 3124 | (condition-case nil | 3167 | (condition-case nil |
| @@ -3129,7 +3172,7 @@ controlled by the sign of prefix numeric value." | |||
| 3129 | (message "End of buffer") | 3172 | (message "End of buffer") |
| 3130 | (goto-char (point-max))))) | 3173 | (goto-char (point-max))))) |
| 3131 | 3174 | ||
| 3132 | (defun vip-scroll-up-one (arg) | 3175 | (defun viper-scroll-up-one (arg) |
| 3133 | "Scroll down one line." | 3176 | "Scroll down one line." |
| 3134 | (interactive "p") | 3177 | (interactive "p") |
| 3135 | (scroll-up arg)) | 3178 | (scroll-up arg)) |
| @@ -3137,25 +3180,28 @@ controlled by the sign of prefix numeric value." | |||
| 3137 | 3180 | ||
| 3138 | ;; searching | 3181 | ;; searching |
| 3139 | 3182 | ||
| 3140 | (defun vip-if-string (prompt) | 3183 | (defun viper-if-string (prompt) |
| 3141 | (let ((s (vip-read-string-with-history | 3184 | (if (memq viper-intermediate-command |
| 3185 | '(viper-command-argument viper-digit-argument viper-repeat)) | ||
| 3186 | (setq viper-this-command-keys (this-command-keys))) | ||
| 3187 | (let ((s (viper-read-string-with-history | ||
| 3142 | prompt | 3188 | prompt |
| 3143 | nil ; no initial | 3189 | nil ; no initial |
| 3144 | 'vip-search-history | 3190 | 'viper-search-history |
| 3145 | (car vip-search-history)))) | 3191 | (car viper-search-history)))) |
| 3146 | (if (not (string= s "")) | 3192 | (if (not (string= s "")) |
| 3147 | (setq vip-s-string s)))) | 3193 | (setq viper-s-string s)))) |
| 3148 | 3194 | ||
| 3149 | 3195 | ||
| 3150 | (defun vip-toggle-search-style (arg) | 3196 | (defun viper-toggle-search-style (arg) |
| 3151 | "Toggle the value of vip-case-fold-search/vip-re-search. | 3197 | "Toggle the value of viper-case-fold-search/viper-re-search. |
| 3152 | Without prefix argument, will ask which search style to toggle. With prefix | 3198 | Without prefix argument, will ask which search style to toggle. With prefix |
| 3153 | arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search. | 3199 | arg 1,toggles viper-case-fold-search; with arg 2 toggles viper-re-search. |
| 3154 | 3200 | ||
| 3155 | Although this function is bound to \\[vip-toggle-search-style], the most | 3201 | Although this function is bound to \\[viper-toggle-search-style], the most |
| 3156 | convenient way to use it is to bind `//' to the macro | 3202 | convenient way to use it is to bind `//' to the macro |
| 3157 | `1 M-x vip-toggle-search-style' and `///' to | 3203 | `1 M-x viper-toggle-search-style' and `///' to |
| 3158 | `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will | 3204 | `2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will |
| 3159 | toggle case-fold-search and hitting `/' three times witth toggle regexp | 3205 | toggle case-fold-search and hitting `/' three times witth toggle regexp |
| 3160 | search. Macros are more convenient in this case because they don't affect | 3206 | search. Macros are more convenient in this case because they don't affect |
| 3161 | the Emacs binding of `/'." | 3207 | the Emacs binding of `/'." |
| @@ -3164,32 +3210,32 @@ the Emacs binding of `/'." | |||
| 3164 | (cond ((or (eq arg 1) | 3210 | (cond ((or (eq arg 1) |
| 3165 | (and (null arg) | 3211 | (and (null arg) |
| 3166 | (y-or-n-p (format "Search style: '%s'. Want '%s'? " | 3212 | (y-or-n-p (format "Search style: '%s'. Want '%s'? " |
| 3167 | (if vip-case-fold-search | 3213 | (if viper-case-fold-search |
| 3168 | "case-insensitive" "case-sensitive") | 3214 | "case-insensitive" "case-sensitive") |
| 3169 | (if vip-case-fold-search | 3215 | (if viper-case-fold-search |
| 3170 | "case-sensitive" | 3216 | "case-sensitive" |
| 3171 | "case-insensitive"))))) | 3217 | "case-insensitive"))))) |
| 3172 | (setq vip-case-fold-search (null vip-case-fold-search)) | 3218 | (setq viper-case-fold-search (null viper-case-fold-search)) |
| 3173 | (if vip-case-fold-search | 3219 | (if viper-case-fold-search |
| 3174 | (setq msg "Search becomes case-insensitive") | 3220 | (setq msg "Search becomes case-insensitive") |
| 3175 | (setq msg "Search becomes case-sensitive"))) | 3221 | (setq msg "Search becomes case-sensitive"))) |
| 3176 | ((or (eq arg 2) | 3222 | ((or (eq arg 2) |
| 3177 | (and (null arg) | 3223 | (and (null arg) |
| 3178 | (y-or-n-p (format "Search style: '%s'. Want '%s'? " | 3224 | (y-or-n-p (format "Search style: '%s'. Want '%s'? " |
| 3179 | (if vip-re-search | 3225 | (if viper-re-search |
| 3180 | "regexp-search" "vanilla-search") | 3226 | "regexp-search" "vanilla-search") |
| 3181 | (if vip-re-search | 3227 | (if viper-re-search |
| 3182 | "vanilla-search" | 3228 | "vanilla-search" |
| 3183 | "regexp-search"))))) | 3229 | "regexp-search"))))) |
| 3184 | (setq vip-re-search (null vip-re-search)) | 3230 | (setq viper-re-search (null viper-re-search)) |
| 3185 | (if vip-re-search | 3231 | (if viper-re-search |
| 3186 | (setq msg "Search becomes regexp-style") | 3232 | (setq msg "Search becomes regexp-style") |
| 3187 | (setq msg "Search becomes vanilla-style"))) | 3233 | (setq msg "Search becomes vanilla-style"))) |
| 3188 | (t | 3234 | (t |
| 3189 | (setq msg "Search style remains unchanged"))) | 3235 | (setq msg "Search style remains unchanged"))) |
| 3190 | (princ msg t))) | 3236 | (princ msg t))) |
| 3191 | 3237 | ||
| 3192 | (defun vip-set-searchstyle-toggling-macros (unset) | 3238 | (defun viper-set-searchstyle-toggling-macros (unset) |
| 3193 | "Set the macros for toggling the search style in Viper's vi-state. | 3239 | "Set the macros for toggling the search style in Viper's vi-state. |
| 3194 | The macro that toggles case sensitivity is bound to `//', and the one that | 3240 | The macro that toggles case sensitivity is bound to `//', and the one that |
| 3195 | toggles regexp search is bound to `///'. | 3241 | toggles regexp search is bound to `///'. |
| @@ -3199,24 +3245,24 @@ With a prefix argument, this function unsets the macros. " | |||
| 3199 | (if (not unset) | 3245 | (if (not unset) |
| 3200 | (progn | 3246 | (progn |
| 3201 | ;; toggle case sensitivity in search | 3247 | ;; toggle case sensitivity in search |
| 3202 | (vip-record-kbd-macro | 3248 | (viper-record-kbd-macro |
| 3203 | "//" 'vi-state | 3249 | "//" 'vi-state |
| 3204 | [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] | 3250 | [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
| 3205 | 't) | 3251 | 't) |
| 3206 | ;; toggle regexp/vanila search | 3252 | ;; toggle regexp/vanila search |
| 3207 | (vip-record-kbd-macro | 3253 | (viper-record-kbd-macro |
| 3208 | "///" 'vi-state | 3254 | "///" 'vi-state |
| 3209 | [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] | 3255 | [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
| 3210 | 't) | 3256 | 't) |
| 3211 | (if (interactive-p) | 3257 | (if (interactive-p) |
| 3212 | (message | 3258 | (message |
| 3213 | "// and /// now toggle case-sensitivity and regexp search"))) | 3259 | "// and /// now toggle case-sensitivity and regexp search"))) |
| 3214 | (vip-unrecord-kbd-macro "//" 'vi-state) | 3260 | (viper-unrecord-kbd-macro "//" 'vi-state) |
| 3215 | (sit-for 2) | 3261 | (sit-for 2) |
| 3216 | (vip-unrecord-kbd-macro "///" 'vi-state)))) | 3262 | (viper-unrecord-kbd-macro "///" 'vi-state)))) |
| 3217 | 3263 | ||
| 3218 | 3264 | ||
| 3219 | (defun vip-set-parsing-style-toggling-macro (unset) | 3265 | (defun viper-set-parsing-style-toggling-macro (unset) |
| 3220 | "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses. | 3266 | "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses. |
| 3221 | This is used in conjunction with the `%' command. | 3267 | This is used in conjunction with the `%' command. |
| 3222 | 3268 | ||
| @@ -3226,17 +3272,17 @@ With a prefix argument, unsets the macro." | |||
| 3226 | (if (not unset) | 3272 | (if (not unset) |
| 3227 | (progn | 3273 | (progn |
| 3228 | ;; Make %%% toggle parsing comments for matching parentheses | 3274 | ;; Make %%% toggle parsing comments for matching parentheses |
| 3229 | (vip-record-kbd-macro | 3275 | (viper-record-kbd-macro |
| 3230 | "%%%" 'vi-state | 3276 | "%%%" 'vi-state |
| 3231 | [(meta x) v i p - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return] | 3277 | [(meta x) v i p e r - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return] |
| 3232 | 't) | 3278 | 't) |
| 3233 | (if (interactive-p) | 3279 | (if (interactive-p) |
| 3234 | (message | 3280 | (message |
| 3235 | "%%%%%% now toggles whether comments should be parsed for matching parentheses"))) | 3281 | "%%%%%% now toggles whether comments should be parsed for matching parentheses"))) |
| 3236 | (vip-unrecord-kbd-macro "%%%" 'vi-state)))) | 3282 | (viper-unrecord-kbd-macro "%%%" 'vi-state)))) |
| 3237 | 3283 | ||
| 3238 | 3284 | ||
| 3239 | (defun vip-set-emacs-state-searchstyle-macros (unset &optional arg-majormode) | 3285 | (defun viper-set-emacs-state-searchstyle-macros (unset &optional arg-majormode) |
| 3240 | "Set the macros for toggling the search style in Viper's emacs-state. | 3286 | "Set the macros for toggling the search style in Viper's emacs-state. |
| 3241 | The macro that toggles case sensitivity is bound to `//', and the one that | 3287 | The macro that toggles case sensitivity is bound to `//', and the one that |
| 3242 | toggles regexp search is bound to `///'. | 3288 | toggles regexp search is bound to `///'. |
| @@ -3250,64 +3296,64 @@ the macros are set in the current major mode. | |||
| 3250 | (if (not unset) | 3296 | (if (not unset) |
| 3251 | (progn | 3297 | (progn |
| 3252 | ;; toggle case sensitivity in search | 3298 | ;; toggle case sensitivity in search |
| 3253 | (vip-record-kbd-macro | 3299 | (viper-record-kbd-macro |
| 3254 | "//" 'emacs-state | 3300 | "//" 'emacs-state |
| 3255 | [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] | 3301 | [1 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
| 3256 | (or arg-majormode major-mode)) | 3302 | (or arg-majormode major-mode)) |
| 3257 | ;; toggle regexp/vanila search | 3303 | ;; toggle regexp/vanila search |
| 3258 | (vip-record-kbd-macro | 3304 | (viper-record-kbd-macro |
| 3259 | "///" 'emacs-state | 3305 | "///" 'emacs-state |
| 3260 | [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] | 3306 | [2 (meta x) v i p e r - t o g g l e - s e a r c h - s t y l e return] |
| 3261 | (or arg-majormode major-mode)) | 3307 | (or arg-majormode major-mode)) |
| 3262 | (if (interactive-p) | 3308 | (if (interactive-p) |
| 3263 | (message | 3309 | (message |
| 3264 | "// and /// now toggle case-sensitivity and regexp search."))) | 3310 | "// and /// now toggle case-sensitivity and regexp search."))) |
| 3265 | (vip-unrecord-kbd-macro "//" 'emacs-state) | 3311 | (viper-unrecord-kbd-macro "//" 'emacs-state) |
| 3266 | (sit-for 2) | 3312 | (sit-for 2) |
| 3267 | (vip-unrecord-kbd-macro "///" 'emacs-state)))) | 3313 | (viper-unrecord-kbd-macro "///" 'emacs-state)))) |
| 3268 | 3314 | ||
| 3269 | 3315 | ||
| 3270 | (defun vip-search-forward (arg) | 3316 | (defun viper-search-forward (arg) |
| 3271 | "Search a string forward. | 3317 | "Search a string forward. |
| 3272 | ARG is used to find the ARG's occurrence of the string. | 3318 | ARG is used to find the ARG's occurrence of the string. |
| 3273 | Null string will repeat previous search." | 3319 | Null string will repeat previous search." |
| 3274 | (interactive "P") | 3320 | (interactive "P") |
| 3275 | (let ((val (vip-P-val arg)) | 3321 | (let ((val (viper-P-val arg)) |
| 3276 | (com (vip-getcom arg)) | 3322 | (com (viper-getcom arg)) |
| 3277 | (old-str vip-s-string)) | 3323 | (old-str viper-s-string)) |
| 3278 | (setq vip-s-forward t) | 3324 | (setq viper-s-forward t) |
| 3279 | (vip-if-string "/") | 3325 | (viper-if-string "/") |
| 3280 | ;; this is not used at present, but may be used later | 3326 | ;; this is not used at present, but may be used later |
| 3281 | (if (or (not (equal old-str vip-s-string)) | 3327 | (if (or (not (equal old-str viper-s-string)) |
| 3282 | (not (markerp vip-local-search-start-marker)) | 3328 | (not (markerp viper-local-search-start-marker)) |
| 3283 | (not (marker-buffer vip-local-search-start-marker))) | 3329 | (not (marker-buffer viper-local-search-start-marker))) |
| 3284 | (setq vip-local-search-start-marker (point-marker))) | 3330 | (setq viper-local-search-start-marker (point-marker))) |
| 3285 | (vip-search vip-s-string t val) | 3331 | (viper-search viper-s-string t val) |
| 3286 | (if com | 3332 | (if com |
| 3287 | (progn | 3333 | (progn |
| 3288 | (vip-move-marker-locally 'vip-com-point (mark t)) | 3334 | (viper-move-marker-locally 'viper-com-point (mark t)) |
| 3289 | (vip-execute-com 'vip-search-next val com))))) | 3335 | (viper-execute-com 'viper-search-next val com))))) |
| 3290 | 3336 | ||
| 3291 | (defun vip-search-backward (arg) | 3337 | (defun viper-search-backward (arg) |
| 3292 | "Search a string backward. | 3338 | "Search a string backward. |
| 3293 | ARG is used to find the ARG's occurrence of the string. | 3339 | ARG is used to find the ARG's occurrence of the string. |
| 3294 | Null string will repeat previous search." | 3340 | Null string will repeat previous search." |
| 3295 | (interactive "P") | 3341 | (interactive "P") |
| 3296 | (let ((val (vip-P-val arg)) | 3342 | (let ((val (viper-P-val arg)) |
| 3297 | (com (vip-getcom arg)) | 3343 | (com (viper-getcom arg)) |
| 3298 | (old-str vip-s-string)) | 3344 | (old-str viper-s-string)) |
| 3299 | (setq vip-s-forward nil) | 3345 | (setq viper-s-forward nil) |
| 3300 | (vip-if-string "?") | 3346 | (viper-if-string "?") |
| 3301 | ;; this is not used at present, but may be used later | 3347 | ;; this is not used at present, but may be used later |
| 3302 | (if (or (not (equal old-str vip-s-string)) | 3348 | (if (or (not (equal old-str viper-s-string)) |
| 3303 | (not (markerp vip-local-search-start-marker)) | 3349 | (not (markerp viper-local-search-start-marker)) |
| 3304 | (not (marker-buffer vip-local-search-start-marker))) | 3350 | (not (marker-buffer viper-local-search-start-marker))) |
| 3305 | (setq vip-local-search-start-marker (point-marker))) | 3351 | (setq viper-local-search-start-marker (point-marker))) |
| 3306 | (vip-search vip-s-string nil val) | 3352 | (viper-search viper-s-string nil val) |
| 3307 | (if com | 3353 | (if com |
| 3308 | (progn | 3354 | (progn |
| 3309 | (vip-move-marker-locally 'vip-com-point (mark t)) | 3355 | (viper-move-marker-locally 'viper-com-point (mark t)) |
| 3310 | (vip-execute-com 'vip-search-next val com))))) | 3356 | (viper-execute-com 'viper-search-next val com))))) |
| 3311 | 3357 | ||
| 3312 | 3358 | ||
| 3313 | ;; Search for COUNT's occurrence of STRING. | 3359 | ;; Search for COUNT's occurrence of STRING. |
| @@ -3315,20 +3361,20 @@ Null string will repeat previous search." | |||
| 3315 | ;; INIT-POINT is the position where search is to start. | 3361 | ;; INIT-POINT is the position where search is to start. |
| 3316 | ;; Arguments: | 3362 | ;; Arguments: |
| 3317 | ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND) | 3363 | ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND) |
| 3318 | (defun vip-search (string forward arg | 3364 | (defun viper-search (string forward arg |
| 3319 | &optional no-offset init-point fail-if-not-found) | 3365 | &optional no-offset init-point fail-if-not-found) |
| 3320 | (if (not (equal string "")) | 3366 | (if (not (equal string "")) |
| 3321 | (let ((val (vip-p-val arg)) | 3367 | (let ((val (viper-p-val arg)) |
| 3322 | (com (vip-getcom arg)) | 3368 | (com (viper-getcom arg)) |
| 3323 | (offset (not no-offset)) | 3369 | (offset (not no-offset)) |
| 3324 | (case-fold-search vip-case-fold-search) | 3370 | (case-fold-search viper-case-fold-search) |
| 3325 | (start-point (or init-point (point)))) | 3371 | (start-point (or init-point (point)))) |
| 3326 | (vip-deactivate-mark) | 3372 | (viper-deactivate-mark) |
| 3327 | (if forward | 3373 | (if forward |
| 3328 | (condition-case nil | 3374 | (condition-case nil |
| 3329 | (progn | 3375 | (progn |
| 3330 | (if offset (vip-forward-char-carefully)) | 3376 | (if offset (viper-forward-char-carefully)) |
| 3331 | (if vip-re-search | 3377 | (if viper-re-search |
| 3332 | (progn | 3378 | (progn |
| 3333 | (re-search-forward string nil nil val) | 3379 | (re-search-forward string nil nil val) |
| 3334 | (re-search-backward string)) | 3380 | (re-search-backward string)) |
| @@ -3337,110 +3383,122 @@ Null string will repeat previous search." | |||
| 3337 | (if (not (equal start-point (point))) | 3383 | (if (not (equal start-point (point))) |
| 3338 | (push-mark start-point t))) | 3384 | (push-mark start-point t))) |
| 3339 | (search-failed | 3385 | (search-failed |
| 3340 | (if (and (not fail-if-not-found) vip-search-wrap-around-t) | 3386 | (if (and (not fail-if-not-found) viper-search-wrap-around-t) |
| 3341 | (progn | 3387 | (progn |
| 3342 | (message "Search wrapped around BOTTOM of buffer") | 3388 | (message "Search wrapped around BOTTOM of buffer") |
| 3343 | (goto-char (point-min)) | 3389 | (goto-char (point-min)) |
| 3344 | (vip-search string forward (cons 1 com) t start-point 'fail) | 3390 | (viper-search string forward (cons 1 com) t start-point 'fail) |
| 3345 | ;; don't wait in macros | 3391 | ;; don't wait in macros |
| 3346 | (or executing-kbd-macro (sit-for 2)) | 3392 | (or executing-kbd-macro |
| 3393 | (memq viper-intermediate-command | ||
| 3394 | '(viper-repeat | ||
| 3395 | viper-digit-argument | ||
| 3396 | viper-command-argument)) | ||
| 3397 | (sit-for 2)) | ||
| 3347 | ;; delete the wrap-around message | 3398 | ;; delete the wrap-around message |
| 3348 | (message "") | 3399 | (message "") |
| 3349 | ) | 3400 | ) |
| 3350 | (goto-char start-point) | 3401 | (goto-char start-point) |
| 3351 | (error "`%s': %s not found" | 3402 | (error "`%s': %s not found" |
| 3352 | string | 3403 | string |
| 3353 | (if vip-re-search "Pattern" "String")) | 3404 | (if viper-re-search "Pattern" "String")) |
| 3354 | ))) | 3405 | ))) |
| 3355 | ;; backward | 3406 | ;; backward |
| 3356 | (condition-case nil | 3407 | (condition-case nil |
| 3357 | (progn | 3408 | (progn |
| 3358 | (if vip-re-search | 3409 | (if viper-re-search |
| 3359 | (re-search-backward string nil nil val) | 3410 | (re-search-backward string nil nil val) |
| 3360 | (search-backward string nil nil val)) | 3411 | (search-backward string nil nil val)) |
| 3361 | (if (not (equal start-point (point))) | 3412 | (if (not (equal start-point (point))) |
| 3362 | (push-mark start-point t))) | 3413 | (push-mark start-point t))) |
| 3363 | (search-failed | 3414 | (search-failed |
| 3364 | (if (and (not fail-if-not-found) vip-search-wrap-around-t) | 3415 | (if (and (not fail-if-not-found) viper-search-wrap-around-t) |
| 3365 | (progn | 3416 | (progn |
| 3366 | (message "Search wrapped around TOP of buffer") | 3417 | (message "Search wrapped around TOP of buffer") |
| 3367 | (goto-char (point-max)) | 3418 | (goto-char (point-max)) |
| 3368 | (vip-search string forward (cons 1 com) t start-point 'fail) | 3419 | (viper-search string forward (cons 1 com) t start-point 'fail) |
| 3369 | ;; don't wait in macros | 3420 | ;; don't wait in macros |
| 3370 | (or executing-kbd-macro (sit-for 2)) | 3421 | (or executing-kbd-macro |
| 3422 | (memq viper-intermediate-command | ||
| 3423 | '(viper-repeat | ||
| 3424 | viper-digit-argument | ||
| 3425 | viper-command-argument)) | ||
| 3426 | (sit-for 2)) | ||
| 3371 | ;; delete the wrap-around message | 3427 | ;; delete the wrap-around message |
| 3372 | (message "") | 3428 | (message "") |
| 3373 | ) | 3429 | ) |
| 3374 | (goto-char start-point) | 3430 | (goto-char start-point) |
| 3375 | (error "`%s': %s not found" | 3431 | (error "`%s': %s not found" |
| 3376 | string | 3432 | string |
| 3377 | (if vip-re-search "Pattern" "String")) | 3433 | (if viper-re-search "Pattern" "String")) |
| 3378 | )))) | 3434 | )))) |
| 3379 | ;; pull up or down if at top/bottom of window | 3435 | ;; pull up or down if at top/bottom of window |
| 3380 | (vip-adjust-window) | 3436 | (viper-adjust-window) |
| 3381 | ;; highlight the result of search | 3437 | ;; highlight the result of search |
| 3382 | ;; don't wait and don't highlight in macros | 3438 | ;; don't wait and don't highlight in macros |
| 3383 | (or executing-kbd-macro | 3439 | (or executing-kbd-macro |
| 3384 | vip-inside-command-argument-action | 3440 | (memq viper-intermediate-command |
| 3385 | (vip-flash-search-pattern)) | 3441 | '(viper-repeat viper-digit-argument viper-command-argument)) |
| 3442 | (viper-flash-search-pattern)) | ||
| 3386 | ))) | 3443 | ))) |
| 3387 | 3444 | ||
| 3388 | (defun vip-search-next (arg) | 3445 | (defun viper-search-next (arg) |
| 3389 | "Repeat previous search." | 3446 | "Repeat previous search." |
| 3390 | (interactive "P") | 3447 | (interactive "P") |
| 3391 | (let ((val (vip-p-val arg)) | 3448 | (let ((val (viper-p-val arg)) |
| 3392 | (com (vip-getcom arg))) | 3449 | (com (viper-getcom arg))) |
| 3393 | (if (null vip-s-string) (error vip-NoPrevSearch)) | 3450 | (if (null viper-s-string) (error viper-NoPrevSearch)) |
| 3394 | (vip-search vip-s-string vip-s-forward arg) | 3451 | (viper-search viper-s-string viper-s-forward arg) |
| 3395 | (if com | 3452 | (if com |
| 3396 | (progn | 3453 | (progn |
| 3397 | (vip-move-marker-locally 'vip-com-point (mark t)) | 3454 | (viper-move-marker-locally 'viper-com-point (mark t)) |
| 3398 | (vip-execute-com 'vip-search-next val com))))) | 3455 | (viper-execute-com 'viper-search-next val com))))) |
| 3399 | 3456 | ||
| 3400 | (defun vip-search-Next (arg) | 3457 | (defun viper-search-Next (arg) |
| 3401 | "Repeat previous search in the reverse direction." | 3458 | "Repeat previous search in the reverse direction." |
| 3402 | (interactive "P") | 3459 | (interactive "P") |
| 3403 | (let ((val (vip-p-val arg)) | 3460 | (let ((val (viper-p-val arg)) |
| 3404 | (com (vip-getcom arg))) | 3461 | (com (viper-getcom arg))) |
| 3405 | (if (null vip-s-string) (error vip-NoPrevSearch)) | 3462 | (if (null viper-s-string) (error viper-NoPrevSearch)) |
| 3406 | (vip-search vip-s-string (not vip-s-forward) arg) | 3463 | (viper-search viper-s-string (not viper-s-forward) arg) |
| 3407 | (if com | 3464 | (if com |
| 3408 | (progn | 3465 | (progn |
| 3409 | (vip-move-marker-locally 'vip-com-point (mark t)) | 3466 | (viper-move-marker-locally 'viper-com-point (mark t)) |
| 3410 | (vip-execute-com 'vip-search-Next val com))))) | 3467 | (viper-execute-com 'viper-search-Next val com))))) |
| 3411 | 3468 | ||
| 3412 | 3469 | ||
| 3413 | ;; Search contents of buffer defined by one of Viper's motion commands. | 3470 | ;; Search contents of buffer defined by one of Viper's motion commands. |
| 3414 | ;; Repeatable via `n' and `N'. | 3471 | ;; Repeatable via `n' and `N'. |
| 3415 | (defun vip-buffer-search-enable (&optional c) | 3472 | (defun viper-buffer-search-enable (&optional c) |
| 3416 | (cond (c (setq vip-buffer-search-char c)) | 3473 | (cond (c (setq viper-buffer-search-char c)) |
| 3417 | ((null vip-buffer-search-char) | 3474 | ((null viper-buffer-search-char) |
| 3418 | (setq vip-buffer-search-char ?g))) | 3475 | (setq viper-buffer-search-char ?g))) |
| 3419 | (define-key vip-vi-basic-map | 3476 | (define-key viper-vi-basic-map |
| 3420 | (char-to-string vip-buffer-search-char) 'vip-command-argument) | 3477 | (char-to-string viper-buffer-search-char) 'viper-command-argument) |
| 3421 | (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | 3478 | (aset viper-exec-array viper-buffer-search-char 'viper-exec-buffer-search) |
| 3422 | (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | 3479 | (setq viper-prefix-commands |
| 3480 | (cons viper-buffer-search-char viper-prefix-commands))) | ||
| 3423 | 3481 | ||
| 3424 | ;; This is a Viper wraper for isearch-forward. | 3482 | ;; This is a Viper wraper for isearch-forward. |
| 3425 | (defun vip-isearch-forward (arg) | 3483 | (defun viper-isearch-forward (arg) |
| 3426 | "Do incremental search forward." | 3484 | "Do incremental search forward." |
| 3427 | (interactive "P") | 3485 | (interactive "P") |
| 3428 | ;; emacs bug workaround | 3486 | ;; emacs bug workaround |
| 3429 | (if (listp arg) (setq arg (car arg))) | 3487 | (if (listp arg) (setq arg (car arg))) |
| 3430 | (vip-exec-form-in-emacs (list 'isearch-forward arg))) | 3488 | (viper-exec-form-in-emacs (list 'isearch-forward arg))) |
| 3431 | 3489 | ||
| 3432 | ;; This is a Viper wraper for isearch-backward." | 3490 | ;; This is a Viper wraper for isearch-backward." |
| 3433 | (defun vip-isearch-backward (arg) | 3491 | (defun viper-isearch-backward (arg) |
| 3434 | "Do incremental search backward." | 3492 | "Do incremental search backward." |
| 3435 | (interactive "P") | 3493 | (interactive "P") |
| 3436 | ;; emacs bug workaround | 3494 | ;; emacs bug workaround |
| 3437 | (if (listp arg) (setq arg (car arg))) | 3495 | (if (listp arg) (setq arg (car arg))) |
| 3438 | (vip-exec-form-in-emacs (list 'isearch-backward arg))) | 3496 | (viper-exec-form-in-emacs (list 'isearch-backward arg))) |
| 3439 | 3497 | ||
| 3440 | 3498 | ||
| 3441 | ;; visiting and killing files, buffers | 3499 | ;; visiting and killing files, buffers |
| 3442 | 3500 | ||
| 3443 | (defun vip-switch-to-buffer () | 3501 | (defun viper-switch-to-buffer () |
| 3444 | "Switch to buffer in the current window." | 3502 | "Switch to buffer in the current window." |
| 3445 | (interactive) | 3503 | (interactive) |
| 3446 | (let (buffer) | 3504 | (let (buffer) |
| @@ -3451,7 +3509,7 @@ Null string will repeat previous search." | |||
| 3451 | (switch-to-buffer buffer) | 3509 | (switch-to-buffer buffer) |
| 3452 | )) | 3510 | )) |
| 3453 | 3511 | ||
| 3454 | (defun vip-switch-to-buffer-other-window () | 3512 | (defun viper-switch-to-buffer-other-window () |
| 3455 | "Switch to buffer in another window." | 3513 | "Switch to buffer in another window." |
| 3456 | (interactive) | 3514 | (interactive) |
| 3457 | (let (buffer) | 3515 | (let (buffer) |
| @@ -3462,7 +3520,7 @@ Null string will repeat previous search." | |||
| 3462 | (switch-to-buffer-other-window buffer) | 3520 | (switch-to-buffer-other-window buffer) |
| 3463 | )) | 3521 | )) |
| 3464 | 3522 | ||
| 3465 | (defun vip-kill-buffer () | 3523 | (defun viper-kill-buffer () |
| 3466 | "Kill a buffer." | 3524 | "Kill a buffer." |
| 3467 | (interactive) | 3525 | (interactive) |
| 3468 | (let (buffer buffer-name) | 3526 | (let (buffer buffer-name) |
| @@ -3484,7 +3542,7 @@ Null string will repeat previous search." | |||
| 3484 | (error "Buffer not killed")))) | 3542 | (error "Buffer not killed")))) |
| 3485 | 3543 | ||
| 3486 | 3544 | ||
| 3487 | (defcustom vip-smart-suffix-list | 3545 | (defcustom viper-smart-suffix-list |
| 3488 | '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p") | 3546 | '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p") |
| 3489 | "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. | 3547 | "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. |
| 3490 | This is useful when you the current directory contains files with the same | 3548 | This is useful when you the current directory contains files with the same |
| @@ -3503,157 +3561,160 @@ To turn this feature off, set this variable to nil." | |||
| 3503 | 3561 | ||
| 3504 | ;; Try to add suffix to files ending with a `.' | 3562 | ;; Try to add suffix to files ending with a `.' |
| 3505 | ;; Useful when the user hits RET on a non-completed file name. | 3563 | ;; Useful when the user hits RET on a non-completed file name. |
| 3506 | (defun vip-file-add-suffix () | 3564 | (defun viper-file-add-suffix () |
| 3507 | (let ((count 0) | 3565 | (let ((count 0) |
| 3508 | (len (length vip-smart-suffix-list)) | 3566 | (len (length viper-smart-suffix-list)) |
| 3509 | (file (buffer-string)) | 3567 | (file (buffer-string)) |
| 3510 | found key cmd suff) | 3568 | found key cmd suff) |
| 3511 | (goto-char (point-max)) | 3569 | (goto-char (point-max)) |
| 3512 | (if (and vip-smart-suffix-list (string-match "\\.$" file)) | 3570 | (if (and viper-smart-suffix-list (string-match "\\.$" file)) |
| 3513 | (progn | 3571 | (progn |
| 3514 | (while (and (not found) (< count len)) | 3572 | (while (and (not found) (< count len)) |
| 3515 | (setq suff (nth count vip-smart-suffix-list) | 3573 | (setq suff (nth count viper-smart-suffix-list) |
| 3516 | count (1+ count)) | 3574 | count (1+ count)) |
| 3517 | (if (file-exists-p (format "%s%s" file suff)) | 3575 | (if (file-exists-p (format "%s%s" file suff)) |
| 3518 | (progn | 3576 | (progn |
| 3519 | (setq found t) | 3577 | (setq found t) |
| 3520 | (insert suff)))) | 3578 | (insert suff)))) |
| 3521 | 3579 | ||
| 3522 | (if found | 3580 | (if found |
| 3523 | () | 3581 | () |
| 3524 | (vip-tmp-insert-at-eob " [Please complete file name]") | 3582 | (viper-tmp-insert-at-eob " [Please complete file name]") |
| 3525 | (unwind-protect | 3583 | (unwind-protect |
| 3526 | (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer))) | 3584 | (while (not (memq cmd |
| 3585 | '(exit-minibuffer viper-exit-minibuffer))) | ||
| 3527 | (setq cmd | 3586 | (setq cmd |
| 3528 | (key-binding (setq key (read-key-sequence nil)))) | 3587 | (key-binding (setq key (read-key-sequence nil)))) |
| 3529 | (cond ((eq cmd 'self-insert-command) | 3588 | (cond ((eq cmd 'self-insert-command) |
| 3530 | (if vip-xemacs-p | 3589 | (if viper-xemacs-p |
| 3531 | (insert (events-to-keys key)) | 3590 | (insert (events-to-keys key)) |
| 3532 | (insert key))) | 3591 | (insert key))) |
| 3533 | ((memq cmd '(exit-minibuffer vip-exit-minibuffer)) | 3592 | ((memq cmd '(exit-minibuffer viper-exit-minibuffer)) |
| 3534 | nil) | 3593 | nil) |
| 3535 | (t (command-execute cmd))) | 3594 | (t (command-execute cmd))) |
| 3536 | ))) | 3595 | ))) |
| 3537 | )) | 3596 | )))) |
| 3538 | )) | ||
| 3539 | 3597 | ||
| 3540 | 3598 | ||
| 3541 | 3599 | ||
| 3542 | 3600 | ||
| 3543 | ;; yank and pop | 3601 | ;; yank and pop |
| 3544 | 3602 | ||
| 3545 | (defsubst vip-yank (text) | 3603 | (defsubst viper-yank (text) |
| 3546 | "Yank TEXT silently. This works correctly with Emacs's yank-pop command." | 3604 | "Yank TEXT silently. This works correctly with Emacs's yank-pop command." |
| 3547 | (insert text) | 3605 | (insert text) |
| 3548 | (setq this-command 'yank)) | 3606 | (setq this-command 'yank)) |
| 3549 | 3607 | ||
| 3550 | (defun vip-put-back (arg) | 3608 | (defun viper-put-back (arg) |
| 3551 | "Put back after point/below line." | 3609 | "Put back after point/below line." |
| 3552 | (interactive "P") | 3610 | (interactive "P") |
| 3553 | (let ((val (vip-p-val arg)) | 3611 | (let ((val (viper-p-val arg)) |
| 3554 | (text (if vip-use-register | 3612 | (text (if viper-use-register |
| 3555 | (cond ((vip-valid-register vip-use-register '(digit)) | 3613 | (cond ((viper-valid-register viper-use-register '(digit)) |
| 3556 | (current-kill (- vip-use-register ?1) 'do-not-rotate)) | 3614 | (current-kill |
| 3557 | ((vip-valid-register vip-use-register) | 3615 | (- viper-use-register ?1) 'do-not-rotate)) |
| 3558 | (get-register (downcase vip-use-register))) | 3616 | ((viper-valid-register viper-use-register) |
| 3559 | (t (error vip-InvalidRegister vip-use-register))) | 3617 | (get-register (downcase viper-use-register))) |
| 3618 | (t (error viper-InvalidRegister viper-use-register))) | ||
| 3560 | (current-kill 0)))) | 3619 | (current-kill 0)))) |
| 3561 | (if (null text) | 3620 | (if (null text) |
| 3562 | (if vip-use-register | 3621 | (if viper-use-register |
| 3563 | (let ((reg vip-use-register)) | 3622 | (let ((reg viper-use-register)) |
| 3564 | (setq vip-use-register nil) | 3623 | (setq viper-use-register nil) |
| 3565 | (error vip-EmptyRegister reg)) | 3624 | (error viper-EmptyRegister reg)) |
| 3566 | (error ""))) | 3625 | (error ""))) |
| 3567 | (setq vip-use-register nil) | 3626 | (setq viper-use-register nil) |
| 3568 | (if (vip-end-with-a-newline-p text) | 3627 | (if (viper-end-with-a-newline-p text) |
| 3569 | (progn | 3628 | (progn |
| 3570 | (end-of-line) | 3629 | (end-of-line) |
| 3571 | (if (eobp) | 3630 | (if (eobp) |
| 3572 | (insert "\n") | 3631 | (insert "\n") |
| 3573 | (forward-line 1)) | 3632 | (forward-line 1)) |
| 3574 | (beginning-of-line)) | 3633 | (beginning-of-line)) |
| 3575 | (if (not (eolp)) (vip-forward-char-carefully))) | 3634 | (if (not (eolp)) (viper-forward-char-carefully))) |
| 3576 | (set-marker (vip-mark-marker) (point) (current-buffer)) | 3635 | (set-marker (viper-mark-marker) (point) (current-buffer)) |
| 3577 | (vip-set-destructive-command | 3636 | (viper-set-destructive-command |
| 3578 | (list 'vip-put-back val nil vip-use-register nil nil)) | 3637 | (list 'viper-put-back val nil viper-use-register nil nil)) |
| 3579 | (vip-loop val (vip-yank text))) | 3638 | (viper-loop val (viper-yank text))) |
| 3580 | ;; Vi puts cursor on the last char when the yanked text doesn't contain a | 3639 | ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
| 3581 | ;; newline; it leaves the cursor at the beginning when the text contains | 3640 | ;; newline; it leaves the cursor at the beginning when the text contains |
| 3582 | ;; a newline | 3641 | ;; a newline |
| 3583 | (if (vip-same-line (point) (mark)) | 3642 | (if (viper-same-line (point) (mark)) |
| 3584 | (or (= (point) (mark)) (vip-backward-char-carefully)) | 3643 | (or (= (point) (mark)) (viper-backward-char-carefully)) |
| 3585 | (exchange-point-and-mark) | 3644 | (exchange-point-and-mark) |
| 3586 | (if (bolp) | 3645 | (if (bolp) |
| 3587 | (back-to-indentation))) | 3646 | (back-to-indentation))) |
| 3588 | (vip-deactivate-mark)) | 3647 | (viper-deactivate-mark)) |
| 3589 | 3648 | ||
| 3590 | (defun vip-Put-back (arg) | 3649 | (defun viper-Put-back (arg) |
| 3591 | "Put back at point/above line." | 3650 | "Put back at point/above line." |
| 3592 | (interactive "P") | 3651 | (interactive "P") |
| 3593 | (let ((val (vip-p-val arg)) | 3652 | (let ((val (viper-p-val arg)) |
| 3594 | (text (if vip-use-register | 3653 | (text (if viper-use-register |
| 3595 | (cond ((vip-valid-register vip-use-register '(digit)) | 3654 | (cond ((viper-valid-register viper-use-register '(digit)) |
| 3596 | (current-kill (- vip-use-register ?1) 'do-not-rotate)) | 3655 | (current-kill |
| 3597 | ((vip-valid-register vip-use-register) | 3656 | (- viper-use-register ?1) 'do-not-rotate)) |
| 3598 | (get-register (downcase vip-use-register))) | 3657 | ((viper-valid-register viper-use-register) |
| 3599 | (t (error vip-InvalidRegister vip-use-register))) | 3658 | (get-register (downcase viper-use-register))) |
| 3659 | (t (error viper-InvalidRegister viper-use-register))) | ||
| 3600 | (current-kill 0)))) | 3660 | (current-kill 0)))) |
| 3601 | (if (null text) | 3661 | (if (null text) |
| 3602 | (if vip-use-register | 3662 | (if viper-use-register |
| 3603 | (let ((reg vip-use-register)) | 3663 | (let ((reg viper-use-register)) |
| 3604 | (setq vip-use-register nil) | 3664 | (setq viper-use-register nil) |
| 3605 | (error vip-EmptyRegister reg)) | 3665 | (error viper-EmptyRegister reg)) |
| 3606 | (error ""))) | 3666 | (error ""))) |
| 3607 | (setq vip-use-register nil) | 3667 | (setq viper-use-register nil) |
| 3608 | (if (vip-end-with-a-newline-p text) (beginning-of-line)) | 3668 | (if (viper-end-with-a-newline-p text) (beginning-of-line)) |
| 3609 | (vip-set-destructive-command | 3669 | (viper-set-destructive-command |
| 3610 | (list 'vip-Put-back val nil vip-use-register nil nil)) | 3670 | (list 'viper-Put-back val nil viper-use-register nil nil)) |
| 3611 | (set-marker (vip-mark-marker) (point) (current-buffer)) | 3671 | (set-marker (viper-mark-marker) (point) (current-buffer)) |
| 3612 | (vip-loop val (vip-yank text))) | 3672 | (viper-loop val (viper-yank text))) |
| 3613 | ;; Vi puts cursor on the last char when the yanked text doesn't contain a | 3673 | ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
| 3614 | ;; newline; it leaves the cursor at the beginning when the text contains | 3674 | ;; newline; it leaves the cursor at the beginning when the text contains |
| 3615 | ;; a newline | 3675 | ;; a newline |
| 3616 | (if (vip-same-line (point) (mark)) | 3676 | (if (viper-same-line (point) (mark)) |
| 3617 | (or (= (point) (mark)) (vip-backward-char-carefully)) | 3677 | (or (= (point) (mark)) (viper-backward-char-carefully)) |
| 3618 | (exchange-point-and-mark) | 3678 | (exchange-point-and-mark) |
| 3619 | (if (bolp) | 3679 | (if (bolp) |
| 3620 | (back-to-indentation))) | 3680 | (back-to-indentation))) |
| 3621 | (vip-deactivate-mark)) | 3681 | (viper-deactivate-mark)) |
| 3622 | 3682 | ||
| 3623 | 3683 | ||
| 3624 | ;; Copy region to kill-ring. | 3684 | ;; Copy region to kill-ring. |
| 3625 | ;; If BEG and END do not belong to the same buffer, copy empty region. | 3685 | ;; If BEG and END do not belong to the same buffer, copy empty region. |
| 3626 | (defun vip-copy-region-as-kill (beg end) | 3686 | (defun viper-copy-region-as-kill (beg end) |
| 3627 | (condition-case nil | 3687 | (condition-case nil |
| 3628 | (copy-region-as-kill beg end) | 3688 | (copy-region-as-kill beg end) |
| 3629 | (error (copy-region-as-kill beg beg)))) | 3689 | (error (copy-region-as-kill beg beg)))) |
| 3630 | 3690 | ||
| 3631 | 3691 | ||
| 3632 | (defun vip-delete-char (arg) | 3692 | (defun viper-delete-char (arg) |
| 3633 | "Delete character." | 3693 | "Delete character." |
| 3634 | (interactive "P") | 3694 | (interactive "P") |
| 3635 | (let ((val (vip-p-val arg))) | 3695 | (let ((val (viper-p-val arg))) |
| 3636 | (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil)) | 3696 | (viper-set-destructive-command |
| 3697 | (list 'viper-delete-char val nil nil nil nil)) | ||
| 3637 | (if (> val 1) | 3698 | (if (> val 1) |
| 3638 | (save-excursion | 3699 | (save-excursion |
| 3639 | (let ((here (point))) | 3700 | (let ((here (point))) |
| 3640 | (end-of-line) | 3701 | (end-of-line) |
| 3641 | (if (> val (- (point) here)) | 3702 | (if (> val (- (point) here)) |
| 3642 | (setq val (- (point) here)))))) | 3703 | (setq val (- (point) here)))))) |
| 3643 | (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1)) | 3704 | (if (and (eq val 0) (not viper-ex-style-motion)) (setq val 1)) |
| 3644 | (if (and vip-ex-style-motion (eolp)) | 3705 | (if (and viper-ex-style-motion (eolp)) |
| 3645 | (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch | 3706 | (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch |
| 3646 | (if vip-use-register | 3707 | (if viper-use-register |
| 3647 | (progn | 3708 | (progn |
| 3648 | (cond ((vip-valid-register vip-use-register '((Letter))) | 3709 | (cond ((viper-valid-register viper-use-register '((Letter))) |
| 3649 | (vip-append-to-register | 3710 | (viper-append-to-register |
| 3650 | (downcase vip-use-register) (point) (- (point) val))) | 3711 | (downcase viper-use-register) (point) (- (point) val))) |
| 3651 | ((vip-valid-register vip-use-register) | 3712 | ((viper-valid-register viper-use-register) |
| 3652 | (copy-to-register | 3713 | (copy-to-register |
| 3653 | vip-use-register (point) (- (point) val) nil)) | 3714 | viper-use-register (point) (- (point) val) nil)) |
| 3654 | (t (error vip-InvalidRegister vip-use-register))) | 3715 | (t (error viper-InvalidRegister viper-use-register))) |
| 3655 | (setq vip-use-register nil))) | 3716 | (setq viper-use-register nil))) |
| 3656 | (if vip-ex-style-motion | 3717 | (if viper-ex-style-motion |
| 3657 | (progn | 3718 | (progn |
| 3658 | (delete-char val t) | 3719 | (delete-char val t) |
| 3659 | (if (and (eolp) (not (bolp))) (backward-char 1))) | 3720 | (if (and (eolp) (not (bolp))) (backward-char 1))) |
| @@ -3661,55 +3722,55 @@ To turn this feature off, set this variable to nil." | |||
| 3661 | (delete-backward-char val t) | 3722 | (delete-backward-char val t) |
| 3662 | (delete-char val t))))) | 3723 | (delete-char val t))))) |
| 3663 | 3724 | ||
| 3664 | (defun vip-delete-backward-char (arg) | 3725 | (defun viper-delete-backward-char (arg) |
| 3665 | "Delete previous character. On reaching beginning of line, stop and beep." | 3726 | "Delete previous character. On reaching beginning of line, stop and beep." |
| 3666 | (interactive "P") | 3727 | (interactive "P") |
| 3667 | (let ((val (vip-p-val arg))) | 3728 | (let ((val (viper-p-val arg))) |
| 3668 | (vip-set-destructive-command | 3729 | (viper-set-destructive-command |
| 3669 | (list 'vip-delete-backward-char val nil nil nil nil)) | 3730 | (list 'viper-delete-backward-char val nil nil nil nil)) |
| 3670 | (if (> val 1) | 3731 | (if (> val 1) |
| 3671 | (save-excursion | 3732 | (save-excursion |
| 3672 | (let ((here (point))) | 3733 | (let ((here (point))) |
| 3673 | (beginning-of-line) | 3734 | (beginning-of-line) |
| 3674 | (if (> val (- here (point))) | 3735 | (if (> val (- here (point))) |
| 3675 | (setq val (- here (point))))))) | 3736 | (setq val (- here (point))))))) |
| 3676 | (if vip-use-register | 3737 | (if viper-use-register |
| 3677 | (progn | 3738 | (progn |
| 3678 | (cond ((vip-valid-register vip-use-register '(Letter)) | 3739 | (cond ((viper-valid-register viper-use-register '(Letter)) |
| 3679 | (vip-append-to-register | 3740 | (viper-append-to-register |
| 3680 | (downcase vip-use-register) (point) (+ (point) val))) | 3741 | (downcase viper-use-register) (point) (+ (point) val))) |
| 3681 | ((vip-valid-register vip-use-register) | 3742 | ((viper-valid-register viper-use-register) |
| 3682 | (copy-to-register | 3743 | (copy-to-register |
| 3683 | vip-use-register (point) (+ (point) val) nil)) | 3744 | viper-use-register (point) (+ (point) val) nil)) |
| 3684 | (t (error vip-InvalidRegister vip-use-register))) | 3745 | (t (error viper-InvalidRegister viper-use-register))) |
| 3685 | (setq vip-use-register nil))) | 3746 | (setq viper-use-register nil))) |
| 3686 | (if (bolp) (ding) | 3747 | (if (bolp) (ding) |
| 3687 | (delete-backward-char val t)))) | 3748 | (delete-backward-char val t)))) |
| 3688 | 3749 | ||
| 3689 | (defun vip-del-backward-char-in-insert () | 3750 | (defun viper-del-backward-char-in-insert () |
| 3690 | "Delete 1 char backwards while in insert mode." | 3751 | "Delete 1 char backwards while in insert mode." |
| 3691 | (interactive) | 3752 | (interactive) |
| 3692 | (if (and vip-ex-style-editing-in-insert (bolp)) | 3753 | (if (and viper-ex-style-editing-in-insert (bolp)) |
| 3693 | (beep 1) | 3754 | (beep 1) |
| 3694 | (delete-backward-char 1 t))) | 3755 | (delete-backward-char 1 t))) |
| 3695 | 3756 | ||
| 3696 | (defun vip-del-backward-char-in-replace () | 3757 | (defun viper-del-backward-char-in-replace () |
| 3697 | "Delete one character in replace mode. | 3758 | "Delete one character in replace mode. |
| 3698 | If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes | 3759 | If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes |
| 3699 | charecters. If it is nil, then the cursor just moves backwards, similarly | 3760 | charecters. If it is nil, then the cursor just moves backwards, similarly |
| 3700 | to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the | 3761 | to Vi. The variable `viper-ex-style-editing-in-insert', if t, doesn't let the |
| 3701 | cursor move past the beginning of line." | 3762 | cursor move past the beginning of line." |
| 3702 | (interactive) | 3763 | (interactive) |
| 3703 | (cond (vip-delete-backwards-in-replace | 3764 | (cond (viper-delete-backwards-in-replace |
| 3704 | (cond ((not (bolp)) | 3765 | (cond ((not (bolp)) |
| 3705 | (delete-backward-char 1 t)) | 3766 | (delete-backward-char 1 t)) |
| 3706 | (vip-ex-style-editing-in-insert | 3767 | (viper-ex-style-editing-in-insert |
| 3707 | (beep 1)) | 3768 | (beep 1)) |
| 3708 | ((bobp) | 3769 | ((bobp) |
| 3709 | (beep 1)) | 3770 | (beep 1)) |
| 3710 | (t | 3771 | (t |
| 3711 | (delete-backward-char 1 t)))) | 3772 | (delete-backward-char 1 t)))) |
| 3712 | (vip-ex-style-editing-in-insert | 3773 | (viper-ex-style-editing-in-insert |
| 3713 | (if (bolp) | 3774 | (if (bolp) |
| 3714 | (beep 1) | 3775 | (beep 1) |
| 3715 | (backward-char 1))) | 3776 | (backward-char 1))) |
| @@ -3720,12 +3781,13 @@ cursor move past the beginning of line." | |||
| 3720 | 3781 | ||
| 3721 | ;; join lines. | 3782 | ;; join lines. |
| 3722 | 3783 | ||
| 3723 | (defun vip-join-lines (arg) | 3784 | (defun viper-join-lines (arg) |
| 3724 | "Join this line to next, if ARG is nil. Otherwise, join ARG lines." | 3785 | "Join this line to next, if ARG is nil. Otherwise, join ARG lines." |
| 3725 | (interactive "*P") | 3786 | (interactive "*P") |
| 3726 | (let ((val (vip-P-val arg))) | 3787 | (let ((val (viper-P-val arg))) |
| 3727 | (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil)) | 3788 | (viper-set-destructive-command |
| 3728 | (vip-loop (if (null val) 1 (1- val)) | 3789 | (list 'viper-join-lines val nil nil nil nil)) |
| 3790 | (viper-loop (if (null val) 1 (1- val)) | ||
| 3729 | (progn | 3791 | (progn |
| 3730 | (end-of-line) | 3792 | (end-of-line) |
| 3731 | (if (not (eobp)) | 3793 | (if (not (eobp)) |
| @@ -3743,80 +3805,80 @@ cursor move past the beginning of line." | |||
| 3743 | 3805 | ||
| 3744 | ;; Replace state | 3806 | ;; Replace state |
| 3745 | 3807 | ||
| 3746 | (defun vip-change (beg end) | 3808 | (defun viper-change (beg end) |
| 3747 | (if (markerp beg) (setq beg (marker-position beg))) | 3809 | (if (markerp beg) (setq beg (marker-position beg))) |
| 3748 | (if (markerp end) (setq end (marker-position end))) | 3810 | (if (markerp end) (setq end (marker-position end))) |
| 3749 | ;; beg is sometimes (mark t), which may be nil | 3811 | ;; beg is sometimes (mark t), which may be nil |
| 3750 | (or beg (setq beg end)) | 3812 | (or beg (setq beg end)) |
| 3751 | 3813 | ||
| 3752 | (vip-set-complex-command-for-undo) | 3814 | (viper-set-complex-command-for-undo) |
| 3753 | (if vip-use-register | 3815 | (if viper-use-register |
| 3754 | (progn | 3816 | (progn |
| 3755 | (copy-to-register vip-use-register beg end nil) | 3817 | (copy-to-register viper-use-register beg end nil) |
| 3756 | (setq vip-use-register nil))) | 3818 | (setq viper-use-register nil))) |
| 3757 | (vip-set-replace-overlay beg end) | 3819 | (viper-set-replace-overlay beg end) |
| 3758 | (setq last-command nil) ; separate repl text from prev kills | 3820 | (setq last-command nil) ; separate repl text from prev kills |
| 3759 | 3821 | ||
| 3760 | (if (= (vip-replace-start) (point-max)) | 3822 | (if (= (viper-replace-start) (point-max)) |
| 3761 | (error "End of buffer")) | 3823 | (error "End of buffer")) |
| 3762 | 3824 | ||
| 3763 | (setq vip-last-replace-region | 3825 | (setq viper-last-replace-region |
| 3764 | (buffer-substring (vip-replace-start) | 3826 | (buffer-substring (viper-replace-start) |
| 3765 | (vip-replace-end))) | 3827 | (viper-replace-end))) |
| 3766 | 3828 | ||
| 3767 | ;; protect against error while inserting "@" and other disasters | 3829 | ;; protect against error while inserting "@" and other disasters |
| 3768 | ;; (e.g., read-only buff) | 3830 | ;; (e.g., read-only buff) |
| 3769 | (condition-case conds | 3831 | (condition-case conds |
| 3770 | (if (or vip-allow-multiline-replace-regions | 3832 | (if (or viper-allow-multiline-replace-regions |
| 3771 | (vip-same-line (vip-replace-start) | 3833 | (viper-same-line (viper-replace-start) |
| 3772 | (vip-replace-end))) | 3834 | (viper-replace-end))) |
| 3773 | (progn | 3835 | (progn |
| 3774 | ;; tabs cause problems in replace, so untabify | 3836 | ;; tabs cause problems in replace, so untabify |
| 3775 | (goto-char (vip-replace-end)) | 3837 | (goto-char (viper-replace-end)) |
| 3776 | (insert-before-markers "@") ; put placeholder after the TAB | 3838 | (insert-before-markers "@") ; put placeholder after the TAB |
| 3777 | (untabify (vip-replace-start) (point)) | 3839 | (untabify (viper-replace-start) (point)) |
| 3778 | ;; del @, don't put on kill ring | 3840 | ;; del @, don't put on kill ring |
| 3779 | (delete-backward-char 1) | 3841 | (delete-backward-char 1) |
| 3780 | 3842 | ||
| 3781 | (vip-set-replace-overlay-glyphs | 3843 | (viper-set-replace-overlay-glyphs |
| 3782 | vip-replace-region-start-delimiter | 3844 | viper-replace-region-start-delimiter |
| 3783 | vip-replace-region-end-delimiter) | 3845 | viper-replace-region-end-delimiter) |
| 3784 | ;; this move takes care of the last posn in the overlay, which | 3846 | ;; this move takes care of the last posn in the overlay, which |
| 3785 | ;; has to be shifted because of insert. We can't simply insert | 3847 | ;; has to be shifted because of insert. We can't simply insert |
| 3786 | ;; "$" before-markers because then overlay-start will shift the | 3848 | ;; "$" before-markers because then overlay-start will shift the |
| 3787 | ;; beginning of the overlay in case we are replacing a single | 3849 | ;; beginning of the overlay in case we are replacing a single |
| 3788 | ;; character. This fixes the bug with `s' and `cl' commands. | 3850 | ;; character. This fixes the bug with `s' and `cl' commands. |
| 3789 | (vip-move-replace-overlay (vip-replace-start) (point)) | 3851 | (viper-move-replace-overlay (viper-replace-start) (point)) |
| 3790 | (goto-char (vip-replace-start)) | 3852 | (goto-char (viper-replace-start)) |
| 3791 | (vip-change-state-to-replace t)) | 3853 | (viper-change-state-to-replace t)) |
| 3792 | (kill-region (vip-replace-start) | 3854 | (kill-region (viper-replace-start) |
| 3793 | (vip-replace-end)) | 3855 | (viper-replace-end)) |
| 3794 | (vip-hide-replace-overlay) | 3856 | (viper-hide-replace-overlay) |
| 3795 | (vip-change-state-to-insert)) | 3857 | (viper-change-state-to-insert)) |
| 3796 | (error ;; make sure that the overlay doesn't stay. | 3858 | (error ;; make sure that the overlay doesn't stay. |
| 3797 | ;; go back to the original point | 3859 | ;; go back to the original point |
| 3798 | (goto-char (vip-replace-start)) | 3860 | (goto-char (viper-replace-start)) |
| 3799 | (vip-hide-replace-overlay) | 3861 | (viper-hide-replace-overlay) |
| 3800 | (vip-message-conditions conds)))) | 3862 | (viper-message-conditions conds)))) |
| 3801 | 3863 | ||
| 3802 | 3864 | ||
| 3803 | (defun vip-change-subr (beg end) | 3865 | (defun viper-change-subr (beg end) |
| 3804 | ;; beg is sometimes (mark t), which may be nil | 3866 | ;; beg is sometimes (mark t), which may be nil |
| 3805 | (or beg (setq beg end)) | 3867 | (or beg (setq beg end)) |
| 3806 | 3868 | (if viper-use-register | |
| 3807 | (if vip-use-register | ||
| 3808 | (progn | 3869 | (progn |
| 3809 | (copy-to-register vip-use-register beg end nil) | 3870 | (copy-to-register viper-use-register beg end nil) |
| 3810 | (setq vip-use-register nil))) | 3871 | (setq viper-use-register nil))) |
| 3811 | (kill-region beg end) | 3872 | (kill-region beg end) |
| 3812 | (setq this-command 'vip-change) | 3873 | (setq this-command 'viper-change) |
| 3813 | (vip-yank-last-insertion)) | 3874 | (viper-yank-last-insertion)) |
| 3814 | 3875 | ||
| 3815 | (defun vip-toggle-case (arg) | 3876 | (defun viper-toggle-case (arg) |
| 3816 | "Toggle character case." | 3877 | "Toggle character case." |
| 3817 | (interactive "P") | 3878 | (interactive "P") |
| 3818 | (let ((val (vip-p-val arg)) (c)) | 3879 | (let ((val (viper-p-val arg)) (c)) |
| 3819 | (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil)) | 3880 | (viper-set-destructive-command |
| 3881 | (list 'viper-toggle-case val nil nil nil nil)) | ||
| 3820 | (while (> val 0) | 3882 | (while (> val 0) |
| 3821 | (setq c (following-char)) | 3883 | (setq c (following-char)) |
| 3822 | (delete-char 1 nil) | 3884 | (delete-char 1 nil) |
| @@ -3829,48 +3891,48 @@ cursor move past the beginning of line." | |||
| 3829 | 3891 | ||
| 3830 | ;; query replace | 3892 | ;; query replace |
| 3831 | 3893 | ||
| 3832 | (defun vip-query-replace () | 3894 | (defun viper-query-replace () |
| 3833 | "Query replace. | 3895 | "Query replace. |
| 3834 | If a null string is suplied as the string to be replaced, | 3896 | If a null string is suplied as the string to be replaced, |
| 3835 | the query replace mode will toggle between string replace | 3897 | the query replace mode will toggle between string replace |
| 3836 | and regexp replace." | 3898 | and regexp replace." |
| 3837 | (interactive) | 3899 | (interactive) |
| 3838 | (let (str) | 3900 | (let (str) |
| 3839 | (setq str (vip-read-string-with-history | 3901 | (setq str (viper-read-string-with-history |
| 3840 | (if vip-re-query-replace "Query replace regexp: " | 3902 | (if viper-re-query-replace "Query replace regexp: " |
| 3841 | "Query replace: ") | 3903 | "Query replace: ") |
| 3842 | nil ; no initial | 3904 | nil ; no initial |
| 3843 | 'vip-replace1-history | 3905 | 'viper-replace1-history |
| 3844 | (car vip-replace1-history) ; default | 3906 | (car viper-replace1-history) ; default |
| 3845 | )) | 3907 | )) |
| 3846 | (if (string= str "") | 3908 | (if (string= str "") |
| 3847 | (progn | 3909 | (progn |
| 3848 | (setq vip-re-query-replace (not vip-re-query-replace)) | 3910 | (setq viper-re-query-replace (not viper-re-query-replace)) |
| 3849 | (message "Query replace mode changed to %s" | 3911 | (message "Query replace mode changed to %s" |
| 3850 | (if vip-re-query-replace "regexp replace" | 3912 | (if viper-re-query-replace "regexp replace" |
| 3851 | "string replace"))) | 3913 | "string replace"))) |
| 3852 | (if vip-re-query-replace | 3914 | (if viper-re-query-replace |
| 3853 | (query-replace-regexp | 3915 | (query-replace-regexp |
| 3854 | str | 3916 | str |
| 3855 | (vip-read-string-with-history | 3917 | (viper-read-string-with-history |
| 3856 | (format "Query replace regexp `%s' with: " str) | 3918 | (format "Query replace regexp `%s' with: " str) |
| 3857 | nil ; no initial | 3919 | nil ; no initial |
| 3858 | 'vip-replace1-history | 3920 | 'viper-replace1-history |
| 3859 | (car vip-replace1-history) ; default | 3921 | (car viper-replace1-history) ; default |
| 3860 | )) | 3922 | )) |
| 3861 | (query-replace | 3923 | (query-replace |
| 3862 | str | 3924 | str |
| 3863 | (vip-read-string-with-history | 3925 | (viper-read-string-with-history |
| 3864 | (format "Query replace `%s' with: " str) | 3926 | (format "Query replace `%s' with: " str) |
| 3865 | nil ; no initial | 3927 | nil ; no initial |
| 3866 | 'vip-replace1-history | 3928 | 'viper-replace1-history |
| 3867 | (car vip-replace1-history) ; default | 3929 | (car viper-replace1-history) ; default |
| 3868 | )))))) | 3930 | )))))) |
| 3869 | 3931 | ||
| 3870 | 3932 | ||
| 3871 | ;; marking | 3933 | ;; marking |
| 3872 | 3934 | ||
| 3873 | (defun vip-mark-beginning-of-buffer () | 3935 | (defun viper-mark-beginning-of-buffer () |
| 3874 | "Mark beginning of buffer." | 3936 | "Mark beginning of buffer." |
| 3875 | (interactive) | 3937 | (interactive) |
| 3876 | (push-mark (point)) | 3938 | (push-mark (point)) |
| @@ -3878,7 +3940,7 @@ and regexp replace." | |||
| 3878 | (exchange-point-and-mark) | 3940 | (exchange-point-and-mark) |
| 3879 | (message "Mark set at the beginning of buffer")) | 3941 | (message "Mark set at the beginning of buffer")) |
| 3880 | 3942 | ||
| 3881 | (defun vip-mark-end-of-buffer () | 3943 | (defun viper-mark-end-of-buffer () |
| 3882 | "Mark end of buffer." | 3944 | "Mark end of buffer." |
| 3883 | (interactive) | 3945 | (interactive) |
| 3884 | (push-mark (point)) | 3946 | (push-mark (point)) |
| @@ -3886,16 +3948,16 @@ and regexp replace." | |||
| 3886 | (exchange-point-and-mark) | 3948 | (exchange-point-and-mark) |
| 3887 | (message "Mark set at the end of buffer")) | 3949 | (message "Mark set at the end of buffer")) |
| 3888 | 3950 | ||
| 3889 | (defun vip-mark-point () | 3951 | (defun viper-mark-point () |
| 3890 | "Set mark at point of buffer." | 3952 | "Set mark at point of buffer." |
| 3891 | (interactive) | 3953 | (interactive) |
| 3892 | (let ((char (read-char))) | 3954 | (let ((char (read-char))) |
| 3893 | (cond ((and (<= ?a char) (<= char ?z)) | 3955 | (cond ((and (<= ?a char) (<= char ?z)) |
| 3894 | (point-to-register (1+ (- char ?a)))) | 3956 | (point-to-register (1+ (- char ?a)))) |
| 3895 | ((= char ?<) (vip-mark-beginning-of-buffer)) | 3957 | ((= char ?<) (viper-mark-beginning-of-buffer)) |
| 3896 | ((= char ?>) (vip-mark-end-of-buffer)) | 3958 | ((= char ?>) (viper-mark-end-of-buffer)) |
| 3897 | ((= char ?.) (vip-set-mark-if-necessary)) | 3959 | ((= char ?.) (viper-set-mark-if-necessary)) |
| 3898 | ((= char ?,) (vip-cycle-through-mark-ring)) | 3960 | ((= char ?,) (viper-cycle-through-mark-ring)) |
| 3899 | ((= char ?D) (mark-defun)) | 3961 | ((= char ?D) (mark-defun)) |
| 3900 | (t (error "")) | 3962 | (t (error "")) |
| 3901 | ))) | 3963 | ))) |
| @@ -3911,7 +3973,7 @@ and regexp replace." | |||
| 3911 | ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from | 3973 | ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from |
| 3912 | ;; the ring into mark. Push M2 back on the ring and set mark to M0. | 3974 | ;; the ring into mark. Push M2 back on the ring and set mark to M0. |
| 3913 | ;; etc. | 3975 | ;; etc. |
| 3914 | (defun vip-cycle-through-mark-ring () | 3976 | (defun viper-cycle-through-mark-ring () |
| 3915 | "Visit previous locations on the mark ring. | 3977 | "Visit previous locations on the mark ring. |
| 3916 | One can use `` and '' to temporarily jump 1 step back." | 3978 | One can use `` and '' to temporarily jump 1 step back." |
| 3917 | (let* ((sv-pt (point))) | 3979 | (let* ((sv-pt (point))) |
| @@ -3923,96 +3985,96 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 3923 | ;; Then push the current mark (popped off the ring) and set current | 3985 | ;; Then push the current mark (popped off the ring) and set current |
| 3924 | ;; point to be the mark. Current pt as mark is discarded by the next | 3986 | ;; point to be the mark. Current pt as mark is discarded by the next |
| 3925 | ;; m, command. | 3987 | ;; m, command. |
| 3926 | (if (eq last-command 'vip-cycle-through-mark-ring) | 3988 | (if (eq last-command 'viper-cycle-through-mark-ring) |
| 3927 | () | 3989 | () |
| 3928 | ;; save current mark if the first iteration | 3990 | ;; save current mark if the first iteration |
| 3929 | (setq mark-ring (delete (vip-mark-marker) mark-ring)) | 3991 | (setq mark-ring (delete (viper-mark-marker) mark-ring)) |
| 3930 | (if (mark t) | 3992 | (if (mark t) |
| 3931 | (push-mark (mark t) t)) ) | 3993 | (push-mark (mark t) t)) ) |
| 3932 | (pop-mark) | 3994 | (pop-mark) |
| 3933 | (set-mark-command 1) | 3995 | (set-mark-command 1) |
| 3934 | ;; don't duplicate mark on the ring | 3996 | ;; don't duplicate mark on the ring |
| 3935 | (setq mark-ring (delete (vip-mark-marker) mark-ring)) | 3997 | (setq mark-ring (delete (viper-mark-marker) mark-ring)) |
| 3936 | (push-mark sv-pt t) | 3998 | (push-mark sv-pt t) |
| 3937 | (vip-deactivate-mark) | 3999 | (viper-deactivate-mark) |
| 3938 | (setq this-command 'vip-cycle-through-mark-ring) | 4000 | (setq this-command 'viper-cycle-through-mark-ring) |
| 3939 | )) | 4001 | )) |
| 3940 | 4002 | ||
| 3941 | 4003 | ||
| 3942 | (defun vip-goto-mark (arg) | 4004 | (defun viper-goto-mark (arg) |
| 3943 | "Go to mark." | 4005 | "Go to mark." |
| 3944 | (interactive "P") | 4006 | (interactive "P") |
| 3945 | (let ((char (read-char)) | 4007 | (let ((char (read-char)) |
| 3946 | (com (vip-getcom arg))) | 4008 | (com (viper-getcom arg))) |
| 3947 | (vip-goto-mark-subr char com nil))) | 4009 | (viper-goto-mark-subr char com nil))) |
| 3948 | 4010 | ||
| 3949 | (defun vip-goto-mark-and-skip-white (arg) | 4011 | (defun viper-goto-mark-and-skip-white (arg) |
| 3950 | "Go to mark and skip to first non-white character on line." | 4012 | "Go to mark and skip to first non-white character on line." |
| 3951 | (interactive "P") | 4013 | (interactive "P") |
| 3952 | (let ((char (read-char)) | 4014 | (let ((char (read-char)) |
| 3953 | (com (vip-getCom arg))) | 4015 | (com (viper-getCom arg))) |
| 3954 | (vip-goto-mark-subr char com t))) | 4016 | (viper-goto-mark-subr char com t))) |
| 3955 | 4017 | ||
| 3956 | (defun vip-goto-mark-subr (char com skip-white) | 4018 | (defun viper-goto-mark-subr (char com skip-white) |
| 3957 | (if (eobp) | 4019 | (if (eobp) |
| 3958 | (if (bobp) | 4020 | (if (bobp) |
| 3959 | (error "Empty buffer") | 4021 | (error "Empty buffer") |
| 3960 | (backward-char 1))) | 4022 | (backward-char 1))) |
| 3961 | (cond ((vip-valid-register char '(letter)) | 4023 | (cond ((viper-valid-register char '(letter)) |
| 3962 | (let* ((buff (current-buffer)) | 4024 | (let* ((buff (current-buffer)) |
| 3963 | (reg (1+ (- char ?a))) | 4025 | (reg (1+ (- char ?a))) |
| 3964 | (text-marker (get-register reg))) | 4026 | (text-marker (get-register reg))) |
| 3965 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 4027 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3966 | (if (not (vip-valid-marker text-marker)) | 4028 | (if (not (viper-valid-marker text-marker)) |
| 3967 | (error vip-EmptyTextmarker char)) | 4029 | (error viper-EmptyTextmarker char)) |
| 3968 | (if (and (vip-same-line (point) vip-last-jump) | 4030 | (if (and (viper-same-line (point) viper-last-jump) |
| 3969 | (= (point) vip-last-jump-ignore)) | 4031 | (= (point) viper-last-jump-ignore)) |
| 3970 | (push-mark vip-last-jump t) | 4032 | (push-mark viper-last-jump t) |
| 3971 | (push-mark nil t)) ; no msg | 4033 | (push-mark nil t)) ; no msg |
| 3972 | (vip-register-to-point reg) | 4034 | (viper-register-to-point reg) |
| 3973 | (setq vip-last-jump (point-marker)) | 4035 | (setq viper-last-jump (point-marker)) |
| 3974 | (cond (skip-white | 4036 | (cond (skip-white |
| 3975 | (back-to-indentation) | 4037 | (back-to-indentation) |
| 3976 | (setq vip-last-jump-ignore (point)))) | 4038 | (setq viper-last-jump-ignore (point)))) |
| 3977 | (if com | 4039 | (if com |
| 3978 | (if (equal buff (current-buffer)) | 4040 | (if (equal buff (current-buffer)) |
| 3979 | (vip-execute-com (if skip-white | 4041 | (viper-execute-com (if skip-white |
| 3980 | 'vip-goto-mark-and-skip-white | 4042 | 'viper-goto-mark-and-skip-white |
| 3981 | 'vip-goto-mark) | 4043 | 'viper-goto-mark) |
| 3982 | nil com) | 4044 | nil com) |
| 3983 | (switch-to-buffer buff) | 4045 | (switch-to-buffer buff) |
| 3984 | (goto-char vip-com-point) | 4046 | (goto-char viper-com-point) |
| 3985 | (vip-change-state-to-vi) | 4047 | (viper-change-state-to-vi) |
| 3986 | (error ""))))) | 4048 | (error ""))))) |
| 3987 | ((and (not skip-white) (= char ?`)) | 4049 | ((and (not skip-white) (= char ?`)) |
| 3988 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 4050 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 3989 | (if (and (vip-same-line (point) vip-last-jump) | 4051 | (if (and (viper-same-line (point) viper-last-jump) |
| 3990 | (= (point) vip-last-jump-ignore)) | 4052 | (= (point) viper-last-jump-ignore)) |
| 3991 | (goto-char vip-last-jump)) | 4053 | (goto-char viper-last-jump)) |
| 3992 | (if (null (mark t)) (error "Mark is not set in this buffer")) | 4054 | (if (null (mark t)) (error "Mark is not set in this buffer")) |
| 3993 | (if (= (point) (mark t)) (pop-mark)) | 4055 | (if (= (point) (mark t)) (pop-mark)) |
| 3994 | (exchange-point-and-mark) | 4056 | (exchange-point-and-mark) |
| 3995 | (setq vip-last-jump (point-marker) | 4057 | (setq viper-last-jump (point-marker) |
| 3996 | vip-last-jump-ignore 0) | 4058 | viper-last-jump-ignore 0) |
| 3997 | (if com (vip-execute-com 'vip-goto-mark nil com))) | 4059 | (if com (viper-execute-com 'viper-goto-mark nil com))) |
| 3998 | ((and skip-white (= char ?')) | 4060 | ((and skip-white (= char ?')) |
| 3999 | (if com (vip-move-marker-locally 'vip-com-point (point))) | 4061 | (if com (viper-move-marker-locally 'viper-com-point (point))) |
| 4000 | (if (and (vip-same-line (point) vip-last-jump) | 4062 | (if (and (viper-same-line (point) viper-last-jump) |
| 4001 | (= (point) vip-last-jump-ignore)) | 4063 | (= (point) viper-last-jump-ignore)) |
| 4002 | (goto-char vip-last-jump)) | 4064 | (goto-char viper-last-jump)) |
| 4003 | (if (= (point) (mark t)) (pop-mark)) | 4065 | (if (= (point) (mark t)) (pop-mark)) |
| 4004 | (exchange-point-and-mark) | 4066 | (exchange-point-and-mark) |
| 4005 | (setq vip-last-jump (point)) | 4067 | (setq viper-last-jump (point)) |
| 4006 | (back-to-indentation) | 4068 | (back-to-indentation) |
| 4007 | (setq vip-last-jump-ignore (point)) | 4069 | (setq viper-last-jump-ignore (point)) |
| 4008 | (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) | 4070 | (if com (viper-execute-com 'viper-goto-mark-and-skip-white nil com))) |
| 4009 | (t (error vip-InvalidTextmarker char)))) | 4071 | (t (error viper-InvalidTextmarker char)))) |
| 4010 | 4072 | ||
| 4011 | (defun vip-insert-tab () | 4073 | (defun viper-insert-tab () |
| 4012 | (interactive) | 4074 | (interactive) |
| 4013 | (insert-tab)) | 4075 | (insert-tab)) |
| 4014 | 4076 | ||
| 4015 | (defun vip-exchange-point-and-mark () | 4077 | (defun viper-exchange-point-and-mark () |
| 4016 | (interactive) | 4078 | (interactive) |
| 4017 | (exchange-point-and-mark) | 4079 | (exchange-point-and-mark) |
| 4018 | (back-to-indentation)) | 4080 | (back-to-indentation)) |
| @@ -4020,26 +4082,26 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 4020 | ;; Input Mode Indentation | 4082 | ;; Input Mode Indentation |
| 4021 | 4083 | ||
| 4022 | ;; Returns t, if the string before point matches the regexp STR. | 4084 | ;; Returns t, if the string before point matches the regexp STR. |
| 4023 | (defsubst vip-looking-back (str) | 4085 | (defsubst viper-looking-back (str) |
| 4024 | (and (save-excursion (re-search-backward str nil t)) | 4086 | (and (save-excursion (re-search-backward str nil t)) |
| 4025 | (= (point) (match-end 0)))) | 4087 | (= (point) (match-end 0)))) |
| 4026 | 4088 | ||
| 4027 | 4089 | ||
| 4028 | (defun vip-forward-indent () | 4090 | (defun viper-forward-indent () |
| 4029 | "Indent forward -- `C-t' in Vi." | 4091 | "Indent forward -- `C-t' in Vi." |
| 4030 | (interactive) | 4092 | (interactive) |
| 4031 | (setq vip-cted t) | 4093 | (setq viper-cted t) |
| 4032 | (indent-to (+ (current-column) vip-shift-width))) | 4094 | (indent-to (+ (current-column) viper-shift-width))) |
| 4033 | 4095 | ||
| 4034 | (defun vip-backward-indent () | 4096 | (defun viper-backward-indent () |
| 4035 | "Backtab, C-d in VI" | 4097 | "Backtab, C-d in VI" |
| 4036 | (interactive) | 4098 | (interactive) |
| 4037 | (if vip-cted | 4099 | (if viper-cted |
| 4038 | (let ((p (point)) (c (current-column)) bol (indent t)) | 4100 | (let ((p (point)) (c (current-column)) bol (indent t)) |
| 4039 | (if (vip-looking-back "[0^]") | 4101 | (if (viper-looking-back "[0^]") |
| 4040 | (progn | 4102 | (progn |
| 4041 | (if (eq ?^ (preceding-char)) | 4103 | (if (eq ?^ (preceding-char)) |
| 4042 | (setq vip-preserve-indent t)) | 4104 | (setq viper-preserve-indent t)) |
| 4043 | (delete-backward-char 1) | 4105 | (delete-backward-char 1) |
| 4044 | (setq p (point)) | 4106 | (setq p (point)) |
| 4045 | (setq indent nil))) | 4107 | (setq indent nil))) |
| @@ -4049,47 +4111,50 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 4049 | (if (re-search-backward "[^ \t]" bol 1) (forward-char)) | 4111 | (if (re-search-backward "[^ \t]" bol 1) (forward-char)) |
| 4050 | (delete-region (point) p) | 4112 | (delete-region (point) p) |
| 4051 | (if indent | 4113 | (if indent |
| 4052 | (indent-to (- c vip-shift-width))) | 4114 | (indent-to (- c viper-shift-width))) |
| 4053 | (if (or (bolp) (vip-looking-back "[^ \t]")) | 4115 | (if (or (bolp) (viper-looking-back "[^ \t]")) |
| 4054 | (setq vip-cted nil))))) | 4116 | (setq viper-cted nil))))) |
| 4055 | 4117 | ||
| 4056 | (defun vip-autoindent () | 4118 | (defun viper-autoindent () |
| 4057 | "Auto Indentation, Vi-style." | 4119 | "Auto Indentation, Vi-style." |
| 4058 | (interactive) | 4120 | (interactive) |
| 4059 | (let ((col (current-indentation))) | 4121 | (let ((col (current-indentation))) |
| 4060 | (if abbrev-mode (expand-abbrev)) | 4122 | (if abbrev-mode (expand-abbrev)) |
| 4061 | (if vip-preserve-indent | 4123 | (if viper-preserve-indent |
| 4062 | (setq vip-preserve-indent nil) | 4124 | (setq viper-preserve-indent nil) |
| 4063 | (setq vip-current-indent col)) | 4125 | (setq viper-current-indent col)) |
| 4064 | ;; don't leave whitespace lines around | 4126 | ;; don't leave whitespace lines around |
| 4065 | (if (memq last-command | 4127 | (if (memq last-command |
| 4066 | '(vip-autoindent | 4128 | '(viper-autoindent |
| 4067 | vip-open-line vip-Open-line | 4129 | viper-open-line viper-Open-line |
| 4068 | vip-replace-state-exit-cmd)) | 4130 | viper-replace-state-exit-cmd)) |
| 4069 | (indent-to-left-margin)) | 4131 | (indent-to-left-margin)) |
| 4070 | ;; use \n instead of newline, or else <Return> will move the insert point | 4132 | ;; use \n instead of newline, or else <Return> will move the insert point |
| 4071 | ;;(newline 1) | 4133 | ;;(newline 1) |
| 4072 | (insert "\n") | 4134 | (insert "\n") |
| 4073 | (if vip-auto-indent | 4135 | (if viper-auto-indent |
| 4074 | (progn | 4136 | (progn |
| 4075 | (setq vip-cted t) | 4137 | (setq viper-cted t) |
| 4076 | (if (and vip-electric-mode | 4138 | (if (and viper-electric-mode |
| 4077 | (not (eq major-mode 'fundamental-mode))) | 4139 | (not |
| 4140 | (memq major-mode '(fundamental-mode | ||
| 4141 | text-mode | ||
| 4142 | paragraph-indent-text-mode )))) | ||
| 4078 | (indent-according-to-mode) | 4143 | (indent-according-to-mode) |
| 4079 | (indent-to vip-current-indent)) | 4144 | (indent-to viper-current-indent)) |
| 4080 | )) | 4145 | )) |
| 4081 | )) | 4146 | )) |
| 4082 | 4147 | ||
| 4083 | 4148 | ||
| 4084 | ;; Viewing registers | 4149 | ;; Viewing registers |
| 4085 | 4150 | ||
| 4086 | (defun vip-ket-function (arg) | 4151 | (defun viper-ket-function (arg) |
| 4087 | "Function called by \], the ket. View registers and call \]\]." | 4152 | "Function called by \], the ket. View registers and call \]\]." |
| 4088 | (interactive "P") | 4153 | (interactive "P") |
| 4089 | (let ((reg (read-char))) | 4154 | (let ((reg (read-char))) |
| 4090 | (cond ((vip-valid-register reg '(letter Letter)) | 4155 | (cond ((viper-valid-register reg '(letter Letter)) |
| 4091 | (view-register (downcase reg))) | 4156 | (view-register (downcase reg))) |
| 4092 | ((vip-valid-register reg '(digit)) | 4157 | ((viper-valid-register reg '(digit)) |
| 4093 | (let ((text (current-kill (- reg ?1) 'do-not-rotate))) | 4158 | (let ((text (current-kill (- reg ?1) 'do-not-rotate))) |
| 4094 | (save-excursion | 4159 | (save-excursion |
| 4095 | (set-buffer (get-buffer-create "*Output*")) | 4160 | (set-buffer (get-buffer-create "*Output*")) |
| @@ -4099,22 +4164,22 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 4099 | (goto-char (point-min))) | 4164 | (goto-char (point-min))) |
| 4100 | (display-buffer "*Output*"))) | 4165 | (display-buffer "*Output*"))) |
| 4101 | ((= ?\] reg) | 4166 | ((= ?\] reg) |
| 4102 | (vip-next-heading arg)) | 4167 | (viper-next-heading arg)) |
| 4103 | (t (error | 4168 | (t (error |
| 4104 | vip-InvalidRegister reg))))) | 4169 | viper-InvalidRegister reg))))) |
| 4105 | 4170 | ||
| 4106 | (defun vip-brac-function (arg) | 4171 | (defun viper-brac-function (arg) |
| 4107 | "Function called by \[, the brac. View textmarkers and call \[\[" | 4172 | "Function called by \[, the brac. View textmarkers and call \[\[" |
| 4108 | (interactive "P") | 4173 | (interactive "P") |
| 4109 | (let ((reg (read-char))) | 4174 | (let ((reg (read-char))) |
| 4110 | (cond ((= ?\[ reg) | 4175 | (cond ((= ?\[ reg) |
| 4111 | (vip-prev-heading arg)) | 4176 | (viper-prev-heading arg)) |
| 4112 | ((= ?\] reg) | 4177 | ((= ?\] reg) |
| 4113 | (vip-heading-end arg)) | 4178 | (viper-heading-end arg)) |
| 4114 | ((vip-valid-register reg '(letter)) | 4179 | ((viper-valid-register reg '(letter)) |
| 4115 | (let* ((val (get-register (1+ (- reg ?a)))) | 4180 | (let* ((val (get-register (1+ (- reg ?a)))) |
| 4116 | (buf (if (not val) | 4181 | (buf (if (not val) |
| 4117 | (error vip-EmptyTextmarker reg) | 4182 | (error viper-EmptyTextmarker reg) |
| 4118 | (marker-buffer val))) | 4183 | (marker-buffer val))) |
| 4119 | (pos (marker-position val)) | 4184 | (pos (marker-position val)) |
| 4120 | line-no text (s pos) (e pos)) | 4185 | line-no text (s pos) (e pos)) |
| @@ -4148,16 +4213,16 @@ One can use `` and '' to temporarily jump 1 step back." | |||
| 4148 | reg (buffer-name buf) line-no)) | 4213 | reg (buffer-name buf) line-no)) |
| 4149 | (insert (format "Here is some text around %c:\n\n %s" | 4214 | (insert (format "Here is some text around %c:\n\n %s" |
| 4150 | reg text))) | 4215 | reg text))) |
| 4151 | (insert (format vip-EmptyTextmarker reg))) | 4216 | (insert (format viper-EmptyTextmarker reg))) |
| 4152 | (goto-char (point-min))) | 4217 | (goto-char (point-min))) |
| 4153 | (display-buffer "*Output*"))) | 4218 | (display-buffer "*Output*"))) |
| 4154 | (t (error vip-InvalidTextmarker reg))))) | 4219 | (t (error viper-InvalidTextmarker reg))))) |
| 4155 | 4220 | ||
| 4156 | 4221 | ||
| 4157 | 4222 | ||
| 4158 | ;; commands in insertion mode | 4223 | ;; commands in insertion mode |
| 4159 | 4224 | ||
| 4160 | (defun vip-delete-backward-word (arg) | 4225 | (defun viper-delete-backward-word (arg) |
| 4161 | "Delete previous word." | 4226 | "Delete previous word." |
| 4162 | (interactive "p") | 4227 | (interactive "p") |
| 4163 | (save-excursion | 4228 | (save-excursion |
| @@ -4187,84 +4252,84 @@ sensitive for VI-style look-and-feel." | |||
| 4187 | (delete-other-windows) | 4252 | (delete-other-windows) |
| 4188 | ;; if 0 < viper-expert-level < viper-max-expert-level | 4253 | ;; if 0 < viper-expert-level < viper-max-expert-level |
| 4189 | ;; & dont-change-unless = t -- use it; else ask | 4254 | ;; & dont-change-unless = t -- use it; else ask |
| 4190 | (vip-ask-level dont-change-unless)) | 4255 | (viper-ask-level dont-change-unless)) |
| 4191 | 4256 | ||
| 4192 | (setq viper-always t | 4257 | (setq viper-always t |
| 4193 | vip-ex-style-motion t | 4258 | viper-ex-style-motion t |
| 4194 | vip-ex-style-editing-in-insert t | 4259 | viper-ex-style-editing-in-insert t |
| 4195 | vip-want-ctl-h-help nil) | 4260 | viper-want-ctl-h-help nil) |
| 4196 | 4261 | ||
| 4197 | (cond ((eq viper-expert-level 1) ; novice or beginner | 4262 | (cond ((eq viper-expert-level 1) ; novice or beginner |
| 4198 | (global-set-key ; in emacs-state | 4263 | (global-set-key ; in emacs-state |
| 4199 | vip-toggle-key | 4264 | viper-toggle-key |
| 4200 | (if (vip-window-display-p) 'vip-iconify 'suspend-emacs)) | 4265 | (if (viper-window-display-p) 'viper-iconify 'suspend-emacs)) |
| 4201 | (setq vip-no-multiple-ESC t | 4266 | (setq viper-no-multiple-ESC t |
| 4202 | vip-re-search t | 4267 | viper-re-search t |
| 4203 | vip-vi-style-in-minibuffer t | 4268 | viper-vi-style-in-minibuffer t |
| 4204 | vip-search-wrap-around-t t | 4269 | viper-search-wrap-around-t t |
| 4205 | vip-electric-mode nil | 4270 | viper-electric-mode nil |
| 4206 | vip-want-emacs-keys-in-vi nil | 4271 | viper-want-emacs-keys-in-vi nil |
| 4207 | vip-want-emacs-keys-in-insert nil)) | 4272 | viper-want-emacs-keys-in-insert nil)) |
| 4208 | 4273 | ||
| 4209 | ((and (> viper-expert-level 1) (< viper-expert-level 5)) | 4274 | ((and (> viper-expert-level 1) (< viper-expert-level 5)) |
| 4210 | ;; intermediate to guru | 4275 | ;; intermediate to guru |
| 4211 | (setq vip-no-multiple-ESC (if (vip-window-display-p) | 4276 | (setq viper-no-multiple-ESC (if (viper-window-display-p) |
| 4212 | t 'twice) | 4277 | t 'twice) |
| 4213 | vip-electric-mode t | 4278 | viper-electric-mode t |
| 4214 | vip-want-emacs-keys-in-vi t | 4279 | viper-want-emacs-keys-in-vi t |
| 4215 | vip-want-emacs-keys-in-insert (> viper-expert-level 2)) | 4280 | viper-want-emacs-keys-in-insert (> viper-expert-level 2)) |
| 4216 | 4281 | ||
| 4217 | (if (eq viper-expert-level 4) ; respect user's ex-style motion | 4282 | (if (eq viper-expert-level 4) ; respect user's ex-style motion |
| 4218 | ; and vip-no-multiple-ESC | 4283 | ; and viper-no-multiple-ESC |
| 4219 | (progn | 4284 | (progn |
| 4220 | (setq-default | 4285 | (setq-default |
| 4221 | vip-ex-style-editing-in-insert | 4286 | viper-ex-style-editing-in-insert |
| 4222 | (viper-standard-value 'vip-ex-style-editing-in-insert) | 4287 | (viper-standard-value 'viper-ex-style-editing-in-insert) |
| 4223 | vip-ex-style-motion | 4288 | viper-ex-style-motion |
| 4224 | (viper-standard-value 'vip-ex-style-motion)) | 4289 | (viper-standard-value 'viper-ex-style-motion)) |
| 4225 | (setq vip-ex-style-motion | 4290 | (setq viper-ex-style-motion |
| 4226 | (viper-standard-value 'vip-ex-style-motion) | 4291 | (viper-standard-value 'viper-ex-style-motion) |
| 4227 | vip-ex-style-editing-in-insert | 4292 | viper-ex-style-editing-in-insert |
| 4228 | (viper-standard-value 'vip-ex-style-editing-in-insert) | 4293 | (viper-standard-value 'viper-ex-style-editing-in-insert) |
| 4229 | vip-re-search | 4294 | viper-re-search |
| 4230 | (viper-standard-value 'vip-re-search) | 4295 | (viper-standard-value 'viper-re-search) |
| 4231 | vip-no-multiple-ESC | 4296 | viper-no-multiple-ESC |
| 4232 | (viper-standard-value 'vip-no-multiple-ESC))))) | 4297 | (viper-standard-value 'viper-no-multiple-ESC))))) |
| 4233 | 4298 | ||
| 4234 | ;; A wizard!! | 4299 | ;; A wizard!! |
| 4235 | ;; Ideally, if 5 is selected, a buffer should pop up to let the | 4300 | ;; Ideally, if 5 is selected, a buffer should pop up to let the |
| 4236 | ;; user toggle the values of variables. | 4301 | ;; user toggle the values of variables. |
| 4237 | (t (setq-default vip-ex-style-editing-in-insert | 4302 | (t (setq-default viper-ex-style-editing-in-insert |
| 4238 | (viper-standard-value 'vip-ex-style-editing-in-insert) | 4303 | (viper-standard-value 'viper-ex-style-editing-in-insert) |
| 4239 | vip-ex-style-motion | 4304 | viper-ex-style-motion |
| 4240 | (viper-standard-value 'vip-ex-style-motion)) | 4305 | (viper-standard-value 'viper-ex-style-motion)) |
| 4241 | (setq vip-want-ctl-h-help | 4306 | (setq viper-want-ctl-h-help |
| 4242 | (viper-standard-value 'vip-want-ctl-h-help) | 4307 | (viper-standard-value 'viper-want-ctl-h-help) |
| 4243 | viper-always | 4308 | viper-always |
| 4244 | (viper-standard-value 'viper-always) | 4309 | (viper-standard-value 'viper-always) |
| 4245 | vip-no-multiple-ESC | 4310 | viper-no-multiple-ESC |
| 4246 | (viper-standard-value 'vip-no-multiple-ESC) | 4311 | (viper-standard-value 'viper-no-multiple-ESC) |
| 4247 | vip-ex-style-motion | 4312 | viper-ex-style-motion |
| 4248 | (viper-standard-value 'vip-ex-style-motion) | 4313 | (viper-standard-value 'viper-ex-style-motion) |
| 4249 | vip-ex-style-editing-in-insert | 4314 | viper-ex-style-editing-in-insert |
| 4250 | (viper-standard-value 'vip-ex-style-editing-in-insert) | 4315 | (viper-standard-value 'viper-ex-style-editing-in-insert) |
| 4251 | vip-re-search | 4316 | viper-re-search |
| 4252 | (viper-standard-value 'vip-re-search) | 4317 | (viper-standard-value 'viper-re-search) |
| 4253 | vip-electric-mode | 4318 | viper-electric-mode |
| 4254 | (viper-standard-value 'vip-electric-mode) | 4319 | (viper-standard-value 'viper-electric-mode) |
| 4255 | vip-want-emacs-keys-in-vi | 4320 | viper-want-emacs-keys-in-vi |
| 4256 | (viper-standard-value 'vip-want-emacs-keys-in-vi) | 4321 | (viper-standard-value 'viper-want-emacs-keys-in-vi) |
| 4257 | vip-want-emacs-keys-in-insert | 4322 | viper-want-emacs-keys-in-insert |
| 4258 | (viper-standard-value 'vip-want-emacs-keys-in-insert)))) | 4323 | (viper-standard-value 'viper-want-emacs-keys-in-insert)))) |
| 4259 | 4324 | ||
| 4260 | (vip-set-mode-vars-for vip-current-state) | 4325 | (viper-set-mode-vars-for viper-current-state) |
| 4261 | (if (or viper-always | 4326 | (if (or viper-always |
| 4262 | (and (> viper-expert-level 0) (> 5 viper-expert-level))) | 4327 | (and (> viper-expert-level 0) (> 5 viper-expert-level))) |
| 4263 | (vip-set-hooks))) | 4328 | (viper-set-hooks))) |
| 4264 | 4329 | ||
| 4265 | ;; Ask user expert level. | 4330 | ;; Ask user expert level. |
| 4266 | (defun vip-ask-level (dont-change-unless) | 4331 | (defun viper-ask-level (dont-change-unless) |
| 4267 | (let ((ask-buffer " *vip-ask-level*") | 4332 | (let ((ask-buffer " *viper-ask-level*") |
| 4268 | level-changed repeated) | 4333 | level-changed repeated) |
| 4269 | (save-window-excursion | 4334 | (save-window-excursion |
| 4270 | (switch-to-buffer ask-buffer) | 4335 | (switch-to-buffer ask-buffer) |
| @@ -4286,24 +4351,24 @@ Please specify your level of familiarity with the venomous VI PERil | |||
| 4286 | You can change it at any time by typing `M-x viper-set-expert-level RET' | 4351 | You can change it at any time by typing `M-x viper-set-expert-level RET' |
| 4287 | 4352 | ||
| 4288 | 1 -- BEGINNER: Almost all Emacs features are suppressed. | 4353 | 1 -- BEGINNER: Almost all Emacs features are suppressed. |
| 4289 | Feels almost like straight Vi. File name completion and | 4354 | Feels almost like straight Vi. File name completion and |
| 4290 | command history in the minibuffer are thrown in as a bonus. | 4355 | command history in the minibuffer are thrown in as a bonus. |
| 4291 | To use Emacs productively, you must reach level 3 or higher. | 4356 | To use Emacs productively, you must reach level 3 or higher. |
| 4292 | 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, | 4357 | 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, |
| 4293 | so most Emacs commands can be used when Viper is in Vi state. | 4358 | so most Emacs commands can be used when Viper is in Vi state. |
| 4294 | Good progress---you are well on the way to level 3! | 4359 | Good progress---you are well on the way to level 3! |
| 4295 | 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also | 4360 | 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also |
| 4296 | in Viper's insert state. | 4361 | in Viper's insert state. |
| 4297 | 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, | 4362 | 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC, |
| 4298 | vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert | 4363 | viper-ex-style-motion, viper-ex-style-editing-in-insert, and |
| 4299 | variables. Adjust these settings to your taste. | 4364 | viper-re-search variables. Adjust these settings to your taste. |
| 4300 | 5 -- WIZARD: Like 4, but user settings are also respected for viper-always, | 4365 | 5 -- WIZARD: Like 4, but user settings are also respected for viper-always, |
| 4301 | vip-electric-mode, vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, | 4366 | viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi, |
| 4302 | and vip-want-emacs-keys-in-insert. Adjust these to your taste. | 4367 | and viper-want-emacs-keys-in-insert. Adjust these to your taste. |
| 4303 | 4368 | ||
| 4304 | Please, specify your level now: ") | 4369 | Please, specify your level now: ") |
| 4305 | 4370 | ||
| 4306 | (setq viper-expert-level (- (vip-read-char-exclusive) ?0)) | 4371 | (setq viper-expert-level (- (viper-read-char-exclusive) ?0)) |
| 4307 | ) ; end while | 4372 | ) ; end while |
| 4308 | 4373 | ||
| 4309 | ;; tell the user if level was changed | 4374 | ;; tell the user if level was changed |
| @@ -4314,23 +4379,23 @@ Please, specify your level now: ") | |||
| 4314 | viper-expert-level)) | 4379 | viper-expert-level)) |
| 4315 | (if (y-or-n-p "Do you wish to make this change permanent? ") | 4380 | (if (y-or-n-p "Do you wish to make this change permanent? ") |
| 4316 | ;; save the setting for viper-expert-level | 4381 | ;; save the setting for viper-expert-level |
| 4317 | (vip-save-setting | 4382 | (viper-save-setting |
| 4318 | 'viper-expert-level | 4383 | 'viper-expert-level |
| 4319 | (format "Saving user level %d ..." viper-expert-level) | 4384 | (format "Saving user level %d ..." viper-expert-level) |
| 4320 | vip-custom-file-name)) | 4385 | viper-custom-file-name)) |
| 4321 | )) | 4386 | )) |
| 4322 | (bury-buffer) ; remove ask-buffer from screen | 4387 | (bury-buffer) ; remove ask-buffer from screen |
| 4323 | (message "") | 4388 | (message "") |
| 4324 | ))) | 4389 | ))) |
| 4325 | 4390 | ||
| 4326 | 4391 | ||
| 4327 | (defun vip-nil () | 4392 | (defun viper-nil () |
| 4328 | (interactive) | 4393 | (interactive) |
| 4329 | (beep 1)) | 4394 | (beep 1)) |
| 4330 | 4395 | ||
| 4331 | 4396 | ||
| 4332 | ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer | 4397 | ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer |
| 4333 | (defun vip-register-to-point (char &optional enforce-buffer) | 4398 | (defun viper-register-to-point (char &optional enforce-buffer) |
| 4334 | "Like jump-to-register, but switches to another buffer in another window." | 4399 | "Like jump-to-register, but switches to another buffer in another window." |
| 4335 | (interactive "cViper register to point: ") | 4400 | (interactive "cViper register to point: ") |
| 4336 | (let ((val (get-register char))) | 4401 | (let ((val (get-register char))) |
| @@ -4340,20 +4405,20 @@ Please, specify your level now: ") | |||
| 4340 | (set-frame-configuration val)) | 4405 | (set-frame-configuration val)) |
| 4341 | ((window-configuration-p val) | 4406 | ((window-configuration-p val) |
| 4342 | (set-window-configuration val)) | 4407 | (set-window-configuration val)) |
| 4343 | ((vip-valid-marker val) | 4408 | ((viper-valid-marker val) |
| 4344 | (if (and enforce-buffer | 4409 | (if (and enforce-buffer |
| 4345 | (not (equal (current-buffer) (marker-buffer val)))) | 4410 | (not (equal (current-buffer) (marker-buffer val)))) |
| 4346 | (error (concat vip-EmptyTextmarker " in this buffer") | 4411 | (error (concat viper-EmptyTextmarker " in this buffer") |
| 4347 | (1- (+ char ?a)))) | 4412 | (1- (+ char ?a)))) |
| 4348 | (pop-to-buffer (marker-buffer val)) | 4413 | (pop-to-buffer (marker-buffer val)) |
| 4349 | (goto-char val)) | 4414 | (goto-char val)) |
| 4350 | ((and (consp val) (eq (car val) 'file)) | 4415 | ((and (consp val) (eq (car val) 'file)) |
| 4351 | (find-file (cdr val))) | 4416 | (find-file (cdr val))) |
| 4352 | (t | 4417 | (t |
| 4353 | (error vip-EmptyTextmarker (1- (+ char ?a))))))) | 4418 | (error viper-EmptyTextmarker (1- (+ char ?a))))))) |
| 4354 | 4419 | ||
| 4355 | 4420 | ||
| 4356 | (defun vip-save-kill-buffer () | 4421 | (defun viper-save-kill-buffer () |
| 4357 | "Save then kill current buffer. " | 4422 | "Save then kill current buffer. " |
| 4358 | (interactive) | 4423 | (interactive) |
| 4359 | (if (< viper-expert-level 2) | 4424 | (if (< viper-expert-level 2) |
| @@ -4365,74 +4430,76 @@ Please, specify your level now: ") | |||
| 4365 | 4430 | ||
| 4366 | ;;; Bug Report | 4431 | ;;; Bug Report |
| 4367 | 4432 | ||
| 4368 | (defun vip-submit-report () | 4433 | (defun viper-submit-report () |
| 4369 | "Submit bug report on Viper." | 4434 | "Submit bug report on Viper." |
| 4370 | (interactive) | 4435 | (interactive) |
| 4371 | (let ((reporter-prompt-for-summary-p t) | 4436 | (let ((reporter-prompt-for-summary-p t) |
| 4372 | (vip-device-type (vip-device-type)) | 4437 | (viper-device-type (viper-device-type)) |
| 4373 | color-display-p frame-parameters | 4438 | color-display-p frame-parameters |
| 4374 | minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face | 4439 | minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face |
| 4375 | varlist salutation window-config) | 4440 | varlist salutation window-config) |
| 4376 | 4441 | ||
| 4377 | ;; If mode info is needed, add variable to `let' and then set it below, | 4442 | ;; If mode info is needed, add variable to `let' and then set it below, |
| 4378 | ;; like we did with color-display-p. | 4443 | ;; like we did with color-display-p. |
| 4379 | (setq color-display-p (if (vip-window-display-p) | 4444 | (setq color-display-p (if (viper-window-display-p) |
| 4380 | (vip-color-display-p) | 4445 | (viper-color-display-p) |
| 4381 | 'non-x) | 4446 | 'non-x) |
| 4382 | minibuffer-vi-face (if (vip-has-face-support-p) | 4447 | minibuffer-vi-face (if (viper-has-face-support-p) |
| 4383 | (vip-get-face vip-minibuffer-vi-face) | 4448 | (viper-get-face viper-minibuffer-vi-face) |
| 4384 | 'non-x) | 4449 | 'non-x) |
| 4385 | minibuffer-insert-face (if (vip-has-face-support-p) | 4450 | minibuffer-insert-face (if (viper-has-face-support-p) |
| 4386 | (vip-get-face vip-minibuffer-insert-face) | 4451 | (viper-get-face |
| 4452 | viper-minibuffer-insert-face) | ||
| 4387 | 'non-x) | 4453 | 'non-x) |
| 4388 | minibuffer-emacs-face (if (vip-has-face-support-p) | 4454 | minibuffer-emacs-face (if (viper-has-face-support-p) |
| 4389 | (vip-get-face vip-minibuffer-emacs-face) | 4455 | (viper-get-face |
| 4456 | viper-minibuffer-emacs-face) | ||
| 4390 | 'non-x) | 4457 | 'non-x) |
| 4391 | frame-parameters (if (fboundp 'frame-parameters) | 4458 | frame-parameters (if (fboundp 'frame-parameters) |
| 4392 | (frame-parameters (selected-frame)))) | 4459 | (frame-parameters (selected-frame)))) |
| 4393 | 4460 | ||
| 4394 | (setq varlist (list 'vip-vi-minibuffer-minor-mode | 4461 | (setq varlist (list 'viper-vi-minibuffer-minor-mode |
| 4395 | 'vip-insert-minibuffer-minor-mode | 4462 | 'viper-insert-minibuffer-minor-mode |
| 4396 | 'vip-vi-intercept-minor-mode | 4463 | 'viper-vi-intercept-minor-mode |
| 4397 | 'vip-vi-local-user-minor-mode | 4464 | 'viper-vi-local-user-minor-mode |
| 4398 | 'vip-vi-kbd-minor-mode | 4465 | 'viper-vi-kbd-minor-mode |
| 4399 | 'vip-vi-global-user-minor-mode | 4466 | 'viper-vi-global-user-minor-mode |
| 4400 | 'vip-vi-state-modifier-minor-mode | 4467 | 'viper-vi-state-modifier-minor-mode |
| 4401 | 'vip-vi-diehard-minor-mode | 4468 | 'viper-vi-diehard-minor-mode |
| 4402 | 'vip-vi-basic-minor-mode | 4469 | 'viper-vi-basic-minor-mode |
| 4403 | 'vip-replace-minor-mode | 4470 | 'viper-replace-minor-mode |
| 4404 | 'vip-insert-intercept-minor-mode | 4471 | 'viper-insert-intercept-minor-mode |
| 4405 | 'vip-insert-local-user-minor-mode | 4472 | 'viper-insert-local-user-minor-mode |
| 4406 | 'vip-insert-kbd-minor-mode | 4473 | 'viper-insert-kbd-minor-mode |
| 4407 | 'vip-insert-global-user-minor-mode | 4474 | 'viper-insert-global-user-minor-mode |
| 4408 | 'vip-insert-state-modifier-minor-mode | 4475 | 'viper-insert-state-modifier-minor-mode |
| 4409 | 'vip-insert-diehard-minor-mode | 4476 | 'viper-insert-diehard-minor-mode |
| 4410 | 'vip-insert-basic-minor-mode | 4477 | 'viper-insert-basic-minor-mode |
| 4411 | 'vip-emacs-intercept-minor-mode | 4478 | 'viper-emacs-intercept-minor-mode |
| 4412 | 'vip-emacs-local-user-minor-mode | 4479 | 'viper-emacs-local-user-minor-mode |
| 4413 | 'vip-emacs-kbd-minor-mode | 4480 | 'viper-emacs-kbd-minor-mode |
| 4414 | 'vip-emacs-global-user-minor-mode | 4481 | 'viper-emacs-global-user-minor-mode |
| 4415 | 'vip-emacs-state-modifier-minor-mode | 4482 | 'viper-emacs-state-modifier-minor-mode |
| 4416 | 'vip-automatic-iso-accents | 4483 | 'viper-automatic-iso-accents |
| 4417 | 'vip-want-emacs-keys-in-insert | 4484 | 'viper-want-emacs-keys-in-insert |
| 4418 | 'vip-want-emacs-keys-in-vi | 4485 | 'viper-want-emacs-keys-in-vi |
| 4419 | 'vip-keep-point-on-undo | 4486 | 'viper-keep-point-on-undo |
| 4420 | 'vip-no-multiple-ESC | 4487 | 'viper-no-multiple-ESC |
| 4421 | 'vip-electric-mode | 4488 | 'viper-electric-mode |
| 4422 | 'vip-ESC-key | 4489 | 'viper-ESC-key |
| 4423 | 'vip-want-ctl-h-help | 4490 | 'viper-want-ctl-h-help |
| 4424 | 'vip-ex-style-editing-in-insert | 4491 | 'viper-ex-style-editing-in-insert |
| 4425 | 'vip-delete-backwards-in-replace | 4492 | 'viper-delete-backwards-in-replace |
| 4426 | 'vip-vi-style-in-minibuffer | 4493 | 'viper-vi-style-in-minibuffer |
| 4427 | 'vip-vi-state-hook | 4494 | 'viper-vi-state-hook |
| 4428 | 'vip-insert-state-hook | 4495 | 'viper-insert-state-hook |
| 4429 | 'vip-replace-state-hook | 4496 | 'viper-replace-state-hook |
| 4430 | 'vip-emacs-state-hook | 4497 | 'viper-emacs-state-hook |
| 4431 | 'ex-cycle-other-window | 4498 | 'ex-cycle-other-window |
| 4432 | 'ex-cycle-through-non-files | 4499 | 'ex-cycle-through-non-files |
| 4433 | 'viper-expert-level | 4500 | 'viper-expert-level |
| 4434 | 'major-mode | 4501 | 'major-mode |
| 4435 | 'vip-device-type | 4502 | 'viper-device-type |
| 4436 | 'color-display-p | 4503 | 'color-display-p |
| 4437 | 'frame-parameters | 4504 | 'frame-parameters |
| 4438 | 'minibuffer-vi-face | 4505 | 'minibuffer-vi-face |
| @@ -4445,8 +4512,8 @@ Please mail a concise, accurate summary of the problem to the address above. | |||
| 4445 | 4512 | ||
| 4446 | -------------------------------------------------------------------") | 4513 | -------------------------------------------------------------------") |
| 4447 | (setq window-config (current-window-configuration)) | 4514 | (setq window-config (current-window-configuration)) |
| 4448 | (with-output-to-temp-buffer " *vip-info*" | 4515 | (with-output-to-temp-buffer " *viper-info*" |
| 4449 | (switch-to-buffer " *vip-info*") | 4516 | (switch-to-buffer " *viper-info*") |
| 4450 | (delete-other-windows) | 4517 | (delete-other-windows) |
| 4451 | (princ " | 4518 | (princ " |
| 4452 | PLEASE FOLLOW THESE PROCEDURES | 4519 | PLEASE FOLLOW THESE PROCEDURES |
| @@ -4489,7 +4556,7 @@ Mail anyway (y or n)? ") | |||
| 4489 | (set-window-configuration window-config) | 4556 | (set-window-configuration window-config) |
| 4490 | 4557 | ||
| 4491 | (reporter-submit-bug-report "kifer@cs.sunysb.edu" | 4558 | (reporter-submit-bug-report "kifer@cs.sunysb.edu" |
| 4492 | (vip-version) | 4559 | (viper-version) |
| 4493 | varlist | 4560 | varlist |
| 4494 | nil 'delete-other-windows | 4561 | nil 'delete-other-windows |
| 4495 | salutation) | 4562 | salutation) |
| @@ -4506,8 +4573,8 @@ Mail anyway (y or n)? ") | |||
| 4506 | ;; symbol in unread-command-events list may cause Emacs to turn this symbol | 4573 | ;; symbol in unread-command-events list may cause Emacs to turn this symbol |
| 4507 | ;; into an event. Below, we delete nil from event lists, since nil is the most | 4574 | ;; into an event. Below, we delete nil from event lists, since nil is the most |
| 4508 | ;; common symbol that might appear in this wrong context. | 4575 | ;; common symbol that might appear in this wrong context. |
| 4509 | (defun vip-set-unread-command-events (arg) | 4576 | (defun viper-set-unread-command-events (arg) |
| 4510 | (if vip-emacs-p | 4577 | (if viper-emacs-p |
| 4511 | (setq | 4578 | (setq |
| 4512 | unread-command-events | 4579 | unread-command-events |
| 4513 | (let ((new-events | 4580 | (let ((new-events |
| @@ -4516,7 +4583,7 @@ Mail anyway (y or n)? ") | |||
| 4516 | ((sequencep arg) | 4583 | ((sequencep arg) |
| 4517 | (listify-key-sequence arg)) | 4584 | (listify-key-sequence arg)) |
| 4518 | (t (error | 4585 | (t (error |
| 4519 | "vip-set-unread-command-events: Invalid argument, %S" | 4586 | "viper-set-unread-command-events: Invalid argument, %S" |
| 4520 | arg))))) | 4587 | arg))))) |
| 4521 | (if (not (eventp nil)) | 4588 | (if (not (eventp nil)) |
| 4522 | (setq new-events (delq nil new-events))) | 4589 | (setq new-events (delq nil new-events))) |
| @@ -4525,23 +4592,23 @@ Mail anyway (y or n)? ") | |||
| 4525 | (setq | 4592 | (setq |
| 4526 | unread-command-events | 4593 | unread-command-events |
| 4527 | (append | 4594 | (append |
| 4528 | (cond ((vip-characterp arg) (list (character-to-event arg))) | 4595 | (cond ((viper-characterp arg) (list (character-to-event arg))) |
| 4529 | ((eventp arg) (list arg)) | 4596 | ((eventp arg) (list arg)) |
| 4530 | ((stringp arg) (mapcar 'character-to-event arg)) | 4597 | ((stringp arg) (mapcar 'character-to-event arg)) |
| 4531 | ((vectorp arg) (append arg nil)) ; turn into list | 4598 | ((vectorp arg) (append arg nil)) ; turn into list |
| 4532 | ((listp arg) (vip-eventify-list-xemacs arg)) | 4599 | ((listp arg) (viper-eventify-list-xemacs arg)) |
| 4533 | (t (error | 4600 | (t (error |
| 4534 | "vip-set-unread-command-events: Invalid argument, %S" arg))) | 4601 | "viper-set-unread-command-events: Invalid argument, %S" arg))) |
| 4535 | unread-command-events)))) | 4602 | unread-command-events)))) |
| 4536 | 4603 | ||
| 4537 | ;; list is assumed to be a list of events of characters | 4604 | ;; list is assumed to be a list of events of characters |
| 4538 | (defun vip-eventify-list-xemacs (lis) | 4605 | (defun viper-eventify-list-xemacs (lis) |
| 4539 | (mapcar | 4606 | (mapcar |
| 4540 | (function (lambda (elt) | 4607 | (function (lambda (elt) |
| 4541 | (cond ((vip-characterp elt) (character-to-event elt)) | 4608 | (cond ((viper-characterp elt) (character-to-event elt)) |
| 4542 | ((eventp elt) elt) | 4609 | ((eventp elt) elt) |
| 4543 | (t (error | 4610 | (t (error |
| 4544 | "vip-eventify-list-xemacs: can't convert to event, %S" | 4611 | "viper-eventify-list-xemacs: can't convert to event, %S" |
| 4545 | elt))))) | 4612 | elt))))) |
| 4546 | lis)) | 4613 | lis)) |
| 4547 | 4614 | ||