comparison lisp/viper/viper-cmd.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 2d532a89d707
children 3d6bfa290dbd
comparison
equal deleted inserted replaced
180:add28d59e586 181:bfd6434d15b3
6 6
7 (provide 'viper-cmd) 7 (provide 'viper-cmd)
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)
21 21
22 ;; loading happens only in non-interactive compilation 22 ;; loading happens only in non-interactive compilation
51 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane 51 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane
52 52
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
204 ;; will remain red. Restoring the default, below, fixes this problem. 207 ;; will remain red. Restoring the default, below, fixes this problem.
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
262 ;; the last posn was recorded when we hit ESC. 266 ;; the last posn was recorded when we hit ESC.
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
361 (cdr (assoc major-mode vip-vi-state-modifier-alist)) 366 viper-vi-state-modifier-alist)))
362 vip-empty-keymap)) 367 (cdr (assoc major-mode viper-vi-state-modifier-alist))
363 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map) 368 viper-empty-keymap))
364 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map) 369 (cons 'viper-vi-diehard-minor-mode viper-vi-diehard-map)
365 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map) 370 (cons 'viper-vi-basic-minor-mode viper-vi-basic-map)
366 (cons 'vip-replace-minor-mode vip-replace-map) 371 (cons 'viper-insert-intercept-minor-mode
367 ;; vip-insert-minibuffer-minor-mode must come after 372 viper-insert-intercept-map)
368 ;; vip-replace-minor-mode 373 (cons 'viper-replace-minor-mode viper-replace-map)
369 (cons 'vip-insert-minibuffer-minor-mode 374 ;; viper-insert-minibuffer-minor-mode must come after
370 vip-minibuffer-map) 375 ;; viper-replace-minor-mode
371 (cons 'vip-insert-local-user-minor-mode 376 (cons 'viper-insert-minibuffer-minor-mode
372 vip-insert-local-user-map) 377 viper-minibuffer-map)
373 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map) 378 (cons 'viper-insert-local-user-minor-mode
374 (cons 'vip-insert-global-user-minor-mode 379 viper-insert-local-user-map)
375 vip-insert-global-user-map) 380 (cons 'viper-insert-kbd-minor-mode viper-insert-kbd-map)
376 (cons 'vip-insert-state-modifier-minor-mode 381 (cons 'viper-insert-global-user-minor-mode
382 viper-insert-global-user-map)
383 (cons 'viper-insert-state-modifier-minor-mode
384 (if (keymapp
385 (cdr (assoc major-mode
386 viper-insert-state-modifier-alist)))
387 (cdr (assoc major-mode
388 viper-insert-state-modifier-alist))
389 viper-empty-keymap))
390 (cons 'viper-insert-diehard-minor-mode viper-insert-diehard-map)
391 (cons 'viper-insert-basic-minor-mode viper-insert-basic-map)
392 (cons 'viper-emacs-intercept-minor-mode
393 viper-emacs-intercept-map)
394 (cons 'viper-emacs-local-user-minor-mode
395 viper-emacs-local-user-map)
396 (cons 'viper-emacs-kbd-minor-mode viper-emacs-kbd-map)
397 (cons 'viper-emacs-global-user-minor-mode
398 viper-emacs-global-user-map)
399 (cons 'viper-emacs-state-modifier-minor-mode
377 (if (keymapp 400 (if (keymapp
378 (cdr 401 (cdr
379 (assoc major-mode vip-insert-state-modifier-alist))) 402 (assoc major-mode viper-emacs-state-modifier-alist)))
380 (cdr 403 (cdr
381 (assoc major-mode vip-insert-state-modifier-alist)) 404 (assoc major-mode viper-emacs-state-modifier-alist))
382 vip-empty-keymap)) 405 viper-empty-keymap))
383 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map)
384 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map)
385 (cons 'vip-emacs-intercept-minor-mode
386 vip-emacs-intercept-map)
387 (cons 'vip-emacs-local-user-minor-mode
388 vip-emacs-local-user-map)
389 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map)
390 (cons 'vip-emacs-global-user-minor-mode
391 vip-emacs-global-user-map)
392 (cons 'vip-emacs-state-modifier-minor-mode
393 (if (keymapp
394 (cdr
395 (assoc major-mode vip-emacs-state-modifier-alist)))
396 (cdr
397 (assoc major-mode vip-emacs-state-modifier-alist))
398 vip-empty-keymap))
399 ) 406 )
400 minor-mode-map-alist))) 407 minor-mode-map-alist)))
401 408
402 409
403 410
404 411
405 412
406 ;; Viper mode-changing commands and utilities 413 ;; Viper mode-changing commands and utilities
407 414
408 ;; Modifies mode-line-buffer-identification. 415 ;; Modifies mode-line-buffer-identification.
409 (defun vip-refresh-mode-line () 416 (defun viper-refresh-mode-line ()
410 (setq vip-mode-string 417 (setq viper-mode-string
411 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id) 418 (cond ((eq viper-current-state 'emacs-state) viper-emacs-state-id)
412 ((eq vip-current-state 'vi-state) vip-vi-state-id) 419 ((eq viper-current-state 'vi-state) viper-vi-state-id)
413 ((eq vip-current-state 'replace-state) vip-replace-state-id) 420 ((eq viper-current-state 'replace-state) viper-replace-state-id)
414 ((eq vip-current-state 'insert-state) vip-insert-state-id))) 421 ((eq viper-current-state 'insert-state) viper-insert-state-id)))
415 422
416 ;; Sets Viper mode string in global-mode-string 423 ;; Sets Viper mode string in global-mode-string
417 (force-mode-line-update)) 424 (force-mode-line-update))
418 425
419 426
420 ;; Switch from Insert state to Vi state. 427 ;; Switch from Insert state to Vi state.
421 (defun vip-exit-insert-state () 428 (defun viper-exit-insert-state ()
422 (interactive) 429 (interactive)
423 (vip-change-state-to-vi)) 430 (viper-change-state-to-vi))
424 431
425 (defun vip-set-mode-vars-for (state) 432 (defun viper-set-mode-vars-for (state)
426 "Sets Viper minor mode variables to put Viper's state STATE in effect." 433 "Sets Viper minor mode variables to put Viper's state STATE in effect."
427 434
428 ;; Emacs state 435 ;; Emacs state
429 (setq vip-vi-minibuffer-minor-mode nil 436 (setq viper-vi-minibuffer-minor-mode nil
430 vip-insert-minibuffer-minor-mode nil 437 viper-insert-minibuffer-minor-mode nil
431 vip-vi-intercept-minor-mode nil 438 viper-vi-intercept-minor-mode nil
432 vip-insert-intercept-minor-mode nil 439 viper-insert-intercept-minor-mode nil
433 440
434 vip-vi-local-user-minor-mode nil 441 viper-vi-local-user-minor-mode nil
435 vip-vi-kbd-minor-mode nil 442 viper-vi-kbd-minor-mode nil
436 vip-vi-global-user-minor-mode nil 443 viper-vi-global-user-minor-mode nil
437 vip-vi-state-modifier-minor-mode nil 444 viper-vi-state-modifier-minor-mode nil
438 vip-vi-diehard-minor-mode nil 445 viper-vi-diehard-minor-mode nil
439 vip-vi-basic-minor-mode nil 446 viper-vi-basic-minor-mode nil
440 447
441 vip-replace-minor-mode nil 448 viper-replace-minor-mode nil
442 449
443 vip-insert-local-user-minor-mode nil 450 viper-insert-local-user-minor-mode nil
444 vip-insert-kbd-minor-mode nil 451 viper-insert-kbd-minor-mode nil
445 vip-insert-global-user-minor-mode nil 452 viper-insert-global-user-minor-mode nil
446 vip-insert-state-modifier-minor-mode nil 453 viper-insert-state-modifier-minor-mode nil
447 vip-insert-diehard-minor-mode nil 454 viper-insert-diehard-minor-mode nil
448 vip-insert-basic-minor-mode nil 455 viper-insert-basic-minor-mode nil
449 vip-emacs-intercept-minor-mode t 456 viper-emacs-intercept-minor-mode t
450 vip-emacs-local-user-minor-mode t 457 viper-emacs-local-user-minor-mode t
451 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer)) 458 viper-emacs-kbd-minor-mode (not (viper-is-in-minibuffer))
452 vip-emacs-global-user-minor-mode t 459 viper-emacs-global-user-minor-mode t
453 vip-emacs-state-modifier-minor-mode t 460 viper-emacs-state-modifier-minor-mode t
454 ) 461 )
455 462
456 ;; Vi state 463 ;; Vi state
457 (if (eq state 'vi-state) ; adjust for vi-state 464 (if (eq state 'vi-state) ; adjust for vi-state
458 (setq 465 (setq
459 vip-vi-intercept-minor-mode t 466 viper-vi-intercept-minor-mode t
460 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer) 467 viper-vi-minibuffer-minor-mode (viper-is-in-minibuffer)
461 vip-vi-local-user-minor-mode t 468 viper-vi-local-user-minor-mode t
462 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer)) 469 viper-vi-kbd-minor-mode (not (viper-is-in-minibuffer))
463 vip-vi-global-user-minor-mode t 470 viper-vi-global-user-minor-mode t
464 vip-vi-state-modifier-minor-mode t 471 viper-vi-state-modifier-minor-mode t
465 ;; don't let the diehard keymap block command completion 472 ;; don't let the diehard keymap block command completion
466 ;; and other things in the minibuffer 473 ;; and other things in the minibuffer
467 vip-vi-diehard-minor-mode (not 474 viper-vi-diehard-minor-mode (not
468 (or vip-want-emacs-keys-in-vi 475 (or viper-want-emacs-keys-in-vi
469 (vip-is-in-minibuffer))) 476 (viper-is-in-minibuffer)))
470 vip-vi-basic-minor-mode t 477 viper-vi-basic-minor-mode t
471 vip-emacs-intercept-minor-mode nil 478 viper-emacs-intercept-minor-mode nil
472 vip-emacs-local-user-minor-mode nil 479 viper-emacs-local-user-minor-mode nil
473 vip-emacs-kbd-minor-mode nil 480 viper-emacs-kbd-minor-mode nil
474 vip-emacs-global-user-minor-mode nil 481 viper-emacs-global-user-minor-mode nil
475 vip-emacs-state-modifier-minor-mode nil 482 viper-emacs-state-modifier-minor-mode nil
476 )) 483 ))
477 484
478 ;; Insert and Replace states 485 ;; Insert and Replace states
479 (if (member state '(insert-state replace-state)) 486 (if (member state '(insert-state replace-state))
480 (setq 487 (setq
481 vip-insert-intercept-minor-mode t 488 viper-insert-intercept-minor-mode t
482 vip-replace-minor-mode (eq state 'replace-state) 489 viper-replace-minor-mode (eq state 'replace-state)
483 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer) 490 viper-insert-minibuffer-minor-mode (viper-is-in-minibuffer)
484 vip-insert-local-user-minor-mode t 491 viper-insert-local-user-minor-mode t
485 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer)) 492 viper-insert-kbd-minor-mode (not (viper-is-in-minibuffer))
486 vip-insert-global-user-minor-mode t 493 viper-insert-global-user-minor-mode t
487 vip-insert-state-modifier-minor-mode t 494 viper-insert-state-modifier-minor-mode t
488 ;; don't let the diehard keymap block command completion 495 ;; don't let the diehard keymap block command completion
489 ;; and other things in the minibuffer 496 ;; and other things in the minibuffer
490 vip-insert-diehard-minor-mode (not 497 viper-insert-diehard-minor-mode (not
491 (or vip-want-emacs-keys-in-insert 498 (or
492 (vip-is-in-minibuffer))) 499 viper-want-emacs-keys-in-insert
493 vip-insert-basic-minor-mode t 500 (viper-is-in-minibuffer)))
494 vip-emacs-intercept-minor-mode nil 501 viper-insert-basic-minor-mode t
495 vip-emacs-local-user-minor-mode nil 502 viper-emacs-intercept-minor-mode nil
496 vip-emacs-kbd-minor-mode nil 503 viper-emacs-local-user-minor-mode nil
497 vip-emacs-global-user-minor-mode nil 504 viper-emacs-kbd-minor-mode nil
498 vip-emacs-state-modifier-minor-mode nil 505 viper-emacs-global-user-minor-mode nil
506 viper-emacs-state-modifier-minor-mode nil
499 )) 507 ))
500 508
501 ;; minibuffer faces 509 ;; minibuffer faces
502 (if (vip-has-face-support-p) 510 (if (viper-has-face-support-p)
503 (setq vip-minibuffer-current-face 511 (setq viper-minibuffer-current-face
504 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face) 512 (cond ((eq state 'emacs-state) viper-minibuffer-emacs-face)
505 ((eq state 'vi-state) vip-minibuffer-vi-face) 513 ((eq state 'vi-state) viper-minibuffer-vi-face)
506 ((memq state '(insert-state replace-state)) 514 ((memq state '(insert-state replace-state))
507 vip-minibuffer-insert-face)))) 515 viper-minibuffer-insert-face))))
508 516
509 (if (vip-is-in-minibuffer) 517 (if (viper-is-in-minibuffer)
510 (vip-set-minibuffer-overlay)) 518 (viper-set-minibuffer-overlay))
511 ) 519 )
512 520
513 ;; This also takes care of the annoying incomplete lines in files. 521 ;; This also takes care of the annoying incomplete lines in files.
514 ;; Also, this fixes `undo' to work vi-style for complex commands. 522 ;; Also, this fixes `undo' to work vi-style for complex commands.
515 (defun vip-change-state-to-vi () 523 (defun viper-change-state-to-vi ()
516 "Change Viper state to Vi." 524 "Change Viper state to Vi."
517 (interactive) 525 (interactive)
518 (if (and vip-first-time (not (vip-is-in-minibuffer))) 526 (if (and viper-first-time (not (viper-is-in-minibuffer)))
519 (viper-mode) 527 (viper-mode)
520 (if overwrite-mode (overwrite-mode nil)) 528 (if overwrite-mode (overwrite-mode nil))
521 (if abbrev-mode (expand-abbrev)) 529 (if abbrev-mode (expand-abbrev))
522 (if (and auto-fill-function (> (current-column) fill-column)) 530 (if (and auto-fill-function (> (current-column) fill-column))
523 (funcall auto-fill-function)) 531 (funcall auto-fill-function))
524 ;; don't leave whitespace lines around 532 ;; don't leave whitespace lines around
525 (if (and (memq last-command 533 (if (and (memq last-command
526 '(vip-autoindent 534 '(viper-autoindent
527 vip-open-line vip-Open-line 535 viper-open-line viper-Open-line
528 vip-replace-state-exit-cmd)) 536 viper-replace-state-exit-cmd))
529 (vip-over-whitespace-line)) 537 (viper-over-whitespace-line))
530 (indent-to-left-margin)) 538 (indent-to-left-margin))
531 (vip-add-newline-at-eob-if-necessary) 539 (viper-add-newline-at-eob-if-necessary)
532 (if vip-undo-needs-adjustment (vip-adjust-undo)) 540 (if viper-undo-needs-adjustment (viper-adjust-undo))
533 (vip-change-state 'vi-state) 541 (viper-change-state 'vi-state)
534 542
535 ;; always turn off iso-accents-mode, or else we won't be able to use the 543 ;; 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. 544 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions.
537 (if (and (boundp 'iso-accents-mode) iso-accents-mode) 545 (if (and (boundp 'iso-accents-mode) iso-accents-mode)
538 (iso-accents-mode -1)) 546 (iso-accents-mode -1))
539 547
540 (vip-restore-cursor-color-after-insert) 548 (viper-restore-cursor-color-after-insert)
541 549
542 ;; Protection against user errors in hooks 550 ;; Protection against user errors in hooks
543 (condition-case conds 551 (condition-case conds
544 (run-hooks 'vip-vi-state-hook) 552 (run-hooks 'viper-vi-state-hook)
545 (error 553 (error
546 (vip-message-conditions conds))))) 554 (viper-message-conditions conds)))))
547 555
548 (defun vip-change-state-to-insert () 556 (defun viper-change-state-to-insert ()
549 "Change Viper state to Insert." 557 "Change Viper state to Insert."
550 (interactive) 558 (interactive)
551 (vip-change-state 'insert-state) 559 (viper-change-state 'insert-state)
552 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) 560 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode))
553 (iso-accents-mode 1)) ; turn iso accents on 561 (iso-accents-mode 1)) ; turn iso accents on
554 562
555 (or (stringp vip-saved-cursor-color) 563 (or (stringp viper-saved-cursor-color)
556 (string= (vip-get-cursor-color) vip-insert-state-cursor-color) 564 (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
557 (setq vip-saved-cursor-color (vip-get-cursor-color))) 565 (setq viper-saved-cursor-color (viper-get-cursor-color)))
558 ;; Commented out, because if vip-change-state-to-insert is executed 566 ;; 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 567 ;; non-interactively then the old cursor color may get lost. Same old Emacs
560 ;; bug related to local variables? 568 ;; bug related to local variables?
561 ;;;(if (stringp vip-saved-cursor-color) 569 ;;;(if (stringp viper-saved-cursor-color)
562 ;;; (vip-change-cursor-color vip-insert-state-cursor-color)) 570 ;;; (viper-change-cursor-color viper-insert-state-cursor-color))
563 ;; Protection against user errors in hooks 571 ;; Protection against user errors in hooks
564 (condition-case conds 572 (condition-case conds
565 (run-hooks 'vip-insert-state-hook) 573 (run-hooks 'viper-insert-state-hook)
566 (error 574 (error
567 (vip-message-conditions conds)))) 575 (viper-message-conditions conds))))
568 576
569 (defsubst vip-downgrade-to-insert () 577 (defsubst viper-downgrade-to-insert ()
570 (setq vip-current-state 'insert-state 578 (setq viper-current-state 'insert-state
571 vip-replace-minor-mode nil) 579 viper-replace-minor-mode nil))
572 )
573 580
574 581
575 582
576 ;; Change to replace state. When the end of replacement region is reached, 583 ;; Change to replace state. When the end of replacement region is reached,
577 ;; replace state changes to insert state. 584 ;; replace state changes to insert state.
578 (defun vip-change-state-to-replace (&optional non-R-cmd) 585 (defun viper-change-state-to-replace (&optional non-R-cmd)
579 (vip-change-state 'replace-state) 586 (viper-change-state 'replace-state)
580 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) 587 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode))
581 (iso-accents-mode 1)) ; turn iso accents on 588 (iso-accents-mode 1)) ; turn iso accents on
582 ;; Run insert-state-hook 589 ;; Run insert-state-hook
583 (condition-case conds 590 (condition-case conds
584 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook) 591 (run-hooks 'viper-insert-state-hook 'viper-replace-state-hook)
585 (error 592 (error
586 (vip-message-conditions conds))) 593 (viper-message-conditions conds)))
587 594
588 (if non-R-cmd 595 (if non-R-cmd
589 (vip-start-replace) 596 (viper-start-replace)
590 ;; 'R' is implemented using Emacs's overwrite-mode 597 ;; 'R' is implemented using Emacs's overwrite-mode
591 (vip-start-R-mode)) 598 (viper-start-R-mode))
592 ) 599 )
593 600
594 601
595 (defun vip-change-state-to-emacs () 602 (defun viper-change-state-to-emacs ()
596 "Change Viper state to Emacs." 603 "Change Viper state to Emacs."
597 (interactive) 604 (interactive)
598 (vip-change-state 'emacs-state) 605 (viper-change-state 'emacs-state)
599 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) 606 (if (and viper-automatic-iso-accents (fboundp 'iso-accents-mode))
600 (iso-accents-mode 1)) ; turn iso accents on 607 (iso-accents-mode 1)) ; turn iso accents on
601 608
602 ;; Protection agains user errors in hooks 609 ;; Protection agains user errors in hooks
603 (condition-case conds 610 (condition-case conds
604 (run-hooks 'vip-emacs-state-hook) 611 (run-hooks 'viper-emacs-state-hook)
605 (error 612 (error
606 (vip-message-conditions conds)))) 613 (viper-message-conditions conds))))
607 614
608 ;; escape to emacs mode termporarily 615 ;; escape to emacs mode termporarily
609 (defun vip-escape-to-emacs (arg &optional events) 616 (defun viper-escape-to-emacs (arg &optional events)
610 "Escape to Emacs state from Vi state for one Emacs command. 617 "Escape to Emacs state from Vi state for one Emacs command.
611 ARG is used as the prefix value for the executed command. If 618 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." 619 EVENTS is a list of events, which become the beginning of the command."
613 (interactive "P") 620 (interactive "P")
614 (if (= last-command-char ?\\) 621 (if (= last-command-char ?\\)
615 (message "Switched to EMACS state for the next command...")) 622 (message "Switched to EMACS state for the next command..."))
616 (vip-escape-to-state arg events 'emacs-state)) 623 (viper-escape-to-state arg events 'emacs-state))
617 624
618 ;; escape to Vi mode termporarily 625 ;; escape to Vi mode termporarily
619 (defun vip-escape-to-vi (arg) 626 (defun viper-escape-to-vi (arg)
620 "Escape from Emacs state to Vi state for one Vi 1-character command. 627 "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 628 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 629 Vi's prefix argument will be used. Otherwise, the prefix argument passed to
623 `vip-escape-to-vi' is used." 630 `viper-escape-to-vi' is used."
624 (interactive "P") 631 (interactive "P")
625 (message "Switched to VI state for the next command...") 632 (message "Switched to VI state for the next command...")
626 (vip-escape-to-state arg nil 'vi-state)) 633 (viper-escape-to-state arg nil 'vi-state))
627 634
628 ;; Escape to STATE mode for one Emacs command. 635 ;; Escape to STATE mode for one Emacs command.
629 (defun vip-escape-to-state (arg events state) 636 (defun viper-escape-to-state (arg events state)
630 ;;(let (com key prefix-arg) 637 ;;(let (com key prefix-arg)
631 (let (com key) 638 (let (com key)
632 ;; this temporarily turns off Viper's minor mode keymaps 639 ;; this temporarily turns off Viper's minor mode keymaps
633 (vip-set-mode-vars-for state) 640 (viper-set-mode-vars-for state)
634 (vip-normalize-minor-mode-map-alist) 641 (viper-normalize-minor-mode-map-alist)
635 (if events (vip-set-unread-command-events events)) 642 (if events (viper-set-unread-command-events events))
636 643
637 ;; protect against keyboard quit and other errors 644 ;; protect against keyboard quit and other errors
638 (condition-case nil 645 (condition-case nil
639 (let (vip-vi-kbd-minor-mode 646 (let (viper-vi-kbd-minor-mode
640 vip-insert-kbd-minor-mode 647 viper-insert-kbd-minor-mode
641 vip-emacs-kbd-minor-mode) 648 viper-emacs-kbd-minor-mode)
642 (unwind-protect 649 (unwind-protect
643 (progn 650 (progn
644 (setq com (key-binding (setq key 651 (setq com (key-binding (setq key
645 (if vip-xemacs-p 652 (if viper-xemacs-p
646 (read-key-sequence nil) 653 (read-key-sequence nil)
647 (read-key-sequence nil t))))) 654 (read-key-sequence nil t)))))
648 ;; In case of binding indirection--chase definitions. 655 ;; In case of binding indirection--chase definitions.
649 ;; Have to do it here because we execute this command under 656 ;; Have to do it here because we execute this command under
650 ;; different keymaps, so command-execute may not do the 657 ;; different keymaps, so command-execute may not do the
654 ;; Execute command com in the original Viper state, not in state 661 ;; Execute command com in the original Viper state, not in state
655 ;; `state'. Otherwise, if we switch buffers while executing the 662 ;; `state'. Otherwise, if we switch buffers while executing the
656 ;; escaped to command, Viper's mode vars will remain those of 663 ;; escaped to command, Viper's mode vars will remain those of
657 ;; `state'. When we return to the orig buffer, the bindings will be 664 ;; `state'. When we return to the orig buffer, the bindings will be
658 ;; screwed up. 665 ;; screwed up.
659 (vip-set-mode-vars-for vip-current-state) 666 (viper-set-mode-vars-for viper-current-state)
660 667
661 ;; this-command, last-command-char, last-command-event 668 ;; this-command, last-command-char, last-command-event
662 (setq this-command com) 669 (setq this-command com)
663 (if vip-xemacs-p ; XEmacs represents key sequences as vectors 670 (if viper-xemacs-p ; XEmacs represents key sequences as vectors
664 (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) 671 (setq last-command-event
672 (viper-copy-event (viper-seq-last-elt key))
665 last-command-char (event-to-character last-command-event)) 673 last-command-char (event-to-character last-command-event))
666 ;; Emacs represents them as sequences (str or vec) 674 ;; Emacs represents them as sequences (str or vec)
667 (setq last-command-event (vip-copy-event (vip-seq-last-elt key)) 675 (setq last-command-event
676 (viper-copy-event (viper-seq-last-elt key))
668 last-command-char last-command-event)) 677 last-command-char last-command-event))
669 678
670 (if (commandp com) 679 (if (commandp com)
671 (progn 680 (progn
672 (setq prefix-arg (or prefix-arg arg)) 681 (setq prefix-arg (or prefix-arg arg))
673 (command-execute com))) 682 (command-execute com)))
674 ) 683 )
675 (quit (ding)) 684 (quit (ding))
676 (error (beep 1)))) 685 (error (beep 1))))
677 ;; set state in the new buffer 686 ;; set state in the new buffer
678 (vip-set-mode-vars-for vip-current-state)) 687 (viper-set-mode-vars-for viper-current-state))
679 688
680 (defun vip-exec-form-in-vi (form) 689 (defun viper-exec-form-in-vi (form)
681 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." 690 "Execute FORM in Vi state, regardless of the Ccurrent Vi state."
682 (let ((buff (current-buffer)) 691 (let ((buff (current-buffer))
683 result) 692 result)
684 (vip-set-mode-vars-for 'vi-state) 693 (viper-set-mode-vars-for 'vi-state)
685 694
686 (condition-case nil 695 (condition-case nil
687 (setq result (eval form)) 696 (let (viper-vi-kbd-minor-mode) ; execute without kbd macros
697 (setq result (eval form))
698 )
688 (error 699 (error
689 (signal 'quit nil))) 700 (signal 'quit nil)))
690 701
691 (if (not (equal buff (current-buffer))) ; cmd switched buffer 702 (if (not (equal buff (current-buffer))) ; cmd switched buffer
692 (save-excursion 703 (save-excursion
693 (set-buffer buff) 704 (set-buffer buff)
694 (vip-set-mode-vars-for vip-current-state))) 705 (viper-set-mode-vars-for viper-current-state)))
695 (vip-set-mode-vars-for vip-current-state) 706 (viper-set-mode-vars-for viper-current-state)
696 result)) 707 result))
697 708
698 (defun vip-exec-form-in-emacs (form) 709 (defun viper-exec-form-in-emacs (form)
699 "Execute FORM in Emacs, temporarily disabling Viper's minor modes. 710 "Execute FORM in Emacs, temporarily disabling Viper's minor modes.
700 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes." 711 Similar to viper-escape-to-emacs, but accepts forms rather than keystrokes."
701 (let ((buff (current-buffer)) 712 (let ((buff (current-buffer))
702 result) 713 result)
703 (vip-set-mode-vars-for 'emacs-state) 714 (viper-set-mode-vars-for 'emacs-state)
704 (setq result (eval form)) 715 (setq result (eval form))
705 (if (not (equal buff (current-buffer))) ; cmd switched buffer 716 (if (not (equal buff (current-buffer))) ; cmd switched buffer
706 (save-excursion 717 (save-excursion
707 (set-buffer buff) 718 (set-buffer buff)
708 (vip-set-mode-vars-for vip-current-state))) 719 (viper-set-mode-vars-for viper-current-state)))
709 (vip-set-mode-vars-for vip-current-state) 720 (viper-set-mode-vars-for viper-current-state)
710 result)) 721 result))
711 722
712 723
713 ;; This is needed because minor modes sometimes override essential Viper 724 ;; This is needed because minor modes sometimes override essential Viper
714 ;; bindings. By letting Viper know which files these modes are in, it will 725 ;; 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. 726 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
716 (defun vip-harness-minor-mode (load-file) 727 (defun viper-harness-minor-mode (load-file)
717 "Familiarize Viper with a minor mode defined in LOAD_FILE. 728 "Familiarize Viper with a minor mode defined in LOAD_FILE.
718 Minor modes that have their own keymaps may overshadow Viper keymaps. 729 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 730 This function is designed to make Viper aware of the packages that define
720 such minor modes. 731 such minor modes.
721 Usage: 732 Usage:
722 (vip-harness-minor-mode load-file) 733 (viper-harness-minor-mode load-file)
723 734
724 LOAD-FILE is a name of the file where the specific minor mode is defined. 735 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." 736 Suffixes such as .el or .elc should be stripped."
726 737
727 (interactive "sEnter name of the load file: ") 738 (interactive "sEnter name of the load file: ")
728 739
729 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist)) 740 (eval-after-load load-file '(viper-normalize-minor-mode-map-alist))
730 741
731 ;; Change the default for minor-mode-map-alist each time a harnessed minor 742 ;; Change the default for minor-mode-map-alist each time a harnessed minor
732 ;; mode adds its own keymap to the a-list. 743 ;; mode adds its own keymap to the a-list.
733 (vip-eval-after-load 744 (eval-after-load
734 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) 745 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist))
735 ) 746 )
736 747
737 748
738 (defun vip-ESC (arg) 749 (defun viper-ESC (arg)
739 "Emulate ESC key in Emacs. 750 "Emulate ESC key in Emacs.
740 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. 751 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. 752 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 753 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 754 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 755 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 756 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." 757 as a Meta key and any number of multiple escapes is allowed."
747 (interactive "P") 758 (interactive "P")
748 (let (char) 759 (let (char)
749 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state)) 760 (cond ((and (not viper-no-multiple-ESC) (eq viper-current-state 'vi-state))
750 (setq char (vip-read-char-exclusive)) 761 (setq char (viper-read-char-exclusive))
751 (vip-escape-to-emacs arg (list ?\e char) )) 762 (viper-escape-to-emacs arg (list ?\e char) ))
752 ((and (eq vip-no-multiple-ESC 'twice) 763 ((and (eq viper-no-multiple-ESC 'twice)
753 (eq vip-current-state 'vi-state)) 764 (eq viper-current-state 'vi-state))
754 (setq char (vip-read-char-exclusive)) 765 (setq char (viper-read-char-exclusive))
755 (if (= char (string-to-char vip-ESC-key)) 766 (if (= char (string-to-char viper-ESC-key))
756 (ding) 767 (ding)
757 (vip-escape-to-emacs arg (list ?\e char) ))) 768 (viper-escape-to-emacs arg (list ?\e char) )))
758 (t (ding))) 769 (t (ding)))
759 )) 770 ))
760 771
761 (defun vip-alternate-Meta-key (arg) 772 (defun viper-alternate-Meta-key (arg)
762 "Simulate Emacs Meta key." 773 "Simulate Emacs Meta key."
763 (interactive "P") 774 (interactive "P")
764 (sit-for 1) (message "ESC-") 775 (sit-for 1) (message "ESC-")
765 (vip-escape-to-emacs arg '(?\e))) 776 (viper-escape-to-emacs arg '(?\e)))
766 777
767 (defun vip-toggle-key-action () 778 (defun viper-toggle-key-action ()
768 "Action bound to `vip-toggle-key'." 779 "Action bound to `viper-toggle-key'."
769 (interactive) 780 (interactive)
770 (if (and (< viper-expert-level 2) (equal vip-toggle-key "\C-z")) 781 (if (and (< viper-expert-level 2) (equal viper-toggle-key "\C-z"))
771 (if (vip-window-display-p) 782 (if (viper-window-display-p)
772 (vip-iconify) 783 (viper-iconify)
773 (suspend-emacs)) 784 (suspend-emacs))
774 (vip-change-state-to-emacs))) 785 (viper-change-state-to-emacs)))
775 786
776 787
777 ;; Intercept ESC sequences on dumb terminals. 788 ;; Intercept ESC sequences on dumb terminals.
778 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> 789 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es>
779 790
780 ;; Check if last key was ESC and if so try to reread it as a function key. 791 ;; 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. 792 ;; But only if there are characters to read during a very short time.
782 ;; Returns the last event, if any. 793 ;; Returns the last event, if any.
783 (defun vip-envelop-ESC-key () 794 (defun viper-envelop-ESC-key ()
784 (let ((event last-input-event) 795 (let ((event last-input-event)
785 (keyseq [nil]) 796 (keyseq [nil])
786 inhibit-quit) 797 inhibit-quit)
787 (if (vip-ESC-event-p event) 798 (if (viper-ESC-event-p event)
788 (progn 799 (progn
789 (if (vip-fast-keysequence-p) 800 (if (viper-fast-keysequence-p)
790 (progn 801 (progn
791 (let (minor-mode-map-alist) 802 (let (minor-mode-map-alist)
792 (vip-set-unread-command-events event) 803 (viper-set-unread-command-events event)
793 (setq keyseq 804 (setq keyseq
794 (funcall 805 (funcall
795 (ad-get-orig-definition 'read-key-sequence) nil)) 806 (ad-get-orig-definition 'read-key-sequence) nil))
796 ) ; let 807 ) ; let
797 ;; If keyseq translates into something that still has ESC 808 ;; If keyseq translates into something that still has ESC
810 ;; f11 in an xterm window into the symbolic key f11. 821 ;; f11 in an xterm window into the symbolic key f11.
811 ;; 822 ;;
812 ;; If `first-key' is not an ESC event, we make it into the 823 ;; 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 824 ;; last-command-event in order to pretend that this key was
814 ;; pressed. This is needed to allow arrow keys to be bound to 825 ;; pressed. This is needed to allow arrow keys to be bound to
815 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that 826 ;; macros. Otherwise, viper-exec-mapped-kbd-macro will think
816 ;; the last event was ESC and so it'll execute whatever is 827 ;; that the last event was ESC and so it'll execute whatever is
817 ;; bound to ESC. (Viper macros can't be bound to 828 ;; bound to ESC. (Viper macros can't be bound to
818 ;; ESC-sequences). 829 ;; ESC-sequences).
819 (let* ((first-key (elt keyseq 0)) 830 (let* ((first-key (elt keyseq 0))
820 (key-mod (event-modifiers first-key))) 831 (key-mod (event-modifiers first-key)))
821 (cond ((vip-ESC-event-p first-key) 832 (cond ((viper-ESC-event-p first-key)
822 ;; put keys following ESC on the unread list 833 ;; put keys following ESC on the unread list
823 ;; and return ESC as the key-sequence 834 ;; and return ESC as the key-sequence
824 (vip-set-unread-command-events (subseq keyseq 1)) 835 (viper-set-unread-command-events (subseq keyseq 1))
825 (setq last-input-event event 836 (setq last-input-event event
826 keyseq (if vip-emacs-p 837 keyseq (if viper-emacs-p
827 "\e" 838 "\e"
828 (vector (character-to-event ?\e))))) 839 (vector (character-to-event ?\e)))))
829 ((and vip-xemacs-p 840 ((and viper-xemacs-p
830 (key-press-event-p first-key) 841 (key-press-event-p first-key)
831 (equal '(meta) key-mod)) 842 (equal '(meta) key-mod))
832 (vip-set-unread-command-events 843 (viper-set-unread-command-events
833 (vconcat (vector 844 (vconcat (vector
834 (character-to-event (event-key first-key))) 845 (character-to-event (event-key first-key)))
835 (subseq keyseq 1))) 846 (subseq keyseq 1)))
836 (setq last-input-event event 847 (setq last-input-event event
837 keyseq (vector (character-to-event ?\e)))) 848 keyseq (vector (character-to-event ?\e))))
838 ((eventp first-key) 849 ((eventp first-key)
839 (setq last-command-event (vip-copy-event first-key))) 850 (setq last-command-event
851 (viper-copy-event first-key)))
840 )) 852 ))
841 ) ; end progn 853 ) ; end progn
842 854
843 ;; this is escape event with nothing after it 855 ;; this is escape event with nothing after it
844 ;; put in unread-command-event and then re-read 856 ;; put in unread-command-event and then re-read
845 (vip-set-unread-command-events event) 857 (viper-set-unread-command-events event)
846 (setq keyseq 858 (setq keyseq
847 (funcall (ad-get-orig-definition 'read-key-sequence) nil)) 859 (funcall (ad-get-orig-definition 'read-key-sequence) nil))
848 )) 860 ))
849 ;; not an escape event 861 ;; not an escape event
850 (setq keyseq (vector event))) 862 (setq keyseq (vector event)))
853 865
854 866
855 ;; Listen to ESC key. 867 ;; Listen to ESC key.
856 ;; If a sequence of keys starting with ESC is issued with very short delays, 868 ;; 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. 869 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key.
858 (defun vip-intercept-ESC-key () 870 (defun viper-intercept-ESC-key ()
859 "Function that implements ESC key in Viper emulation of Vi." 871 "Function that implements ESC key in Viper emulation of Vi."
860 (interactive) 872 (interactive)
861 (let ((cmd (or (key-binding (vip-envelop-ESC-key)) 873 (let ((cmd (or (key-binding (viper-envelop-ESC-key))
862 '(lambda () (interactive) (error ""))))) 874 '(lambda () (interactive) (error "")))))
863 875
864 ;; call the actual function to execute ESC (if no other symbols followed) 876 ;; 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 877 ;; or the key bound to the ESC sequence (if the sequence was issued
866 ;; with very short delay between characters. 878 ;; with very short delay between characters.
867 (if (eq cmd 'vip-intercept-ESC-key) 879 (if (eq cmd 'viper-intercept-ESC-key)
868 (setq cmd 880 (setq cmd
869 (cond ((eq vip-current-state 'vi-state) 881 (cond ((eq viper-current-state 'vi-state)
870 'vip-ESC) 882 'viper-ESC)
871 ((eq vip-current-state 'insert-state) 883 ((eq viper-current-state 'insert-state)
872 'vip-exit-insert-state) 884 'viper-exit-insert-state)
873 ((eq vip-current-state 'replace-state) 885 ((eq viper-current-state 'replace-state)
874 'vip-replace-state-exit-cmd) 886 'viper-replace-state-exit-cmd)
875 (t 'vip-change-state-to-vi) 887 (t 'viper-change-state-to-vi)
876 ))) 888 )))
877 (call-interactively cmd))) 889 (call-interactively cmd)))
878 890
879 891
880 892
884 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM 896 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
885 ;; represents the numeric value of the prefix argument and COM represents 897 ;; represents the numeric value of the prefix argument and COM represents
886 ;; command prefix such as "c", "d", "m" and "y". 898 ;; command prefix such as "c", "d", "m" and "y".
887 899
888 ;; Get value part of prefix-argument ARG. 900 ;; Get value part of prefix-argument ARG.
889 (defsubst vip-p-val (arg) 901 (defsubst viper-p-val (arg)
890 (cond ((null arg) 1) 902 (cond ((null arg) 1)
891 ((consp arg) 903 ((consp arg)
892 (if (or (null (car arg)) (equal (car arg) '(nil))) 904 (if (or (null (car arg)) (equal (car arg) '(nil)))
893 1 (car arg))) 905 1 (car arg)))
894 (t arg))) 906 (t arg)))
895 907
896 ;; Get raw value part of prefix-argument ARG. 908 ;; Get raw value part of prefix-argument ARG.
897 (defsubst vip-P-val (arg) 909 (defsubst viper-P-val (arg)
898 (cond ((consp arg) (car arg)) 910 (cond ((consp arg) (car arg))
899 (t arg))) 911 (t arg)))
900 912
901 ;; Get com part of prefix-argument ARG. 913 ;; Get com part of prefix-argument ARG.
902 (defsubst vip-getcom (arg) 914 (defsubst viper-getcom (arg)
903 (cond ((null arg) nil) 915 (cond ((null arg) nil)
904 ((consp arg) (cdr arg)) 916 ((consp arg) (cdr arg))
905 (t nil))) 917 (t nil)))
906 918
907 ;; Get com part of prefix-argument ARG and modify it. 919 ;; Get com part of prefix-argument ARG and modify it.
908 (defun vip-getCom (arg) 920 (defun viper-getCom (arg)
909 (let ((com (vip-getcom arg))) 921 (let ((com (viper-getcom arg)))
910 (cond ((equal com ?c) ?C) 922 (cond ((equal com ?c) ?c)
923 ;; Previously, ?c was being converted to ?C, but this prevented
924 ;; multiline replace regions.
925 ;;((equal com ?c) ?C)
911 ((equal com ?d) ?D) 926 ((equal com ?d) ?D)
912 ((equal com ?y) ?Y) 927 ((equal com ?y) ?Y)
913 (t com)))) 928 (t com))))
914 929
915 930
916 ;; Compute numeric prefix arg value. 931 ;; Compute numeric prefix arg value.
917 ;; Invoked by EVENT. COM is the command part obtained so far. 932 ;; Invoked by EVENT. COM is the command part obtained so far.
918 (defun vip-prefix-arg-value (event com) 933 (defun viper-prefix-arg-value (event com)
919 (let (value func) 934 (let ((viper-intermediate-command 'viper-digit-argument)
935 value func)
920 ;; read while number 936 ;; read while number
921 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) 937 (while (and (viper-characterp event) (>= event ?0) (<= event ?9))
922 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0))) 938 (setq value (+ (* (if (integerp value) value 0) 10) (- event ?0)))
923 (setq event (vip-read-event-convert-to-char))) 939 (setq event (viper-read-event-convert-to-char)))
924 940
925 (setq prefix-arg value) 941 (setq prefix-arg value)
926 (if com (setq prefix-arg (cons prefix-arg com))) 942 (if com (setq prefix-arg (cons prefix-arg com)))
927 (while (eq event ?U) 943 (while (eq event ?U)
928 (vip-describe-arg prefix-arg) 944 (viper-describe-arg prefix-arg)
929 (setq event (vip-read-event-convert-to-char))) 945 (setq event (viper-read-event-convert-to-char)))
930 946
931 (if (or com (and (not (eq vip-current-state 'vi-state)) 947 (if (or com (and (not (eq viper-current-state 'vi-state))
932 ;; make sure it is a Vi command 948 ;; make sure it is a Vi command
933 (vip-characterp event) (vip-vi-command-p event) 949 (viper-characterp event) (viper-vi-command-p event)
934 )) 950 ))
935 ;; If appears to be one of the vi commands, 951 ;; If appears to be one of the vi commands,
936 ;; then execute it with funcall and clear prefix-arg in order to not 952 ;; then execute it with funcall and clear prefix-arg in order to not
937 ;; confuse subsequent commands 953 ;; confuse subsequent commands
938 (progn 954 (progn
939 ;; last-command-char is the char we want emacs to think was typed 955 ;; 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 956 ;; 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., 957 ;; 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', 958 ;; etc., i.e., the user typed, say, d2. In this case, `com' would be
943 ;; etc. 959 ;; `d', `w', etc. If viper-digit-argument was invoked by
944 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is 960 ;; 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), 961 ;; current state is not vi-state), then `event' represents the vi
946 ;; then `event' represents the vi command to be executed (e.g., `d', 962 ;; command to be executed (e.g., `d', `w', etc). Again,
947 ;; `w', etc). Again, last-command-char must make emacs believe that 963 ;; last-command-char must make emacs believe that this is the command
948 ;; this is the command we typed. 964 ;; we typed.
965 (cond ((eq event 'return) (setq event ?\C-m))
966 ((eq event 'delete) (setq event ?\C-?))
967 ((eq event 'backspace) (setq event ?\C-h))
968 ((eq event 'space) (setq event ?\ )))
949 (setq last-command-char (or com event)) 969 (setq last-command-char (or com event))
950 (setq func (vip-exec-form-in-vi 970 (setq func (viper-exec-form-in-vi
951 (` (key-binding (char-to-string (, event)))))) 971 (` (key-binding (char-to-string (, event))))))
952 (funcall func prefix-arg) 972 (funcall func prefix-arg)
953 (setq prefix-arg nil)) 973 (setq prefix-arg nil))
954 ;; some other command -- let emacs do it in its own way 974 ;; some other command -- let emacs do it in its own way
955 (vip-set-unread-command-events event)) 975 (viper-set-unread-command-events event))
956 )) 976 ))
957 977
958 978
959 ;; Vi operator as prefix argument." 979 ;; Vi operator as prefix argument."
960 (defun vip-prefix-arg-com (char value com) 980 (defun viper-prefix-arg-com (char value com)
961 (let ((cont t) 981 (let ((cont t)
962 cmd-info mv-or-digit-cmd) 982 cmd-info
983 cmd-to-exec-at-end)
963 (while (and cont 984 (while (and cont
964 (memq char 985 (memq char
965 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" 986 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\"
966 vip-buffer-search-char))) 987 viper-buffer-search-char)))
967 (if com 988 (if com
968 ;; this means that we already have a command character, so we 989 ;; this means that we already have a command character, so we
969 ;; construct a com list and exit while. however, if char is " 990 ;; construct a com list and exit while. however, if char is "
970 ;; it is an error. 991 ;; it is an error.
971 (progn 992 (progn
972 ;; new com is (CHAR . OLDCOM) 993 ;; new com is (CHAR . OLDCOM)
973 (if (memq char '(?# ?\")) (error "")) 994 (if (memq char '(?# ?\")) (error ""))
974 (setq com (cons char com)) 995 (setq com (cons char com))
975 (setq cont nil)) 996 (setq cont nil))
976 ;; If com is nil we set com as char, and read more. Again, if char 997 ;; If com is nil we set com as char, and read more. Again, if char is
977 ;; is ", we read the name of register and store it in vip-use-register. 998 ;; ", we read the name of register and store it in viper-use-register.
978 ;; if char is !, =, or #, a complete com is formed so we exit the 999 ;; if char is !, =, or #, a complete com is formed so we exit the while
979 ;; while loop. 1000 ;; loop.
980 (cond ((memq char '(?! ?=)) 1001 (cond ((memq char '(?! ?=))
981 (setq com char) 1002 (setq com char)
982 (setq char (read-char)) 1003 (setq char (read-char))
983 (setq cont nil)) 1004 (setq cont nil))
984 ((= char ?#) 1005 ((= char ?#)
985 ;; read a char and encode it as com 1006 ;; read a char and encode it as com
986 (setq com (+ 128 (read-char))) 1007 (setq com (+ 128 (read-char)))
987 (setq char (read-char))) 1008 (setq char (read-char)))
988 ((= char ?\") 1009 ((= char ?\")
989 (let ((reg (read-char))) 1010 (let ((reg (read-char)))
990 (if (vip-valid-register reg) 1011 (if (viper-valid-register reg)
991 (setq vip-use-register reg) 1012 (setq viper-use-register reg)
992 (error "")) 1013 (error ""))
993 (setq char (read-char)))) 1014 (setq char (read-char))))
994 (t 1015 (t
995 (setq com char) 1016 (setq com char)
996 (setq char (read-char)))))) 1017 (setq char (read-char))))))
1000 ;; and if `char' is `?', we describe the arg; otherwise 1021 ;; and if `char' is `?', we describe the arg; otherwise
1001 ;; we prepare the command that will be executed at the end. 1022 ;; we prepare the command that will be executed at the end.
1002 (progn 1023 (progn
1003 (setq cmd-info (cons value com)) 1024 (setq cmd-info (cons value com))
1004 (while (= char ?U) 1025 (while (= char ?U)
1005 (vip-describe-arg cmd-info) 1026 (viper-describe-arg cmd-info)
1006 (setq char (read-char))) 1027 (setq char (read-char)))
1007 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we 1028 ;; `char' is a movement cmd, a digit arg cmd, or a register cmd---so we
1008 ;; execute it at the very end 1029 ;; execute it at the very end
1009 (or (vip-movement-command-p char) 1030 (or (viper-movement-command-p char)
1010 (vip-digit-command-p char) 1031 (viper-digit-command-p char)
1011 (vip-regsuffix-command-p char) 1032 (viper-regsuffix-command-p char)
1033 (= char ?!) ; bang command
1012 (error "")) 1034 (error ""))
1013 (setq mv-or-digit-cmd 1035 (setq cmd-to-exec-at-end
1014 (vip-exec-form-in-vi 1036 (viper-exec-form-in-vi
1015 (` (key-binding (char-to-string (, char))))))) 1037 (` (key-binding (char-to-string (, char)))))))
1016 1038
1017 ;; as com is non-nil, this means that we have a command to execute 1039 ;; as com is non-nil, this means that we have a command to execute
1018 (if (memq (car com) '(?r ?R)) 1040 (if (memq (car com) '(?r ?R))
1019 ;; execute apropriate region command. 1041 ;; execute apropriate region command.
1020 (let ((char (car com)) (com (cdr com))) 1042 (let ((char (car com)) (com (cdr com)))
1021 (setq prefix-arg (cons value com)) 1043 (setq prefix-arg (cons value com))
1022 (if (= char ?r) (vip-region prefix-arg) 1044 (if (= char ?r) (viper-region prefix-arg)
1023 (vip-Region prefix-arg)) 1045 (viper-Region prefix-arg))
1024 ;; reset prefix-arg 1046 ;; reset prefix-arg
1025 (setq prefix-arg nil)) 1047 (setq prefix-arg nil))
1026 ;; otherwise, reset prefix arg and call appropriate command 1048 ;; otherwise, reset prefix arg and call appropriate command
1027 (setq value (if (null value) 1 value)) 1049 (setq value (if (null value) 1 value))
1028 (setq prefix-arg nil) 1050 (setq prefix-arg nil)
1029 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C))) 1051 (cond
1030 ((equal com '(?d . ?d)) (vip-line (cons value ?D))) 1052 ;; If we change ?C to ?c here, then cc will enter replacement mode
1031 ((equal com '(?d . ?y)) (vip-yank-defun)) 1053 ;; rather than deleting lines. However, it will affect 1 less line than
1032 ((equal com '(?y . ?y)) (vip-line (cons value ?Y))) 1054 ;; normal. We decided to not use replacement mode here and follow Vi,
1033 ((equal com '(?< . ?<)) (vip-line (cons value ?<))) 1055 ;; since replacement mode on n full lines can be achieved with nC.
1034 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) 1056 ((equal com '(?c . ?c)) (viper-line (cons value ?C)))
1035 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) 1057 ((equal com '(?d . ?d)) (viper-line (cons value ?D)))
1036 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) 1058 ((equal com '(?d . ?y)) (viper-yank-defun))
1037 (t (error ""))))) 1059 ((equal com '(?y . ?y)) (viper-line (cons value ?Y)))
1038 1060 ((equal com '(?< . ?<)) (viper-line (cons value ?<)))
1039 (if mv-or-digit-cmd 1061 ((equal com '(?> . ?>)) (viper-line (cons value ?>)))
1062 ((equal com '(?! . ?!)) (viper-line (cons value ?!)))
1063 ((equal com '(?= . ?=)) (viper-line (cons value ?=)))
1064 (t (error "")))))
1065
1066 (if cmd-to-exec-at-end
1040 (progn 1067 (progn
1041 (setq last-command-char char) 1068 (setq last-command-char char)
1042 (setq last-command-event 1069 (setq last-command-event
1043 (vip-copy-event 1070 (viper-copy-event
1044 (if vip-xemacs-p (character-to-event char) char))) 1071 (if viper-xemacs-p (character-to-event char) char)))
1045 (condition-case nil 1072 (condition-case nil
1046 (funcall mv-or-digit-cmd cmd-info) 1073 (funcall cmd-to-exec-at-end cmd-info)
1047 (error 1074 (error
1048 (error ""))))) 1075 (error "")))))
1049 )) 1076 ))
1050 1077
1051 (defun vip-describe-arg (arg) 1078 (defun viper-describe-arg (arg)
1052 (let (val com) 1079 (let (val com)
1053 (setq val (vip-P-val arg) 1080 (setq val (viper-P-val arg)
1054 com (vip-getcom arg)) 1081 com (viper-getcom arg))
1055 (if (null val) 1082 (if (null val)
1056 (if (null com) 1083 (if (null com)
1057 (message "Value is nil, and command is nil") 1084 (message "Value is nil, and command is nil")
1058 (message "Value is nil, and command is `%c'" com)) 1085 (message "Value is nil, and command is `%c'" com))
1059 (if (null com) 1086 (if (null com)
1060 (message "Value is `%d', and command is nil" val) 1087 (message "Value is `%d', and command is nil" val)
1061 (message "Value is `%d', and command is `%c'" val com))))) 1088 (message "Value is `%d', and command is `%c'" val com)))))
1062 1089
1063 (defun vip-digit-argument (arg) 1090 (defun viper-digit-argument (arg)
1064 "Begin numeric argument for the next command." 1091 "Begin numeric argument for the next command."
1065 (interactive "P") 1092 (interactive "P")
1066 (vip-leave-region-active) 1093 (viper-leave-region-active)
1067 (vip-prefix-arg-value 1094 (viper-prefix-arg-value
1068 last-command-char (if (consp arg) (cdr arg) nil))) 1095 last-command-char (if (consp arg) (cdr arg) nil)))
1069 1096
1070 (defun vip-command-argument (arg) 1097 (defun viper-command-argument (arg)
1071 "Accept a motion command as an argument." 1098 "Accept a motion command as an argument."
1072 (interactive "P") 1099 (interactive "P")
1073 (let ((vip-inside-command-argument-action t)) 1100 (let ((viper-intermediate-command 'viper-command-argument))
1074 (condition-case nil 1101 (condition-case nil
1075 (vip-prefix-arg-com 1102 (viper-prefix-arg-com
1076 last-command-char 1103 last-command-char
1077 (cond ((null arg) nil) 1104 (cond ((null arg) nil)
1078 ((consp arg) (car arg)) 1105 ((consp arg) (car arg))
1079 ((integerp arg) arg) 1106 ((integerp arg) arg)
1080 (t (error vip-InvalidCommandArgument))) 1107 (t (error viper-InvalidCommandArgument)))
1081 (cond ((null arg) nil) 1108 (cond ((null arg) nil)
1082 ((consp arg) (cdr arg)) 1109 ((consp arg) (cdr arg))
1083 ((integerp arg) nil) 1110 ((integerp arg) nil)
1084 (t (error vip-InvalidCommandArgument)))) 1111 (t (error viper-InvalidCommandArgument))))
1085 (quit (setq vip-use-register nil) 1112 (quit (setq viper-use-register nil)
1086 (signal 'quit nil))) 1113 (signal 'quit nil)))
1087 (vip-deactivate-mark))) 1114 (viper-deactivate-mark)))
1088 1115
1089 1116
1090 ;; repeat last destructive command 1117 ;; repeat last destructive command
1091 1118
1092 ;; Append region to text in register REG. 1119 ;; Append region to text in register REG.
1093 ;; START and END are buffer positions indicating what to append. 1120 ;; START and END are buffer positions indicating what to append.
1094 (defsubst vip-append-to-register (reg start end) 1121 (defsubst viper-append-to-register (reg start end)
1095 (set-register reg (concat (if (stringp (get-register reg)) 1122 (set-register reg (concat (if (stringp (get-register reg))
1096 (get-register reg) "") 1123 (get-register reg) "")
1097 (buffer-substring start end)))) 1124 (buffer-substring start end))))
1098 1125
1099 ;; Saves last inserted text for possible use by vip-repeat command. 1126 ;; Saves last inserted text for possible use by viper-repeat command.
1100 (defun vip-save-last-insertion (beg end) 1127 (defun viper-save-last-insertion (beg end)
1101 (setq vip-last-insertion (buffer-substring beg end)) 1128 (setq viper-last-insertion (buffer-substring beg end))
1102 (or (< (length vip-d-com) 5) 1129 (or (< (length viper-d-com) 5)
1103 (setcar (nthcdr 4 vip-d-com) vip-last-insertion)) 1130 (setcar (nthcdr 4 viper-d-com) viper-last-insertion))
1104 (or (null vip-command-ring) 1131 (or (null viper-command-ring)
1105 (ring-empty-p vip-command-ring) 1132 (ring-empty-p viper-command-ring)
1106 (progn 1133 (progn
1107 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring)) 1134 (setcar (nthcdr 4 (viper-current-ring-item viper-command-ring))
1108 vip-last-insertion) 1135 viper-last-insertion)
1109 ;; del most recent elt, if identical to the second most-recent 1136 ;; del most recent elt, if identical to the second most-recent
1110 (vip-cleanup-ring vip-command-ring))) 1137 (viper-cleanup-ring viper-command-ring)))
1111 ) 1138 )
1112 1139
1113 (defsubst vip-yank-last-insertion () 1140 (defsubst viper-yank-last-insertion ()
1114 "Inserts the text saved by the previous vip-save-last-insertion command." 1141 "Inserts the text saved by the previous viper-save-last-insertion command."
1115 (condition-case nil 1142 (condition-case nil
1116 (insert vip-last-insertion) 1143 (insert viper-last-insertion)
1117 (error nil))) 1144 (error nil)))
1118 1145
1119 1146
1120 ;; define functions to be executed 1147 ;; define functions to be executed
1121 1148
1122 ;; invoked by the `C' command 1149 ;; invoked by the `C' command
1123 (defun vip-exec-change (m-com com) 1150 (defun viper-exec-change (m-com com)
1124 (or (and (markerp vip-com-point) (marker-position vip-com-point)) 1151 (or (and (markerp viper-com-point) (marker-position viper-com-point))
1125 (set-marker vip-com-point (point) (current-buffer))) 1152 (set-marker viper-com-point (point) (current-buffer)))
1126 ;; handle C cmd at the eol and at eob. 1153 ;; handle C cmd at the eol and at eob.
1127 (if (or (and (eolp) (= vip-com-point (point))) 1154 (if (or (and (eolp) (= viper-com-point (point)))
1128 (= vip-com-point (point-max))) 1155 (= viper-com-point (point-max)))
1129 (progn 1156 (progn
1130 (insert " ")(backward-char 1))) 1157 (insert " ")(backward-char 1)))
1131 (if (= vip-com-point (point)) 1158 (if (= viper-com-point (point))
1132 (vip-forward-char-carefully)) 1159 (viper-forward-char-carefully))
1160 (set-mark viper-com-point)
1161 (if (eq m-com 'viper-next-line-at-bol)
1162 (viper-enlarge-region (mark t) (point)))
1163 (if (< (point) (mark t))
1164 (exchange-point-and-mark))
1165 (if (eq (preceding-char) ?\n)
1166 (viper-backward-char-carefully)) ; give back the newline
1133 (if (= com ?c) 1167 (if (= com ?c)
1134 (vip-change vip-com-point (point)) 1168 (viper-change (mark t) (point))
1135 (vip-change-subr vip-com-point (point)))) 1169 (viper-change-subr (mark t) (point))))
1136 1170
1137 ;; this is invoked by vip-substitute-line 1171 ;; this is invoked by viper-substitute-line
1138 (defun vip-exec-Change (m-com com) 1172 (defun viper-exec-Change (m-com com)
1139 (save-excursion 1173 (save-excursion
1140 (set-mark vip-com-point) 1174 (set-mark viper-com-point)
1141 (vip-enlarge-region (mark t) (point)) 1175 (viper-enlarge-region (mark t) (point))
1142 (if vip-use-register 1176 (if viper-use-register
1143 (progn 1177 (progn
1144 (cond ((vip-valid-register vip-use-register '(letter digit)) 1178 (cond ((viper-valid-register viper-use-register '(letter digit))
1145 ;;(vip-valid-register vip-use-register '(letter)
1146 (copy-to-register 1179 (copy-to-register
1147 vip-use-register (mark t) (point) nil)) 1180 viper-use-register (mark t) (point) nil))
1148 ((vip-valid-register vip-use-register '(Letter)) 1181 ((viper-valid-register viper-use-register '(Letter))
1149 (vip-append-to-register 1182 (viper-append-to-register
1150 (downcase vip-use-register) (mark t) (point))) 1183 (downcase viper-use-register) (mark t) (point)))
1151 (t (setq vip-use-register nil) 1184 (t (setq viper-use-register nil)
1152 (error vip-InvalidRegister vip-use-register))) 1185 (error viper-InvalidRegister viper-use-register)))
1153 (setq vip-use-register nil))) 1186 (setq viper-use-register nil)))
1154 (delete-region (mark t) (point))) 1187 (delete-region (mark t) (point)))
1155 (open-line 1) 1188 (open-line 1)
1156 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) 1189 (if (= com ?C)
1157 1190 (viper-change-state-to-insert)
1158 (defun vip-exec-delete (m-com com) 1191 (viper-yank-last-insertion)))
1159 (or (and (markerp vip-com-point) (marker-position vip-com-point)) 1192
1160 (set-marker vip-com-point (point) (current-buffer))) 1193 (defun viper-exec-delete (m-com com)
1161 (if vip-use-register 1194 (or (and (markerp viper-com-point) (marker-position viper-com-point))
1195 (set-marker viper-com-point (point) (current-buffer)))
1196 (if viper-use-register
1162 (progn 1197 (progn
1163 (cond ((vip-valid-register vip-use-register '(letter digit)) 1198 (cond ((viper-valid-register viper-use-register '(letter digit))
1164 ;;(vip-valid-register vip-use-register '(letter))
1165 (copy-to-register 1199 (copy-to-register
1166 vip-use-register vip-com-point (point) nil)) 1200 viper-use-register viper-com-point (point) nil))
1167 ((vip-valid-register vip-use-register '(Letter)) 1201 ((viper-valid-register viper-use-register '(Letter))
1168 (vip-append-to-register 1202 (viper-append-to-register
1169 (downcase vip-use-register) vip-com-point (point))) 1203 (downcase viper-use-register) viper-com-point (point)))
1170 (t (setq vip-use-register nil) 1204 (t (setq viper-use-register nil)
1171 (error vip-InvalidRegister vip-use-register))) 1205 (error viper-InvalidRegister viper-use-register)))
1172 (setq vip-use-register nil))) 1206 (setq viper-use-register nil)))
1173 (setq last-command 1207 (setq last-command
1174 (if (eq last-command 'd-command) 'kill-region nil)) 1208 (if (eq last-command 'd-command) 'kill-region nil))
1175 (kill-region vip-com-point (point)) 1209 (kill-region viper-com-point (point))
1176 (setq this-command 'd-command) 1210 (setq this-command 'd-command)
1177 (if vip-ex-style-motion 1211 (if viper-ex-style-motion
1178 (if (and (eolp) (not (bolp))) (backward-char 1)))) 1212 (if (and (eolp) (not (bolp))) (backward-char 1))))
1179 1213
1180 (defun vip-exec-Delete (m-com com) 1214 (defun viper-exec-Delete (m-com com)
1181 (save-excursion 1215 (save-excursion
1182 (set-mark vip-com-point) 1216 (set-mark viper-com-point)
1183 (vip-enlarge-region (mark t) (point)) 1217 (viper-enlarge-region (mark t) (point))
1184 (if vip-use-register 1218 (if viper-use-register
1185 (progn 1219 (progn
1186 (cond ((vip-valid-register vip-use-register '(letter digit)) 1220 (cond ((viper-valid-register viper-use-register '(letter digit))
1187 ;;(vip-valid-register vip-use-register '(letter))
1188 (copy-to-register 1221 (copy-to-register
1189 vip-use-register (mark t) (point) nil)) 1222 viper-use-register (mark t) (point) nil))
1190 ((vip-valid-register vip-use-register '(Letter)) 1223 ((viper-valid-register viper-use-register '(Letter))
1191 (vip-append-to-register 1224 (viper-append-to-register
1192 (downcase vip-use-register) (mark t) (point))) 1225 (downcase viper-use-register) (mark t) (point)))
1193 (t (setq vip-use-register nil) 1226 (t (setq viper-use-register nil)
1194 (error vip-InvalidRegister vip-use-register))) 1227 (error viper-InvalidRegister viper-use-register)))
1195 (setq vip-use-register nil))) 1228 (setq viper-use-register nil)))
1196 (setq last-command 1229 (setq last-command
1197 (if (eq last-command 'D-command) 'kill-region nil)) 1230 (if (eq last-command 'D-command) 'kill-region nil))
1198 (kill-region (mark t) (point)) 1231 (kill-region (mark t) (point))
1199 (if (eq m-com 'vip-line) (setq this-command 'D-command))) 1232 (if (eq m-com 'viper-line) (setq this-command 'D-command)))
1200 (back-to-indentation)) 1233 (back-to-indentation))
1201 1234
1202 (defun vip-exec-yank (m-com com) 1235 (defun viper-exec-yank (m-com com)
1203 (or (and (markerp vip-com-point) (marker-position vip-com-point)) 1236 (or (and (markerp viper-com-point) (marker-position viper-com-point))
1204 (set-marker vip-com-point (point) (current-buffer))) 1237 (set-marker viper-com-point (point) (current-buffer)))
1205 (if vip-use-register 1238 (if viper-use-register
1206 (progn 1239 (progn
1207 (cond ((vip-valid-register vip-use-register '(letter digit)) 1240 (cond ((viper-valid-register viper-use-register '(letter digit))
1208 ;; (vip-valid-register vip-use-register '(letter))
1209 (copy-to-register 1241 (copy-to-register
1210 vip-use-register vip-com-point (point) nil)) 1242 viper-use-register viper-com-point (point) nil))
1211 ((vip-valid-register vip-use-register '(Letter)) 1243 ((viper-valid-register viper-use-register '(Letter))
1212 (vip-append-to-register 1244 (viper-append-to-register
1213 (downcase vip-use-register) vip-com-point (point))) 1245 (downcase viper-use-register) viper-com-point (point)))
1214 (t (setq vip-use-register nil) 1246 (t (setq viper-use-register nil)
1215 (error vip-InvalidRegister vip-use-register))) 1247 (error viper-InvalidRegister viper-use-register)))
1216 (setq vip-use-register nil))) 1248 (setq viper-use-register nil)))
1217 (setq last-command nil) 1249 (setq last-command nil)
1218 (copy-region-as-kill vip-com-point (point)) 1250 (copy-region-as-kill viper-com-point (point))
1219 (goto-char vip-com-point)) 1251 (goto-char viper-com-point))
1220 1252
1221 (defun vip-exec-Yank (m-com com) 1253 (defun viper-exec-Yank (m-com com)
1222 (save-excursion 1254 (save-excursion
1223 (set-mark vip-com-point) 1255 (set-mark viper-com-point)
1224 (vip-enlarge-region (mark t) (point)) 1256 (viper-enlarge-region (mark t) (point))
1225 (if vip-use-register 1257 (if viper-use-register
1226 (progn 1258 (progn
1227 (cond ((vip-valid-register vip-use-register '(letter digit)) 1259 (cond ((viper-valid-register viper-use-register '(letter digit))
1228 (copy-to-register 1260 (copy-to-register
1229 vip-use-register (mark t) (point) nil)) 1261 viper-use-register (mark t) (point) nil))
1230 ((vip-valid-register vip-use-register '(Letter)) 1262 ((viper-valid-register viper-use-register '(Letter))
1231 (vip-append-to-register 1263 (viper-append-to-register
1232 (downcase vip-use-register) (mark t) (point))) 1264 (downcase viper-use-register) (mark t) (point)))
1233 (t (setq vip-use-register nil) 1265 (t (setq viper-use-register nil)
1234 (error vip-InvalidRegister vip-use-register))) 1266 (error viper-InvalidRegister viper-use-register)))
1235 (setq vip-use-register nil))) 1267 (setq viper-use-register nil)))
1236 (setq last-command nil) 1268 (setq last-command nil)
1237 (copy-region-as-kill (mark t) (point))) 1269 (copy-region-as-kill (mark t) (point)))
1238 (vip-deactivate-mark) 1270 (viper-deactivate-mark)
1239 (goto-char vip-com-point)) 1271 (goto-char viper-com-point))
1240 1272
1241 (defun vip-exec-bang (m-com com) 1273 (defun viper-exec-bang (m-com com)
1242 (save-excursion 1274 (save-excursion
1243 (set-mark vip-com-point) 1275 (set-mark viper-com-point)
1244 (vip-enlarge-region (mark t) (point)) 1276 (viper-enlarge-region (mark t) (point))
1277 (exchange-point-and-mark)
1245 (shell-command-on-region 1278 (shell-command-on-region
1246 (mark t) (point) 1279 (mark t) (point)
1247 (if (= com ?!) 1280 (if (= com ?!)
1248 (setq vip-last-shell-com 1281 (setq viper-last-shell-com
1249 (vip-read-string-with-history 1282 (viper-read-string-with-history
1250 "!" 1283 "!"
1251 nil 1284 nil
1252 'vip-shell-history 1285 'viper-shell-history
1253 (car vip-shell-history) 1286 (car viper-shell-history)
1254 )) 1287 ))
1255 vip-last-shell-com) 1288 viper-last-shell-com)
1256 t))) 1289 t)))
1257 1290
1258 (defun vip-exec-equals (m-com com) 1291 (defun viper-exec-equals (m-com com)
1259 (save-excursion 1292 (save-excursion
1260 (set-mark vip-com-point) 1293 (set-mark viper-com-point)
1261 (vip-enlarge-region (mark t) (point)) 1294 (viper-enlarge-region (mark t) (point))
1262 (if (> (mark t) (point)) (exchange-point-and-mark)) 1295 (if (> (mark t) (point)) (exchange-point-and-mark))
1263 (indent-region (mark t) (point) nil))) 1296 (indent-region (mark t) (point) nil)))
1264 1297
1265 (defun vip-exec-shift (m-com com) 1298 (defun viper-exec-shift (m-com com)
1266 (save-excursion 1299 (save-excursion
1267 (set-mark vip-com-point) 1300 (set-mark viper-com-point)
1268 (vip-enlarge-region (mark t) (point)) 1301 (viper-enlarge-region (mark t) (point))
1269 (if (> (mark t) (point)) (exchange-point-and-mark)) 1302 (if (> (mark t) (point)) (exchange-point-and-mark))
1270 (indent-rigidly (mark t) (point) 1303 (indent-rigidly (mark t) (point)
1271 (if (= com ?>) 1304 (if (= com ?>)
1272 vip-shift-width 1305 viper-shift-width
1273 (- vip-shift-width)))) 1306 (- viper-shift-width))))
1274 ;; return point to where it was before shift 1307 ;; return point to where it was before shift
1275 (goto-char vip-com-point)) 1308 (goto-char viper-com-point))
1276 1309
1277 ;; this is needed because some commands fake com by setting it to ?r, which 1310 ;; this is needed because some commands fake com by setting it to ?r, which
1278 ;; denotes repeated insert command. 1311 ;; denotes repeated insert command.
1279 (defsubst vip-exec-dummy (m-com com) 1312 (defsubst viper-exec-dummy (m-com com)
1280 nil) 1313 nil)
1281 1314
1282 (defun vip-exec-buffer-search (m-com com) 1315 (defun viper-exec-buffer-search (m-com com)
1283 (setq vip-s-string (buffer-substring (point) vip-com-point)) 1316 (setq viper-s-string (buffer-substring (point) viper-com-point))
1284 (setq vip-s-forward t) 1317 (setq viper-s-forward t)
1285 (setq vip-search-history (cons vip-s-string vip-search-history)) 1318 (setq viper-search-history (cons viper-s-string viper-search-history))
1286 (vip-search vip-s-string vip-s-forward 1)) 1319 (viper-search viper-s-string viper-s-forward 1))
1287 1320
1288 (defvar vip-exec-array (make-vector 128 nil)) 1321 (defvar viper-exec-array (make-vector 128 nil))
1289 1322
1290 ;; Using a dispatch array allows adding functions like buffer search 1323 ;; Using a dispatch array allows adding functions like buffer search
1291 ;; without affecting other functions. Buffer search can now be bound 1324 ;; without affecting other functions. Buffer search can now be bound
1292 ;; to any character. 1325 ;; to any character.
1293 1326
1294 (aset vip-exec-array ?c 'vip-exec-change) 1327 (aset viper-exec-array ?c 'viper-exec-change)
1295 (aset vip-exec-array ?C 'vip-exec-Change) 1328 (aset viper-exec-array ?C 'viper-exec-Change)
1296 (aset vip-exec-array ?d 'vip-exec-delete) 1329 (aset viper-exec-array ?d 'viper-exec-delete)
1297 (aset vip-exec-array ?D 'vip-exec-Delete) 1330 (aset viper-exec-array ?D 'viper-exec-Delete)
1298 (aset vip-exec-array ?y 'vip-exec-yank) 1331 (aset viper-exec-array ?y 'viper-exec-yank)
1299 (aset vip-exec-array ?Y 'vip-exec-Yank) 1332 (aset viper-exec-array ?Y 'viper-exec-Yank)
1300 (aset vip-exec-array ?r 'vip-exec-dummy) 1333 (aset viper-exec-array ?r 'viper-exec-dummy)
1301 (aset vip-exec-array ?! 'vip-exec-bang) 1334 (aset viper-exec-array ?! 'viper-exec-bang)
1302 (aset vip-exec-array ?< 'vip-exec-shift) 1335 (aset viper-exec-array ?< 'viper-exec-shift)
1303 (aset vip-exec-array ?> 'vip-exec-shift) 1336 (aset viper-exec-array ?> 'viper-exec-shift)
1304 (aset vip-exec-array ?= 'vip-exec-equals) 1337 (aset viper-exec-array ?= 'viper-exec-equals)
1305 1338
1306 1339
1307 1340
1308 ;; This function is called by various movement commands to execute a 1341 ;; This function is called by various movement commands to execute a
1309 ;; destructive command on the region specified by the movement command. For 1342 ;; destructive command on the region specified by the movement command. For
1310 ;; instance, if the user types cw, then the command vip-forward-word will 1343 ;; instance, if the user types cw, then the command viper-forward-word will
1311 ;; call vip-execute-com to execute vip-exec-change, which eventually will 1344 ;; call viper-execute-com to execute viper-exec-change, which eventually will
1312 ;; call vip-change to invoke the replace mode on the region. 1345 ;; call viper-change to invoke the replace mode on the region.
1313 ;; 1346 ;;
1314 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to 1347 ;; The var viper-d-com is set to (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS)
1315 ;; vip-d-com for later use by vip-repeat. 1348 ;; via a call to viper-set-destructive-command, for later use by viper-repeat.
1316 (defun vip-execute-com (m-com val com) 1349 (defun viper-execute-com (m-com val com)
1317 (let ((reg vip-use-register)) 1350 (let ((reg viper-use-register))
1318 ;; this is the special command `#' 1351 ;; this is the special command `#'
1319 (if (> com 128) 1352 (if (> com 128)
1320 (vip-special-prefix-com (- com 128)) 1353 (viper-special-prefix-com (- com 128))
1321 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com)))) 1354 (let ((fn (aref viper-exec-array (if (< com 0) (- com) com))))
1322 (if (null fn) 1355 (if (null fn)
1323 (error "%c: %s" com vip-InvalidViCommand) 1356 (error "%c: %s" com viper-InvalidViCommand)
1324 (funcall fn m-com com)))) 1357 (funcall fn m-com com))))
1325 (if (vip-dotable-command-p com) 1358 (if (viper-dotable-command-p com)
1326 (vip-set-destructive-command 1359 (viper-set-destructive-command
1327 (list m-com val 1360 (list m-com val
1328 (if (memq com (list ?c ?C ?!)) (- com) com) 1361 (if (memq com (list ?c ?C ?!)) (- com) com)
1329 reg nil nil))) 1362 reg nil nil)))
1330 )) 1363 ))
1331 1364
1332 1365
1333 (defun vip-repeat (arg) 1366 (defun viper-repeat (arg)
1334 "Re-execute last destructive command. 1367 "Re-execute last destructive command.
1335 Use the info in vip-d-com, which has the form 1368 Use the info in viper-d-com, which has the form
1336 \(com val ch reg inserted-text command-keys\), 1369 \(com val ch reg inserted-text command-keys\),
1337 where `com' is the command to be re-executed, `val' is the 1370 where `com' is the command to be re-executed, `val' is the
1338 argument to `com', `ch' is a flag for repeat, and `reg' is optional; 1371 argument to `com', `ch' is a flag for repeat, and `reg' is optional;
1339 if it exists, it is the name of the register for `com'. 1372 if it exists, it is the name of the register for `com'.
1340 If the prefix argument, ARG, is non-nil, it is used instead of `val'." 1373 If the prefix argument, ARG, is non-nil, it is used instead of `val'."
1341 (interactive "P") 1374 (interactive "P")
1342 (let ((save-point (point)) ; save point before repeating prev cmd 1375 (let ((save-point (point)) ; save point before repeating prev cmd
1343 ;; Pass along that we are repeating a destructive command 1376 ;; Pass along that we are repeating a destructive command
1344 ;; This tells vip-set-destructive-command not to update 1377 ;; This tells viper-set-destructive-command not to update
1345 ;; vip-command-ring 1378 ;; viper-command-ring
1346 (vip-intermediate-command 'vip-repeat)) 1379 (viper-intermediate-command 'viper-repeat))
1347 (if (eq last-command 'vip-undo) 1380 (if (eq last-command 'viper-undo)
1348 ;; if the last command was vip-undo, then undo-more 1381 ;; if the last command was viper-undo, then undo-more
1349 (vip-undo-more) 1382 (viper-undo-more)
1350 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil 1383 ;; otherwise execute the command stored in viper-d-com. if arg is
1351 ;; its prefix value is used as new prefix value for the command. 1384 ;; non-nil its prefix value is used as new prefix value for the command.
1352 (let ((m-com (car vip-d-com)) 1385 (let ((m-com (car viper-d-com))
1353 (val (vip-P-val arg)) 1386 (val (viper-P-val arg))
1354 (com (nth 2 vip-d-com)) 1387 (com (nth 2 viper-d-com))
1355 (reg (nth 3 vip-d-com))) 1388 (reg (nth 3 viper-d-com)))
1356 (if (null val) (setq val (nth 1 vip-d-com))) 1389 (if (null val) (setq val (nth 1 viper-d-com)))
1357 (if (null m-com) (error "No previous command to repeat.")) 1390 (if (null m-com) (error "No previous command to repeat."))
1358 (setq vip-use-register reg) 1391 (setq viper-use-register reg)
1359 (if (nth 4 vip-d-com) ; text inserted by command 1392 (if (nth 4 viper-d-com) ; text inserted by command
1360 (setq vip-last-insertion (nth 4 vip-d-com) 1393 (setq viper-last-insertion (nth 4 viper-d-com)
1361 vip-d-char (nth 4 vip-d-com))) 1394 viper-d-char (nth 4 viper-d-com)))
1362 (funcall m-com (cons val com)) 1395 (funcall m-com (cons val com))
1363 (cond ((and (< save-point (point)) vip-keep-point-on-repeat) 1396 (cond ((and (< save-point (point)) viper-keep-point-on-repeat)
1364 (goto-char save-point)) ; go back to before repeat. 1397 (goto-char save-point)) ; go back to before repeat.
1365 ((and (< save-point (point)) vip-ex-style-editing-in-insert) 1398 ((and (< save-point (point)) viper-ex-style-editing-in-insert)
1366 (or (bolp) (backward-char 1)))) 1399 (or (bolp) (backward-char 1))))
1367 (if (and (eolp) (not (bolp))) 1400 (if (and (eolp) (not (bolp)))
1368 (backward-char 1)) 1401 (backward-char 1))
1369 )) 1402 ))
1370 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo 1403 (if viper-undo-needs-adjustment (viper-adjust-undo)) ; take care of undo
1371 ;; If the prev cmd was rotating the command ring, this means that `.' has 1404 ;; If the prev cmd was rotating the command ring, this means that `.' has
1372 ;; just executed a command from that ring. So, push it on the ring again. 1405 ;; just executed a command from that ring. So, push it on the ring again.
1373 ;; If we are just executing previous command , then don't push vip-d-com 1406 ;; If we are just executing previous command , then don't push viper-d-com
1374 ;; because vip-d-com is not fully constructed in this case (its keys and 1407 ;; because viper-d-com is not fully constructed in this case (its keys and
1375 ;; the inserted text may be nil). Besides, in this case, the command 1408 ;; the inserted text may be nil). Besides, in this case, the command
1376 ;; executed by `.' is already on the ring. 1409 ;; executed by `.' is already on the ring.
1377 (if (eq last-command 'vip-display-current-destructive-command) 1410 (if (eq last-command 'viper-display-current-destructive-command)
1378 (vip-push-onto-ring vip-d-com 'vip-command-ring)) 1411 (viper-push-onto-ring viper-d-com 'viper-command-ring))
1379 (vip-deactivate-mark) 1412 (viper-deactivate-mark)
1380 )) 1413 ))
1381 1414
1382 (defun vip-repeat-from-history () 1415 (defun viper-repeat-from-history ()
1383 "Repeat a destructive command from history. 1416 "Repeat a destructive command from history.
1384 Doesn't change vip-command-ring in any way, so `.' will work as before 1417 Doesn't change viper-command-ring in any way, so `.' will work as before
1385 executing this command. 1418 executing this command.
1386 This command is supposed to be bound to a two-character Vi macro where 1419 This command is supposed to be bound to a two-character Vi macro where
1387 the second character is a digit 0 to 9. The digit indicates which 1420 the second character is a digit 0 to 9. The digit indicates which
1388 history command to execute. `<char>0' is equivalent to `.', `<char>1' 1421 history command to execute. `<char>0' is equivalent to `.', `<char>1'
1389 invokes the command before that, etc." 1422 invokes the command before that, etc."
1390 (interactive) 1423 (interactive)
1391 (let* ((vip-intermediate-command 'repeating-display-destructive-command) 1424 (let* ((viper-intermediate-command 'repeating-display-destructive-command)
1392 (idx (cond (vip-this-kbd-macro 1425 (idx (cond (viper-this-kbd-macro
1393 (string-to-number 1426 (string-to-number
1394 (symbol-name (elt vip-this-kbd-macro 1)))) 1427 (symbol-name (elt viper-this-kbd-macro 1))))
1395 (t 0))) 1428 (t 0)))
1396 (num idx) 1429 (num idx)
1397 (vip-d-com vip-d-com)) 1430 (viper-d-com viper-d-com))
1398 1431
1399 (or (and (numberp num) (<= 0 num) (<= num 9)) 1432 (or (and (numberp num) (<= 0 num) (<= num 9))
1400 (progn 1433 (progn
1401 (setq idx 0 1434 (setq idx 0
1402 num 0) 1435 num 0)
1403 (message 1436 (message
1404 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) 1437 "`viper-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'")))
1405 (while (< 0 num) 1438 (while (< 0 num)
1406 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) 1439 (setq viper-d-com (viper-special-ring-rotate1 viper-command-ring -1))
1407 (setq num (1- num))) 1440 (setq num (1- num)))
1408 (vip-repeat nil) 1441 (viper-repeat nil)
1409 (while (> idx num) 1442 (while (> idx num)
1410 (vip-special-ring-rotate1 vip-command-ring 1) 1443 (viper-special-ring-rotate1 viper-command-ring 1)
1411 (setq num (1+ num))) 1444 (setq num (1+ num)))
1412 )) 1445 ))
1413 1446
1414 1447
1415 ;; The hash-command. It is invoked interactively by the key sequence #<char>. 1448 ;; The hash-command. It is invoked interactively by the key sequence #<char>.
1416 ;; The chars that can follow `#' are determined by vip-hash-command-p 1449 ;; The chars that can follow `#' are determined by viper-hash-command-p
1417 (defun vip-special-prefix-com (char) 1450 (defun viper-special-prefix-com (char)
1418 (cond ((= char ?c) 1451 (cond ((= char ?c)
1419 (downcase-region (min vip-com-point (point)) 1452 (downcase-region (min viper-com-point (point))
1420 (max vip-com-point (point)))) 1453 (max viper-com-point (point))))
1421 ((= char ?C) 1454 ((= char ?C)
1422 (upcase-region (min vip-com-point (point)) 1455 (upcase-region (min viper-com-point (point))
1423 (max vip-com-point (point)))) 1456 (max viper-com-point (point))))
1424 ((= char ?g) 1457 ((= char ?g)
1425 (push-mark vip-com-point t) 1458 (push-mark viper-com-point t)
1426 (vip-global-execute)) 1459 (viper-global-execute))
1427 ((= char ?q) 1460 ((= char ?q)
1428 (push-mark vip-com-point t) 1461 (push-mark viper-com-point t)
1429 (vip-quote-region)) 1462 (viper-quote-region))
1430 ((= char ?s) (funcall vip-spell-function vip-com-point (point))) 1463 ((= char ?s) (funcall viper-spell-function viper-com-point (point)))
1431 (t (error "#%c: %s" char vip-InvalidViCommand)))) 1464 (t (error "#%c: %s" char viper-InvalidViCommand))))
1432 1465
1433 1466
1434 ;; undoing 1467 ;; undoing
1435 1468
1436 (defun vip-undo () 1469 (defun viper-undo ()
1437 "Undo previous change." 1470 "Undo previous change."
1438 (interactive) 1471 (interactive)
1439 (message "undo!") 1472 (message "undo!")
1440 (let ((modified (buffer-modified-p)) 1473 (let ((modified (buffer-modified-p))
1441 (before-undo-pt (point-marker)) 1474 (before-undo-pt (point-marker))
1453 (setq undo-beg-posn (or undo-beg-posn before-undo-pt) 1486 (setq undo-beg-posn (or undo-beg-posn before-undo-pt)
1454 undo-end-posn (or undo-end-posn undo-beg-posn)) 1487 undo-end-posn (or undo-end-posn undo-beg-posn))
1455 1488
1456 (goto-char undo-beg-posn) 1489 (goto-char undo-beg-posn)
1457 (sit-for 0) 1490 (sit-for 0)
1458 (if (and vip-keep-point-on-undo 1491 (if (and viper-keep-point-on-undo
1459 (pos-visible-in-window-p before-undo-pt)) 1492 (pos-visible-in-window-p before-undo-pt))
1460 (progn 1493 (progn
1461 (push-mark (point-marker) t) 1494 (push-mark (point-marker) t)
1462 (vip-sit-for-short 300) 1495 (viper-sit-for-short 300)
1463 (goto-char undo-end-posn) 1496 (goto-char undo-end-posn)
1464 (vip-sit-for-short 300) 1497 (viper-sit-for-short 300)
1465 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) 1498 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1)
1466 (> (abs (- undo-end-posn before-undo-pt)) 1)) 1499 (> (abs (- undo-end-posn before-undo-pt)) 1))
1467 (goto-char before-undo-pt) 1500 (goto-char before-undo-pt)
1468 (goto-char undo-beg-posn))) 1501 (goto-char undo-beg-posn)))
1469 (push-mark before-undo-pt t)) 1502 (push-mark before-undo-pt t))
1470 (if (and (eolp) (not (bolp))) (backward-char 1)) 1503 (if (and (eolp) (not (bolp))) (backward-char 1))
1471 (if (not modified) (set-buffer-modified-p t))) 1504 (if (not modified) (set-buffer-modified-p t)))
1472 (setq this-command 'vip-undo)) 1505 (setq this-command 'viper-undo))
1473 1506
1474 ;; Continue undoing previous changes. 1507 ;; Continue undoing previous changes.
1475 (defun vip-undo-more () 1508 (defun viper-undo-more ()
1476 (message "undo more!") 1509 (message "undo more!")
1477 (condition-case nil 1510 (condition-case nil
1478 (undo-more 1) 1511 (undo-more 1)
1479 (error (beep) 1512 (error (beep)
1480 (message "No further undo information in this buffer"))) 1513 (message "No further undo information in this buffer")))
1481 (if (and (eolp) (not (bolp))) (backward-char 1)) 1514 (if (and (eolp) (not (bolp))) (backward-char 1))
1482 (setq this-command 'vip-undo)) 1515 (setq this-command 'viper-undo))
1483 1516
1484 ;; The following two functions are used to set up undo properly. 1517 ;; The following two functions are used to set up undo properly.
1485 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, 1518 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
1486 ;; they are undone all at once. 1519 ;; they are undone all at once.
1487 (defun vip-adjust-undo () 1520 (defun viper-adjust-undo ()
1488 (let ((inhibit-quit t) 1521 (let ((inhibit-quit t)
1489 tmp tmp2) 1522 tmp tmp2)
1490 (setq vip-undo-needs-adjustment nil) 1523 (setq viper-undo-needs-adjustment nil)
1491 (if (listp buffer-undo-list) 1524 (if (listp buffer-undo-list)
1492 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list)) 1525 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
1493 (progn 1526 (progn
1494 (setq tmp2 (cdr tmp)) ; the part after mark 1527 (setq tmp2 (cdr tmp)) ; the part after mark
1495 1528
1496 ;; cut tail from buffer-undo-list temporarily by direct 1529 ;; cut tail from buffer-undo-list temporarily by direct
1497 ;; manipulation with pointers in buffer-undo-list 1530 ;; manipulation with pointers in buffer-undo-list
1498 (setcdr tmp nil) 1531 (setcdr tmp nil)
1499 1532
1500 (setq buffer-undo-list (delq nil buffer-undo-list)) 1533 (setq buffer-undo-list (delq nil buffer-undo-list))
1501 (setq buffer-undo-list 1534 (setq buffer-undo-list
1502 (delq vip-buffer-undo-list-mark buffer-undo-list)) 1535 (delq viper-buffer-undo-list-mark buffer-undo-list))
1503 ;; restore tail of buffer-undo-list 1536 ;; restore tail of buffer-undo-list
1504 (setq buffer-undo-list (nconc buffer-undo-list tmp2))) 1537 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
1505 (setq buffer-undo-list (delq nil buffer-undo-list)))))) 1538 (setq buffer-undo-list (delq nil buffer-undo-list))))))
1506 1539
1507 1540
1508 (defun vip-set-complex-command-for-undo () 1541 (defun viper-set-complex-command-for-undo ()
1509 (if (listp buffer-undo-list) 1542 (if (listp buffer-undo-list)
1510 (if (not vip-undo-needs-adjustment) 1543 (if (not viper-undo-needs-adjustment)
1511 (let ((inhibit-quit t)) 1544 (let ((inhibit-quit t))
1512 (setq buffer-undo-list 1545 (setq buffer-undo-list
1513 (cons vip-buffer-undo-list-mark buffer-undo-list)) 1546 (cons viper-buffer-undo-list-mark buffer-undo-list))
1514 (setq vip-undo-needs-adjustment t))))) 1547 (setq viper-undo-needs-adjustment t)))))
1515 1548
1516 1549
1517 1550
1518 1551
1519 (defun vip-display-current-destructive-command () 1552 (defun viper-display-current-destructive-command ()
1520 (let ((text (nth 4 vip-d-com)) 1553 (let ((text (nth 4 viper-d-com))
1521 (keys (nth 5 vip-d-com)) 1554 (keys (nth 5 viper-d-com))
1522 (max-text-len 30)) 1555 (max-text-len 30))
1523 1556
1524 (setq this-command 'vip-display-current-destructive-command) 1557 (setq this-command 'viper-display-current-destructive-command)
1525 1558
1526 (message " `.' runs %s%s" 1559 (message " `.' runs %s%s"
1527 (concat "`" (vip-array-to-string keys) "'") 1560 (concat "`" (viper-array-to-string keys) "'")
1528 (vip-abbreviate-string text max-text-len 1561 (viper-abbreviate-string
1529 " inserting `" "'" " .......")) 1562 (if viper-xemacs-p
1563 (replace-in-string text "\n" "^J")
1564 text)
1565 max-text-len
1566 " inserting `" "'" " ......."))
1530 )) 1567 ))
1531 1568
1532 1569
1533 ;; don't change vip-d-com if it was vip-repeat command invoked with `.' 1570 ;; don't change viper-d-com if it was viper-repeat command invoked with `.'
1534 ;; or in some other way (non-interactively). 1571 ;; or in some other way (non-interactively).
1535 (defun vip-set-destructive-command (list) 1572 (defun viper-set-destructive-command (list)
1536 (or (eq vip-intermediate-command 'vip-repeat) 1573 (or (eq viper-intermediate-command 'viper-repeat)
1537 (progn 1574 (progn
1538 (setq vip-d-com list) 1575 (setq viper-d-com list)
1539 (setcar (nthcdr 5 vip-d-com) 1576 (setcar (nthcdr 5 viper-d-com)
1540 (vip-array-to-string (this-command-keys))) 1577 (viper-array-to-string (if (arrayp viper-this-command-keys)
1541 (vip-push-onto-ring vip-d-com 'vip-command-ring)))) 1578 viper-this-command-keys
1579 (this-command-keys))))
1580 (viper-push-onto-ring viper-d-com 'viper-command-ring)))
1581 (setq viper-this-command-keys nil))
1542 1582
1543 (defun vip-prev-destructive-command (next) 1583 (defun viper-prev-destructive-command (next)
1544 "Find previous destructive command in the history of destructive commands. 1584 "Find previous destructive command in the history of destructive commands.
1545 With prefix argument, find next destructive command." 1585 With prefix argument, find next destructive command."
1546 (interactive "P") 1586 (interactive "P")
1547 (let (cmd vip-intermediate-command) 1587 (let (cmd viper-intermediate-command)
1548 (if (eq last-command 'vip-display-current-destructive-command) 1588 (if (eq last-command 'viper-display-current-destructive-command)
1549 ;; repeated search through command history 1589 ;; repeated search through command history
1550 (setq vip-intermediate-command 'repeating-display-destructive-command) 1590 (setq viper-intermediate-command
1591 'repeating-display-destructive-command)
1551 ;; first search through command history--set temp ring 1592 ;; first search through command history--set temp ring
1552 (setq vip-temp-command-ring (copy-list vip-command-ring))) 1593 (setq viper-temp-command-ring (copy-list viper-command-ring)))
1553 (setq cmd (if next 1594 (setq cmd (if next
1554 (vip-special-ring-rotate1 vip-temp-command-ring 1) 1595 (viper-special-ring-rotate1 viper-temp-command-ring 1)
1555 (vip-special-ring-rotate1 vip-temp-command-ring -1))) 1596 (viper-special-ring-rotate1 viper-temp-command-ring -1)))
1556 (if (null cmd) 1597 (if (null cmd)
1557 () 1598 ()
1558 (setq vip-d-com cmd)) 1599 (setq viper-d-com cmd))
1559 (vip-display-current-destructive-command))) 1600 (viper-display-current-destructive-command)))
1560 1601
1561 (defun vip-next-destructive-command () 1602 (defun viper-next-destructive-command ()
1562 "Find next destructive command in the history of destructive commands." 1603 "Find next destructive command in the history of destructive commands."
1563 (interactive) 1604 (interactive)
1564 (vip-prev-destructive-command 'next)) 1605 (viper-prev-destructive-command 'next))
1565 1606
1566 (defun vip-insert-prev-from-insertion-ring (arg) 1607 (defun viper-insert-prev-from-insertion-ring (arg)
1567 "Cycle through insertion ring in the direction of older insertions. 1608 "Cycle through insertion ring in the direction of older insertions.
1568 Undoes previous insertion and inserts new. 1609 Undoes previous insertion and inserts new.
1569 With prefix argument, cycles in the direction of newer elements. 1610 With prefix argument, cycles in the direction of newer elements.
1570 In minibuffer, this command executes whatever the invocation key is bound 1611 In minibuffer, this command executes whatever the invocation key is bound
1571 to in the global map, instead of cycling through the insertion ring." 1612 to in the global map, instead of cycling through the insertion ring."
1572 (interactive "P") 1613 (interactive "P")
1573 (let (vip-intermediate-command) 1614 (let (viper-intermediate-command)
1574 (if (eq last-command 'vip-insert-from-insertion-ring) 1615 (if (eq last-command 'viper-insert-from-insertion-ring)
1575 (progn ; repeated search through insertion history 1616 (progn ; repeated search through insertion history
1576 (setq vip-intermediate-command 'repeating-insertion-from-ring) 1617 (setq viper-intermediate-command 'repeating-insertion-from-ring)
1577 (if (eq vip-current-state 'replace-state) 1618 (if (eq viper-current-state 'replace-state)
1578 (undo 1) 1619 (undo 1)
1579 (if vip-last-inserted-string-from-insertion-ring 1620 (if viper-last-inserted-string-from-insertion-ring
1580 (backward-delete-char 1621 (backward-delete-char
1581 (length vip-last-inserted-string-from-insertion-ring)))) 1622 (length viper-last-inserted-string-from-insertion-ring))))
1582 ) 1623 )
1583 ;;first search through insertion history 1624 ;;first search through insertion history
1584 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring))) 1625 (setq viper-temp-insertion-ring (copy-list viper-insertion-ring)))
1585 (setq this-command 'vip-insert-from-insertion-ring) 1626 (setq this-command 'viper-insert-from-insertion-ring)
1586 ;; so that things will be undone properly 1627 ;; so that things will be undone properly
1587 (setq buffer-undo-list (cons nil buffer-undo-list)) 1628 (setq buffer-undo-list (cons nil buffer-undo-list))
1588 (setq vip-last-inserted-string-from-insertion-ring 1629 (setq viper-last-inserted-string-from-insertion-ring
1589 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1))) 1630 (viper-special-ring-rotate1 viper-temp-insertion-ring (if arg 1 -1)))
1590 1631
1591 ;; this change of vip-intermediate-command must come after 1632 ;; this change of viper-intermediate-command must come after
1592 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the 1633 ;; viper-special-ring-rotate1, so that the ring will rotate, but before the
1593 ;; insertion. 1634 ;; insertion.
1594 (setq vip-intermediate-command nil) 1635 (setq viper-intermediate-command nil)
1595 (if vip-last-inserted-string-from-insertion-ring 1636 (if viper-last-inserted-string-from-insertion-ring
1596 (insert vip-last-inserted-string-from-insertion-ring)) 1637 (insert viper-last-inserted-string-from-insertion-ring))
1597 )) 1638 ))
1598 1639
1599 (defun vip-insert-next-from-insertion-ring () 1640 (defun viper-insert-next-from-insertion-ring ()
1600 "Cycle through insertion ring in the direction of older insertions. 1641 "Cycle through insertion ring in the direction of older insertions.
1601 Undo previous insertion and inserts new." 1642 Undo previous insertion and inserts new."
1602 (interactive) 1643 (interactive)
1603 (vip-insert-prev-from-insertion-ring 'next)) 1644 (viper-insert-prev-from-insertion-ring 'next))
1604 1645
1605 1646
1606 ;; some region utilities 1647 ;; some region utilities
1607 1648
1608 ;; If at the last line of buffer, add \\n before eob, if newline is missing. 1649 ;; If at the last line of buffer, add \\n before eob, if newline is missing.
1609 (defun vip-add-newline-at-eob-if-necessary () 1650 (defun viper-add-newline-at-eob-if-necessary ()
1610 (save-excursion 1651 (save-excursion
1611 (end-of-line) 1652 (end-of-line)
1612 ;; make sure all lines end with newline, unless in the minibuffer or 1653 ;; make sure all lines end with newline, unless in the minibuffer or
1613 ;; when requested otherwise (require-final-newline is nil) 1654 ;; when requested otherwise (require-final-newline is nil)
1614 (if (and (eobp) 1655 (if (and (eobp)
1615 (not (bolp)) 1656 (not (bolp))
1616 require-final-newline 1657 require-final-newline
1617 (not (vip-is-in-minibuffer)) 1658 (not (viper-is-in-minibuffer))
1618 (not buffer-read-only)) 1659 (not buffer-read-only))
1619 (insert "\n")))) 1660 (insert "\n"))))
1620 1661
1621 (defun vip-yank-defun () 1662 (defun viper-yank-defun ()
1622 (mark-defun) 1663 (mark-defun)
1623 (copy-region-as-kill (point) (mark t))) 1664 (copy-region-as-kill (point) (mark t)))
1624 1665
1625 ;; Enlarge region between BEG and END. 1666 ;; Enlarge region between BEG and END.
1626 (defun vip-enlarge-region (beg end) 1667 (defun viper-enlarge-region (beg end)
1627 (or beg (setq beg end)) ; if beg is nil, set to end 1668 (or beg (setq beg end)) ; if beg is nil, set to end
1628 (or end (setq end beg)) ; if end is nil, set to beg 1669 (or end (setq end beg)) ; if end is nil, set to beg
1629 1670
1630 (if (< beg end) 1671 (if (< beg end)
1631 (progn (goto-char beg) (set-mark end)) 1672 (progn (goto-char beg) (set-mark end))
1637 (if (not (eobp)) (beginning-of-line)) 1678 (if (not (eobp)) (beginning-of-line))
1638 (if (> beg end) (exchange-point-and-mark))) 1679 (if (> beg end) (exchange-point-and-mark)))
1639 1680
1640 1681
1641 ;; Quote region by each line with a user supplied string. 1682 ;; Quote region by each line with a user supplied string.
1642 (defun vip-quote-region () 1683 (defun viper-quote-region ()
1643 (setq vip-quote-string 1684 (setq viper-quote-string
1644 (vip-read-string-with-history 1685 (viper-read-string-with-history
1645 "Quote string: " 1686 "Quote string: "
1646 nil 1687 nil
1647 'vip-quote-region-history 1688 'viper-quote-region-history
1648 vip-quote-string)) 1689 viper-quote-string))
1649 (vip-enlarge-region (point) (mark t)) 1690 (viper-enlarge-region (point) (mark t))
1650 (if (> (point) (mark t)) (exchange-point-and-mark)) 1691 (if (> (point) (mark t)) (exchange-point-and-mark))
1651 (insert vip-quote-string) 1692 (insert viper-quote-string)
1652 (beginning-of-line) 1693 (beginning-of-line)
1653 (forward-line 1) 1694 (forward-line 1)
1654 (while (and (< (point) (mark t)) (bolp)) 1695 (while (and (< (point) (mark t)) (bolp))
1655 (insert vip-quote-string) 1696 (insert viper-quote-string)
1656 (beginning-of-line) 1697 (beginning-of-line)
1657 (forward-line 1))) 1698 (forward-line 1)))
1658 1699
1659 ;; Tells whether BEG is on the same line as END. 1700 ;; Tells whether BEG is on the same line as END.
1660 ;; If one of the args is nil, it'll return nil. 1701 ;; If one of the args is nil, it'll return nil.
1661 (defun vip-same-line (beg end) 1702 (defun viper-same-line (beg end)
1662 (let ((selective-display nil) 1703 (let ((selective-display nil)
1663 (incr 0) 1704 (incr 0)
1664 temp) 1705 temp)
1665 (if (and beg end (> beg end)) 1706 (if (and beg end (> beg end))
1666 (setq temp beg 1707 (setq temp beg
1670 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range 1711 (cond ((or (> beg (point-max)) (> end (point-max))) ; out of range
1671 nil) 1712 nil)
1672 (t 1713 (t
1673 ;; This 'if' is needed because Emacs treats the next empty line 1714 ;; This 'if' is needed because Emacs treats the next empty line
1674 ;; as part of the previous line. 1715 ;; as part of the previous line.
1675 (if (= (vip-line-pos 'start) end) 1716 (if (= (viper-line-pos 'start) end)
1676 (setq incr 1)) 1717 (setq incr 1))
1677 (<= (+ incr (count-lines beg end)) 1)))) 1718 (<= (+ incr (count-lines beg end)) 1))))
1678 )) 1719 ))
1679 1720
1680 1721
1681 ;; Check if the string ends with a newline. 1722 ;; Check if the string ends with a newline.
1682 (defun vip-end-with-a-newline-p (string) 1723 (defun viper-end-with-a-newline-p (string)
1683 (or (string= string "") 1724 (or (string= string "")
1684 (= (vip-seq-last-elt string) ?\n))) 1725 (= (viper-seq-last-elt string) ?\n)))
1685 1726
1686 (defun vip-tmp-insert-at-eob (msg) 1727 (defun viper-tmp-insert-at-eob (msg)
1687 (let ((savemax (point-max))) 1728 (let ((savemax (point-max)))
1688 (goto-char savemax) 1729 (goto-char savemax)
1689 (insert msg) 1730 (insert msg)
1690 (sit-for 2) 1731 (sit-for 2)
1691 (goto-char savemax) (delete-region (point) (point-max)) 1732 (goto-char savemax) (delete-region (point) (point-max))
1693 1734
1694 1735
1695 1736
1696 ;;; Minibuffer business 1737 ;;; Minibuffer business
1697 1738
1698 (defsubst vip-set-minibuffer-style () 1739 (defsubst viper-set-minibuffer-style ()
1699 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel)) 1740 (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel))
1700 1741
1701 1742
1702 (defun vip-minibuffer-setup-sentinel () 1743 (defun viper-minibuffer-setup-sentinel ()
1703 (let ((hook (if vip-vi-style-in-minibuffer 1744 (let ((hook (if viper-vi-style-in-minibuffer
1704 'vip-change-state-to-insert 1745 'viper-change-state-to-insert
1705 'vip-change-state-to-emacs))) 1746 'viper-change-state-to-emacs)))
1706 (funcall hook) 1747 (funcall hook)
1707 )) 1748 ))
1708 1749
1709 ;; Interpret last event in the local map 1750 ;; Interpret last event in the local map
1710 (defun vip-exit-minibuffer () 1751 (defun viper-exit-minibuffer ()
1711 (interactive) 1752 (interactive)
1712 (let (command) 1753 (let (command)
1713 (setq command (local-key-binding (char-to-string last-command-char))) 1754 (setq command (local-key-binding (char-to-string last-command-char)))
1714 (if command 1755 (if command
1715 (command-execute command) 1756 (command-execute command)
1716 (exit-minibuffer)))) 1757 (exit-minibuffer))))
1717 1758
1718 1759
1719 ;;; Reading string with history 1760 ;;; Reading string with history
1720 1761
1721 (defun vip-read-string-with-history (prompt &optional initial 1762 (defun viper-read-string-with-history (prompt &optional initial
1722 history-var default keymap) 1763 history-var default keymap)
1723 ;; Read string, prompting with PROMPT and inserting the INITIAL 1764 ;; Read string, prompting with PROMPT and inserting the INITIAL
1724 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the 1765 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
1725 ;; input is an empty string. Use KEYMAP, if given, or the 1766 ;; input is an empty string. Use KEYMAP, if given, or the
1726 ;; minibuffer-local-map. 1767 ;; minibuffer-local-map.
1734 (or unread-command-events 1775 (or unread-command-events
1735 executing-kbd-macro 1776 executing-kbd-macro
1736 (sit-for 840)) 1777 (sit-for 840))
1737 (erase-buffer) 1778 (erase-buffer)
1738 (insert initial))) 1779 (insert initial)))
1739 (vip-minibuffer-setup-sentinel))) 1780 (viper-minibuffer-setup-sentinel)))
1740 (val "") 1781 (val "")
1741 (padding "") 1782 (padding "")
1742 temp-msg) 1783 temp-msg)
1743 1784
1744 (setq keymap (or keymap minibuffer-local-map) 1785 (setq keymap (or keymap minibuffer-local-map)
1745 initial (or initial "") 1786 initial (or initial "")
1746 temp-msg (if default 1787 temp-msg (if default
1747 (format "(default: %s) " default) 1788 (format "(default: %s) " default)
1748 "")) 1789 ""))
1749 1790
1750 (setq vip-incomplete-ex-cmd nil) 1791 (setq viper-incomplete-ex-cmd nil)
1751 (setq val (read-from-minibuffer prompt 1792 (setq val (read-from-minibuffer prompt
1752 (concat temp-msg initial val padding) 1793 (concat temp-msg initial val padding)
1753 keymap nil history-var)) 1794 keymap nil history-var))
1754 (setq minibuffer-setup-hook nil 1795 (setq minibuffer-setup-hook nil
1755 padding (vip-array-to-string (this-command-keys)) 1796 padding (viper-array-to-string (this-command-keys))
1756 temp-msg "") 1797 temp-msg "")
1757 ;; the following tries to be smart about what to put in history 1798 ;; the following tries to be smart about what to put in history
1758 (if (not (string= val (car (eval history-var)))) 1799 (if (not (string= val (car (eval history-var))))
1759 (set history-var (cons val (eval history-var)))) 1800 (set history-var (cons val (eval history-var))))
1760 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) 1801 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var)))
1761 (string= (nth 0 (eval history-var)) "")) 1802 (string= (nth 0 (eval history-var)) ""))
1762 (set history-var (cdr (eval history-var)))) 1803 (set history-var (cdr (eval history-var))))
1763 ;; If the user enters nothing but the prev cmd wasn't vip-ex, 1804 ;; If the user enters nothing but the prev cmd wasn't viper-ex,
1764 ;; vip-command-argument, or `! shell-command', this probably means 1805 ;; viper-command-argument, or `! shell-command', this probably means
1765 ;; that the user typed something then erased. Return "" in this case, not 1806 ;; that the user typed something then erased. Return "" in this case, not
1766 ;; the default---the default is too confusing in this case. 1807 ;; the default---the default is too confusing in this case.
1767 (cond ((and (string= val "") 1808 (cond ((and (string= val "")
1768 (not (string= prompt "!")) ; was a `! shell-command' 1809 (not (string= prompt "!")) ; was a `! shell-command'
1769 (not (memq last-command 1810 (not (memq last-command
1770 '(vip-ex 1811 '(viper-ex
1771 vip-command-argument 1812 viper-command-argument
1772 t) 1813 t)
1773 ))) 1814 )))
1774 "") 1815 "")
1775 ((string= val "") (or default "")) 1816 ((string= val "") (or default ""))
1776 (t val)) 1817 (t val))
1781 ;; insertion commands 1822 ;; insertion commands
1782 1823
1783 ;; Called when state changes from Insert Vi command mode. 1824 ;; Called when state changes from Insert Vi command mode.
1784 ;; Repeats the insertion command if Insert state was entered with prefix 1825 ;; Repeats the insertion command if Insert state was entered with prefix
1785 ;; argument > 1. 1826 ;; argument > 1.
1786 (defun vip-repeat-insert-command () 1827 (defun viper-repeat-insert-command ()
1787 (let ((i-com (car vip-d-com)) 1828 (let ((i-com (car viper-d-com))
1788 (val (nth 1 vip-d-com)) 1829 (val (nth 1 viper-d-com))
1789 (char (nth 2 vip-d-com))) 1830 (char (nth 2 viper-d-com)))
1790 (if (and val (> val 1)) ; first check that val is non-nil 1831 (if (and val (> val 1)) ; first check that val is non-nil
1791 (progn 1832 (progn
1792 (setq vip-d-com (list i-com (1- val) ?r nil nil nil)) 1833 (setq viper-d-com (list i-com (1- val) ?r nil nil nil))
1793 (vip-repeat nil) 1834 (viper-repeat nil)
1794 (setq vip-d-com (list i-com val char nil nil nil)) 1835 (setq viper-d-com (list i-com val char nil nil nil))
1795 )))) 1836 ))))
1796 1837
1797 (defun vip-insert (arg) 1838 (defun viper-insert (arg)
1798 "Insert before point." 1839 "Insert before point."
1799 (interactive "P") 1840 (interactive "P")
1800 (vip-set-complex-command-for-undo) 1841 (viper-set-complex-command-for-undo)
1801 (let ((val (vip-p-val arg)) 1842 (let ((val (viper-p-val arg))
1802 (com (vip-getcom arg))) 1843 (com (viper-getcom arg)))
1803 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil)) 1844 (viper-set-destructive-command (list 'viper-insert val ?r nil nil nil))
1804 (if com 1845 (if com
1805 (vip-loop val (vip-yank-last-insertion)) 1846 (viper-loop val (viper-yank-last-insertion))
1806 (vip-change-state-to-insert)))) 1847 (viper-change-state-to-insert))))
1807 1848
1808 (defun vip-append (arg) 1849 (defun viper-append (arg)
1809 "Append after point." 1850 "Append after point."
1810 (interactive "P") 1851 (interactive "P")
1811 (vip-set-complex-command-for-undo) 1852 (viper-set-complex-command-for-undo)
1812 (let ((val (vip-p-val arg)) 1853 (let ((val (viper-p-val arg))
1813 (com (vip-getcom arg))) 1854 (com (viper-getcom arg)))
1814 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil)) 1855 (viper-set-destructive-command (list 'viper-append val ?r nil nil nil))
1815 (if (not (eolp)) (forward-char)) 1856 (if (not (eolp)) (forward-char))
1816 (if (equal com ?r) 1857 (if (equal com ?r)
1817 (vip-loop val (vip-yank-last-insertion)) 1858 (viper-loop val (viper-yank-last-insertion))
1818 (vip-change-state-to-insert)))) 1859 (viper-change-state-to-insert))))
1819 1860
1820 (defun vip-Append (arg) 1861 (defun viper-Append (arg)
1821 "Append at end of line." 1862 "Append at end of line."
1822 (interactive "P") 1863 (interactive "P")
1823 (vip-set-complex-command-for-undo) 1864 (viper-set-complex-command-for-undo)
1824 (let ((val (vip-p-val arg)) 1865 (let ((val (viper-p-val arg))
1825 (com (vip-getcom arg))) 1866 (com (viper-getcom arg)))
1826 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil)) 1867 (viper-set-destructive-command (list 'viper-Append val ?r nil nil nil))
1827 (end-of-line) 1868 (end-of-line)
1828 (if (equal com ?r) 1869 (if (equal com ?r)
1829 (vip-loop val (vip-yank-last-insertion)) 1870 (viper-loop val (viper-yank-last-insertion))
1830 (vip-change-state-to-insert)))) 1871 (viper-change-state-to-insert))))
1831 1872
1832 (defun vip-Insert (arg) 1873 (defun viper-Insert (arg)
1833 "Insert before first non-white." 1874 "Insert before first non-white."
1834 (interactive "P") 1875 (interactive "P")
1835 (vip-set-complex-command-for-undo) 1876 (viper-set-complex-command-for-undo)
1836 (let ((val (vip-p-val arg)) 1877 (let ((val (viper-p-val arg))
1837 (com (vip-getcom arg))) 1878 (com (viper-getcom arg)))
1838 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil)) 1879 (viper-set-destructive-command (list 'viper-Insert val ?r nil nil nil))
1839 (back-to-indentation) 1880 (back-to-indentation)
1840 (if (equal com ?r) 1881 (if (equal com ?r)
1841 (vip-loop val (vip-yank-last-insertion)) 1882 (viper-loop val (viper-yank-last-insertion))
1842 (vip-change-state-to-insert)))) 1883 (viper-change-state-to-insert))))
1843 1884
1844 (defun vip-open-line (arg) 1885 (defun viper-open-line (arg)
1845 "Open line below." 1886 "Open line below."
1846 (interactive "P") 1887 (interactive "P")
1847 (vip-set-complex-command-for-undo) 1888 (viper-set-complex-command-for-undo)
1848 (let ((val (vip-p-val arg)) 1889 (let ((val (viper-p-val arg))
1849 (com (vip-getcom arg))) 1890 (com (viper-getcom arg)))
1850 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil)) 1891 (viper-set-destructive-command (list 'viper-open-line val ?r nil nil nil))
1851 (let ((col (current-indentation))) 1892 (let ((col (current-indentation)))
1852 (if (equal com ?r) 1893 (if (equal com ?r)
1853 (vip-loop val 1894 (viper-loop val
1854 (progn 1895 (progn
1855 (end-of-line) 1896 (end-of-line)
1856 (newline 1) 1897 (newline 1)
1857 (if vip-auto-indent 1898 (if viper-auto-indent
1858 (progn 1899 (progn
1859 (setq vip-cted t) 1900 (setq viper-cted t)
1860 (if vip-electric-mode 1901 (if viper-electric-mode
1861 (indent-according-to-mode) 1902 (indent-according-to-mode)
1862 (indent-to col)) 1903 (indent-to col))
1863 )) 1904 ))
1864 (vip-yank-last-insertion))) 1905 (viper-yank-last-insertion)))
1865 (end-of-line) 1906 (end-of-line)
1866 (newline 1) 1907 (newline 1)
1867 (if vip-auto-indent 1908 (if viper-auto-indent
1868 (progn 1909 (progn
1869 (setq vip-cted t) 1910 (setq viper-cted t)
1870 (if vip-electric-mode 1911 (if viper-electric-mode
1871 (indent-according-to-mode) 1912 (indent-according-to-mode)
1872 (indent-to col)))) 1913 (indent-to col))))
1873 (vip-change-state-to-insert))))) 1914 (viper-change-state-to-insert)))))
1874 1915
1875 (defun vip-Open-line (arg) 1916 (defun viper-Open-line (arg)
1876 "Open line above." 1917 "Open line above."
1877 (interactive "P") 1918 (interactive "P")
1878 (vip-set-complex-command-for-undo) 1919 (viper-set-complex-command-for-undo)
1879 (let ((val (vip-p-val arg)) 1920 (let ((val (viper-p-val arg))
1880 (com (vip-getcom arg))) 1921 (com (viper-getcom arg)))
1881 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil)) 1922 (viper-set-destructive-command (list 'viper-Open-line val ?r nil nil nil))
1882 (let ((col (current-indentation))) 1923 (let ((col (current-indentation)))
1883 (if (equal com ?r) 1924 (if (equal com ?r)
1884 (vip-loop val 1925 (viper-loop val
1885 (progn 1926 (progn
1886 (beginning-of-line) 1927 (beginning-of-line)
1887 (open-line 1) 1928 (open-line 1)
1888 (if vip-auto-indent 1929 (if viper-auto-indent
1889 (progn 1930 (progn
1890 (setq vip-cted t) 1931 (setq viper-cted t)
1891 (if vip-electric-mode 1932 (if viper-electric-mode
1892 (indent-according-to-mode) 1933 (indent-according-to-mode)
1893 (indent-to col)) 1934 (indent-to col))
1894 )) 1935 ))
1895 (vip-yank-last-insertion))) 1936 (viper-yank-last-insertion)))
1896 (beginning-of-line) 1937 (beginning-of-line)
1897 (open-line 1) 1938 (open-line 1)
1898 (if vip-auto-indent 1939 (if viper-auto-indent
1899 (progn 1940 (progn
1900 (setq vip-cted t) 1941 (setq viper-cted t)
1901 (if vip-electric-mode 1942 (if viper-electric-mode
1902 (indent-according-to-mode) 1943 (indent-according-to-mode)
1903 (indent-to col)) 1944 (indent-to col))
1904 )) 1945 ))
1905 (vip-change-state-to-insert))))) 1946 (viper-change-state-to-insert)))))
1906 1947
1907 (defun vip-open-line-at-point (arg) 1948 (defun viper-open-line-at-point (arg)
1908 "Open line at point." 1949 "Open line at point."
1909 (interactive "P") 1950 (interactive "P")
1910 (vip-set-complex-command-for-undo) 1951 (viper-set-complex-command-for-undo)
1911 (let ((val (vip-p-val arg)) 1952 (let ((val (viper-p-val arg))
1912 (com (vip-getcom arg))) 1953 (com (viper-getcom arg)))
1913 (vip-set-destructive-command 1954 (viper-set-destructive-command
1914 (list 'vip-open-line-at-point val ?r nil nil nil)) 1955 (list 'viper-open-line-at-point val ?r nil nil nil))
1915 (if (equal com ?r) 1956 (if (equal com ?r)
1916 (vip-loop val 1957 (viper-loop val
1917 (progn 1958 (progn
1918 (open-line 1) 1959 (open-line 1)
1919 (vip-yank-last-insertion))) 1960 (viper-yank-last-insertion)))
1920 (open-line 1) 1961 (open-line 1)
1921 (vip-change-state-to-insert)))) 1962 (viper-change-state-to-insert))))
1922 1963
1923 (defun vip-substitute (arg) 1964 (defun viper-substitute (arg)
1924 "Substitute characters." 1965 "Substitute characters."
1925 (interactive "P") 1966 (interactive "P")
1926 (let ((val (vip-p-val arg)) 1967 (let ((val (viper-p-val arg))
1927 (com (vip-getcom arg))) 1968 (com (viper-getcom arg)))
1928 (push-mark nil t) 1969 (push-mark nil t)
1929 (forward-char val) 1970 (forward-char val)
1930 (if (equal com ?r) 1971 (if (equal com ?r)
1931 (vip-change-subr (mark t) (point)) 1972 (viper-change-subr (mark t) (point))
1932 (vip-change (mark t) (point))) 1973 (viper-change (mark t) (point)))
1933 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil)) 1974 (viper-set-destructive-command (list 'viper-substitute val ?r nil nil nil))
1934 )) 1975 ))
1935 1976
1936 (defun vip-substitute-line (arg) 1977 ;; Command bound to S
1978 (defun viper-substitute-line (arg)
1937 "Substitute lines." 1979 "Substitute lines."
1938 (interactive "p") 1980 (interactive "p")
1939 (vip-set-complex-command-for-undo) 1981 (viper-set-complex-command-for-undo)
1940 (vip-line (cons arg ?C))) 1982 (viper-line (cons arg ?C)))
1941 1983
1942 ;; Prepare for replace 1984 ;; Prepare for replace
1943 (defun vip-start-replace () 1985 (defun viper-start-replace ()
1944 (setq vip-began-as-replace t 1986 (setq viper-began-as-replace t
1945 vip-sitting-in-replace t 1987 viper-sitting-in-replace t
1946 vip-replace-chars-to-delete 0 1988 viper-replace-chars-to-delete 0
1947 vip-replace-chars-deleted 0) 1989 viper-replace-chars-deleted 0)
1948 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t) 1990 (viper-add-hook
1949 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t) 1991 'viper-after-change-functions 'viper-replace-mode-spy-after t)
1992 (viper-add-hook
1993 'viper-before-change-functions 'viper-replace-mode-spy-before t)
1950 ;; this will get added repeatedly, but no harm 1994 ;; this will get added repeatedly, but no harm
1951 (add-hook 'after-change-functions 'vip-after-change-sentinel t) 1995 (add-hook 'after-change-functions 'viper-after-change-sentinel t)
1952 (add-hook 'before-change-functions 'vip-before-change-sentinel t) 1996 (add-hook 'before-change-functions 'viper-before-change-sentinel t)
1953 (vip-move-marker-locally 'vip-last-posn-in-replace-region 1997 (viper-move-marker-locally 'viper-last-posn-in-replace-region
1954 (vip-replace-start)) 1998 (viper-replace-start))
1955 (vip-add-hook 1999 (viper-add-hook
1956 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) 2000 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel t)
1957 (vip-add-hook 2001 (viper-add-hook
1958 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) 2002 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
1959 ;; guard against a smartie who switched from R-replace to normal replace 2003 ;; guard against a smartie who switched from R-replace to normal replace
1960 (vip-remove-hook 2004 (viper-remove-hook
1961 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) 2005 'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
1962 (if overwrite-mode (overwrite-mode nil)) 2006 (if overwrite-mode (overwrite-mode nil))
1963 ) 2007 )
1964 2008
1965 2009
1966 ;; checks how many chars were deleted by the last change 2010 ;; checks how many chars were deleted by the last change
1967 (defun vip-replace-mode-spy-before (beg end) 2011 (defun viper-replace-mode-spy-before (beg end)
1968 (setq vip-replace-chars-deleted 2012 (setq viper-replace-chars-deleted
1969 (- end beg 2013 (- end beg
1970 (max 0 (- end (vip-replace-end))) 2014 (max 0 (- end (viper-replace-end)))
1971 (max 0 (- (vip-replace-start) beg)) 2015 (max 0 (- (viper-replace-start) beg))
1972 ))) 2016 )))
1973 2017
1974 ;; Invoked as an after-change-function to set up parameters of the last change 2018 ;; Invoked as an after-change-function to set up parameters of the last change
1975 (defun vip-replace-mode-spy-after (beg end length) 2019 (defun viper-replace-mode-spy-after (beg end length)
1976 (if (memq vip-intermediate-command '(repeating-insertion-from-ring)) 2020 (if (memq viper-intermediate-command '(repeating-insertion-from-ring))
1977 (progn 2021 (progn
1978 (setq vip-replace-chars-to-delete 0) 2022 (setq viper-replace-chars-to-delete 0)
1979 (vip-move-marker-locally 2023 (viper-move-marker-locally
1980 'vip-last-posn-in-replace-region (point))) 2024 'viper-last-posn-in-replace-region (point)))
1981 2025
1982 (let (beg-col end-col real-end chars-to-delete) 2026 (let (beg-col end-col real-end chars-to-delete)
1983 (setq real-end (min end (vip-replace-end))) 2027 (setq real-end (min end (viper-replace-end)))
1984 (save-excursion 2028 (save-excursion
1985 (goto-char beg) 2029 (goto-char beg)
1986 (setq beg-col (current-column)) 2030 (setq beg-col (current-column))
1987 (goto-char real-end) 2031 (goto-char real-end)
1988 (setq end-col (current-column))) 2032 (setq end-col (current-column)))
2008 ;; 2052 ;;
2009 ;; In fact, it might be also useful to have overlays for insert 2053 ;; In fact, it might be also useful to have overlays for insert
2010 ;; regions as well, since this will let us capture the situation when 2054 ;; regions as well, since this will let us capture the situation when
2011 ;; dabbrev-expand goes back past the insertion point to find the 2055 ;; dabbrev-expand goes back past the insertion point to find the
2012 ;; beginning of the word to be expanded. 2056 ;; beginning of the word to be expanded.
2013 (if (or (and (<= (vip-replace-start) beg) 2057 (if (or (and (<= (viper-replace-start) beg)
2014 (<= beg (vip-replace-end))) 2058 (<= beg (viper-replace-end)))
2015 (and (= length 0) (eq this-command 'dabbrev-expand))) 2059 (and (= length 0) (eq this-command 'dabbrev-expand)))
2016 (setq chars-to-delete 2060 (setq chars-to-delete
2017 (max (- end-col beg-col) (- real-end beg) 0)) 2061 (max (- end-col beg-col) (- real-end beg) 0))
2018 (setq chars-to-delete 0)) 2062 (setq chars-to-delete 0))
2019 2063
2020 ;; if beg = last change position, it means that we are within the 2064 ;; if beg = last change position, it means that we are within the
2021 ;; same command that does multiple changes. Moreover, it means 2065 ;; same command that does multiple changes. Moreover, it means
2022 ;; that we have two subsequent changes (insert/delete) that 2066 ;; that we have two subsequent changes (insert/delete) that
2023 ;; complement each other. 2067 ;; complement each other.
2024 (if (= beg (marker-position vip-last-posn-in-replace-region)) 2068 (if (= beg (marker-position viper-last-posn-in-replace-region))
2025 (setq vip-replace-chars-to-delete 2069 (setq viper-replace-chars-to-delete
2026 (- (+ chars-to-delete vip-replace-chars-to-delete) 2070 (- (+ chars-to-delete viper-replace-chars-to-delete)
2027 vip-replace-chars-deleted)) 2071 viper-replace-chars-deleted))
2028 (setq vip-replace-chars-to-delete chars-to-delete)) 2072 (setq viper-replace-chars-to-delete chars-to-delete))
2029 2073
2030 (vip-move-marker-locally 2074 (viper-move-marker-locally
2031 'vip-last-posn-in-replace-region 2075 'viper-last-posn-in-replace-region
2032 (max (if (> end (vip-replace-end)) (vip-replace-start) end) 2076 (max (if (> end (viper-replace-end)) (viper-replace-start) end)
2033 (or (marker-position vip-last-posn-in-replace-region) 2077 (or (marker-position viper-last-posn-in-replace-region)
2034 (vip-replace-start)) 2078 (viper-replace-start))
2035 )) 2079 ))
2036 2080
2037 (setq vip-replace-chars-to-delete 2081 (setq viper-replace-chars-to-delete
2038 (max 0 2082 (max 0
2039 (min vip-replace-chars-to-delete 2083 (min viper-replace-chars-to-delete
2040 (- (vip-replace-end) vip-last-posn-in-replace-region) 2084 (- (viper-replace-end) viper-last-posn-in-replace-region)
2041 (- (vip-line-pos 'end) vip-last-posn-in-replace-region) 2085 (- (viper-line-pos 'end)
2086 viper-last-posn-in-replace-region)
2042 ))) 2087 )))
2043 ))) 2088 )))
2044 2089
2045 2090
2046 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if 2091 ;; Delete stuff between posn and the end of viper-replace-overlay-marker, if
2047 ;; posn is within the overlay. 2092 ;; posn is within the overlay.
2048 (defun vip-finish-change (posn) 2093 (defun viper-finish-change (posn)
2049 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after) 2094 (viper-remove-hook
2050 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before) 2095 'viper-after-change-functions 'viper-replace-mode-spy-after)
2051 (vip-remove-hook 'vip-post-command-hooks 2096 (viper-remove-hook
2052 'vip-replace-state-post-command-sentinel) 2097 'viper-before-change-functions 'viper-replace-mode-spy-before)
2053 (vip-remove-hook 2098 (viper-remove-hook
2054 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) 2099 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel)
2055 (vip-restore-cursor-color-after-replace) 2100 (viper-remove-hook
2056 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it 2101 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
2102 (viper-restore-cursor-color-after-replace)
2103 (setq viper-sitting-in-replace nil) ; just in case we'll need to know it
2057 (save-excursion 2104 (save-excursion
2058 (if (and 2105 (if (and
2059 vip-replace-overlay 2106 viper-replace-overlay
2060 (>= posn (vip-replace-start)) 2107 (>= posn (viper-replace-start))
2061 (< posn (vip-replace-end))) 2108 (< posn (viper-replace-end)))
2062 (delete-region posn (vip-replace-end))) 2109 (delete-region posn (viper-replace-end)))
2063 ) 2110 )
2064 2111
2065 (if (eq vip-current-state 'replace-state) 2112 (if (eq viper-current-state 'replace-state)
2066 (vip-downgrade-to-insert)) 2113 (viper-downgrade-to-insert))
2067 ;; replace mode ended => nullify vip-last-posn-in-replace-region 2114 ;; replace mode ended => nullify viper-last-posn-in-replace-region
2068 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil) 2115 (viper-move-marker-locally 'viper-last-posn-in-replace-region nil)
2069 (vip-hide-replace-overlay) 2116 (viper-hide-replace-overlay)
2070 (vip-refresh-mode-line) 2117 (viper-refresh-mode-line)
2071 (vip-put-string-on-kill-ring vip-last-replace-region) 2118 (viper-put-string-on-kill-ring viper-last-replace-region)
2072 ) 2119 )
2073 2120
2074 ;; Make STRING be the first element of the kill ring. 2121 ;; Make STRING be the first element of the kill ring.
2075 (defun vip-put-string-on-kill-ring (string) 2122 (defun viper-put-string-on-kill-ring (string)
2076 (setq kill-ring (cons string kill-ring)) 2123 (setq kill-ring (cons string kill-ring))
2077 (if (> (length kill-ring) kill-ring-max) 2124 (if (> (length kill-ring) kill-ring-max)
2078 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) 2125 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
2079 (setq kill-ring-yank-pointer kill-ring)) 2126 (setq kill-ring-yank-pointer kill-ring))
2080 2127
2081 (defun vip-finish-R-mode () 2128 (defun viper-finish-R-mode ()
2082 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) 2129 (viper-remove-hook
2083 (vip-remove-hook 2130 'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
2084 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) 2131 (viper-remove-hook
2085 (vip-downgrade-to-insert)) 2132 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
2086 2133 (viper-downgrade-to-insert))
2087 (defun vip-start-R-mode () 2134
2135 (defun viper-start-R-mode ()
2088 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number 2136 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
2089 (overwrite-mode 1) 2137 (overwrite-mode 1)
2090 (vip-add-hook 2138 (viper-add-hook
2091 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) 2139 'viper-post-command-hooks 'viper-R-state-post-command-sentinel t)
2092 (vip-add-hook 2140 (viper-add-hook
2093 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) 2141 'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
2094 ;; guard against a smartie who switched from R-replace to normal replace 2142 ;; guard against a smartie who switched from R-replace to normal replace
2095 (vip-remove-hook 2143 (viper-remove-hook
2096 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel) 2144 'viper-post-command-hooks 'viper-replace-state-post-command-sentinel)
2097 ) 2145 )
2098 2146
2099 2147
2100 2148
2101 (defun vip-replace-state-exit-cmd () 2149 (defun viper-replace-state-exit-cmd ()
2102 "Binding for keys that cause Replace state to switch to Vi or to Insert. 2150 "Binding for keys that cause Replace state to switch to Vi or to Insert.
2103 These keys are ESC, RET, and LineFeed" 2151 These keys are ESC, RET, and LineFeed"
2104 (interactive) 2152 (interactive)
2105 (if overwrite-mode ;; If you are in replace mode invoked via 'R' 2153 (if overwrite-mode ;; If you are in replace mode invoked via 'R'
2106 (vip-finish-R-mode) 2154 (viper-finish-R-mode)
2107 (vip-finish-change vip-last-posn-in-replace-region)) 2155 (viper-finish-change viper-last-posn-in-replace-region))
2108 (let (com) 2156 (let (com)
2109 (if (eq this-command 'vip-intercept-ESC-key) 2157 (if (eq this-command 'viper-intercept-ESC-key)
2110 (setq com 'vip-exit-insert-state) 2158 (setq com 'viper-exit-insert-state)
2111 (vip-set-unread-command-events last-input-char) 2159 (viper-set-unread-command-events last-input-char)
2112 (setq com (key-binding (read-key-sequence nil)))) 2160 (setq com (key-binding (read-key-sequence nil))))
2113 2161
2114 (condition-case conds 2162 (condition-case conds
2115 (command-execute com) 2163 (command-execute com)
2116 (error 2164 (error
2117 (vip-message-conditions conds))) 2165 (viper-message-conditions conds)))
2118 ) 2166 )
2119 (vip-hide-replace-overlay)) 2167 (viper-hide-replace-overlay))
2120 2168
2121 (defun vip-replace-state-carriage-return () 2169
2122 "Implements carriage return in Viper replace state." 2170 (defun viper-replace-state-carriage-return ()
2171 "Carriage return in Viper replace state."
2123 (interactive) 2172 (interactive)
2124 ;; If Emacs start supporting overlay maps, as it currently supports 2173 ;; If Emacs start supporting overlay maps, as it currently supports
2125 ;; text-property maps, we could do away with vip-replace-minor-mode and 2174 ;; text-property maps, we could do away with viper-replace-minor-mode and
2126 ;; just have keymap attached to replace overlay. Then the "if part" of this 2175 ;; just have keymap attached to replace overlay. Then the "if part" of this
2127 ;; statement can be deleted. 2176 ;; statement can be deleted.
2128 (if (or (< (point) (vip-replace-start)) 2177 (if (or (< (point) (viper-replace-start))
2129 (> (point) (vip-replace-end))) 2178 (> (point) (viper-replace-end)))
2130 (let (vip-replace-minor-mode com) 2179 (let (viper-replace-minor-mode com)
2131 (vip-set-unread-command-events last-input-char) 2180 (viper-set-unread-command-events last-input-char)
2132 (setq com (key-binding (read-key-sequence nil))) 2181 (setq com (key-binding (read-key-sequence nil)))
2133 (condition-case conds 2182 (condition-case conds
2134 (command-execute com) 2183 (command-execute com)
2135 (error 2184 (error
2136 (vip-message-conditions conds)))) 2185 (viper-message-conditions conds))))
2137 (if (not vip-allow-multiline-replace-regions) 2186 (if (not viper-allow-multiline-replace-regions)
2138 (vip-replace-state-exit-cmd) 2187 (viper-replace-state-exit-cmd)
2139 (if (vip-same-line (point) (vip-replace-end)) 2188 (if (viper-same-line (point) (viper-replace-end))
2140 (vip-replace-state-exit-cmd) 2189 (viper-replace-state-exit-cmd)
2141 (vip-kill-line nil) 2190 ;; delete the rest of line
2142 (vip-next-line-at-bol nil))))) 2191 (delete-region (point) (viper-line-pos 'end))
2192 (save-excursion
2193 (end-of-line)
2194 (if (eobp) (error "Last line in buffer")))
2195 ;; skip to the next line
2196 (forward-line 1)
2197 (back-to-indentation)
2198 ))))
2143 2199
2144 2200
2145 ;; This is the function bound to 'R'---unlimited replace. 2201 ;; This is the function bound to 'R'---unlimited replace.
2146 ;; Similar to Emacs's own overwrite-mode. 2202 ;; Similar to Emacs's own overwrite-mode.
2147 (defun vip-overwrite (arg) 2203 (defun viper-overwrite (arg)
2148 "Begin overwrite mode." 2204 "Begin overwrite mode."
2149 (interactive "P") 2205 (interactive "P")
2150 (let ((val (vip-p-val arg)) 2206 (let ((val (viper-p-val arg))
2151 (com (vip-getcom arg)) (len)) 2207 (com (viper-getcom arg)) (len))
2152 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil)) 2208 (viper-set-destructive-command (list 'viper-overwrite val ?r nil nil nil))
2153 (if com 2209 (if com
2154 (progn 2210 (progn
2155 ;; Viper saves inserted text in vip-last-insertion 2211 ;; Viper saves inserted text in viper-last-insertion
2156 (setq len (length vip-last-insertion)) 2212 (setq len (length viper-last-insertion))
2157 (delete-char len) 2213 (delete-char len)
2158 (vip-loop val (vip-yank-last-insertion))) 2214 (viper-loop val (viper-yank-last-insertion)))
2159 (setq last-command 'vip-overwrite) 2215 (setq last-command 'viper-overwrite)
2160 (vip-set-complex-command-for-undo) 2216 (viper-set-complex-command-for-undo)
2161 (vip-set-replace-overlay (point) (vip-line-pos 'end)) 2217 (viper-set-replace-overlay (point) (viper-line-pos 'end))
2162 (vip-change-state-to-replace) 2218 (viper-change-state-to-replace)
2163 ))) 2219 )))
2164 2220
2165 2221
2166 ;; line commands 2222 ;; line commands
2167 2223
2168 (defun vip-line (arg) 2224 (defun viper-line (arg)
2169 (let ((val (car arg)) 2225 (let ((val (car arg))
2170 (com (cdr arg))) 2226 (com (cdr arg)))
2171 (vip-move-marker-locally 'vip-com-point (point)) 2227 (viper-move-marker-locally 'viper-com-point (point))
2172 (if (not (eobp)) 2228 (if (not (eobp))
2173 (vip-next-line-carefully (1- val))) 2229 (viper-next-line-carefully (1- val)))
2174 ;; this ensures that dd, cc, D, yy will do the right thing on the last 2230 ;; this ensures that dd, cc, D, yy will do the right thing on the last
2175 ;; line of buffer when this line has no \n. 2231 ;; line of buffer when this line has no \n.
2176 (vip-add-newline-at-eob-if-necessary) 2232 (viper-add-newline-at-eob-if-necessary)
2177 (vip-execute-com 'vip-line val com)) 2233 (viper-execute-com 'viper-line val com))
2178 (if (and (eobp) (not (bobp))) (forward-line -1)) 2234 (if (and (eobp) (not (bobp))) (forward-line -1))
2179 ) 2235 )
2180 2236
2181 (defun vip-yank-line (arg) 2237 (defun viper-yank-line (arg)
2182 "Yank ARG lines (in Vi's sense)." 2238 "Yank ARG lines (in Vi's sense)."
2183 (interactive "P") 2239 (interactive "P")
2184 (let ((val (vip-p-val arg))) 2240 (let ((val (viper-p-val arg)))
2185 (vip-line (cons val ?Y)))) 2241 (viper-line (cons val ?Y))))
2186 2242
2187 2243
2188 ;; region commands 2244 ;; region commands
2189 2245
2190 (defun vip-region (arg) 2246 (defun viper-region (arg)
2191 "Execute command on a region." 2247 "Execute command on a region."
2192 (interactive "P") 2248 (interactive "P")
2193 (let ((val (vip-P-val arg)) 2249 (let ((val (viper-P-val arg))
2194 (com (vip-getcom arg))) 2250 (com (viper-getcom arg)))
2195 (vip-move-marker-locally 'vip-com-point (point)) 2251 (viper-move-marker-locally 'viper-com-point (point))
2196 (exchange-point-and-mark) 2252 (exchange-point-and-mark)
2197 (vip-execute-com 'vip-region val com))) 2253 (viper-execute-com 'viper-region val com)))
2198 2254
2199 (defun vip-Region (arg) 2255 (defun viper-Region (arg)
2200 "Execute command on a Region." 2256 "Execute command on a Region."
2201 (interactive "P") 2257 (interactive "P")
2202 (let ((val (vip-P-val arg)) 2258 (let ((val (viper-P-val arg))
2203 (com (vip-getCom arg))) 2259 (com (viper-getCom arg)))
2204 (vip-move-marker-locally 'vip-com-point (point)) 2260 (viper-move-marker-locally 'viper-com-point (point))
2205 (exchange-point-and-mark) 2261 (exchange-point-and-mark)
2206 (vip-execute-com 'vip-Region val com))) 2262 (viper-execute-com 'viper-Region val com)))
2207 2263
2208 (defun vip-replace-char (arg) 2264 (defun viper-replace-char (arg)
2209 "Replace the following ARG chars by the character read." 2265 "Replace the following ARG chars by the character read."
2210 (interactive "P") 2266 (interactive "P")
2211 (if (and (eolp) (bolp)) (error "No character to replace here")) 2267 (if (and (eolp) (bolp)) (error "No character to replace here"))
2212 (let ((val (vip-p-val arg)) 2268 (let ((val (viper-p-val arg))
2213 (com (vip-getcom arg))) 2269 (com (viper-getcom arg)))
2214 (vip-replace-char-subr com val) 2270 (viper-replace-char-subr com val)
2215 (if (and (eolp) (not (bolp))) (forward-char 1)) 2271 (if (and (eolp) (not (bolp))) (forward-char 1))
2216 (vip-set-destructive-command 2272 (viper-set-destructive-command
2217 (list 'vip-replace-char val ?r nil vip-d-char nil)) 2273 (list 'viper-replace-char val ?r nil viper-d-char nil))
2218 )) 2274 ))
2219 2275
2220 (defun vip-replace-char-subr (com arg) 2276 (defun viper-replace-char-subr (com arg)
2221 (let ((take-care-of-iso-accents 2277 (let ((take-care-of-iso-accents
2222 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents)) 2278 (and (boundp 'iso-accents-mode) viper-automatic-iso-accents))
2223 char) 2279 char)
2224 (setq char (if (equal com ?r) 2280 (setq char (if (equal com ?r)
2225 vip-d-char 2281 viper-d-char
2226 (read-char))) 2282 (read-char)))
2227 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~))) 2283 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~)))
2228 ;; get European characters 2284 ;; get European characters
2229 (progn 2285 (progn
2230 (iso-accents-mode 1) 2286 (iso-accents-mode 1)
2231 (vip-set-unread-command-events char) 2287 (viper-set-unread-command-events char)
2232 (setq char (aref (read-key-sequence nil) 0)) 2288 (setq char (aref (read-key-sequence nil) 0))
2233 (iso-accents-mode -1))) 2289 (iso-accents-mode -1)))
2234 (delete-char arg t) 2290 (delete-char arg t)
2235 (setq vip-d-char char) 2291 (setq viper-d-char char)
2236 (vip-loop (if (> arg 0) arg (- arg)) 2292 (viper-loop (if (> arg 0) arg (- arg))
2237 (if (eq char ?\C-m) (insert "\n") (insert char))) 2293 (if (eq char ?\C-m) (insert "\n") (insert char)))
2238 (backward-char arg))) 2294 (backward-char arg)))
2239 2295
2240 2296
2241 ;; basic cursor movement. j, k, l, h commands. 2297 ;; basic cursor movement. j, k, l, h commands.
2242 2298
2243 (defun vip-forward-char (arg) 2299 (defun viper-forward-char (arg)
2244 "Move point right ARG characters (left if ARG negative). 2300 "Move point right ARG characters (left if ARG negative).
2245 On reaching end of line, stop and signal error." 2301 On reaching end of line, stop and signal error."
2246 (interactive "P") 2302 (interactive "P")
2247 (vip-leave-region-active) 2303 (viper-leave-region-active)
2248 (let ((val (vip-p-val arg)) 2304 (let ((val (viper-p-val arg))
2249 (com (vip-getcom arg))) 2305 (com (viper-getcom arg)))
2250 (if com (vip-move-marker-locally 'vip-com-point (point))) 2306 (if com (viper-move-marker-locally 'viper-com-point (point)))
2251 (if vip-ex-style-motion 2307 (if viper-ex-style-motion
2252 (progn 2308 (progn
2253 ;; the boundary condition check gets weird here because 2309 ;; the boundary condition check gets weird here because
2254 ;; forward-char may be the parameter of a delete, and 'dl' works 2310 ;; forward-char may be the parameter of a delete, and 'dl' works
2255 ;; just like 'x' for the last char on a line, so we have to allow 2311 ;; just like 'x' for the last char on a line, so we have to allow
2256 ;; the forward motion before the 'vip-execute-com', but, of 2312 ;; the forward motion before the 'viper-execute-com', but, of
2257 ;; course, 'dl' doesn't work on an empty line, so we have to 2313 ;; course, 'dl' doesn't work on an empty line, so we have to
2258 ;; catch that condition before 'vip-execute-com' 2314 ;; catch that condition before 'viper-execute-com'
2259 (if (and (eolp) (bolp)) (error "") (forward-char val)) 2315 (if (and (eolp) (bolp)) (error "") (forward-char val))
2260 (if com (vip-execute-com 'vip-forward-char val com)) 2316 (if com (viper-execute-com 'viper-forward-char val com))
2261 (if (eolp) (progn (backward-char 1) (error "")))) 2317 (if (eolp) (progn (backward-char 1) (error ""))))
2262 (forward-char val) 2318 (forward-char val)
2263 (if com (vip-execute-com 'vip-forward-char val com))))) 2319 (if com (viper-execute-com 'viper-forward-char val com)))))
2264 2320
2265 (defun vip-backward-char (arg) 2321 (defun viper-backward-char (arg)
2266 "Move point left ARG characters (right if ARG negative). 2322 "Move point left ARG characters (right if ARG negative).
2267 On reaching beginning of line, stop and signal error." 2323 On reaching beginning of line, stop and signal error."
2268 (interactive "P") 2324 (interactive "P")
2269 (vip-leave-region-active) 2325 (viper-leave-region-active)
2270 (let ((val (vip-p-val arg)) 2326 (let ((val (viper-p-val arg))
2271 (com (vip-getcom arg))) 2327 (com (viper-getcom arg)))
2272 (if com (vip-move-marker-locally 'vip-com-point (point))) 2328 (if com (viper-move-marker-locally 'viper-com-point (point)))
2273 (if vip-ex-style-motion 2329 (if viper-ex-style-motion
2274 (progn 2330 (progn
2275 (if (bolp) (error "") (backward-char val)) 2331 (if (bolp) (error "") (backward-char val))
2276 (if com (vip-execute-com 'vip-backward-char val com))) 2332 (if com (viper-execute-com 'viper-backward-char val com)))
2277 (backward-char val) 2333 (backward-char val)
2278 (if com (vip-execute-com 'vip-backward-char val com))))) 2334 (if com (viper-execute-com 'viper-backward-char val com)))))
2279 2335
2280 ;; Like forward-char, but doesn't move at end of buffer. 2336 ;; Like forward-char, but doesn't move at end of buffer.
2281 (defun vip-forward-char-carefully (&optional arg) 2337 (defun viper-forward-char-carefully (&optional arg)
2282 (setq arg (or arg 1)) 2338 (setq arg (or arg 1))
2283 (if (>= (point-max) (+ (point) arg)) 2339 (if (>= (point-max) (+ (point) arg))
2284 (forward-char arg) 2340 (forward-char arg)
2285 (goto-char (point-max)))) 2341 (goto-char (point-max))))
2286 2342
2287 ;; Like backward-char, but doesn't move at end of buffer. 2343 ;; Like backward-char, but doesn't move at end of buffer.
2288 (defun vip-backward-char-carefully (&optional arg) 2344 (defun viper-backward-char-carefully (&optional arg)
2289 (setq arg (or arg 1)) 2345 (setq arg (or arg 1))
2290 (if (<= (point-min) (- (point) arg)) 2346 (if (<= (point-min) (- (point) arg))
2291 (backward-char arg) 2347 (backward-char arg)
2292 (goto-char (point-min)))) 2348 (goto-char (point-min))))
2293 2349
2294 (defun vip-next-line-carefully (arg) 2350 (defun viper-next-line-carefully (arg)
2295 (condition-case nil 2351 (condition-case nil
2296 (next-line arg) 2352 (next-line arg)
2297 (error nil))) 2353 (error nil)))
2298 2354
2299 2355
2300 2356
2301 ;;; Word command 2357 ;;; Word command
2302 2358
2303 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators 2359 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for
2304 ;; for word movement. When executed with a destructive command, \n is 2360 ;; word movement. When executed with a destructive command, \n is usually left
2305 ;; usually left untouched for the last word. 2361 ;; untouched for the last word. Viper uses syntax table to determine what is a
2306 ;; Viper uses syntax table to determine what is a word and what is a 2362 ;; word and what is a separator. However, \n is always a separator. Also, if
2307 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference 2363 ;; viper-syntax-preference is 'vi, then `_' is part of the word.
2308 ;; is 'vi, then `_' is part of the word.
2309 2364
2310 ;; skip only one \n 2365 ;; skip only one \n
2311 (defun vip-skip-separators (forward) 2366 (defun viper-skip-separators (forward)
2312 (if forward 2367 (if forward
2313 (progn 2368 (progn
2314 (vip-skip-all-separators-forward 'within-line) 2369 (viper-skip-all-separators-forward 'within-line)
2315 (if (looking-at "\n") 2370 (if (looking-at "\n")
2316 (progn 2371 (progn
2317 (forward-char) 2372 (forward-char)
2318 (vip-skip-all-separators-forward 'within-line)))) 2373 (viper-skip-all-separators-forward 'within-line))))
2319 (vip-skip-all-separators-backward 'within-line) 2374 (viper-skip-all-separators-backward 'within-line)
2320 (backward-char) 2375 (backward-char)
2321 (if (looking-at "\n") 2376 (if (looking-at "\n")
2322 (vip-skip-all-separators-backward 'within-line) 2377 (viper-skip-all-separators-backward 'within-line)
2323 (forward-char)))) 2378 (forward-char))))
2324 2379
2325 (defun vip-forward-word-kernel (val) 2380 (defun viper-forward-word-kernel (val)
2326 (while (> val 0) 2381 (while (> val 0)
2327 (cond ((vip-looking-at-alpha) 2382 (cond ((viper-looking-at-alpha)
2328 (vip-skip-alpha-forward "_") 2383 (viper-skip-alpha-forward "_")
2329 (vip-skip-separators t)) 2384 (viper-skip-separators t))
2330 ((vip-looking-at-separator) 2385 ((viper-looking-at-separator)
2331 (vip-skip-separators t)) 2386 (viper-skip-separators t))
2332 ((not (vip-looking-at-alphasep)) 2387 ((not (viper-looking-at-alphasep))
2333 (vip-skip-nonalphasep-forward) 2388 (viper-skip-nonalphasep-forward)
2334 (vip-skip-separators t))) 2389 (viper-skip-separators t)))
2335 (setq val (1- val)))) 2390 (setq val (1- val))))
2336 2391
2337 ;; first search backward for pat. Then skip chars backwards using aux-pat 2392 ;; first search backward for pat. Then skip chars backwards using aux-pat
2338 (defun vip-fwd-skip (pat aux-pat lim) 2393 (defun viper-fwd-skip (pat aux-pat lim)
2339 (if (and (save-excursion 2394 (if (and (save-excursion
2340 (re-search-backward pat lim t)) 2395 (re-search-backward pat lim t))
2341 (= (point) (match-end 0))) 2396 (= (point) (match-end 0)))
2342 (goto-char (match-beginning 0))) 2397 (goto-char (match-beginning 0)))
2343 (skip-chars-backward aux-pat lim) 2398 (skip-chars-backward aux-pat lim)
2344 (if (= (point) lim) 2399 (if (= (point) lim)
2345 (vip-forward-char-carefully)) 2400 (viper-forward-char-carefully))
2346 ) 2401 )
2347 2402
2348 2403
2349 (defun vip-forward-word (arg) 2404 (defun viper-forward-word (arg)
2350 "Forward word." 2405 "Forward word."
2351 (interactive "P") 2406 (interactive "P")
2352 (vip-leave-region-active) 2407 (viper-leave-region-active)
2353 (let ((val (vip-p-val arg)) 2408 (let ((val (viper-p-val arg))
2354 (com (vip-getcom arg))) 2409 (com (viper-getcom arg)))
2355 (if com (vip-move-marker-locally 'vip-com-point (point))) 2410 (if com (viper-move-marker-locally 'viper-com-point (point)))
2356 (vip-forward-word-kernel val) 2411 (viper-forward-word-kernel val)
2357 (if com (progn 2412 (if com (progn
2358 (cond ((memq com (list ?c (- ?c))) 2413 (cond ((memq com (list ?c (- ?c)))
2359 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) 2414 (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point))
2360 ;; Yank words including the whitespace, but not newline 2415 ;; Yank words including the whitespace, but not newline
2361 ((memq com (list ?y (- ?y))) 2416 ((memq com (list ?y (- ?y)))
2362 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) 2417 (viper-fwd-skip "\n[ \t]*" "" viper-com-point))
2363 ((vip-dotable-command-p com) 2418 ((viper-dotable-command-p com)
2364 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) 2419 (viper-fwd-skip "\n[ \t]*" "" viper-com-point)))
2365 (vip-execute-com 'vip-forward-word val com))))) 2420 (viper-execute-com 'viper-forward-word val com)))))
2366 2421
2367 2422
2368 (defun vip-forward-Word (arg) 2423 (defun viper-forward-Word (arg)
2369 "Forward word delimited by white characters." 2424 "Forward word delimited by white characters."
2370 (interactive "P") 2425 (interactive "P")
2371 (vip-leave-region-active) 2426 (viper-leave-region-active)
2372 (let ((val (vip-p-val arg)) 2427 (let ((val (viper-p-val arg))
2373 (com (vip-getcom arg))) 2428 (com (viper-getcom arg)))
2374 (if com (vip-move-marker-locally 'vip-com-point (point))) 2429 (if com (viper-move-marker-locally 'viper-com-point (point)))
2375 (vip-loop val 2430 (viper-loop val
2376 (progn 2431 (progn
2377 (vip-skip-nonseparators 'forward) 2432 (viper-skip-nonseparators 'forward)
2378 (vip-skip-separators t))) 2433 (viper-skip-separators t)))
2379 (if com (progn 2434 (if com (progn
2380 (cond ((memq com (list ?c (- ?c))) 2435 (cond ((memq com (list ?c (- ?c)))
2381 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) 2436 (viper-fwd-skip "\n[ \t]*" " \t" viper-com-point))
2382 ;; Yank words including the whitespace, but not newline 2437 ;; Yank words including the whitespace, but not newline
2383 ((memq com (list ?y (- ?y))) 2438 ((memq com (list ?y (- ?y)))
2384 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) 2439 (viper-fwd-skip "\n[ \t]*" "" viper-com-point))
2385 ((vip-dotable-command-p com) 2440 ((viper-dotable-command-p com)
2386 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) 2441 (viper-fwd-skip "\n[ \t]*" "" viper-com-point)))
2387 (vip-execute-com 'vip-forward-Word val com))))) 2442 (viper-execute-com 'viper-forward-Word val com)))))
2388 2443
2389 2444
2390 ;; this is a bit different from Vi, but Vi's end of word 2445 ;; this is a bit different from Vi, but Vi's end of word
2391 ;; makes no sense whatsoever 2446 ;; makes no sense whatsoever
2392 (defun vip-end-of-word-kernel () 2447 (defun viper-end-of-word-kernel ()
2393 (if (vip-end-of-word-p) (forward-char)) 2448 (if (viper-end-of-word-p) (forward-char))
2394 (if (vip-looking-at-separator) 2449 (if (viper-looking-at-separator)
2395 (vip-skip-all-separators-forward)) 2450 (viper-skip-all-separators-forward))
2396 2451
2397 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_")) 2452 (cond ((viper-looking-at-alpha) (viper-skip-alpha-forward "_"))
2398 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward))) 2453 ((not (viper-looking-at-alphasep)) (viper-skip-nonalphasep-forward)))
2399 (vip-backward-char-carefully)) 2454 (viper-backward-char-carefully))
2400 2455
2401 (defun vip-end-of-word-p () 2456 (defun viper-end-of-word-p ()
2402 (or (eobp) 2457 (or (eobp)
2403 (save-excursion 2458 (save-excursion
2404 (cond ((vip-looking-at-alpha) 2459 (cond ((viper-looking-at-alpha)
2405 (forward-char) 2460 (forward-char)
2406 (not (vip-looking-at-alpha))) 2461 (not (viper-looking-at-alpha)))
2407 ((not (vip-looking-at-alphasep)) 2462 ((not (viper-looking-at-alphasep))
2408 (forward-char) 2463 (forward-char)
2409 (vip-looking-at-alphasep)))))) 2464 (viper-looking-at-alphasep))))))
2410 2465
2411 2466
2412 (defun vip-end-of-word (arg &optional careful) 2467 (defun viper-end-of-word (arg &optional careful)
2413 "Move point to end of current word." 2468 "Move point to end of current word."
2414 (interactive "P") 2469 (interactive "P")
2415 (vip-leave-region-active) 2470 (viper-leave-region-active)
2416 (let ((val (vip-p-val arg)) 2471 (let ((val (viper-p-val arg))
2417 (com (vip-getcom arg))) 2472 (com (viper-getcom arg)))
2418 (if com (vip-move-marker-locally 'vip-com-point (point))) 2473 (if com (viper-move-marker-locally 'viper-com-point (point)))
2419 (vip-loop val (vip-end-of-word-kernel)) 2474 (viper-loop val (viper-end-of-word-kernel))
2420 (if com 2475 (if com
2421 (progn 2476 (progn
2422 (forward-char) 2477 (forward-char)
2423 (vip-execute-com 'vip-end-of-word val com))))) 2478 (viper-execute-com 'viper-end-of-word val com)))))
2424 2479
2425 (defun vip-end-of-Word (arg) 2480 (defun viper-end-of-Word (arg)
2426 "Forward to end of word delimited by white character." 2481 "Forward to end of word delimited by white character."
2427 (interactive "P") 2482 (interactive "P")
2428 (vip-leave-region-active) 2483 (viper-leave-region-active)
2429 (let ((val (vip-p-val arg)) 2484 (let ((val (viper-p-val arg))
2430 (com (vip-getcom arg))) 2485 (com (viper-getcom arg)))
2431 (if com (vip-move-marker-locally 'vip-com-point (point))) 2486 (if com (viper-move-marker-locally 'viper-com-point (point)))
2432 (vip-loop val 2487 (viper-loop val
2433 (progn 2488 (progn
2434 (vip-end-of-word-kernel) 2489 (viper-end-of-word-kernel)
2435 (vip-skip-nonseparators 'forward) 2490 (viper-skip-nonseparators 'forward)
2436 (backward-char))) 2491 (backward-char)))
2437 (if com 2492 (if com
2438 (progn 2493 (progn
2439 (forward-char) 2494 (forward-char)
2440 (vip-execute-com 'vip-end-of-Word val com))))) 2495 (viper-execute-com 'viper-end-of-Word val com)))))
2441 2496
2442 (defun vip-backward-word-kernel (val) 2497 (defun viper-backward-word-kernel (val)
2443 (while (> val 0) 2498 (while (> val 0)
2444 (backward-char) 2499 (backward-char)
2445 (cond ((vip-looking-at-alpha) 2500 (cond ((viper-looking-at-alpha)
2446 (vip-skip-alpha-backward "_")) 2501 (viper-skip-alpha-backward "_"))
2447 ((vip-looking-at-separator) 2502 ((viper-looking-at-separator)
2448 (forward-char) 2503 (forward-char)
2449 (vip-skip-separators nil) 2504 (viper-skip-separators nil)
2450 (backward-char) 2505 (backward-char)
2451 (cond ((vip-looking-at-alpha) 2506 (cond ((viper-looking-at-alpha)
2452 (vip-skip-alpha-backward "_")) 2507 (viper-skip-alpha-backward "_"))
2453 ((not (vip-looking-at-alphasep)) 2508 ((not (viper-looking-at-alphasep))
2454 (vip-skip-nonalphasep-backward)) 2509 (viper-skip-nonalphasep-backward))
2455 (t (forward-char)))) 2510 (t (forward-char))))
2456 ((not (vip-looking-at-alphasep)) 2511 ((not (viper-looking-at-alphasep))
2457 (vip-skip-nonalphasep-backward))) 2512 (viper-skip-nonalphasep-backward)))
2458 (setq val (1- val)))) 2513 (setq val (1- val))))
2459 2514
2460 (defun vip-backward-word (arg) 2515 (defun viper-backward-word (arg)
2461 "Backward word." 2516 "Backward word."
2462 (interactive "P") 2517 (interactive "P")
2463 (vip-leave-region-active) 2518 (viper-leave-region-active)
2464 (let ((val (vip-p-val arg)) 2519 (let ((val (viper-p-val arg))
2465 (com (vip-getcom arg))) 2520 (com (viper-getcom arg)))
2466 (if com 2521 (if com
2467 (let (i) 2522 (let (i)
2468 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) 2523 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
2469 (backward-char)) 2524 (backward-char))
2470 (vip-move-marker-locally 'vip-com-point (point)) 2525 (viper-move-marker-locally 'viper-com-point (point))
2471 (if i (forward-char)))) 2526 (if i (forward-char))))
2472 (vip-backward-word-kernel val) 2527 (viper-backward-word-kernel val)
2473 (if com (vip-execute-com 'vip-backward-word val com)))) 2528 (if com (viper-execute-com 'viper-backward-word val com))))
2474 2529
2475 (defun vip-backward-Word (arg) 2530 (defun viper-backward-Word (arg)
2476 "Backward word delimited by white character." 2531 "Backward word delimited by white character."
2477 (interactive "P") 2532 (interactive "P")
2478 (vip-leave-region-active) 2533 (viper-leave-region-active)
2479 (let ((val (vip-p-val arg)) 2534 (let ((val (viper-p-val arg))
2480 (com (vip-getcom arg))) 2535 (com (viper-getcom arg)))
2481 (if com 2536 (if com
2482 (let (i) 2537 (let (i)
2483 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) 2538 (if (setq i (save-excursion (backward-char) (looking-at "\n")))
2484 (backward-char)) 2539 (backward-char))
2485 (vip-move-marker-locally 'vip-com-point (point)) 2540 (viper-move-marker-locally 'viper-com-point (point))
2486 (if i (forward-char)))) 2541 (if i (forward-char))))
2487 (vip-loop val 2542 (viper-loop val
2488 (progn 2543 (progn
2489 (vip-skip-separators nil) 2544 (viper-skip-separators nil)
2490 (vip-skip-nonseparators 'backward))) 2545 (viper-skip-nonseparators 'backward)))
2491 (if com (vip-execute-com 'vip-backward-Word val com)))) 2546 (if com (viper-execute-com 'viper-backward-Word val com))))
2492 2547
2493 2548
2494 2549
2495 ;; line commands 2550 ;; line commands
2496 2551
2497 (defun vip-beginning-of-line (arg) 2552 (defun viper-beginning-of-line (arg)
2498 "Go to beginning of line." 2553 "Go to beginning of line."
2499 (interactive "P") 2554 (interactive "P")
2500 (vip-leave-region-active) 2555 (viper-leave-region-active)
2501 (let ((val (vip-p-val arg)) 2556 (let ((val (viper-p-val arg))
2502 (com (vip-getcom arg))) 2557 (com (viper-getcom arg)))
2503 (if com (vip-move-marker-locally 'vip-com-point (point))) 2558 (if com (viper-move-marker-locally 'viper-com-point (point)))
2504 (beginning-of-line val) 2559 (beginning-of-line val)
2505 (if com (vip-execute-com 'vip-beginning-of-line val com)))) 2560 (if com (viper-execute-com 'viper-beginning-of-line val com))))
2506 2561
2507 (defun vip-bol-and-skip-white (arg) 2562 (defun viper-bol-and-skip-white (arg)
2508 "Beginning of line at first non-white character." 2563 "Beginning of line at first non-white character."
2509 (interactive "P") 2564 (interactive "P")
2510 (vip-leave-region-active) 2565 (viper-leave-region-active)
2511 (let ((val (vip-p-val arg)) 2566 (let ((val (viper-p-val arg))
2512 (com (vip-getcom arg))) 2567 (com (viper-getcom arg)))
2513 (if com (vip-move-marker-locally 'vip-com-point (point))) 2568 (if com (viper-move-marker-locally 'viper-com-point (point)))
2514 (forward-to-indentation (1- val)) 2569 (forward-to-indentation (1- val))
2515 (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) 2570 (if com (viper-execute-com 'viper-bol-and-skip-white val com))))
2516 2571
2517 (defun vip-goto-eol (arg) 2572 (defun viper-goto-eol (arg)
2518 "Go to end of line." 2573 "Go to end of line."
2519 (interactive "P") 2574 (interactive "P")
2520 (vip-leave-region-active) 2575 (viper-leave-region-active)
2521 (let ((val (vip-p-val arg)) 2576 (let ((val (viper-p-val arg))
2522 (com (vip-getcom arg))) 2577 (com (viper-getcom arg)))
2523 (if com (vip-move-marker-locally 'vip-com-point (point))) 2578 (if com (viper-move-marker-locally 'viper-com-point (point)))
2524 (end-of-line val) 2579 (end-of-line val)
2525 (if com (vip-execute-com 'vip-goto-eol val com)) 2580 (if com (viper-execute-com 'viper-goto-eol val com))
2526 (if vip-ex-style-motion 2581 (if viper-ex-style-motion
2527 (if (and (eolp) (not (bolp)) 2582 (if (and (eolp) (not (bolp))
2528 ;; a fix for vip-change-to-eol 2583 ;; a fix for viper-change-to-eol
2529 (not (equal vip-current-state 'insert-state))) 2584 (not (equal viper-current-state 'insert-state)))
2530 (backward-char 1) 2585 (backward-char 1)
2531 )))) 2586 ))))
2532 2587
2533 2588
2534 (defun vip-goto-col (arg) 2589 (defun viper-goto-col (arg)
2535 "Go to ARG's column." 2590 "Go to ARG's column."
2536 (interactive "P") 2591 (interactive "P")
2537 (vip-leave-region-active) 2592 (viper-leave-region-active)
2538 (let ((val (vip-p-val arg)) 2593 (let ((val (viper-p-val arg))
2539 (com (vip-getcom arg)) 2594 (com (viper-getcom arg))
2540 line-len) 2595 line-len)
2541 (setq line-len (- (vip-line-pos 'end) (vip-line-pos 'start))) 2596 (setq line-len (- (viper-line-pos 'end) (viper-line-pos 'start)))
2542 (if com (vip-move-marker-locally 'vip-com-point (point))) 2597 (if com (viper-move-marker-locally 'viper-com-point (point)))
2543 (beginning-of-line) 2598 (beginning-of-line)
2544 (forward-char (1- (min line-len val))) 2599 (forward-char (1- (min line-len val)))
2545 (while (> (current-column) (1- val)) 2600 (while (> (current-column) (1- val))
2546 (backward-char 1)) 2601 (backward-char 1))
2547 (if com (vip-execute-com 'vip-goto-col val com)) 2602 (if com (viper-execute-com 'viper-goto-col val com))
2548 (save-excursion 2603 (save-excursion
2549 (end-of-line) 2604 (end-of-line)
2550 (if (> val (current-column)) (error ""))) 2605 (if (> val (current-column)) (error "")))
2551 )) 2606 ))
2552 2607
2553 2608
2554 (defun vip-next-line (arg) 2609 (defun viper-next-line (arg)
2555 "Go to next line." 2610 "Go to next line."
2556 (interactive "P") 2611 (interactive "P")
2557 (vip-leave-region-active) 2612 (viper-leave-region-active)
2558 (let ((val (vip-p-val arg)) 2613 (let ((val (viper-p-val arg))
2559 (com (vip-getCom arg))) 2614 (com (viper-getCom arg)))
2560 (if com (vip-move-marker-locally 'vip-com-point (point))) 2615 (if com (viper-move-marker-locally 'viper-com-point (point)))
2561 (next-line val) 2616 (next-line val)
2562 (if vip-ex-style-motion 2617 (if viper-ex-style-motion
2563 (if (and (eolp) (not (bolp))) (backward-char 1))) 2618 (if (and (eolp) (not (bolp))) (backward-char 1)))
2564 (setq this-command 'next-line) 2619 (setq this-command 'next-line)
2565 (if com (vip-execute-com 'vip-next-line val com)))) 2620 (if com (viper-execute-com 'viper-next-line val com))))
2566 2621
2567 (defun vip-next-line-at-bol (arg) 2622 (defun viper-next-line-at-bol (arg)
2568 "Next line at beginning of line." 2623 "Next line at beginning of line."
2569 (interactive "P") 2624 (interactive "P")
2570 (vip-leave-region-active) 2625 (viper-leave-region-active)
2571 (save-excursion 2626 (save-excursion
2572 (end-of-line) 2627 (end-of-line)
2573 (if (eobp) (error "Last line in buffer"))) 2628 (if (eobp) (error "Last line in buffer")))
2574 (let ((val (vip-p-val arg)) 2629 (let ((val (viper-p-val arg))
2575 (com (vip-getCom arg))) 2630 (com (viper-getCom arg)))
2576 (if com (vip-move-marker-locally 'vip-com-point (point))) 2631 (if com (viper-move-marker-locally 'viper-com-point (point)))
2577 (forward-line val) 2632 (forward-line val)
2578 (back-to-indentation) 2633 (back-to-indentation)
2579 (if com (vip-execute-com 'vip-next-line-at-bol val com)))) 2634 (if com (viper-execute-com 'viper-next-line-at-bol val com))))
2580 2635
2581 (defun vip-previous-line (arg) 2636 (defun viper-previous-line (arg)
2582 "Go to previous line." 2637 "Go to previous line."
2583 (interactive "P") 2638 (interactive "P")
2584 (vip-leave-region-active) 2639 (viper-leave-region-active)
2585 (let ((val (vip-p-val arg)) 2640 (let ((val (viper-p-val arg))
2586 (com (vip-getCom arg))) 2641 (com (viper-getCom arg)))
2587 (if com (vip-move-marker-locally 'vip-com-point (point))) 2642 (if com (viper-move-marker-locally 'viper-com-point (point)))
2588 (previous-line val) 2643 (previous-line val)
2589 (if vip-ex-style-motion 2644 (if viper-ex-style-motion
2590 (if (and (eolp) (not (bolp))) (backward-char 1))) 2645 (if (and (eolp) (not (bolp))) (backward-char 1)))
2591 (setq this-command 'previous-line) 2646 (setq this-command 'previous-line)
2592 (if com (vip-execute-com 'vip-previous-line val com)))) 2647 (if com (viper-execute-com 'viper-previous-line val com))))
2593 2648
2594 2649
2595 (defun vip-previous-line-at-bol (arg) 2650 (defun viper-previous-line-at-bol (arg)
2596 "Previous line at beginning of line." 2651 "Previous line at beginning of line."
2597 (interactive "P") 2652 (interactive "P")
2598 (vip-leave-region-active) 2653 (viper-leave-region-active)
2599 (save-excursion 2654 (save-excursion
2600 (beginning-of-line) 2655 (beginning-of-line)
2601 (if (bobp) (error "First line in buffer"))) 2656 (if (bobp) (error "First line in buffer")))
2602 (let ((val (vip-p-val arg)) 2657 (let ((val (viper-p-val arg))
2603 (com (vip-getCom arg))) 2658 (com (viper-getCom arg)))
2604 (if com (vip-move-marker-locally 'vip-com-point (point))) 2659 (if com (viper-move-marker-locally 'viper-com-point (point)))
2605 (forward-line (- val)) 2660 (forward-line (- val))
2606 (back-to-indentation) 2661 (back-to-indentation)
2607 (if com (vip-execute-com 'vip-previous-line val com)))) 2662 (if com (viper-execute-com 'viper-previous-line val com))))
2608 2663
2609 (defun vip-change-to-eol (arg) 2664 (defun viper-change-to-eol (arg)
2610 "Change to end of line." 2665 "Change to end of line."
2611 (interactive "P") 2666 (interactive "P")
2612 (vip-goto-eol (cons arg ?c))) 2667 (viper-goto-eol (cons arg ?c)))
2613 2668
2614 (defun vip-kill-line (arg) 2669 (defun viper-kill-line (arg)
2615 "Delete line." 2670 "Delete line."
2616 (interactive "P") 2671 (interactive "P")
2617 (vip-goto-eol (cons arg ?d))) 2672 (viper-goto-eol (cons arg ?d)))
2618 2673
2619 (defun vip-erase-line (arg) 2674 (defun viper-erase-line (arg)
2620 "Erase line." 2675 "Erase line."
2621 (interactive "P") 2676 (interactive "P")
2622 (vip-beginning-of-line (cons arg ?d))) 2677 (viper-beginning-of-line (cons arg ?d)))
2623 2678
2624 2679
2625 ;;; Moving around 2680 ;;; Moving around
2626 2681
2627 (defun vip-goto-line (arg) 2682 (defun viper-goto-line (arg)
2628 "Go to ARG's line. Without ARG go to end of buffer." 2683 "Go to ARG's line. Without ARG go to end of buffer."
2629 (interactive "P") 2684 (interactive "P")
2630 (let ((val (vip-P-val arg)) 2685 (let ((val (viper-P-val arg))
2631 (com (vip-getCom arg))) 2686 (com (viper-getCom arg)))
2632 (vip-move-marker-locally 'vip-com-point (point)) 2687 (viper-move-marker-locally 'viper-com-point (point))
2633 (vip-deactivate-mark) 2688 (viper-deactivate-mark)
2634 (push-mark nil t) 2689 (push-mark nil t)
2635 (if (null val) 2690 (if (null val)
2636 (goto-char (point-max)) 2691 (goto-char (point-max))
2637 (goto-char (point-min)) 2692 (goto-char (point-min))
2638 (forward-line (1- val))) 2693 (forward-line (1- val)))
2639 2694
2640 ;; positioning is done twice: before and after command execution 2695 ;; positioning is done twice: before and after command execution
2641 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2696 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2642 (back-to-indentation) 2697 (back-to-indentation)
2643 2698
2644 (if com (vip-execute-com 'vip-goto-line val com)) 2699 (if com (viper-execute-com 'viper-goto-line val com))
2645 2700
2646 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2701 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2647 (back-to-indentation) 2702 (back-to-indentation)
2648 )) 2703 ))
2649 2704
2650 ;; Find ARG's occurrence of CHAR on the current line. 2705 ;; Find ARG's occurrence of CHAR on the current line.
2651 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to 2706 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to
2652 ;; adjust point after search. 2707 ;; adjust point after search.
2653 (defun vip-find-char (arg char forward offset) 2708 (defun viper-find-char (arg char forward offset)
2654 (or (char-or-string-p char) (error "")) 2709 (or (char-or-string-p char) (error ""))
2655 (let ((arg (if forward arg (- arg))) 2710 (let ((arg (if forward arg (- arg)))
2656 (cmd (if (eq vip-intermediate-command 'vip-repeat) 2711 (cmd (if (eq viper-intermediate-command 'viper-repeat)
2657 (nth 5 vip-d-com) 2712 (nth 5 viper-d-com)
2658 (vip-array-to-string (this-command-keys)))) 2713 (viper-array-to-string (this-command-keys))))
2659 point) 2714 point)
2660 (save-excursion 2715 (save-excursion
2661 (save-restriction 2716 (save-restriction
2662 (if (> arg 0) 2717 (if (> arg 0)
2663 (narrow-to-region 2718 (narrow-to-region
2678 (search-forward (char-to-string char) nil 0 arg)) 2733 (search-forward (char-to-string char) nil 0 arg))
2679 (setq point (point)) 2734 (setq point (point))
2680 (error "Command `%s': `%c' not found" cmd char)))) 2735 (error "Command `%s': `%c' not found" cmd char))))
2681 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) 2736 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
2682 2737
2683 (defun vip-find-char-forward (arg) 2738 (defun viper-find-char-forward (arg)
2684 "Find char on the line. 2739 "Find char on the line.
2685 If called interactively read the char to find from the terminal, and if 2740 If called interactively read the char to find from the terminal, and if
2686 called from vip-repeat, the char last used is used. This behaviour is 2741 called from viper-repeat, the char last used is used. This behaviour is
2687 controlled by the sign of prefix numeric value." 2742 controlled by the sign of prefix numeric value."
2688 (interactive "P") 2743 (interactive "P")
2689 (let ((val (vip-p-val arg)) 2744 (let ((val (viper-p-val arg))
2690 (com (vip-getcom arg)) 2745 (com (viper-getcom arg))
2691 (cmd-representation (nth 5 vip-d-com))) 2746 (cmd-representation (nth 5 viper-d-com)))
2692 (if (> val 0) 2747 (if (> val 0)
2693 ;; this means that the function was called interactively 2748 ;; this means that the function was called interactively
2694 (setq vip-f-char (read-char) 2749 (setq viper-f-char (read-char)
2695 vip-f-forward t 2750 viper-f-forward t
2696 vip-f-offset nil) 2751 viper-f-offset nil)
2697 ;; vip-repeat --- set vip-F-char from command-keys 2752 ;; viper-repeat --- set viper-F-char from command-keys
2698 (setq vip-F-char (if (stringp cmd-representation) 2753 (setq viper-F-char (if (stringp cmd-representation)
2699 (vip-seq-last-elt cmd-representation) 2754 (viper-seq-last-elt cmd-representation)
2700 vip-F-char) 2755 viper-F-char)
2701 vip-f-char vip-F-char) 2756 viper-f-char viper-F-char)
2702 (setq val (- val))) 2757 (setq val (- val)))
2703 (if com (vip-move-marker-locally 'vip-com-point (point))) 2758 (if com (viper-move-marker-locally 'viper-com-point (point)))
2704 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) 2759 (viper-find-char
2760 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t nil)
2705 (setq val (- val)) 2761 (setq val (- val))
2706 (if com 2762 (if com
2707 (progn 2763 (progn
2708 (setq vip-F-char vip-f-char) ; set new vip-F-char 2764 (setq viper-F-char viper-f-char) ; set new viper-F-char
2709 (forward-char) 2765 (forward-char)
2710 (vip-execute-com 'vip-find-char-forward val com))))) 2766 (viper-execute-com 'viper-find-char-forward val com)))))
2711 2767
2712 (defun vip-goto-char-forward (arg) 2768 (defun viper-goto-char-forward (arg)
2713 "Go up to char ARG forward on line." 2769 "Go up to char ARG forward on line."
2714 (interactive "P") 2770 (interactive "P")
2715 (let ((val (vip-p-val arg)) 2771 (let ((val (viper-p-val arg))
2716 (com (vip-getcom arg)) 2772 (com (viper-getcom arg))
2717 (cmd-representation (nth 5 vip-d-com))) 2773 (cmd-representation (nth 5 viper-d-com)))
2718 (if (> val 0) 2774 (if (> val 0)
2719 ;; this means that the function was called interactively 2775 ;; this means that the function was called interactively
2720 (setq vip-f-char (read-char) 2776 (setq viper-f-char (read-char)
2721 vip-f-forward t 2777 viper-f-forward t
2722 vip-f-offset t) 2778 viper-f-offset t)
2723 ;; vip-repeat --- set vip-F-char from command-keys 2779 ;; viper-repeat --- set viper-F-char from command-keys
2724 (setq vip-F-char (if (stringp cmd-representation) 2780 (setq viper-F-char (if (stringp cmd-representation)
2725 (vip-seq-last-elt cmd-representation) 2781 (viper-seq-last-elt cmd-representation)
2726 vip-F-char) 2782 viper-F-char)
2727 vip-f-char vip-F-char) 2783 viper-f-char viper-F-char)
2728 (setq val (- val))) 2784 (setq val (- val)))
2729 (if com (vip-move-marker-locally 'vip-com-point (point))) 2785 (if com (viper-move-marker-locally 'viper-com-point (point)))
2730 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) 2786 (viper-find-char
2787 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) t t)
2731 (setq val (- val)) 2788 (setq val (- val))
2732 (if com 2789 (if com
2733 (progn 2790 (progn
2734 (setq vip-F-char vip-f-char) ; set new vip-F-char 2791 (setq viper-F-char viper-f-char) ; set new viper-F-char
2735 (forward-char) 2792 (forward-char)
2736 (vip-execute-com 'vip-goto-char-forward val com))))) 2793 (viper-execute-com 'viper-goto-char-forward val com)))))
2737 2794
2738 (defun vip-find-char-backward (arg) 2795 (defun viper-find-char-backward (arg)
2739 "Find char ARG on line backward." 2796 "Find char ARG on line backward."
2740 (interactive "P") 2797 (interactive "P")
2741 (let ((val (vip-p-val arg)) 2798 (let ((val (viper-p-val arg))
2742 (com (vip-getcom arg)) 2799 (com (viper-getcom arg))
2743 (cmd-representation (nth 5 vip-d-com))) 2800 (cmd-representation (nth 5 viper-d-com)))
2744 (if (> val 0) 2801 (if (> val 0)
2745 ;; this means that the function was called interactively 2802 ;; this means that the function was called interactively
2746 (setq vip-f-char (read-char) 2803 (setq viper-f-char (read-char)
2747 vip-f-forward nil 2804 viper-f-forward nil
2748 vip-f-offset nil) 2805 viper-f-offset nil)
2749 ;; vip-repeat --- set vip-F-char from command-keys 2806 ;; viper-repeat --- set viper-F-char from command-keys
2750 (setq vip-F-char (if (stringp cmd-representation) 2807 (setq viper-F-char (if (stringp cmd-representation)
2751 (vip-seq-last-elt cmd-representation) 2808 (viper-seq-last-elt cmd-representation)
2752 vip-F-char) 2809 viper-F-char)
2753 vip-f-char vip-F-char) 2810 viper-f-char viper-F-char)
2754 (setq val (- val))) 2811 (setq val (- val)))
2755 (if com (vip-move-marker-locally 'vip-com-point (point))) 2812 (if com (viper-move-marker-locally 'viper-com-point (point)))
2756 (vip-find-char 2813 (viper-find-char
2757 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) 2814 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil nil)
2758 (setq val (- val)) 2815 (setq val (- val))
2759 (if com 2816 (if com
2760 (progn 2817 (progn
2761 (setq vip-F-char vip-f-char) ; set new vip-F-char 2818 (setq viper-F-char viper-f-char) ; set new viper-F-char
2762 (vip-execute-com 'vip-find-char-backward val com))))) 2819 (viper-execute-com 'viper-find-char-backward val com)))))
2763 2820
2764 (defun vip-goto-char-backward (arg) 2821 (defun viper-goto-char-backward (arg)
2765 "Go up to char ARG backward on line." 2822 "Go up to char ARG backward on line."
2766 (interactive "P") 2823 (interactive "P")
2767 (let ((val (vip-p-val arg)) 2824 (let ((val (viper-p-val arg))
2768 (com (vip-getcom arg)) 2825 (com (viper-getcom arg))
2769 (cmd-representation (nth 5 vip-d-com))) 2826 (cmd-representation (nth 5 viper-d-com)))
2770 (if (> val 0) 2827 (if (> val 0)
2771 ;; this means that the function was called interactively 2828 ;; this means that the function was called interactively
2772 (setq vip-f-char (read-char) 2829 (setq viper-f-char (read-char)
2773 vip-f-forward nil 2830 viper-f-forward nil
2774 vip-f-offset t) 2831 viper-f-offset t)
2775 ;; vip-repeat --- set vip-F-char from command-keys 2832 ;; viper-repeat --- set viper-F-char from command-keys
2776 (setq vip-F-char (if (stringp cmd-representation) 2833 (setq viper-F-char (if (stringp cmd-representation)
2777 (vip-seq-last-elt cmd-representation) 2834 (viper-seq-last-elt cmd-representation)
2778 vip-F-char) 2835 viper-F-char)
2779 vip-f-char vip-F-char) 2836 viper-f-char viper-F-char)
2780 (setq val (- val))) 2837 (setq val (- val)))
2781 (if com (vip-move-marker-locally 'vip-com-point (point))) 2838 (if com (viper-move-marker-locally 'viper-com-point (point)))
2782 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) 2839 (viper-find-char
2840 val (if (> (viper-p-val arg) 0) viper-f-char viper-F-char) nil t)
2783 (setq val (- val)) 2841 (setq val (- val))
2784 (if com 2842 (if com
2785 (progn 2843 (progn
2786 (setq vip-F-char vip-f-char) ; set new vip-F-char 2844 (setq viper-F-char viper-f-char) ; set new viper-F-char
2787 (vip-execute-com 'vip-goto-char-backward val com))))) 2845 (viper-execute-com 'viper-goto-char-backward val com)))))
2788 2846
2789 (defun vip-repeat-find (arg) 2847 (defun viper-repeat-find (arg)
2790 "Repeat previous find command." 2848 "Repeat previous find command."
2791 (interactive "P") 2849 (interactive "P")
2792 (let ((val (vip-p-val arg)) 2850 (let ((val (viper-p-val arg))
2793 (com (vip-getcom arg))) 2851 (com (viper-getcom arg)))
2794 (vip-deactivate-mark) 2852 (viper-deactivate-mark)
2795 (if com (vip-move-marker-locally 'vip-com-point (point))) 2853 (if com (viper-move-marker-locally 'viper-com-point (point)))
2796 (vip-find-char val vip-f-char vip-f-forward vip-f-offset) 2854 (viper-find-char val viper-f-char viper-f-forward viper-f-offset)
2797 (if com 2855 (if com
2798 (progn 2856 (progn
2799 (if vip-f-forward (forward-char)) 2857 (if viper-f-forward (forward-char))
2800 (vip-execute-com 'vip-repeat-find val com))))) 2858 (viper-execute-com 'viper-repeat-find val com)))))
2801 2859
2802 (defun vip-repeat-find-opposite (arg) 2860 (defun viper-repeat-find-opposite (arg)
2803 "Repeat previous find command in the opposite direction." 2861 "Repeat previous find command in the opposite direction."
2804 (interactive "P") 2862 (interactive "P")
2805 (let ((val (vip-p-val arg)) 2863 (let ((val (viper-p-val arg))
2806 (com (vip-getcom arg))) 2864 (com (viper-getcom arg)))
2807 (vip-deactivate-mark) 2865 (viper-deactivate-mark)
2808 (if com (vip-move-marker-locally 'vip-com-point (point))) 2866 (if com (viper-move-marker-locally 'viper-com-point (point)))
2809 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) 2867 (viper-find-char val viper-f-char (not viper-f-forward) viper-f-offset)
2810 (if com 2868 (if com
2811 (progn 2869 (progn
2812 (if vip-f-forward (forward-char)) 2870 (if viper-f-forward (forward-char))
2813 (vip-execute-com 'vip-repeat-find-opposite val com))))) 2871 (viper-execute-com 'viper-repeat-find-opposite val com)))))
2814 2872
2815 2873
2816 ;; window scrolling etc. 2874 ;; window scrolling etc.
2817 2875
2818 (defun vip-other-window (arg) 2876 (defun viper-window-top (arg)
2819 "Switch to other window."
2820 (interactive "p")
2821 (other-window arg)
2822 (or (not (eq vip-current-state 'emacs-state))
2823 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
2824 (vip-change-state-to-vi)))
2825
2826 (defun vip-window-top (arg)
2827 "Go to home window line." 2877 "Go to home window line."
2828 (interactive "P") 2878 (interactive "P")
2829 (let ((val (vip-p-val arg)) 2879 (let ((val (viper-p-val arg))
2830 (com (vip-getCom arg))) 2880 (com (viper-getCom arg)))
2831 (if com (vip-move-marker-locally 'vip-com-point (point))) 2881 (if com (viper-move-marker-locally 'viper-com-point (point)))
2832 (push-mark nil t) 2882 (push-mark nil t)
2833 (move-to-window-line (1- val)) 2883 (move-to-window-line (1- val))
2834 2884
2835 ;; positioning is done twice: before and after command execution 2885 ;; positioning is done twice: before and after command execution
2836 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2886 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2837 (back-to-indentation) 2887 (back-to-indentation)
2838 2888
2839 (if com (vip-execute-com 'vip-window-top val com)) 2889 (if com (viper-execute-com 'viper-window-top val com))
2840 2890
2841 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2891 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2842 (back-to-indentation) 2892 (back-to-indentation)
2843 )) 2893 ))
2844 2894
2845 (defun vip-window-middle (arg) 2895 (defun viper-window-middle (arg)
2846 "Go to middle window line." 2896 "Go to middle window line."
2847 (interactive "P") 2897 (interactive "P")
2848 (let ((val (vip-p-val arg)) 2898 (let ((val (viper-p-val arg))
2849 (com (vip-getCom arg)) 2899 (com (viper-getCom arg))
2850 lines) 2900 lines)
2851 (if com (vip-move-marker-locally 'vip-com-point (point))) 2901 (if com (viper-move-marker-locally 'viper-com-point (point)))
2852 (push-mark nil t) 2902 (push-mark nil t)
2853 (if (not (pos-visible-in-window-p (point-max))) 2903 (if (not (pos-visible-in-window-p (point-max)))
2854 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) 2904 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
2855 (setq lines (count-lines (window-start) (point-max))) 2905 (setq lines (count-lines (window-start) (point-max)))
2856 (move-to-window-line (+ (/ lines 2) (1- val)))) 2906 (move-to-window-line (+ (/ lines 2) (1- val))))
2857 2907
2858 ;; positioning is done twice: before and after command execution 2908 ;; positioning is done twice: before and after command execution
2859 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2909 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2860 (back-to-indentation) 2910 (back-to-indentation)
2861 2911
2862 (if com (vip-execute-com 'vip-window-middle val com)) 2912 (if com (viper-execute-com 'viper-window-middle val com))
2863 2913
2864 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2914 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2865 (back-to-indentation) 2915 (back-to-indentation)
2866 )) 2916 ))
2867 2917
2868 (defun vip-window-bottom (arg) 2918 (defun viper-window-bottom (arg)
2869 "Go to last window line." 2919 "Go to last window line."
2870 (interactive "P") 2920 (interactive "P")
2871 (let ((val (vip-p-val arg)) 2921 (let ((val (viper-p-val arg))
2872 (com (vip-getCom arg))) 2922 (com (viper-getCom arg)))
2873 (if com (vip-move-marker-locally 'vip-com-point (point))) 2923 (if com (viper-move-marker-locally 'viper-com-point (point)))
2874 (push-mark nil t) 2924 (push-mark nil t)
2875 (move-to-window-line (- val)) 2925 (move-to-window-line (- val))
2876 2926
2877 ;; positioning is done twice: before and after command execution 2927 ;; positioning is done twice: before and after command execution
2878 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2928 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2879 (back-to-indentation) 2929 (back-to-indentation)
2880 2930
2881 (if com (vip-execute-com 'vip-window-bottom val com)) 2931 (if com (viper-execute-com 'viper-window-bottom val com))
2882 2932
2883 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) 2933 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
2884 (back-to-indentation) 2934 (back-to-indentation)
2885 )) 2935 ))
2886 2936
2887 (defun vip-line-to-top (arg) 2937 (defun viper-line-to-top (arg)
2888 "Put current line on the home line." 2938 "Put current line on the home line."
2889 (interactive "p") 2939 (interactive "p")
2890 (recenter (1- arg))) 2940 (recenter (1- arg)))
2891 2941
2892 (defun vip-line-to-middle (arg) 2942 (defun viper-line-to-middle (arg)
2893 "Put current line on the middle line." 2943 "Put current line on the middle line."
2894 (interactive "p") 2944 (interactive "p")
2895 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) 2945 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
2896 2946
2897 (defun vip-line-to-bottom (arg) 2947 (defun viper-line-to-bottom (arg)
2898 "Put current line on the last line." 2948 "Put current line on the last line."
2899 (interactive "p") 2949 (interactive "p")
2900 (recenter (- (window-height) (1+ arg)))) 2950 (recenter (- (window-height) (1+ arg))))
2901 2951
2902 ;; If point is within vip-search-scroll-threshold of window top or bottom, 2952 ;; If point is within viper-search-scroll-threshold of window top or bottom,
2903 ;; scroll up or down 1/7 of window height, depending on whether we are at the 2953 ;; scroll up or down 1/7 of window height, depending on whether we are at the
2904 ;; bottom or at the top of the window. This function is called by vip-search 2954 ;; bottom or at the top of the window. This function is called by viper-search
2905 ;; (which is called from vip-search-forward/backward/next). If the value of 2955 ;; (which is called from viper-search-forward/backward/next). If the value of
2906 ;; vip-search-scroll-threshold is negative - don't scroll. 2956 ;; viper-search-scroll-threshold is negative - don't scroll.
2907 (defun vip-adjust-window () 2957 (defun viper-adjust-window ()
2908 (let ((win-height (if vip-emacs-p 2958 (let ((win-height (if viper-emacs-p
2909 (1- (window-height)) ; adjust for modeline 2959 (1- (window-height)) ; adjust for modeline
2910 (window-displayed-height))) 2960 (window-displayed-height)))
2911 (pt (point)) 2961 (pt (point))
2912 at-top-p at-bottom-p 2962 at-top-p at-bottom-p
2913 min-scroll direction) 2963 min-scroll direction)
2914 (save-excursion 2964 (save-excursion
2915 (move-to-window-line 0) ; top 2965 (move-to-window-line 0) ; top
2916 (setq at-top-p 2966 (setq at-top-p
2917 (<= (count-lines pt (point)) 2967 (<= (count-lines pt (point))
2918 vip-search-scroll-threshold)) 2968 viper-search-scroll-threshold))
2919 (move-to-window-line -1) ; bottom 2969 (move-to-window-line -1) ; bottom
2920 (setq at-bottom-p 2970 (setq at-bottom-p
2921 (<= (count-lines pt (point)) vip-search-scroll-threshold)) 2971 (<= (count-lines pt (point)) viper-search-scroll-threshold))
2922 ) 2972 )
2923 (cond (at-top-p (setq min-scroll (1- vip-search-scroll-threshold) 2973 (cond (at-top-p (setq min-scroll (1- viper-search-scroll-threshold)
2924 direction 1)) 2974 direction 1))
2925 (at-bottom-p (setq min-scroll (1+ vip-search-scroll-threshold) 2975 (at-bottom-p (setq min-scroll (1+ viper-search-scroll-threshold)
2926 direction -1))) 2976 direction -1)))
2927 (if min-scroll 2977 (if min-scroll
2928 (recenter 2978 (recenter
2929 (* (max min-scroll (/ win-height 7)) direction))) 2979 (* (max min-scroll (/ win-height 7)) direction)))
2930 )) 2980 ))
2933 ;; paren match 2983 ;; paren match
2934 ;; must correct this to only match ( to ) etc. On the other hand 2984 ;; must correct this to only match ( to ) etc. On the other hand
2935 ;; it is good that paren match gets confused, because that way you 2985 ;; it is good that paren match gets confused, because that way you
2936 ;; catch _all_ imbalances. 2986 ;; catch _all_ imbalances.
2937 2987
2938 (defun vip-paren-match (arg) 2988 (defun viper-paren-match (arg)
2939 "Go to the matching parenthesis." 2989 "Go to the matching parenthesis."
2940 (interactive "P") 2990 (interactive "P")
2941 (vip-leave-region-active) 2991 (viper-leave-region-active)
2942 (let ((com (vip-getcom arg)) 2992 (let ((com (viper-getcom arg))
2943 (parse-sexp-ignore-comments vip-parse-sexp-ignore-comments) 2993 (parse-sexp-ignore-comments viper-parse-sexp-ignore-comments)
2944 anchor-point) 2994 anchor-point)
2945 (if (integerp arg) 2995 (if (integerp arg)
2946 (if (or (> arg 99) (< arg 1)) 2996 (if (or (> arg 99) (< arg 1))
2947 (error "Prefix must be between 1 and 99") 2997 (error "Prefix must be between 1 and 99")
2948 (goto-char 2998 (goto-char
2963 (backward-char) ) 3013 (backward-char) )
2964 ((re-search-backward "[][(){}]" beg-lim t)) 3014 ((re-search-backward "[][(){}]" beg-lim t))
2965 (t 3015 (t
2966 (error "No matching character on line")))) 3016 (error "No matching character on line"))))
2967 (cond ((looking-at "[\(\[{]") 3017 (cond ((looking-at "[\(\[{]")
2968 (if com (vip-move-marker-locally 'vip-com-point (point))) 3018 (if com (viper-move-marker-locally 'viper-com-point (point)))
2969 (forward-sexp 1) 3019 (forward-sexp 1)
2970 (if com 3020 (if com
2971 (vip-execute-com 'vip-paren-match nil com) 3021 (viper-execute-com 'viper-paren-match nil com)
2972 (backward-char))) 3022 (backward-char)))
2973 (anchor-point 3023 (anchor-point
2974 (if com 3024 (if com
2975 (progn 3025 (progn
2976 (vip-move-marker-locally 'vip-com-point anchor-point) 3026 (viper-move-marker-locally 'viper-com-point anchor-point)
2977 (forward-char 1) 3027 (forward-char 1)
2978 (vip-execute-com 'vip-paren-match nil com) 3028 (viper-execute-com 'viper-paren-match nil com)
2979 ))) 3029 )))
2980 ((looking-at "[])}]") 3030 ((looking-at "[])}]")
2981 (forward-char) 3031 (forward-char)
2982 (if com (vip-move-marker-locally 'vip-com-point (point))) 3032 (if com (viper-move-marker-locally 'viper-com-point (point)))
2983 (backward-sexp 1) 3033 (backward-sexp 1)
2984 (if com (vip-execute-com 'vip-paren-match nil com))) 3034 (if com (viper-execute-com 'viper-paren-match nil com)))
2985 (t (error "")))))) 3035 (t (error ""))))))
2986 3036
2987 (defun vip-toggle-parse-sexp-ignore-comments () 3037 (defun viper-toggle-parse-sexp-ignore-comments ()
2988 (interactive) 3038 (interactive)
2989 (setq vip-parse-sexp-ignore-comments (not vip-parse-sexp-ignore-comments)) 3039 (setq viper-parse-sexp-ignore-comments
3040 (not viper-parse-sexp-ignore-comments))
2990 (princ (format 3041 (princ (format
2991 "From now on, `%%' will %signore parentheses inside comment fields" 3042 "From now on, `%%' will %signore parentheses inside comment fields"
2992 (if vip-parse-sexp-ignore-comments "" "NOT ")))) 3043 (if viper-parse-sexp-ignore-comments "" "NOT "))))
2993 3044
2994 3045
2995 ;; sentence ,paragraph and heading 3046 ;; sentence ,paragraph and heading
2996 3047
2997 (defun vip-forward-sentence (arg) 3048 (defun viper-forward-sentence (arg)
2998 "Forward sentence." 3049 "Forward sentence."
2999 (interactive "P") 3050 (interactive "P")
3000 (push-mark nil t) 3051 (push-mark nil t)
3001 (let ((val (vip-p-val arg)) 3052 (let ((val (viper-p-val arg))
3002 (com (vip-getcom arg))) 3053 (com (viper-getcom arg)))
3003 (if com (vip-move-marker-locally 'vip-com-point (point))) 3054 (if com (viper-move-marker-locally 'viper-com-point (point)))
3004 (forward-sentence val) 3055 (forward-sentence val)
3005 (if com (vip-execute-com 'vip-forward-sentence nil com)))) 3056 (if com (viper-execute-com 'viper-forward-sentence nil com))))
3006 3057
3007 (defun vip-backward-sentence (arg) 3058 (defun viper-backward-sentence (arg)
3008 "Backward sentence." 3059 "Backward sentence."
3009 (interactive "P") 3060 (interactive "P")
3010 (push-mark nil t) 3061 (push-mark nil t)
3011 (let ((val (vip-p-val arg)) 3062 (let ((val (viper-p-val arg))
3012 (com (vip-getcom arg))) 3063 (com (viper-getcom arg)))
3013 (if com (vip-move-marker-locally 'vip-com-point (point))) 3064 (if com (viper-move-marker-locally 'viper-com-point (point)))
3014 (backward-sentence val) 3065 (backward-sentence val)
3015 (if com (vip-execute-com 'vip-backward-sentence nil com)))) 3066 (if com (viper-execute-com 'viper-backward-sentence nil com))))
3016 3067
3017 (defun vip-forward-paragraph (arg) 3068 (defun viper-forward-paragraph (arg)
3018 "Forward paragraph." 3069 "Forward paragraph."
3019 (interactive "P") 3070 (interactive "P")
3020 (push-mark nil t) 3071 (push-mark nil t)
3021 (let ((val (vip-p-val arg)) 3072 (let ((val (viper-p-val arg))
3022 (com (vip-getCom arg))) 3073 (com (viper-getCom arg)))
3023 (if com (vip-move-marker-locally 'vip-com-point (point))) 3074 (if com (viper-move-marker-locally 'viper-com-point (point)))
3024 (forward-paragraph val) 3075 (forward-paragraph val)
3025 (if com 3076 (if com
3026 (progn 3077 (progn
3027 (backward-char 1) 3078 (backward-char 1)
3028 (vip-execute-com 'vip-forward-paragraph nil com))))) 3079 (viper-execute-com 'viper-forward-paragraph nil com)))))
3029 3080
3030 (defun vip-backward-paragraph (arg) 3081 (defun viper-backward-paragraph (arg)
3031 "Backward paragraph." 3082 "Backward paragraph."
3032 (interactive "P") 3083 (interactive "P")
3033 (push-mark nil t) 3084 (push-mark nil t)
3034 (let ((val (vip-p-val arg)) 3085 (let ((val (viper-p-val arg))
3035 (com (vip-getCom arg))) 3086 (com (viper-getCom arg)))
3036 (if com (vip-move-marker-locally 'vip-com-point (point))) 3087 (if com (viper-move-marker-locally 'viper-com-point (point)))
3037 (backward-paragraph val) 3088 (backward-paragraph val)
3038 (if com 3089 (if com
3039 (progn 3090 (progn
3040 (forward-char 1) 3091 (forward-char 1)
3041 (vip-execute-com 'vip-backward-paragraph nil com) 3092 (viper-execute-com 'viper-backward-paragraph nil com)
3042 (backward-char 1))))) 3093 (backward-char 1)))))
3043 3094
3044 ;; should be mode-specific etc. 3095 ;; should be mode-specific etc.
3045 3096
3046 (defun vip-prev-heading (arg) 3097 (defun viper-prev-heading (arg)
3047 (interactive "P") 3098 (interactive "P")
3048 (let ((val (vip-p-val arg)) 3099 (let ((val (viper-p-val arg))
3049 (com (vip-getCom arg))) 3100 (com (viper-getCom arg)))
3050 (if com (vip-move-marker-locally 'vip-com-point (point))) 3101 (if com (viper-move-marker-locally 'viper-com-point (point)))
3051 (re-search-backward vip-heading-start nil t val) 3102 (re-search-backward viper-heading-start nil t val)
3052 (goto-char (match-beginning 0)) 3103 (goto-char (match-beginning 0))
3053 (if com (vip-execute-com 'vip-prev-heading nil com)))) 3104 (if com (viper-execute-com 'viper-prev-heading nil com))))
3054 3105
3055 (defun vip-heading-end (arg) 3106 (defun viper-heading-end (arg)
3056 (interactive "P") 3107 (interactive "P")
3057 (let ((val (vip-p-val arg)) 3108 (let ((val (viper-p-val arg))
3058 (com (vip-getCom arg))) 3109 (com (viper-getCom arg)))
3059 (if com (vip-move-marker-locally 'vip-com-point (point))) 3110 (if com (viper-move-marker-locally 'viper-com-point (point)))
3060 (re-search-forward vip-heading-end nil t val) 3111 (re-search-forward viper-heading-end nil t val)
3061 (goto-char (match-beginning 0)) 3112 (goto-char (match-beginning 0))
3062 (if com (vip-execute-com 'vip-heading-end nil com)))) 3113 (if com (viper-execute-com 'viper-heading-end nil com))))
3063 3114
3064 (defun vip-next-heading (arg) 3115 (defun viper-next-heading (arg)
3065 (interactive "P") 3116 (interactive "P")
3066 (let ((val (vip-p-val arg)) 3117 (let ((val (viper-p-val arg))
3067 (com (vip-getCom arg))) 3118 (com (viper-getCom arg)))
3068 (if com (vip-move-marker-locally 'vip-com-point (point))) 3119 (if com (viper-move-marker-locally 'viper-com-point (point)))
3069 (end-of-line) 3120 (end-of-line)
3070 (re-search-forward vip-heading-start nil t val) 3121 (re-search-forward viper-heading-start nil t val)
3071 (goto-char (match-beginning 0)) 3122 (goto-char (match-beginning 0))
3072 (if com (vip-execute-com 'vip-next-heading nil com)))) 3123 (if com (viper-execute-com 'viper-next-heading nil com))))
3073 3124
3074 3125
3075 ;; scrolling 3126 ;; scrolling
3076 3127
3077 (defun vip-scroll-screen (arg) 3128 (defun viper-scroll-screen (arg)
3078 "Scroll to next screen." 3129 "Scroll to next screen."
3079 (interactive "p") 3130 (interactive "p")
3080 (condition-case nil 3131 (condition-case nil
3081 (if (> arg 0) 3132 (if (> arg 0)
3082 (while (> arg 0) 3133 (while (> arg 0)
3092 (goto-char (point-max))) 3143 (goto-char (point-max)))
3093 (message "Beginning of buffer") 3144 (message "Beginning of buffer")
3094 (goto-char (point-min)))) 3145 (goto-char (point-min))))
3095 )) 3146 ))
3096 3147
3097 (defun vip-scroll-screen-back (arg) 3148 (defun viper-scroll-screen-back (arg)
3098 "Scroll to previous screen." 3149 "Scroll to previous screen."
3099 (interactive "p") 3150 (interactive "p")
3100 (vip-scroll-screen (- arg))) 3151 (viper-scroll-screen (- arg)))
3101 3152
3102 (defun vip-scroll-down (arg) 3153 (defun viper-scroll-down (arg)
3103 "Pull down half screen." 3154 "Pull down half screen."
3104 (interactive "P") 3155 (interactive "P")
3105 (condition-case nil 3156 (condition-case nil
3106 (if (null arg) 3157 (if (null arg)
3107 (scroll-down (/ (window-height) 2)) 3158 (scroll-down (/ (window-height) 2))
3108 (scroll-down arg)) 3159 (scroll-down arg))
3109 (error (beep 1) 3160 (error (beep 1)
3110 (message "Beginning of buffer") 3161 (message "Beginning of buffer")
3111 (goto-char (point-min))))) 3162 (goto-char (point-min)))))
3112 3163
3113 (defun vip-scroll-down-one (arg) 3164 (defun viper-scroll-down-one (arg)
3114 "Scroll up one line." 3165 "Scroll up one line."
3115 (interactive "p") 3166 (interactive "p")
3116 (scroll-down arg)) 3167 (scroll-down arg))
3117 3168
3118 (defun vip-scroll-up (arg) 3169 (defun viper-scroll-up (arg)
3119 "Pull up half screen." 3170 "Pull up half screen."
3120 (interactive "P") 3171 (interactive "P")
3121 (condition-case nil 3172 (condition-case nil
3122 (if (null arg) 3173 (if (null arg)
3123 (scroll-up (/ (window-height) 2)) 3174 (scroll-up (/ (window-height) 2))
3124 (scroll-up arg)) 3175 (scroll-up arg))
3125 (error (beep 1) 3176 (error (beep 1)
3126 (message "End of buffer") 3177 (message "End of buffer")
3127 (goto-char (point-max))))) 3178 (goto-char (point-max)))))
3128 3179
3129 (defun vip-scroll-up-one (arg) 3180 (defun viper-scroll-up-one (arg)
3130 "Scroll down one line." 3181 "Scroll down one line."
3131 (interactive "p") 3182 (interactive "p")
3132 (scroll-up arg)) 3183 (scroll-up arg))
3133 3184
3134 3185
3135 ;; searching 3186 ;; searching
3136 3187
3137 (defun vip-if-string (prompt) 3188 (defun viper-if-string (prompt)
3138 (let ((s (vip-read-string-with-history 3189 (if (memq viper-intermediate-command
3190 '(viper-command-argument viper-digit-argument viper-repeat))
3191 (setq viper-this-command-keys (this-command-keys)))
3192 (let ((s (viper-read-string-with-history
3139 prompt 3193 prompt
3140 nil ; no initial 3194 nil ; no initial
3141 'vip-search-history 3195 'viper-search-history
3142 (car vip-search-history)))) 3196 (car viper-search-history))))
3143 (if (not (string= s "")) 3197 (if (not (string= s ""))
3144 (setq vip-s-string s)))) 3198 (setq viper-s-string s))))
3145 3199
3146 3200
3147 (defun vip-toggle-search-style (arg) 3201 (defun viper-toggle-search-style (arg)
3148 "Toggle the value of vip-case-fold-search/vip-re-search. 3202 "Toggle the value of viper-case-fold-search/viper-re-search.
3149 Without prefix argument, will ask which search style to toggle. With prefix 3203 Without prefix argument, will ask which search style to toggle. With prefix
3150 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search. 3204 arg 1,toggles viper-case-fold-search; with arg 2 toggles viper-re-search.
3151 3205
3152 Although this function is bound to \\[vip-toggle-search-style], the most 3206 Although this function is bound to \\[viper-toggle-search-style], the most
3153 convenient way to use it is to bind `//' to the macro 3207 convenient way to use it is to bind `//' to the macro
3154 `1 M-x vip-toggle-search-style' and `///' to 3208 `1 M-x viper-toggle-search-style' and `///' to
3155 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will 3209 `2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will
3156 toggle case-fold-search and hitting `/' three times witth toggle regexp 3210 toggle case-fold-search and hitting `/' three times witth toggle regexp
3157 search. Macros are more convenient in this case because they don't affect 3211 search. Macros are more convenient in this case because they don't affect
3158 the Emacs binding of `/'." 3212 the Emacs binding of `/'."
3159 (interactive "P") 3213 (interactive "P")
3160 (let (msg) 3214 (let (msg)
3161 (cond ((or (eq arg 1) 3215 (cond ((or (eq arg 1)
3162 (and (null arg) 3216 (and (null arg)
3163 (y-or-n-p (format "Search style: '%s'. Want '%s'? " 3217 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
3164 (if vip-case-fold-search 3218 (if viper-case-fold-search
3165 "case-insensitive" "case-sensitive") 3219 "case-insensitive" "case-sensitive")
3166 (if vip-case-fold-search 3220 (if viper-case-fold-search
3167 "case-sensitive" 3221 "case-sensitive"
3168 "case-insensitive"))))) 3222 "case-insensitive")))))
3169 (setq vip-case-fold-search (null vip-case-fold-search)) 3223 (setq viper-case-fold-search (null viper-case-fold-search))
3170 (if vip-case-fold-search 3224 (if viper-case-fold-search
3171 (setq msg "Search becomes case-insensitive") 3225 (setq msg "Search becomes case-insensitive")
3172 (setq msg "Search becomes case-sensitive"))) 3226 (setq msg "Search becomes case-sensitive")))
3173 ((or (eq arg 2) 3227 ((or (eq arg 2)
3174 (and (null arg) 3228 (and (null arg)
3175 (y-or-n-p (format "Search style: '%s'. Want '%s'? " 3229 (y-or-n-p (format "Search style: '%s'. Want '%s'? "
3176 (if vip-re-search 3230 (if viper-re-search
3177 "regexp-search" "vanilla-search") 3231 "regexp-search" "vanilla-search")
3178 (if vip-re-search 3232 (if viper-re-search
3179 "vanilla-search" 3233 "vanilla-search"
3180 "regexp-search"))))) 3234 "regexp-search")))))
3181 (setq vip-re-search (null vip-re-search)) 3235 (setq viper-re-search (null viper-re-search))
3182 (if vip-re-search 3236 (if viper-re-search
3183 (setq msg "Search becomes regexp-style") 3237 (setq msg "Search becomes regexp-style")
3184 (setq msg "Search becomes vanilla-style"))) 3238 (setq msg "Search becomes vanilla-style")))
3185 (t 3239 (t
3186 (setq msg "Search style remains unchanged"))) 3240 (setq msg "Search style remains unchanged")))
3187 (princ msg t))) 3241 (princ msg t)))
3188 3242
3189 (defun vip-set-searchstyle-toggling-macros (unset) 3243 (defun viper-set-searchstyle-toggling-macros (unset)
3190 "Set the macros for toggling the search style in Viper's vi-state. 3244 "Set the macros for toggling the search style in Viper's vi-state.
3191 The macro that toggles case sensitivity is bound to `//', and the one that 3245 The macro that toggles case sensitivity is bound to `//', and the one that
3192 toggles regexp search is bound to `///'. 3246 toggles regexp search is bound to `///'.
3193 With a prefix argument, this function unsets the macros. " 3247 With a prefix argument, this function unsets the macros. "
3194 (interactive "P") 3248 (interactive "P")
3195 (or noninteractive 3249 (or noninteractive
3196 (if (not unset) 3250 (if (not unset)
3197 (progn 3251 (progn
3198 ;; toggle case sensitivity in search 3252 ;; toggle case sensitivity in search
3199 (vip-record-kbd-macro 3253 (viper-record-kbd-macro
3200 "//" 'vi-state 3254 "//" 'vi-state
3201 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 3255 [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]
3202 't) 3256 't)
3203 ;; toggle regexp/vanila search 3257 ;; toggle regexp/vanila search
3204 (vip-record-kbd-macro 3258 (viper-record-kbd-macro
3205 "///" 'vi-state 3259 "///" 'vi-state
3206 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 3260 [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]
3207 't) 3261 't)
3208 (if (interactive-p) 3262 (if (interactive-p)
3209 (message 3263 (message
3210 "// and /// now toggle case-sensitivity and regexp search"))) 3264 "// and /// now toggle case-sensitivity and regexp search")))
3211 (vip-unrecord-kbd-macro "//" 'vi-state) 3265 (viper-unrecord-kbd-macro "//" 'vi-state)
3212 (sit-for 2) 3266 (sit-for 2)
3213 (vip-unrecord-kbd-macro "///" 'vi-state)))) 3267 (viper-unrecord-kbd-macro "///" 'vi-state))))
3214 3268
3215 3269
3216 (defun vip-set-parsing-style-toggling-macro (unset) 3270 (defun viper-set-parsing-style-toggling-macro (unset)
3217 "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses. 3271 "Set `%%%' to be a macro that toggles whether comment fields should be parsed for matching parentheses.
3218 This is used in conjunction with the `%' command. 3272 This is used in conjunction with the `%' command.
3219 3273
3220 With a prefix argument, unsets the macro." 3274 With a prefix argument, unsets the macro."
3221 (interactive "P") 3275 (interactive "P")
3222 (or noninteractive 3276 (or noninteractive
3223 (if (not unset) 3277 (if (not unset)
3224 (progn 3278 (progn
3225 ;; Make %%% toggle parsing comments for matching parentheses 3279 ;; Make %%% toggle parsing comments for matching parentheses
3226 (vip-record-kbd-macro 3280 (viper-record-kbd-macro
3227 "%%%" 'vi-state 3281 "%%%" 'vi-state
3228 [(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] 3282 [(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]
3229 't) 3283 't)
3230 (if (interactive-p) 3284 (if (interactive-p)
3231 (message 3285 (message
3232 "%%%%%% now toggles whether comments should be parsed for matching parentheses"))) 3286 "%%%%%% now toggles whether comments should be parsed for matching parentheses")))
3233 (vip-unrecord-kbd-macro "%%%" 'vi-state)))) 3287 (viper-unrecord-kbd-macro "%%%" 'vi-state))))
3234 3288
3235 3289
3236 (defun vip-set-emacs-state-searchstyle-macros (unset &optional arg-majormode) 3290 (defun viper-set-emacs-state-searchstyle-macros (unset &optional arg-majormode)
3237 "Set the macros for toggling the search style in Viper's emacs-state. 3291 "Set the macros for toggling the search style in Viper's emacs-state.
3238 The macro that toggles case sensitivity is bound to `//', and the one that 3292 The macro that toggles case sensitivity is bound to `//', and the one that
3239 toggles regexp search is bound to `///'. 3293 toggles regexp search is bound to `///'.
3240 With a prefix argument, this function unsets the macros. 3294 With a prefix argument, this function unsets the macros.
3241 If the optional prefix argument is non-nil and specifies a valid major mode, 3295 If the optional prefix argument is non-nil and specifies a valid major mode,
3245 (interactive "P") 3299 (interactive "P")
3246 (or noninteractive 3300 (or noninteractive
3247 (if (not unset) 3301 (if (not unset)
3248 (progn 3302 (progn
3249 ;; toggle case sensitivity in search 3303 ;; toggle case sensitivity in search
3250 (vip-record-kbd-macro 3304 (viper-record-kbd-macro
3251 "//" 'emacs-state 3305 "//" 'emacs-state
3252 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 3306 [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]
3253 (or arg-majormode major-mode)) 3307 (or arg-majormode major-mode))
3254 ;; toggle regexp/vanila search 3308 ;; toggle regexp/vanila search
3255 (vip-record-kbd-macro 3309 (viper-record-kbd-macro
3256 "///" 'emacs-state 3310 "///" 'emacs-state
3257 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 3311 [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]
3258 (or arg-majormode major-mode)) 3312 (or arg-majormode major-mode))
3259 (if (interactive-p) 3313 (if (interactive-p)
3260 (message 3314 (message
3261 "// and /// now toggle case-sensitivity and regexp search."))) 3315 "// and /// now toggle case-sensitivity and regexp search.")))
3262 (vip-unrecord-kbd-macro "//" 'emacs-state) 3316 (viper-unrecord-kbd-macro "//" 'emacs-state)
3263 (sit-for 2) 3317 (sit-for 2)
3264 (vip-unrecord-kbd-macro "///" 'emacs-state)))) 3318 (viper-unrecord-kbd-macro "///" 'emacs-state))))
3265 3319
3266 3320
3267 (defun vip-search-forward (arg) 3321 (defun viper-search-forward (arg)
3268 "Search a string forward. 3322 "Search a string forward.
3269 ARG is used to find the ARG's occurrence of the string. 3323 ARG is used to find the ARG's occurrence of the string.
3270 Null string will repeat previous search." 3324 Null string will repeat previous search."
3271 (interactive "P") 3325 (interactive "P")
3272 (let ((val (vip-P-val arg)) 3326 (let ((val (viper-P-val arg))
3273 (com (vip-getcom arg)) 3327 (com (viper-getcom arg))
3274 (old-str vip-s-string)) 3328 (old-str viper-s-string))
3275 (setq vip-s-forward t) 3329 (setq viper-s-forward t)
3276 (vip-if-string "/") 3330 (viper-if-string "/")
3277 ;; this is not used at present, but may be used later 3331 ;; this is not used at present, but may be used later
3278 (if (or (not (equal old-str vip-s-string)) 3332 (if (or (not (equal old-str viper-s-string))
3279 (not (markerp vip-local-search-start-marker)) 3333 (not (markerp viper-local-search-start-marker))
3280 (not (marker-buffer vip-local-search-start-marker))) 3334 (not (marker-buffer viper-local-search-start-marker)))
3281 (setq vip-local-search-start-marker (point-marker))) 3335 (setq viper-local-search-start-marker (point-marker)))
3282 (vip-search vip-s-string t val) 3336 (viper-search viper-s-string t val)
3283 (if com 3337 (if com
3284 (progn 3338 (progn
3285 (vip-move-marker-locally 'vip-com-point (mark t)) 3339 (viper-move-marker-locally 'viper-com-point (mark t))
3286 (vip-execute-com 'vip-search-next val com))))) 3340 (viper-execute-com 'viper-search-next val com)))))
3287 3341
3288 (defun vip-search-backward (arg) 3342 (defun viper-search-backward (arg)
3289 "Search a string backward. 3343 "Search a string backward.
3290 ARG is used to find the ARG's occurrence of the string. 3344 ARG is used to find the ARG's occurrence of the string.
3291 Null string will repeat previous search." 3345 Null string will repeat previous search."
3292 (interactive "P") 3346 (interactive "P")
3293 (let ((val (vip-P-val arg)) 3347 (let ((val (viper-P-val arg))
3294 (com (vip-getcom arg)) 3348 (com (viper-getcom arg))
3295 (old-str vip-s-string)) 3349 (old-str viper-s-string))
3296 (setq vip-s-forward nil) 3350 (setq viper-s-forward nil)
3297 (vip-if-string "?") 3351 (viper-if-string "?")
3298 ;; this is not used at present, but may be used later 3352 ;; this is not used at present, but may be used later
3299 (if (or (not (equal old-str vip-s-string)) 3353 (if (or (not (equal old-str viper-s-string))
3300 (not (markerp vip-local-search-start-marker)) 3354 (not (markerp viper-local-search-start-marker))
3301 (not (marker-buffer vip-local-search-start-marker))) 3355 (not (marker-buffer viper-local-search-start-marker)))
3302 (setq vip-local-search-start-marker (point-marker))) 3356 (setq viper-local-search-start-marker (point-marker)))
3303 (vip-search vip-s-string nil val) 3357 (viper-search viper-s-string nil val)
3304 (if com 3358 (if com
3305 (progn 3359 (progn
3306 (vip-move-marker-locally 'vip-com-point (mark t)) 3360 (viper-move-marker-locally 'viper-com-point (mark t))
3307 (vip-execute-com 'vip-search-next val com))))) 3361 (viper-execute-com 'viper-search-next val com)))))
3308 3362
3309 3363
3310 ;; Search for COUNT's occurrence of STRING. 3364 ;; Search for COUNT's occurrence of STRING.
3311 ;; Search is forward if FORWARD is non-nil, otherwise backward. 3365 ;; Search is forward if FORWARD is non-nil, otherwise backward.
3312 ;; INIT-POINT is the position where search is to start. 3366 ;; INIT-POINT is the position where search is to start.
3313 ;; Arguments: 3367 ;; Arguments:
3314 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND) 3368 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND)
3315 (defun vip-search (string forward arg 3369 (defun viper-search (string forward arg
3316 &optional no-offset init-point fail-if-not-found) 3370 &optional no-offset init-point fail-if-not-found)
3317 (if (not (equal string "")) 3371 (if (not (equal string ""))
3318 (let ((val (vip-p-val arg)) 3372 (let ((val (viper-p-val arg))
3319 (com (vip-getcom arg)) 3373 (com (viper-getcom arg))
3320 (offset (not no-offset)) 3374 (offset (not no-offset))
3321 (case-fold-search vip-case-fold-search) 3375 (case-fold-search viper-case-fold-search)
3322 (start-point (or init-point (point)))) 3376 (start-point (or init-point (point))))
3323 (vip-deactivate-mark) 3377 (viper-deactivate-mark)
3324 (if forward 3378 (if forward
3325 (condition-case nil 3379 (condition-case nil
3326 (progn 3380 (progn
3327 (if offset (vip-forward-char-carefully)) 3381 (if offset (viper-forward-char-carefully))
3328 (if vip-re-search 3382 (if viper-re-search
3329 (progn 3383 (progn
3330 (re-search-forward string nil nil val) 3384 (re-search-forward string nil nil val)
3331 (re-search-backward string)) 3385 (re-search-backward string))
3332 (search-forward string nil nil val) 3386 (search-forward string nil nil val)
3333 (search-backward string)) 3387 (search-backward string))
3334 (if (not (equal start-point (point))) 3388 (if (not (equal start-point (point)))
3335 (push-mark start-point t))) 3389 (push-mark start-point t)))
3336 (search-failed 3390 (search-failed
3337 (if (and (not fail-if-not-found) vip-search-wrap-around-t) 3391 (if (and (not fail-if-not-found) viper-search-wrap-around-t)
3338 (progn 3392 (progn
3339 (message "Search wrapped around BOTTOM of buffer") 3393 (message "Search wrapped around BOTTOM of buffer")
3340 (goto-char (point-min)) 3394 (goto-char (point-min))
3341 (vip-search string forward (cons 1 com) t start-point 'fail) 3395 (viper-search string forward (cons 1 com) t start-point 'fail)
3342 ;; don't wait in macros 3396 ;; don't wait in macros
3343 (or executing-kbd-macro (sit-for 2)) 3397 (or executing-kbd-macro
3398 (memq viper-intermediate-command
3399 '(viper-repeat
3400 viper-digit-argument
3401 viper-command-argument))
3402 (sit-for 2))
3344 ;; delete the wrap-around message 3403 ;; delete the wrap-around message
3345 (message "") 3404 (message "")
3346 ) 3405 )
3347 (goto-char start-point) 3406 (goto-char start-point)
3348 (error "`%s': %s not found" 3407 (error "`%s': %s not found"
3349 string 3408 string
3350 (if vip-re-search "Pattern" "String")) 3409 (if viper-re-search "Pattern" "String"))
3351 ))) 3410 )))
3352 ;; backward 3411 ;; backward
3353 (condition-case nil 3412 (condition-case nil
3354 (progn 3413 (progn
3355 (if vip-re-search 3414 (if viper-re-search
3356 (re-search-backward string nil nil val) 3415 (re-search-backward string nil nil val)
3357 (search-backward string nil nil val)) 3416 (search-backward string nil nil val))
3358 (if (not (equal start-point (point))) 3417 (if (not (equal start-point (point)))
3359 (push-mark start-point t))) 3418 (push-mark start-point t)))
3360 (search-failed 3419 (search-failed
3361 (if (and (not fail-if-not-found) vip-search-wrap-around-t) 3420 (if (and (not fail-if-not-found) viper-search-wrap-around-t)
3362 (progn 3421 (progn
3363 (message "Search wrapped around TOP of buffer") 3422 (message "Search wrapped around TOP of buffer")
3364 (goto-char (point-max)) 3423 (goto-char (point-max))
3365 (vip-search string forward (cons 1 com) t start-point 'fail) 3424 (viper-search string forward (cons 1 com) t start-point 'fail)
3366 ;; don't wait in macros 3425 ;; don't wait in macros
3367 (or executing-kbd-macro (sit-for 2)) 3426 (or executing-kbd-macro
3427 (memq viper-intermediate-command
3428 '(viper-repeat
3429 viper-digit-argument
3430 viper-command-argument))
3431 (sit-for 2))
3368 ;; delete the wrap-around message 3432 ;; delete the wrap-around message
3369 (message "") 3433 (message "")
3370 ) 3434 )
3371 (goto-char start-point) 3435 (goto-char start-point)
3372 (error "`%s': %s not found" 3436 (error "`%s': %s not found"
3373 string 3437 string
3374 (if vip-re-search "Pattern" "String")) 3438 (if viper-re-search "Pattern" "String"))
3375 )))) 3439 ))))
3376 ;; pull up or down if at top/bottom of window 3440 ;; pull up or down if at top/bottom of window
3377 (vip-adjust-window) 3441 (viper-adjust-window)
3378 ;; highlight the result of search 3442 ;; highlight the result of search
3379 ;; don't wait and don't highlight in macros 3443 ;; don't wait and don't highlight in macros
3380 (or executing-kbd-macro 3444 (or executing-kbd-macro
3381 vip-inside-command-argument-action 3445 (memq viper-intermediate-command
3382 (vip-flash-search-pattern)) 3446 '(viper-repeat viper-digit-argument viper-command-argument))
3447 (viper-flash-search-pattern))
3383 ))) 3448 )))
3384 3449
3385 (defun vip-search-next (arg) 3450 (defun viper-search-next (arg)
3386 "Repeat previous search." 3451 "Repeat previous search."
3387 (interactive "P") 3452 (interactive "P")
3388 (let ((val (vip-p-val arg)) 3453 (let ((val (viper-p-val arg))
3389 (com (vip-getcom arg))) 3454 (com (viper-getcom arg)))
3390 (if (null vip-s-string) (error vip-NoPrevSearch)) 3455 (if (null viper-s-string) (error viper-NoPrevSearch))
3391 (vip-search vip-s-string vip-s-forward arg) 3456 (viper-search viper-s-string viper-s-forward arg)
3392 (if com 3457 (if com
3393 (progn 3458 (progn
3394 (vip-move-marker-locally 'vip-com-point (mark t)) 3459 (viper-move-marker-locally 'viper-com-point (mark t))
3395 (vip-execute-com 'vip-search-next val com))))) 3460 (viper-execute-com 'viper-search-next val com)))))
3396 3461
3397 (defun vip-search-Next (arg) 3462 (defun viper-search-Next (arg)
3398 "Repeat previous search in the reverse direction." 3463 "Repeat previous search in the reverse direction."
3399 (interactive "P") 3464 (interactive "P")
3400 (let ((val (vip-p-val arg)) 3465 (let ((val (viper-p-val arg))
3401 (com (vip-getcom arg))) 3466 (com (viper-getcom arg)))
3402 (if (null vip-s-string) (error vip-NoPrevSearch)) 3467 (if (null viper-s-string) (error viper-NoPrevSearch))
3403 (vip-search vip-s-string (not vip-s-forward) arg) 3468 (viper-search viper-s-string (not viper-s-forward) arg)
3404 (if com 3469 (if com
3405 (progn 3470 (progn
3406 (vip-move-marker-locally 'vip-com-point (mark t)) 3471 (viper-move-marker-locally 'viper-com-point (mark t))
3407 (vip-execute-com 'vip-search-Next val com))))) 3472 (viper-execute-com 'viper-search-Next val com)))))
3408 3473
3409 3474
3410 ;; Search contents of buffer defined by one of Viper's motion commands. 3475 ;; Search contents of buffer defined by one of Viper's motion commands.
3411 ;; Repeatable via `n' and `N'. 3476 ;; Repeatable via `n' and `N'.
3412 (defun vip-buffer-search-enable (&optional c) 3477 (defun viper-buffer-search-enable (&optional c)
3413 (cond (c (setq vip-buffer-search-char c)) 3478 (cond (c (setq viper-buffer-search-char c))
3414 ((null vip-buffer-search-char) 3479 ((null viper-buffer-search-char)
3415 (setq vip-buffer-search-char ?g))) 3480 (setq viper-buffer-search-char ?g)))
3416 (define-key vip-vi-basic-map 3481 (define-key viper-vi-basic-map
3417 (char-to-string vip-buffer-search-char) 'vip-command-argument) 3482 (char-to-string viper-buffer-search-char) 'viper-command-argument)
3418 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) 3483 (aset viper-exec-array viper-buffer-search-char 'viper-exec-buffer-search)
3419 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) 3484 (setq viper-prefix-commands
3485 (cons viper-buffer-search-char viper-prefix-commands)))
3420 3486
3421 ;; This is a Viper wraper for isearch-forward. 3487 ;; This is a Viper wraper for isearch-forward.
3422 (defun vip-isearch-forward (arg) 3488 (defun viper-isearch-forward (arg)
3423 "Do incremental search forward." 3489 "Do incremental search forward."
3424 (interactive "P") 3490 (interactive "P")
3425 ;; emacs bug workaround 3491 ;; emacs bug workaround
3426 (if (listp arg) (setq arg (car arg))) 3492 (if (listp arg) (setq arg (car arg)))
3427 (vip-exec-form-in-emacs (list 'isearch-forward arg))) 3493 (viper-exec-form-in-emacs (list 'isearch-forward arg)))
3428 3494
3429 ;; This is a Viper wraper for isearch-backward." 3495 ;; This is a Viper wraper for isearch-backward."
3430 (defun vip-isearch-backward (arg) 3496 (defun viper-isearch-backward (arg)
3431 "Do incremental search backward." 3497 "Do incremental search backward."
3432 (interactive "P") 3498 (interactive "P")
3433 ;; emacs bug workaround 3499 ;; emacs bug workaround
3434 (if (listp arg) (setq arg (car arg))) 3500 (if (listp arg) (setq arg (car arg)))
3435 (vip-exec-form-in-emacs (list 'isearch-backward arg))) 3501 (viper-exec-form-in-emacs (list 'isearch-backward arg)))
3436 3502
3437 3503
3438 ;; visiting and killing files, buffers 3504 ;; visiting and killing files, buffers
3439 3505
3440 (defun vip-switch-to-buffer () 3506 (defun viper-switch-to-buffer ()
3441 "Switch to buffer in the current window." 3507 "Switch to buffer in the current window."
3442 (interactive) 3508 (interactive)
3443 (let (buffer) 3509 (let (buffer)
3444 (setq buffer 3510 (setq buffer
3445 (read-buffer 3511 (read-buffer
3446 (format "Switch to buffer in this window \(%s\): " 3512 (format "Switch to buffer in this window \(%s\): "
3447 (buffer-name (other-buffer (current-buffer)))))) 3513 (buffer-name (other-buffer (current-buffer))))))
3448 (switch-to-buffer buffer) 3514 (switch-to-buffer buffer)
3449 )) 3515 ))
3450 3516
3451 (defun vip-switch-to-buffer-other-window () 3517 (defun viper-switch-to-buffer-other-window ()
3452 "Switch to buffer in another window." 3518 "Switch to buffer in another window."
3453 (interactive) 3519 (interactive)
3454 (let (buffer) 3520 (let (buffer)
3455 (setq buffer 3521 (setq buffer
3456 (read-buffer 3522 (read-buffer
3457 (format "Switch to buffer in another window \(%s\): " 3523 (format "Switch to buffer in another window \(%s\): "
3458 (buffer-name (other-buffer (current-buffer)))))) 3524 (buffer-name (other-buffer (current-buffer))))))
3459 (switch-to-buffer-other-window buffer) 3525 (switch-to-buffer-other-window buffer)
3460 )) 3526 ))
3461 3527
3462 (defun vip-kill-buffer () 3528 (defun viper-kill-buffer ()
3463 "Kill a buffer." 3529 "Kill a buffer."
3464 (interactive) 3530 (interactive)
3465 (let (buffer buffer-name) 3531 (let (buffer buffer-name)
3466 (setq buffer-name 3532 (setq buffer-name
3467 (read-buffer 3533 (read-buffer
3479 buffer-name))) 3545 buffer-name)))
3480 (kill-buffer buffer) 3546 (kill-buffer buffer)
3481 (error "Buffer not killed")))) 3547 (error "Buffer not killed"))))
3482 3548
3483 3549
3484 (defcustom vip-smart-suffix-list 3550 (defcustom viper-smart-suffix-list
3485 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p") 3551 '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
3486 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. 3552 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'.
3487 This is useful when you the current directory contains files with the same 3553 This is useful when you the current directory contains files with the same
3488 prefix and many different suffixes. Usually, only one of the suffixes 3554 prefix and many different suffixes. Usually, only one of the suffixes
3489 represents an editable file. However, file completion will stop at the `.' 3555 represents an editable file. However, file completion will stop at the `.'
3498 :type '(set string) 3564 :type '(set string)
3499 :group 'viper) 3565 :group 'viper)
3500 3566
3501 ;; Try to add suffix to files ending with a `.' 3567 ;; Try to add suffix to files ending with a `.'
3502 ;; Useful when the user hits RET on a non-completed file name. 3568 ;; Useful when the user hits RET on a non-completed file name.
3503 (defun vip-file-add-suffix () 3569 (defun viper-file-add-suffix ()
3504 (let ((count 0) 3570 (let ((count 0)
3505 (len (length vip-smart-suffix-list)) 3571 (len (length viper-smart-suffix-list))
3506 (file (buffer-string)) 3572 (file (buffer-string))
3507 found key cmd suff) 3573 found key cmd suff)
3508 (goto-char (point-max)) 3574 (goto-char (point-max))
3509 (if (and vip-smart-suffix-list (string-match "\\.$" file)) 3575 (if (and viper-smart-suffix-list (string-match "\\.$" file))
3510 (progn 3576 (progn
3511 (while (and (not found) (< count len)) 3577 (while (and (not found) (< count len))
3512 (setq suff (nth count vip-smart-suffix-list) 3578 (setq suff (nth count viper-smart-suffix-list)
3513 count (1+ count)) 3579 count (1+ count))
3514 (if (file-exists-p (format "%s%s" file suff)) 3580 (if (file-exists-p
3581 (format "%s%s" (substitute-in-file-name file) suff))
3515 (progn 3582 (progn
3516 (setq found t) 3583 (setq found t)
3517 (insert suff)))) 3584 (insert suff))))
3518 3585
3519 (if found 3586 (if found
3520 () 3587 ()
3521 (vip-tmp-insert-at-eob " [Please complete file name]") 3588 (viper-tmp-insert-at-eob " [Please complete file name]")
3522 (unwind-protect 3589 (unwind-protect
3523 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer))) 3590 (while (not (memq cmd
3591 '(exit-minibuffer viper-exit-minibuffer)))
3524 (setq cmd 3592 (setq cmd
3525 (key-binding (setq key (read-key-sequence nil)))) 3593 (key-binding (setq key (read-key-sequence nil))))
3526 (cond ((eq cmd 'self-insert-command) 3594 (cond ((eq cmd 'self-insert-command)
3527 (if vip-xemacs-p 3595 (if viper-xemacs-p
3528 (insert (events-to-keys key)) 3596 (insert (events-to-keys key))
3529 (insert key))) 3597 (insert key)))
3530 ((memq cmd '(exit-minibuffer vip-exit-minibuffer)) 3598 ((memq cmd '(exit-minibuffer viper-exit-minibuffer))
3531 nil) 3599 nil)
3532 (t (command-execute cmd))) 3600 (t (command-execute cmd)))
3533 ))) 3601 )))
3534 )) 3602 ))))
3535 ))
3536 3603
3537 3604
3538 3605
3539 3606
3540 ;; yank and pop 3607 ;; yank and pop
3541 3608
3542 (defsubst vip-yank (text) 3609 (defsubst viper-yank (text)
3543 "Yank TEXT silently. This works correctly with Emacs's yank-pop command." 3610 "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
3544 (insert text) 3611 (insert text)
3545 (setq this-command 'yank)) 3612 (setq this-command 'yank))
3546 3613
3547 (defun vip-put-back (arg) 3614 (defun viper-put-back (arg)
3548 "Put back after point/below line." 3615 "Put back after point/below line."
3549 (interactive "P") 3616 (interactive "P")
3550 (let ((val (vip-p-val arg)) 3617 (let ((val (viper-p-val arg))
3551 (text (if vip-use-register 3618 (text (if viper-use-register
3552 (cond ((vip-valid-register vip-use-register '(digit)) 3619 (cond ((viper-valid-register viper-use-register '(digit))
3553 (current-kill (- vip-use-register ?1) 'do-not-rotate)) 3620 (current-kill
3554 ((vip-valid-register vip-use-register) 3621 (- viper-use-register ?1) 'do-not-rotate))
3555 (get-register (downcase vip-use-register))) 3622 ((viper-valid-register viper-use-register)
3556 (t (error vip-InvalidRegister vip-use-register))) 3623 (get-register (downcase viper-use-register)))
3624 (t (error viper-InvalidRegister viper-use-register)))
3557 (current-kill 0)))) 3625 (current-kill 0))))
3558 (if (null text) 3626 (if (null text)
3559 (if vip-use-register 3627 (if viper-use-register
3560 (let ((reg vip-use-register)) 3628 (let ((reg viper-use-register))
3561 (setq vip-use-register nil) 3629 (setq viper-use-register nil)
3562 (error vip-EmptyRegister reg)) 3630 (error viper-EmptyRegister reg))
3563 (error ""))) 3631 (error "")))
3564 (setq vip-use-register nil) 3632 (setq viper-use-register nil)
3565 (if (vip-end-with-a-newline-p text) 3633 (if (viper-end-with-a-newline-p text)
3566 (progn 3634 (progn
3567 (end-of-line) 3635 (end-of-line)
3568 (if (eobp) 3636 (if (eobp)
3569 (insert "\n") 3637 (insert "\n")
3570 (forward-line 1)) 3638 (forward-line 1))
3571 (beginning-of-line)) 3639 (beginning-of-line))
3572 (if (not (eolp)) (vip-forward-char-carefully))) 3640 (if (not (eolp)) (viper-forward-char-carefully)))
3573 (set-marker (vip-mark-marker) (point) (current-buffer)) 3641 (set-marker (viper-mark-marker) (point) (current-buffer))
3574 (vip-set-destructive-command 3642 (viper-set-destructive-command
3575 (list 'vip-put-back val nil vip-use-register nil nil)) 3643 (list 'viper-put-back val nil viper-use-register nil nil))
3576 (vip-loop val (vip-yank text))) 3644 (viper-loop val (viper-yank text)))
3577 ;; Vi puts cursor on the last char when the yanked text doesn't contain a 3645 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
3578 ;; newline; it leaves the cursor at the beginning when the text contains 3646 ;; newline; it leaves the cursor at the beginning when the text contains
3579 ;; a newline 3647 ;; a newline
3580 (if (vip-same-line (point) (mark)) 3648 (if (viper-same-line (point) (mark))
3581 (or (= (point) (mark)) (vip-backward-char-carefully)) 3649 (or (= (point) (mark)) (viper-backward-char-carefully))
3582 (exchange-point-and-mark) 3650 (exchange-point-and-mark)
3583 (if (bolp) 3651 (if (bolp)
3584 (back-to-indentation))) 3652 (back-to-indentation)))
3585 (vip-deactivate-mark)) 3653 (viper-deactivate-mark))
3586 3654
3587 (defun vip-Put-back (arg) 3655 (defun viper-Put-back (arg)
3588 "Put back at point/above line." 3656 "Put back at point/above line."
3589 (interactive "P") 3657 (interactive "P")
3590 (let ((val (vip-p-val arg)) 3658 (let ((val (viper-p-val arg))
3591 (text (if vip-use-register 3659 (text (if viper-use-register
3592 (cond ((vip-valid-register vip-use-register '(digit)) 3660 (cond ((viper-valid-register viper-use-register '(digit))
3593 (current-kill (- vip-use-register ?1) 'do-not-rotate)) 3661 (current-kill
3594 ((vip-valid-register vip-use-register) 3662 (- viper-use-register ?1) 'do-not-rotate))
3595 (get-register (downcase vip-use-register))) 3663 ((viper-valid-register viper-use-register)
3596 (t (error vip-InvalidRegister vip-use-register))) 3664 (get-register (downcase viper-use-register)))
3665 (t (error viper-InvalidRegister viper-use-register)))
3597 (current-kill 0)))) 3666 (current-kill 0))))
3598 (if (null text) 3667 (if (null text)
3599 (if vip-use-register 3668 (if viper-use-register
3600 (let ((reg vip-use-register)) 3669 (let ((reg viper-use-register))
3601 (setq vip-use-register nil) 3670 (setq viper-use-register nil)
3602 (error vip-EmptyRegister reg)) 3671 (error viper-EmptyRegister reg))
3603 (error ""))) 3672 (error "")))
3604 (setq vip-use-register nil) 3673 (setq viper-use-register nil)
3605 (if (vip-end-with-a-newline-p text) (beginning-of-line)) 3674 (if (viper-end-with-a-newline-p text) (beginning-of-line))
3606 (vip-set-destructive-command 3675 (viper-set-destructive-command
3607 (list 'vip-Put-back val nil vip-use-register nil nil)) 3676 (list 'viper-Put-back val nil viper-use-register nil nil))
3608 (set-marker (vip-mark-marker) (point) (current-buffer)) 3677 (set-marker (viper-mark-marker) (point) (current-buffer))
3609 (vip-loop val (vip-yank text))) 3678 (viper-loop val (viper-yank text)))
3610 ;; Vi puts cursor on the last char when the yanked text doesn't contain a 3679 ;; Vi puts cursor on the last char when the yanked text doesn't contain a
3611 ;; newline; it leaves the cursor at the beginning when the text contains 3680 ;; newline; it leaves the cursor at the beginning when the text contains
3612 ;; a newline 3681 ;; a newline
3613 (if (vip-same-line (point) (mark)) 3682 (if (viper-same-line (point) (mark))
3614 (or (= (point) (mark)) (vip-backward-char-carefully)) 3683 (or (= (point) (mark)) (viper-backward-char-carefully))
3615 (exchange-point-and-mark) 3684 (exchange-point-and-mark)
3616 (if (bolp) 3685 (if (bolp)
3617 (back-to-indentation))) 3686 (back-to-indentation)))
3618 (vip-deactivate-mark)) 3687 (viper-deactivate-mark))
3619 3688
3620 3689
3621 ;; Copy region to kill-ring. 3690 ;; Copy region to kill-ring.
3622 ;; If BEG and END do not belong to the same buffer, copy empty region. 3691 ;; If BEG and END do not belong to the same buffer, copy empty region.
3623 (defun vip-copy-region-as-kill (beg end) 3692 (defun viper-copy-region-as-kill (beg end)
3624 (condition-case nil 3693 (condition-case nil
3625 (copy-region-as-kill beg end) 3694 (copy-region-as-kill beg end)
3626 (error (copy-region-as-kill beg beg)))) 3695 (error (copy-region-as-kill beg beg))))
3627 3696
3628 3697
3629 (defun vip-delete-char (arg) 3698 (defun viper-delete-char (arg)
3630 "Delete character." 3699 "Delete character."
3631 (interactive "P") 3700 (interactive "P")
3632 (let ((val (vip-p-val arg))) 3701 (let ((val (viper-p-val arg)))
3633 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil)) 3702 (viper-set-destructive-command
3703 (list 'viper-delete-char val nil nil nil nil))
3634 (if (> val 1) 3704 (if (> val 1)
3635 (save-excursion 3705 (save-excursion
3636 (let ((here (point))) 3706 (let ((here (point)))
3637 (end-of-line) 3707 (end-of-line)
3638 (if (> val (- (point) here)) 3708 (if (> val (- (point) here))
3639 (setq val (- (point) here)))))) 3709 (setq val (- (point) here))))))
3640 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1)) 3710 (if (and (eq val 0) (not viper-ex-style-motion)) (setq val 1))
3641 (if (and vip-ex-style-motion (eolp)) 3711 (if (and viper-ex-style-motion (eolp))
3642 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch 3712 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch
3643 (if vip-use-register 3713 (if viper-use-register
3644 (progn 3714 (progn
3645 (cond ((vip-valid-register vip-use-register '((Letter))) 3715 (cond ((viper-valid-register viper-use-register '((Letter)))
3646 (vip-append-to-register 3716 (viper-append-to-register
3647 (downcase vip-use-register) (point) (- (point) val))) 3717 (downcase viper-use-register) (point) (- (point) val)))
3648 ((vip-valid-register vip-use-register) 3718 ((viper-valid-register viper-use-register)
3649 (copy-to-register 3719 (copy-to-register
3650 vip-use-register (point) (- (point) val) nil)) 3720 viper-use-register (point) (- (point) val) nil))
3651 (t (error vip-InvalidRegister vip-use-register))) 3721 (t (error viper-InvalidRegister viper-use-register)))
3652 (setq vip-use-register nil))) 3722 (setq viper-use-register nil)))
3653 (if vip-ex-style-motion 3723 (if viper-ex-style-motion
3654 (progn 3724 (progn
3655 (delete-char val t) 3725 (delete-char val t)
3656 (if (and (eolp) (not (bolp))) (backward-char 1))) 3726 (if (and (eolp) (not (bolp))) (backward-char 1)))
3657 (if (eolp) 3727 (if (eolp)
3658 (delete-backward-char val t) 3728 (delete-backward-char val t)
3659 (delete-char val t))))) 3729 (delete-char val t)))))
3660 3730
3661 (defun vip-delete-backward-char (arg) 3731 (defun viper-delete-backward-char (arg)
3662 "Delete previous character. On reaching beginning of line, stop and beep." 3732 "Delete previous character. On reaching beginning of line, stop and beep."
3663 (interactive "P") 3733 (interactive "P")
3664 (let ((val (vip-p-val arg))) 3734 (let ((val (viper-p-val arg)))
3665 (vip-set-destructive-command 3735 (viper-set-destructive-command
3666 (list 'vip-delete-backward-char val nil nil nil nil)) 3736 (list 'viper-delete-backward-char val nil nil nil nil))
3667 (if (> val 1) 3737 (if (> val 1)
3668 (save-excursion 3738 (save-excursion
3669 (let ((here (point))) 3739 (let ((here (point)))
3670 (beginning-of-line) 3740 (beginning-of-line)
3671 (if (> val (- here (point))) 3741 (if (> val (- here (point)))
3672 (setq val (- here (point))))))) 3742 (setq val (- here (point)))))))
3673 (if vip-use-register 3743 (if viper-use-register
3674 (progn 3744 (progn
3675 (cond ((vip-valid-register vip-use-register '(Letter)) 3745 (cond ((viper-valid-register viper-use-register '(Letter))
3676 (vip-append-to-register 3746 (viper-append-to-register
3677 (downcase vip-use-register) (point) (+ (point) val))) 3747 (downcase viper-use-register) (point) (+ (point) val)))
3678 ((vip-valid-register vip-use-register) 3748 ((viper-valid-register viper-use-register)
3679 (copy-to-register 3749 (copy-to-register
3680 vip-use-register (point) (+ (point) val) nil)) 3750 viper-use-register (point) (+ (point) val) nil))
3681 (t (error vip-InvalidRegister vip-use-register))) 3751 (t (error viper-InvalidRegister viper-use-register)))
3682 (setq vip-use-register nil))) 3752 (setq viper-use-register nil)))
3683 (if (bolp) (ding) 3753 (if (bolp) (ding)
3684 (delete-backward-char val t)))) 3754 (delete-backward-char val t))))
3685 3755
3686 (defun vip-del-backward-char-in-insert () 3756 (defun viper-del-backward-char-in-insert ()
3687 "Delete 1 char backwards while in insert mode." 3757 "Delete 1 char backwards while in insert mode."
3688 (interactive) 3758 (interactive)
3689 (if (and vip-ex-style-editing-in-insert (bolp)) 3759 (if (and viper-ex-style-editing-in-insert (bolp))
3690 (beep 1) 3760 (beep 1)
3691 (delete-backward-char 1 t))) 3761 (delete-backward-char 1 t)))
3692 3762
3693 (defun vip-del-backward-char-in-replace () 3763 (defun viper-del-backward-char-in-replace ()
3694 "Delete one character in replace mode. 3764 "Delete one character in replace mode.
3695 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes 3765 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes
3696 charecters. If it is nil, then the cursor just moves backwards, similarly 3766 charecters. If it is nil, then the cursor just moves backwards, similarly
3697 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the 3767 to Vi. The variable `viper-ex-style-editing-in-insert', if t, doesn't let the
3698 cursor move past the beginning of line." 3768 cursor move past the beginning of line."
3699 (interactive) 3769 (interactive)
3700 (cond (vip-delete-backwards-in-replace 3770 (cond (viper-delete-backwards-in-replace
3701 (cond ((not (bolp)) 3771 (cond ((not (bolp))
3702 (delete-backward-char 1 t)) 3772 (delete-backward-char 1 t))
3703 (vip-ex-style-editing-in-insert 3773 (viper-ex-style-editing-in-insert
3704 (beep 1)) 3774 (beep 1))
3705 ((bobp) 3775 ((bobp)
3706 (beep 1)) 3776 (beep 1))
3707 (t 3777 (t
3708 (delete-backward-char 1 t)))) 3778 (delete-backward-char 1 t))))
3709 (vip-ex-style-editing-in-insert 3779 (viper-ex-style-editing-in-insert
3710 (if (bolp) 3780 (if (bolp)
3711 (beep 1) 3781 (beep 1)
3712 (backward-char 1))) 3782 (backward-char 1)))
3713 (t 3783 (t
3714 (backward-char 1)))) 3784 (backward-char 1))))
3715 3785
3716 3786
3717 3787
3718 ;; join lines. 3788 ;; join lines.
3719 3789
3720 (defun vip-join-lines (arg) 3790 (defun viper-join-lines (arg)
3721 "Join this line to next, if ARG is nil. Otherwise, join ARG lines." 3791 "Join this line to next, if ARG is nil. Otherwise, join ARG lines."
3722 (interactive "*P") 3792 (interactive "*P")
3723 (let ((val (vip-P-val arg))) 3793 (let ((val (viper-P-val arg)))
3724 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil)) 3794 (viper-set-destructive-command
3725 (vip-loop (if (null val) 1 (1- val)) 3795 (list 'viper-join-lines val nil nil nil nil))
3796 (viper-loop (if (null val) 1 (1- val))
3726 (progn 3797 (progn
3727 (end-of-line) 3798 (end-of-line)
3728 (if (not (eobp)) 3799 (if (not (eobp))
3729 (progn 3800 (progn
3730 (forward-line 1) 3801 (forward-line 1)
3738 )))))) 3809 ))))))
3739 3810
3740 3811
3741 ;; Replace state 3812 ;; Replace state
3742 3813
3743 (defun vip-change (beg end) 3814 (defun viper-change (beg end)
3744 (if (markerp beg) (setq beg (marker-position beg))) 3815 (if (markerp beg) (setq beg (marker-position beg)))
3745 (if (markerp end) (setq end (marker-position end))) 3816 (if (markerp end) (setq end (marker-position end)))
3746 ;; beg is sometimes (mark t), which may be nil 3817 ;; beg is sometimes (mark t), which may be nil
3747 (or beg (setq beg end)) 3818 (or beg (setq beg end))
3748 3819
3749 (vip-set-complex-command-for-undo) 3820 (viper-set-complex-command-for-undo)
3750 (if vip-use-register 3821 (if viper-use-register
3751 (progn 3822 (progn
3752 (copy-to-register vip-use-register beg end nil) 3823 (copy-to-register viper-use-register beg end nil)
3753 (setq vip-use-register nil))) 3824 (setq viper-use-register nil)))
3754 (vip-set-replace-overlay beg end) 3825 (viper-set-replace-overlay beg end)
3755 (setq last-command nil) ; separate repl text from prev kills 3826 (setq last-command nil) ; separate repl text from prev kills
3756 3827
3757 (if (= (vip-replace-start) (point-max)) 3828 (if (= (viper-replace-start) (point-max))
3758 (error "End of buffer")) 3829 (error "End of buffer"))
3759 3830
3760 (setq vip-last-replace-region 3831 (setq viper-last-replace-region
3761 (buffer-substring (vip-replace-start) 3832 (buffer-substring (viper-replace-start)
3762 (vip-replace-end))) 3833 (viper-replace-end)))
3763 3834
3764 ;; protect against error while inserting "@" and other disasters 3835 ;; protect against error while inserting "@" and other disasters
3765 ;; (e.g., read-only buff) 3836 ;; (e.g., read-only buff)
3766 (condition-case conds 3837 (condition-case conds
3767 (if (or vip-allow-multiline-replace-regions 3838 (if (or viper-allow-multiline-replace-regions
3768 (vip-same-line (vip-replace-start) 3839 (viper-same-line (viper-replace-start)
3769 (vip-replace-end))) 3840 (viper-replace-end)))
3770 (progn 3841 (progn
3771 ;; tabs cause problems in replace, so untabify 3842 ;; tabs cause problems in replace, so untabify
3772 (goto-char (vip-replace-end)) 3843 (goto-char (viper-replace-end))
3773 (insert-before-markers "@") ; put placeholder after the TAB 3844 (insert-before-markers "@") ; put placeholder after the TAB
3774 (untabify (vip-replace-start) (point)) 3845 (untabify (viper-replace-start) (point))
3775 ;; del @, don't put on kill ring 3846 ;; del @, don't put on kill ring
3776 (delete-backward-char 1) 3847 (delete-backward-char 1)
3777 3848
3778 (vip-set-replace-overlay-glyphs 3849 (viper-set-replace-overlay-glyphs
3779 vip-replace-region-start-delimiter 3850 viper-replace-region-start-delimiter
3780 vip-replace-region-end-delimiter) 3851 viper-replace-region-end-delimiter)
3781 ;; this move takes care of the last posn in the overlay, which 3852 ;; this move takes care of the last posn in the overlay, which
3782 ;; has to be shifted because of insert. We can't simply insert 3853 ;; has to be shifted because of insert. We can't simply insert
3783 ;; "$" before-markers because then overlay-start will shift the 3854 ;; "$" before-markers because then overlay-start will shift the
3784 ;; beginning of the overlay in case we are replacing a single 3855 ;; beginning of the overlay in case we are replacing a single
3785 ;; character. This fixes the bug with `s' and `cl' commands. 3856 ;; character. This fixes the bug with `s' and `cl' commands.
3786 (vip-move-replace-overlay (vip-replace-start) (point)) 3857 (viper-move-replace-overlay (viper-replace-start) (point))
3787 (goto-char (vip-replace-start)) 3858 (goto-char (viper-replace-start))
3788 (vip-change-state-to-replace t)) 3859 (viper-change-state-to-replace t))
3789 (kill-region (vip-replace-start) 3860 (kill-region (viper-replace-start)
3790 (vip-replace-end)) 3861 (viper-replace-end))
3791 (vip-hide-replace-overlay) 3862 (viper-hide-replace-overlay)
3792 (vip-change-state-to-insert)) 3863 (viper-change-state-to-insert))
3793 (error ;; make sure that the overlay doesn't stay. 3864 (error ;; make sure that the overlay doesn't stay.
3794 ;; go back to the original point 3865 ;; go back to the original point
3795 (goto-char (vip-replace-start)) 3866 (goto-char (viper-replace-start))
3796 (vip-hide-replace-overlay) 3867 (viper-hide-replace-overlay)
3797 (vip-message-conditions conds)))) 3868 (viper-message-conditions conds))))
3798 3869
3799 3870
3800 (defun vip-change-subr (beg end) 3871 (defun viper-change-subr (beg end)
3801 ;; beg is sometimes (mark t), which may be nil 3872 ;; beg is sometimes (mark t), which may be nil
3802 (or beg (setq beg end)) 3873 (or beg (setq beg end))
3803 3874 (if viper-use-register
3804 (if vip-use-register
3805 (progn 3875 (progn
3806 (copy-to-register vip-use-register beg end nil) 3876 (copy-to-register viper-use-register beg end nil)
3807 (setq vip-use-register nil))) 3877 (setq viper-use-register nil)))
3808 (kill-region beg end) 3878 (kill-region beg end)
3809 (setq this-command 'vip-change) 3879 (setq this-command 'viper-change)
3810 (vip-yank-last-insertion)) 3880 (viper-yank-last-insertion))
3811 3881
3812 (defun vip-toggle-case (arg) 3882 (defun viper-toggle-case (arg)
3813 "Toggle character case." 3883 "Toggle character case."
3814 (interactive "P") 3884 (interactive "P")
3815 (let ((val (vip-p-val arg)) (c)) 3885 (let ((val (viper-p-val arg)) (c))
3816 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil)) 3886 (viper-set-destructive-command
3887 (list 'viper-toggle-case val nil nil nil nil))
3817 (while (> val 0) 3888 (while (> val 0)
3818 (setq c (following-char)) 3889 (setq c (following-char))
3819 (delete-char 1 nil) 3890 (delete-char 1 nil)
3820 (if (eq c (upcase c)) 3891 (if (eq c (upcase c))
3821 (insert-char (downcase c) 1) 3892 (insert-char (downcase c) 1)
3824 (setq val (1- val))))) 3895 (setq val (1- val)))))
3825 3896
3826 3897
3827 ;; query replace 3898 ;; query replace
3828 3899
3829 (defun vip-query-replace () 3900 (defun viper-query-replace ()
3830 "Query replace. 3901 "Query replace.
3831 If a null string is suplied as the string to be replaced, 3902 If a null string is suplied as the string to be replaced,
3832 the query replace mode will toggle between string replace 3903 the query replace mode will toggle between string replace
3833 and regexp replace." 3904 and regexp replace."
3834 (interactive) 3905 (interactive)
3835 (let (str) 3906 (let (str)
3836 (setq str (vip-read-string-with-history 3907 (setq str (viper-read-string-with-history
3837 (if vip-re-query-replace "Query replace regexp: " 3908 (if viper-re-query-replace "Query replace regexp: "
3838 "Query replace: ") 3909 "Query replace: ")
3839 nil ; no initial 3910 nil ; no initial
3840 'vip-replace1-history 3911 'viper-replace1-history
3841 (car vip-replace1-history) ; default 3912 (car viper-replace1-history) ; default
3842 )) 3913 ))
3843 (if (string= str "") 3914 (if (string= str "")
3844 (progn 3915 (progn
3845 (setq vip-re-query-replace (not vip-re-query-replace)) 3916 (setq viper-re-query-replace (not viper-re-query-replace))
3846 (message "Query replace mode changed to %s" 3917 (message "Query replace mode changed to %s"
3847 (if vip-re-query-replace "regexp replace" 3918 (if viper-re-query-replace "regexp replace"
3848 "string replace"))) 3919 "string replace")))
3849 (if vip-re-query-replace 3920 (if viper-re-query-replace
3850 (query-replace-regexp 3921 (query-replace-regexp
3851 str 3922 str
3852 (vip-read-string-with-history 3923 (viper-read-string-with-history
3853 (format "Query replace regexp `%s' with: " str) 3924 (format "Query replace regexp `%s' with: " str)
3854 nil ; no initial 3925 nil ; no initial
3855 'vip-replace1-history 3926 'viper-replace1-history
3856 (car vip-replace1-history) ; default 3927 (car viper-replace1-history) ; default
3857 )) 3928 ))
3858 (query-replace 3929 (query-replace
3859 str 3930 str
3860 (vip-read-string-with-history 3931 (viper-read-string-with-history
3861 (format "Query replace `%s' with: " str) 3932 (format "Query replace `%s' with: " str)
3862 nil ; no initial 3933 nil ; no initial
3863 'vip-replace1-history 3934 'viper-replace1-history
3864 (car vip-replace1-history) ; default 3935 (car viper-replace1-history) ; default
3865 )))))) 3936 ))))))
3866 3937
3867 3938
3868 ;; marking 3939 ;; marking
3869 3940
3870 (defun vip-mark-beginning-of-buffer () 3941 (defun viper-mark-beginning-of-buffer ()
3871 "Mark beginning of buffer." 3942 "Mark beginning of buffer."
3872 (interactive) 3943 (interactive)
3873 (push-mark (point)) 3944 (push-mark (point))
3874 (goto-char (point-min)) 3945 (goto-char (point-min))
3875 (exchange-point-and-mark) 3946 (exchange-point-and-mark)
3876 (message "Mark set at the beginning of buffer")) 3947 (message "Mark set at the beginning of buffer"))
3877 3948
3878 (defun vip-mark-end-of-buffer () 3949 (defun viper-mark-end-of-buffer ()
3879 "Mark end of buffer." 3950 "Mark end of buffer."
3880 (interactive) 3951 (interactive)
3881 (push-mark (point)) 3952 (push-mark (point))
3882 (goto-char (point-max)) 3953 (goto-char (point-max))
3883 (exchange-point-and-mark) 3954 (exchange-point-and-mark)
3884 (message "Mark set at the end of buffer")) 3955 (message "Mark set at the end of buffer"))
3885 3956
3886 (defun vip-mark-point () 3957 (defun viper-mark-point ()
3887 "Set mark at point of buffer." 3958 "Set mark at point of buffer."
3888 (interactive) 3959 (interactive)
3889 (let ((char (read-char))) 3960 (let ((char (read-char)))
3890 (cond ((and (<= ?a char) (<= char ?z)) 3961 (cond ((and (<= ?a char) (<= char ?z))
3891 (point-to-register (1+ (- char ?a)))) 3962 (point-to-register (1+ (- char ?a))))
3892 ((= char ?<) (vip-mark-beginning-of-buffer)) 3963 ((= char ?<) (viper-mark-beginning-of-buffer))
3893 ((= char ?>) (vip-mark-end-of-buffer)) 3964 ((= char ?>) (viper-mark-end-of-buffer))
3894 ((= char ?.) (vip-set-mark-if-necessary)) 3965 ((= char ?.) (viper-set-mark-if-necessary))
3895 ((= char ?,) (vip-cycle-through-mark-ring)) 3966 ((= char ?,) (viper-cycle-through-mark-ring))
3896 ((= char ?D) (mark-defun)) 3967 ((= char ?D) (mark-defun))
3897 (t (error "")) 3968 (t (error ""))
3898 ))) 3969 )))
3899 3970
3900 ;; Algorithm: If first invocation of this command save mark on ring, goto 3971 ;; Algorithm: If first invocation of this command save mark on ring, goto
3906 ;; If repeated command, pop top elt from the ring into mark and 3977 ;; If repeated command, pop top elt from the ring into mark and
3907 ;; jump there. This forgets the position, p1, and puts M1 back into mark. 3978 ;; jump there. This forgets the position, p1, and puts M1 back into mark.
3908 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from 3979 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
3909 ;; the ring into mark. Push M2 back on the ring and set mark to M0. 3980 ;; the ring into mark. Push M2 back on the ring and set mark to M0.
3910 ;; etc. 3981 ;; etc.
3911 (defun vip-cycle-through-mark-ring () 3982 (defun viper-cycle-through-mark-ring ()
3912 "Visit previous locations on the mark ring. 3983 "Visit previous locations on the mark ring.
3913 One can use `` and '' to temporarily jump 1 step back." 3984 One can use `` and '' to temporarily jump 1 step back."
3914 (let* ((sv-pt (point))) 3985 (let* ((sv-pt (point)))
3915 ;; if repeated `m,' command, pop the previously saved mark. 3986 ;; if repeated `m,' command, pop the previously saved mark.
3916 ;; Prev saved mark is actually prev saved point. It is used if the 3987 ;; Prev saved mark is actually prev saved point. It is used if the
3918 ;; from the mark ring by the next `m,' command. 3989 ;; from the mark ring by the next `m,' command.
3919 ;; In any case, go to the previous or previously saved mark. 3990 ;; In any case, go to the previous or previously saved mark.
3920 ;; Then push the current mark (popped off the ring) and set current 3991 ;; Then push the current mark (popped off the ring) and set current
3921 ;; point to be the mark. Current pt as mark is discarded by the next 3992 ;; point to be the mark. Current pt as mark is discarded by the next
3922 ;; m, command. 3993 ;; m, command.
3923 (if (eq last-command 'vip-cycle-through-mark-ring) 3994 (if (eq last-command 'viper-cycle-through-mark-ring)
3924 () 3995 ()
3925 ;; save current mark if the first iteration 3996 ;; save current mark if the first iteration
3926 (setq mark-ring (delete (vip-mark-marker) mark-ring)) 3997 (setq mark-ring (delete (viper-mark-marker) mark-ring))
3927 (if (mark t) 3998 (if (mark t)
3928 (push-mark (mark t) t)) ) 3999 (push-mark (mark t) t)) )
3929 (pop-mark) 4000 (pop-mark)
3930 (set-mark-command 1) 4001 (set-mark-command 1)
3931 ;; don't duplicate mark on the ring 4002 ;; don't duplicate mark on the ring
3932 (setq mark-ring (delete (vip-mark-marker) mark-ring)) 4003 (setq mark-ring (delete (viper-mark-marker) mark-ring))
3933 (push-mark sv-pt t) 4004 (push-mark sv-pt t)
3934 (vip-deactivate-mark) 4005 (viper-deactivate-mark)
3935 (setq this-command 'vip-cycle-through-mark-ring) 4006 (setq this-command 'viper-cycle-through-mark-ring)
3936 )) 4007 ))
3937 4008
3938 4009
3939 (defun vip-goto-mark (arg) 4010 (defun viper-goto-mark (arg)
3940 "Go to mark." 4011 "Go to mark."
3941 (interactive "P") 4012 (interactive "P")
3942 (let ((char (read-char)) 4013 (let ((char (read-char))
3943 (com (vip-getcom arg))) 4014 (com (viper-getcom arg)))
3944 (vip-goto-mark-subr char com nil))) 4015 (viper-goto-mark-subr char com nil)))
3945 4016
3946 (defun vip-goto-mark-and-skip-white (arg) 4017 (defun viper-goto-mark-and-skip-white (arg)
3947 "Go to mark and skip to first non-white character on line." 4018 "Go to mark and skip to first non-white character on line."
3948 (interactive "P") 4019 (interactive "P")
3949 (let ((char (read-char)) 4020 (let ((char (read-char))
3950 (com (vip-getCom arg))) 4021 (com (viper-getCom arg)))
3951 (vip-goto-mark-subr char com t))) 4022 (viper-goto-mark-subr char com t)))
3952 4023
3953 (defun vip-goto-mark-subr (char com skip-white) 4024 (defun viper-goto-mark-subr (char com skip-white)
3954 (if (eobp) 4025 (if (eobp)
3955 (if (bobp) 4026 (if (bobp)
3956 (error "Empty buffer") 4027 (error "Empty buffer")
3957 (backward-char 1))) 4028 (backward-char 1)))
3958 (cond ((vip-valid-register char '(letter)) 4029 (cond ((viper-valid-register char '(letter))
3959 (let* ((buff (current-buffer)) 4030 (let* ((buff (current-buffer))
3960 (reg (1+ (- char ?a))) 4031 (reg (1+ (- char ?a)))
3961 (text-marker (get-register reg))) 4032 (text-marker (get-register reg)))
3962 (if com (vip-move-marker-locally 'vip-com-point (point))) 4033 (if com (viper-move-marker-locally 'viper-com-point (point)))
3963 (if (not (vip-valid-marker text-marker)) 4034 (if (not (viper-valid-marker text-marker))
3964 (error vip-EmptyTextmarker char)) 4035 (error viper-EmptyTextmarker char))
3965 (if (and (vip-same-line (point) vip-last-jump) 4036 (if (and (viper-same-line (point) viper-last-jump)
3966 (= (point) vip-last-jump-ignore)) 4037 (= (point) viper-last-jump-ignore))
3967 (push-mark vip-last-jump t) 4038 (push-mark viper-last-jump t)
3968 (push-mark nil t)) ; no msg 4039 (push-mark nil t)) ; no msg
3969 (vip-register-to-point reg) 4040 (viper-register-to-point reg)
3970 (setq vip-last-jump (point-marker)) 4041 (setq viper-last-jump (point-marker))
3971 (cond (skip-white 4042 (cond (skip-white
3972 (back-to-indentation) 4043 (back-to-indentation)
3973 (setq vip-last-jump-ignore (point)))) 4044 (setq viper-last-jump-ignore (point))))
3974 (if com 4045 (if com
3975 (if (equal buff (current-buffer)) 4046 (if (equal buff (current-buffer))
3976 (vip-execute-com (if skip-white 4047 (viper-execute-com (if skip-white
3977 'vip-goto-mark-and-skip-white 4048 'viper-goto-mark-and-skip-white
3978 'vip-goto-mark) 4049 'viper-goto-mark)
3979 nil com) 4050 nil com)
3980 (switch-to-buffer buff) 4051 (switch-to-buffer buff)
3981 (goto-char vip-com-point) 4052 (goto-char viper-com-point)
3982 (vip-change-state-to-vi) 4053 (viper-change-state-to-vi)
3983 (error ""))))) 4054 (error "")))))
3984 ((and (not skip-white) (= char ?`)) 4055 ((and (not skip-white) (= char ?`))
3985 (if com (vip-move-marker-locally 'vip-com-point (point))) 4056 (if com (viper-move-marker-locally 'viper-com-point (point)))
3986 (if (and (vip-same-line (point) vip-last-jump) 4057 (if (and (viper-same-line (point) viper-last-jump)
3987 (= (point) vip-last-jump-ignore)) 4058 (= (point) viper-last-jump-ignore))
3988 (goto-char vip-last-jump)) 4059 (goto-char viper-last-jump))
3989 (if (null (mark t)) (error "Mark is not set in this buffer")) 4060 (if (null (mark t)) (error "Mark is not set in this buffer"))
3990 (if (= (point) (mark t)) (pop-mark)) 4061 (if (= (point) (mark t)) (pop-mark))
3991 (exchange-point-and-mark) 4062 (exchange-point-and-mark)
3992 (setq vip-last-jump (point-marker) 4063 (setq viper-last-jump (point-marker)
3993 vip-last-jump-ignore 0) 4064 viper-last-jump-ignore 0)
3994 (if com (vip-execute-com 'vip-goto-mark nil com))) 4065 (if com (viper-execute-com 'viper-goto-mark nil com)))
3995 ((and skip-white (= char ?')) 4066 ((and skip-white (= char ?'))
3996 (if com (vip-move-marker-locally 'vip-com-point (point))) 4067 (if com (viper-move-marker-locally 'viper-com-point (point)))
3997 (if (and (vip-same-line (point) vip-last-jump) 4068 (if (and (viper-same-line (point) viper-last-jump)
3998 (= (point) vip-last-jump-ignore)) 4069 (= (point) viper-last-jump-ignore))
3999 (goto-char vip-last-jump)) 4070 (goto-char viper-last-jump))
4000 (if (= (point) (mark t)) (pop-mark)) 4071 (if (= (point) (mark t)) (pop-mark))
4001 (exchange-point-and-mark) 4072 (exchange-point-and-mark)
4002 (setq vip-last-jump (point)) 4073 (setq viper-last-jump (point))
4003 (back-to-indentation) 4074 (back-to-indentation)
4004 (setq vip-last-jump-ignore (point)) 4075 (setq viper-last-jump-ignore (point))
4005 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) 4076 (if com (viper-execute-com 'viper-goto-mark-and-skip-white nil com)))
4006 (t (error vip-InvalidTextmarker char)))) 4077 (t (error viper-InvalidTextmarker char))))
4007 4078
4008 (defun vip-insert-tab () 4079 (defun viper-insert-tab ()
4009 (interactive) 4080 (interactive)
4010 (insert-tab)) 4081 (insert-tab))
4011 4082
4012 (defun vip-exchange-point-and-mark () 4083 (defun viper-exchange-point-and-mark ()
4013 (interactive) 4084 (interactive)
4014 (exchange-point-and-mark) 4085 (exchange-point-and-mark)
4015 (back-to-indentation)) 4086 (back-to-indentation))
4016 4087
4017 ;; Input Mode Indentation 4088 ;; Input Mode Indentation
4018 4089
4019 ;; Returns t, if the string before point matches the regexp STR. 4090 ;; Returns t, if the string before point matches the regexp STR.
4020 (defsubst vip-looking-back (str) 4091 (defsubst viper-looking-back (str)
4021 (and (save-excursion (re-search-backward str nil t)) 4092 (and (save-excursion (re-search-backward str nil t))
4022 (= (point) (match-end 0)))) 4093 (= (point) (match-end 0))))
4023 4094
4024 4095
4025 (defun vip-forward-indent () 4096 (defun viper-forward-indent ()
4026 "Indent forward -- `C-t' in Vi." 4097 "Indent forward -- `C-t' in Vi."
4027 (interactive) 4098 (interactive)
4028 (setq vip-cted t) 4099 (setq viper-cted t)
4029 (indent-to (+ (current-column) vip-shift-width))) 4100 (indent-to (+ (current-column) viper-shift-width)))
4030 4101
4031 (defun vip-backward-indent () 4102 (defun viper-backward-indent ()
4032 "Backtab, C-d in VI" 4103 "Backtab, C-d in VI"
4033 (interactive) 4104 (interactive)
4034 (if vip-cted 4105 (if viper-cted
4035 (let ((p (point)) (c (current-column)) bol (indent t)) 4106 (let ((p (point)) (c (current-column)) bol (indent t))
4036 (if (vip-looking-back "[0^]") 4107 (if (viper-looking-back "[0^]")
4037 (progn 4108 (progn
4038 (if (eq ?^ (preceding-char)) 4109 (if (eq ?^ (preceding-char))
4039 (setq vip-preserve-indent t)) 4110 (setq viper-preserve-indent t))
4040 (delete-backward-char 1) 4111 (delete-backward-char 1)
4041 (setq p (point)) 4112 (setq p (point))
4042 (setq indent nil))) 4113 (setq indent nil)))
4043 (save-excursion 4114 (save-excursion
4044 (beginning-of-line) 4115 (beginning-of-line)
4045 (setq bol (point))) 4116 (setq bol (point)))
4046 (if (re-search-backward "[^ \t]" bol 1) (forward-char)) 4117 (if (re-search-backward "[^ \t]" bol 1) (forward-char))
4047 (delete-region (point) p) 4118 (delete-region (point) p)
4048 (if indent 4119 (if indent
4049 (indent-to (- c vip-shift-width))) 4120 (indent-to (- c viper-shift-width)))
4050 (if (or (bolp) (vip-looking-back "[^ \t]")) 4121 (if (or (bolp) (viper-looking-back "[^ \t]"))
4051 (setq vip-cted nil))))) 4122 (setq viper-cted nil)))))
4052 4123
4053 (defun vip-autoindent () 4124 (defun viper-autoindent ()
4054 "Auto Indentation, Vi-style." 4125 "Auto Indentation, Vi-style."
4055 (interactive) 4126 (interactive)
4056 (let ((col (current-indentation))) 4127 (let ((col (current-indentation)))
4057 (if abbrev-mode (expand-abbrev)) 4128 (if abbrev-mode (expand-abbrev))
4058 (if vip-preserve-indent 4129 (if viper-preserve-indent
4059 (setq vip-preserve-indent nil) 4130 (setq viper-preserve-indent nil)
4060 (setq vip-current-indent col)) 4131 (setq viper-current-indent col))
4061 ;; don't leave whitespace lines around 4132 ;; don't leave whitespace lines around
4062 (if (memq last-command 4133 (if (memq last-command
4063 '(vip-autoindent 4134 '(viper-autoindent
4064 vip-open-line vip-Open-line 4135 viper-open-line viper-Open-line
4065 vip-replace-state-exit-cmd)) 4136 viper-replace-state-exit-cmd))
4066 (indent-to-left-margin)) 4137 (indent-to-left-margin))
4067 ;; use \n instead of newline, or else <Return> will move the insert point 4138 ;; use \n instead of newline, or else <Return> will move the insert point
4068 ;;(newline 1) 4139 ;;(newline 1)
4069 (insert "\n") 4140 (insert "\n")
4070 (if vip-auto-indent 4141 (if viper-auto-indent
4071 (progn 4142 (progn
4072 (setq vip-cted t) 4143 (setq viper-cted t)
4073 (if (and vip-electric-mode 4144 (if (and viper-electric-mode
4074 (not (eq major-mode 'fundamental-mode))) 4145 (not
4146 (memq major-mode '(fundamental-mode
4147 text-mode
4148 paragraph-indent-text-mode ))))
4075 (indent-according-to-mode) 4149 (indent-according-to-mode)
4076 (indent-to vip-current-indent)) 4150 (indent-to viper-current-indent))
4077 )) 4151 ))
4078 )) 4152 ))
4079 4153
4080 4154
4081 ;; Viewing registers 4155 ;; Viewing registers
4082 4156
4083 (defun vip-ket-function (arg) 4157 (defun viper-ket-function (arg)
4084 "Function called by \], the ket. View registers and call \]\]." 4158 "Function called by \], the ket. View registers and call \]\]."
4085 (interactive "P") 4159 (interactive "P")
4086 (let ((reg (read-char))) 4160 (let ((reg (read-char)))
4087 (cond ((vip-valid-register reg '(letter Letter)) 4161 (cond ((viper-valid-register reg '(letter Letter))
4088 (view-register (downcase reg))) 4162 (view-register (downcase reg)))
4089 ((vip-valid-register reg '(digit)) 4163 ((viper-valid-register reg '(digit))
4090 (let ((text (current-kill (- reg ?1) 'do-not-rotate))) 4164 (let ((text (current-kill (- reg ?1) 'do-not-rotate)))
4091 (save-excursion 4165 (save-excursion
4092 (set-buffer (get-buffer-create "*Output*")) 4166 (set-buffer (get-buffer-create "*Output*"))
4093 (delete-region (point-min) (point-max)) 4167 (delete-region (point-min) (point-max))
4094 (insert (format "Register %c contains the string:\n" reg)) 4168 (insert (format "Register %c contains the string:\n" reg))
4095 (insert text) 4169 (insert text)
4096 (goto-char (point-min))) 4170 (goto-char (point-min)))
4097 (display-buffer "*Output*"))) 4171 (display-buffer "*Output*")))
4098 ((= ?\] reg) 4172 ((= ?\] reg)
4099 (vip-next-heading arg)) 4173 (viper-next-heading arg))
4100 (t (error 4174 (t (error
4101 vip-InvalidRegister reg))))) 4175 viper-InvalidRegister reg)))))
4102 4176
4103 (defun vip-brac-function (arg) 4177 (defun viper-brac-function (arg)
4104 "Function called by \[, the brac. View textmarkers and call \[\[" 4178 "Function called by \[, the brac. View textmarkers and call \[\["
4105 (interactive "P") 4179 (interactive "P")
4106 (let ((reg (read-char))) 4180 (let ((reg (read-char)))
4107 (cond ((= ?\[ reg) 4181 (cond ((= ?\[ reg)
4108 (vip-prev-heading arg)) 4182 (viper-prev-heading arg))
4109 ((= ?\] reg) 4183 ((= ?\] reg)
4110 (vip-heading-end arg)) 4184 (viper-heading-end arg))
4111 ((vip-valid-register reg '(letter)) 4185 ((viper-valid-register reg '(letter))
4112 (let* ((val (get-register (1+ (- reg ?a)))) 4186 (let* ((val (get-register (1+ (- reg ?a))))
4113 (buf (if (not val) 4187 (buf (if (not val)
4114 (error vip-EmptyTextmarker reg) 4188 (error viper-EmptyTextmarker reg)
4115 (marker-buffer val))) 4189 (marker-buffer val)))
4116 (pos (marker-position val)) 4190 (pos (marker-position val))
4117 line-no text (s pos) (e pos)) 4191 line-no text (s pos) (e pos))
4118 (save-excursion 4192 (save-excursion
4119 (set-buffer (get-buffer-create "*Output*")) 4193 (set-buffer (get-buffer-create "*Output*"))
4143 (format 4217 (format
4144 "Textmarker `%c' is in buffer `%s' at line %d.\n" 4218 "Textmarker `%c' is in buffer `%s' at line %d.\n"
4145 reg (buffer-name buf) line-no)) 4219 reg (buffer-name buf) line-no))
4146 (insert (format "Here is some text around %c:\n\n %s" 4220 (insert (format "Here is some text around %c:\n\n %s"
4147 reg text))) 4221 reg text)))
4148 (insert (format vip-EmptyTextmarker reg))) 4222 (insert (format viper-EmptyTextmarker reg)))
4149 (goto-char (point-min))) 4223 (goto-char (point-min)))
4150 (display-buffer "*Output*"))) 4224 (display-buffer "*Output*")))
4151 (t (error vip-InvalidTextmarker reg))))) 4225 (t (error viper-InvalidTextmarker reg)))))
4152 4226
4153 4227
4154 4228
4155 ;; commands in insertion mode 4229 ;; commands in insertion mode
4156 4230
4157 (defun vip-delete-backward-word (arg) 4231 (defun viper-delete-backward-word (arg)
4158 "Delete previous word." 4232 "Delete previous word."
4159 (interactive "p") 4233 (interactive "p")
4160 (save-excursion 4234 (save-excursion
4161 (push-mark nil t) 4235 (push-mark nil t)
4162 (backward-word arg) 4236 (backward-word arg)
4182 4256
4183 (save-window-excursion 4257 (save-window-excursion
4184 (delete-other-windows) 4258 (delete-other-windows)
4185 ;; if 0 < viper-expert-level < viper-max-expert-level 4259 ;; if 0 < viper-expert-level < viper-max-expert-level
4186 ;; & dont-change-unless = t -- use it; else ask 4260 ;; & dont-change-unless = t -- use it; else ask
4187 (vip-ask-level dont-change-unless)) 4261 (viper-ask-level dont-change-unless))
4188 4262
4189 (setq viper-always t 4263 (setq viper-always t
4190 vip-ex-style-motion t 4264 viper-ex-style-motion t
4191 vip-ex-style-editing-in-insert t 4265 viper-ex-style-editing-in-insert t
4192 vip-want-ctl-h-help nil) 4266 viper-want-ctl-h-help nil)
4193 4267
4194 (cond ((eq viper-expert-level 1) ; novice or beginner 4268 (cond ((eq viper-expert-level 1) ; novice or beginner
4195 (global-set-key ; in emacs-state 4269 (global-set-key ; in emacs-state
4196 vip-toggle-key 4270 viper-toggle-key
4197 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs)) 4271 (if (viper-window-display-p) 'viper-iconify 'suspend-emacs))
4198 (setq vip-no-multiple-ESC t 4272 (setq viper-no-multiple-ESC t
4199 vip-re-search t 4273 viper-re-search t
4200 vip-vi-style-in-minibuffer t 4274 viper-vi-style-in-minibuffer t
4201 vip-search-wrap-around-t t 4275 viper-search-wrap-around-t t
4202 vip-electric-mode nil 4276 viper-electric-mode nil
4203 vip-want-emacs-keys-in-vi nil 4277 viper-want-emacs-keys-in-vi nil
4204 vip-want-emacs-keys-in-insert nil)) 4278 viper-want-emacs-keys-in-insert nil))
4205 4279
4206 ((and (> viper-expert-level 1) (< viper-expert-level 5)) 4280 ((and (> viper-expert-level 1) (< viper-expert-level 5))
4207 ;; intermediate to guru 4281 ;; intermediate to guru
4208 (setq vip-no-multiple-ESC (if (vip-window-display-p) 4282 (setq viper-no-multiple-ESC (if (viper-window-display-p)
4209 t 'twice) 4283 t 'twice)
4210 vip-electric-mode t 4284 viper-electric-mode t
4211 vip-want-emacs-keys-in-vi t 4285 viper-want-emacs-keys-in-vi t
4212 vip-want-emacs-keys-in-insert (> viper-expert-level 2)) 4286 viper-want-emacs-keys-in-insert (> viper-expert-level 2))
4213 4287
4214 (if (eq viper-expert-level 4) ; respect user's ex-style motion 4288 (if (eq viper-expert-level 4) ; respect user's ex-style motion
4215 ; and vip-no-multiple-ESC 4289 ; and viper-no-multiple-ESC
4216 (progn 4290 (progn
4217 (setq-default 4291 (setq-default
4218 vip-ex-style-editing-in-insert 4292 viper-ex-style-editing-in-insert
4219 (viper-standard-value 'vip-ex-style-editing-in-insert) 4293 (viper-standard-value 'viper-ex-style-editing-in-insert)
4220 vip-ex-style-motion 4294 viper-ex-style-motion
4221 (viper-standard-value 'vip-ex-style-motion)) 4295 (viper-standard-value 'viper-ex-style-motion))
4222 (setq vip-ex-style-motion 4296 (setq viper-ex-style-motion
4223 (viper-standard-value 'vip-ex-style-motion) 4297 (viper-standard-value 'viper-ex-style-motion)
4224 vip-ex-style-editing-in-insert 4298 viper-ex-style-editing-in-insert
4225 (viper-standard-value 'vip-ex-style-editing-in-insert) 4299 (viper-standard-value 'viper-ex-style-editing-in-insert)
4226 vip-re-search 4300 viper-re-search
4227 (viper-standard-value 'vip-re-search) 4301 (viper-standard-value 'viper-re-search)
4228 vip-no-multiple-ESC 4302 viper-no-multiple-ESC
4229 (viper-standard-value 'vip-no-multiple-ESC))))) 4303 (viper-standard-value 'viper-no-multiple-ESC)))))
4230 4304
4231 ;; A wizard!! 4305 ;; A wizard!!
4232 ;; Ideally, if 5 is selected, a buffer should pop up to let the 4306 ;; Ideally, if 5 is selected, a buffer should pop up to let the
4233 ;; user toggle the values of variables. 4307 ;; user toggle the values of variables.
4234 (t (setq-default vip-ex-style-editing-in-insert 4308 (t (setq-default viper-ex-style-editing-in-insert
4235 (viper-standard-value 'vip-ex-style-editing-in-insert) 4309 (viper-standard-value 'viper-ex-style-editing-in-insert)
4236 vip-ex-style-motion 4310 viper-ex-style-motion
4237 (viper-standard-value 'vip-ex-style-motion)) 4311 (viper-standard-value 'viper-ex-style-motion))
4238 (setq vip-want-ctl-h-help 4312 (setq viper-want-ctl-h-help
4239 (viper-standard-value 'vip-want-ctl-h-help) 4313 (viper-standard-value 'viper-want-ctl-h-help)
4240 viper-always 4314 viper-always
4241 (viper-standard-value 'viper-always) 4315 (viper-standard-value 'viper-always)
4242 vip-no-multiple-ESC 4316 viper-no-multiple-ESC
4243 (viper-standard-value 'vip-no-multiple-ESC) 4317 (viper-standard-value 'viper-no-multiple-ESC)
4244 vip-ex-style-motion 4318 viper-ex-style-motion
4245 (viper-standard-value 'vip-ex-style-motion) 4319 (viper-standard-value 'viper-ex-style-motion)
4246 vip-ex-style-editing-in-insert 4320 viper-ex-style-editing-in-insert
4247 (viper-standard-value 'vip-ex-style-editing-in-insert) 4321 (viper-standard-value 'viper-ex-style-editing-in-insert)
4248 vip-re-search 4322 viper-re-search
4249 (viper-standard-value 'vip-re-search) 4323 (viper-standard-value 'viper-re-search)
4250 vip-electric-mode 4324 viper-electric-mode
4251 (viper-standard-value 'vip-electric-mode) 4325 (viper-standard-value 'viper-electric-mode)
4252 vip-want-emacs-keys-in-vi 4326 viper-want-emacs-keys-in-vi
4253 (viper-standard-value 'vip-want-emacs-keys-in-vi) 4327 (viper-standard-value 'viper-want-emacs-keys-in-vi)
4254 vip-want-emacs-keys-in-insert 4328 viper-want-emacs-keys-in-insert
4255 (viper-standard-value 'vip-want-emacs-keys-in-insert)))) 4329 (viper-standard-value 'viper-want-emacs-keys-in-insert))))
4256 4330
4257 (vip-set-mode-vars-for vip-current-state) 4331 (viper-set-mode-vars-for viper-current-state)
4258 (if (or viper-always 4332 (if (or viper-always
4259 (and (> viper-expert-level 0) (> 5 viper-expert-level))) 4333 (and (> viper-expert-level 0) (> 5 viper-expert-level)))
4260 (vip-set-hooks))) 4334 (viper-set-hooks)))
4261 4335
4262 ;; Ask user expert level. 4336 ;; Ask user expert level.
4263 (defun vip-ask-level (dont-change-unless) 4337 (defun viper-ask-level (dont-change-unless)
4264 (let ((ask-buffer " *vip-ask-level*") 4338 (let ((ask-buffer " *viper-ask-level*")
4265 level-changed repeated) 4339 level-changed repeated)
4266 (save-window-excursion 4340 (save-window-excursion
4267 (switch-to-buffer ask-buffer) 4341 (switch-to-buffer ask-buffer)
4268 4342
4269 (while (or (> viper-expert-level viper-max-expert-level) 4343 (while (or (> viper-expert-level viper-max-expert-level)
4281 Please specify your level of familiarity with the venomous VI PERil 4355 Please specify your level of familiarity with the venomous VI PERil
4282 (and the VI Plan for Emacs Rescue). 4356 (and the VI Plan for Emacs Rescue).
4283 You can change it at any time by typing `M-x viper-set-expert-level RET' 4357 You can change it at any time by typing `M-x viper-set-expert-level RET'
4284 4358
4285 1 -- BEGINNER: Almost all Emacs features are suppressed. 4359 1 -- BEGINNER: Almost all Emacs features are suppressed.
4286 Feels almost like straight Vi. File name completion and 4360 Feels almost like straight Vi. File name completion and
4287 command history in the minibuffer are thrown in as a bonus. 4361 command history in the minibuffer are thrown in as a bonus.
4288 To use Emacs productively, you must reach level 3 or higher. 4362 To use Emacs productively, you must reach level 3 or higher.
4289 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, 4363 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
4290 so most Emacs commands can be used when Viper is in Vi state. 4364 so most Emacs commands can be used when Viper is in Vi state.
4291 Good progress---you are well on the way to level 3! 4365 Good progress---you are well on the way to level 3!
4292 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also 4366 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also
4293 in Viper's insert state. 4367 in Viper's insert state.
4294 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, 4368 4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC,
4295 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert 4369 viper-ex-style-motion, viper-ex-style-editing-in-insert, and
4296 variables. Adjust these settings to your taste. 4370 viper-re-search variables. Adjust these settings to your taste.
4297 5 -- WIZARD: Like 4, but user settings are also respected for viper-always, 4371 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
4298 vip-electric-mode, vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, 4372 viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
4299 and vip-want-emacs-keys-in-insert. Adjust these to your taste. 4373 and viper-want-emacs-keys-in-insert. Adjust these to your taste.
4300 4374
4301 Please, specify your level now: ") 4375 Please, specify your level now: ")
4302 4376
4303 (setq viper-expert-level (- (vip-read-char-exclusive) ?0)) 4377 (setq viper-expert-level (- (viper-read-char-exclusive) ?0))
4304 ) ; end while 4378 ) ; end while
4305 4379
4306 ;; tell the user if level was changed 4380 ;; tell the user if level was changed
4307 (and level-changed 4381 (and level-changed
4308 (progn 4382 (progn
4309 (insert 4383 (insert
4310 (format "\n\n\n\n\n\t\tYou have selected user level %d" 4384 (format "\n\n\n\n\n\t\tYou have selected user level %d"
4311 viper-expert-level)) 4385 viper-expert-level))
4312 (if (y-or-n-p "Do you wish to make this change permanent? ") 4386 (if (y-or-n-p "Do you wish to make this change permanent? ")
4313 ;; save the setting for viper-expert-level 4387 ;; save the setting for viper-expert-level
4314 (vip-save-setting 4388 (viper-save-setting
4315 'viper-expert-level 4389 'viper-expert-level
4316 (format "Saving user level %d ..." viper-expert-level) 4390 (format "Saving user level %d ..." viper-expert-level)
4317 vip-custom-file-name)) 4391 viper-custom-file-name))
4318 )) 4392 ))
4319 (bury-buffer) ; remove ask-buffer from screen 4393 (bury-buffer) ; remove ask-buffer from screen
4320 (message "") 4394 (message "")
4321 ))) 4395 )))
4322 4396
4323 4397
4324 (defun vip-nil () 4398 (defun viper-nil ()
4325 (interactive) 4399 (interactive)
4326 (beep 1)) 4400 (beep 1))
4327 4401
4328 4402
4329 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer 4403 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer
4330 (defun vip-register-to-point (char &optional enforce-buffer) 4404 (defun viper-register-to-point (char &optional enforce-buffer)
4331 "Like jump-to-register, but switches to another buffer in another window." 4405 "Like jump-to-register, but switches to another buffer in another window."
4332 (interactive "cViper register to point: ") 4406 (interactive "cViper register to point: ")
4333 (let ((val (get-register char))) 4407 (let ((val (get-register char)))
4334 (cond 4408 (cond
4335 ((and (fboundp 'frame-configuration-p) 4409 ((and (fboundp 'frame-configuration-p)
4336 (frame-configuration-p val)) 4410 (frame-configuration-p val))
4337 (set-frame-configuration val)) 4411 (set-frame-configuration val))
4338 ((window-configuration-p val) 4412 ((window-configuration-p val)
4339 (set-window-configuration val)) 4413 (set-window-configuration val))
4340 ((vip-valid-marker val) 4414 ((viper-valid-marker val)
4341 (if (and enforce-buffer 4415 (if (and enforce-buffer
4342 (not (equal (current-buffer) (marker-buffer val)))) 4416 (not (equal (current-buffer) (marker-buffer val))))
4343 (error (concat vip-EmptyTextmarker " in this buffer") 4417 (error (concat viper-EmptyTextmarker " in this buffer")
4344 (1- (+ char ?a)))) 4418 (1- (+ char ?a))))
4345 (pop-to-buffer (marker-buffer val)) 4419 (pop-to-buffer (marker-buffer val))
4346 (goto-char val)) 4420 (goto-char val))
4347 ((and (consp val) (eq (car val) 'file)) 4421 ((and (consp val) (eq (car val) 'file))
4348 (find-file (cdr val))) 4422 (find-file (cdr val)))
4349 (t 4423 (t
4350 (error vip-EmptyTextmarker (1- (+ char ?a))))))) 4424 (error viper-EmptyTextmarker (1- (+ char ?a)))))))
4351 4425
4352 4426
4353 (defun vip-save-kill-buffer () 4427 (defun viper-save-kill-buffer ()
4354 "Save then kill current buffer. " 4428 "Save then kill current buffer. "
4355 (interactive) 4429 (interactive)
4356 (if (< viper-expert-level 2) 4430 (if (< viper-expert-level 2)
4357 (save-buffers-kill-emacs) 4431 (save-buffers-kill-emacs)
4358 (save-buffer) 4432 (save-buffer)
4360 4434
4361 4435
4362 4436
4363 ;;; Bug Report 4437 ;;; Bug Report
4364 4438
4365 (defun vip-submit-report () 4439 (defun viper-submit-report ()
4366 "Submit bug report on Viper." 4440 "Submit bug report on Viper."
4367 (interactive) 4441 (interactive)
4368 (let ((reporter-prompt-for-summary-p t) 4442 (let ((reporter-prompt-for-summary-p t)
4369 (vip-device-type (vip-device-type)) 4443 (viper-device-type (viper-device-type))
4370 color-display-p frame-parameters 4444 color-display-p frame-parameters
4371 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face 4445 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
4372 varlist salutation window-config) 4446 varlist salutation window-config)
4373 4447
4374 ;; If mode info is needed, add variable to `let' and then set it below, 4448 ;; If mode info is needed, add variable to `let' and then set it below,
4375 ;; like we did with color-display-p. 4449 ;; like we did with color-display-p.
4376 (setq color-display-p (if (vip-window-display-p) 4450 (setq color-display-p (if (viper-window-display-p)
4377 (vip-color-display-p) 4451 (viper-color-display-p)
4378 'non-x) 4452 'non-x)
4379 minibuffer-vi-face (if (vip-has-face-support-p) 4453 minibuffer-vi-face (if (viper-has-face-support-p)
4380 (vip-get-face vip-minibuffer-vi-face) 4454 (viper-get-face viper-minibuffer-vi-face)
4381 'non-x) 4455 'non-x)
4382 minibuffer-insert-face (if (vip-has-face-support-p) 4456 minibuffer-insert-face (if (viper-has-face-support-p)
4383 (vip-get-face vip-minibuffer-insert-face) 4457 (viper-get-face
4458 viper-minibuffer-insert-face)
4384 'non-x) 4459 'non-x)
4385 minibuffer-emacs-face (if (vip-has-face-support-p) 4460 minibuffer-emacs-face (if (viper-has-face-support-p)
4386 (vip-get-face vip-minibuffer-emacs-face) 4461 (viper-get-face
4462 viper-minibuffer-emacs-face)
4387 'non-x) 4463 'non-x)
4388 frame-parameters (if (fboundp 'frame-parameters) 4464 frame-parameters (if (fboundp 'frame-parameters)
4389 (frame-parameters (selected-frame)))) 4465 (frame-parameters (selected-frame))))
4390 4466
4391 (setq varlist (list 'vip-vi-minibuffer-minor-mode 4467 (setq varlist (list 'viper-vi-minibuffer-minor-mode
4392 'vip-insert-minibuffer-minor-mode 4468 'viper-insert-minibuffer-minor-mode
4393 'vip-vi-intercept-minor-mode 4469 'viper-vi-intercept-minor-mode
4394 'vip-vi-local-user-minor-mode 4470 'viper-vi-local-user-minor-mode
4395 'vip-vi-kbd-minor-mode 4471 'viper-vi-kbd-minor-mode
4396 'vip-vi-global-user-minor-mode 4472 'viper-vi-global-user-minor-mode
4397 'vip-vi-state-modifier-minor-mode 4473 'viper-vi-state-modifier-minor-mode
4398 'vip-vi-diehard-minor-mode 4474 'viper-vi-diehard-minor-mode
4399 'vip-vi-basic-minor-mode 4475 'viper-vi-basic-minor-mode
4400 'vip-replace-minor-mode 4476 'viper-replace-minor-mode
4401 'vip-insert-intercept-minor-mode 4477 'viper-insert-intercept-minor-mode
4402 'vip-insert-local-user-minor-mode 4478 'viper-insert-local-user-minor-mode
4403 'vip-insert-kbd-minor-mode 4479 'viper-insert-kbd-minor-mode
4404 'vip-insert-global-user-minor-mode 4480 'viper-insert-global-user-minor-mode
4405 'vip-insert-state-modifier-minor-mode 4481 'viper-insert-state-modifier-minor-mode
4406 'vip-insert-diehard-minor-mode 4482 'viper-insert-diehard-minor-mode
4407 'vip-insert-basic-minor-mode 4483 'viper-insert-basic-minor-mode
4408 'vip-emacs-intercept-minor-mode 4484 'viper-emacs-intercept-minor-mode
4409 'vip-emacs-local-user-minor-mode 4485 'viper-emacs-local-user-minor-mode
4410 'vip-emacs-kbd-minor-mode 4486 'viper-emacs-kbd-minor-mode
4411 'vip-emacs-global-user-minor-mode 4487 'viper-emacs-global-user-minor-mode
4412 'vip-emacs-state-modifier-minor-mode 4488 'viper-emacs-state-modifier-minor-mode
4413 'vip-automatic-iso-accents 4489 'viper-automatic-iso-accents
4414 'vip-want-emacs-keys-in-insert 4490 'viper-want-emacs-keys-in-insert
4415 'vip-want-emacs-keys-in-vi 4491 'viper-want-emacs-keys-in-vi
4416 'vip-keep-point-on-undo 4492 'viper-keep-point-on-undo
4417 'vip-no-multiple-ESC 4493 'viper-no-multiple-ESC
4418 'vip-electric-mode 4494 'viper-electric-mode
4419 'vip-ESC-key 4495 'viper-ESC-key
4420 'vip-want-ctl-h-help 4496 'viper-want-ctl-h-help
4421 'vip-ex-style-editing-in-insert 4497 'viper-ex-style-editing-in-insert
4422 'vip-delete-backwards-in-replace 4498 'viper-delete-backwards-in-replace
4423 'vip-vi-style-in-minibuffer 4499 'viper-vi-style-in-minibuffer
4424 'vip-vi-state-hook 4500 'viper-vi-state-hook
4425 'vip-insert-state-hook 4501 'viper-insert-state-hook
4426 'vip-replace-state-hook 4502 'viper-replace-state-hook
4427 'vip-emacs-state-hook 4503 'viper-emacs-state-hook
4428 'ex-cycle-other-window 4504 'ex-cycle-other-window
4429 'ex-cycle-through-non-files 4505 'ex-cycle-through-non-files
4430 'viper-expert-level 4506 'viper-expert-level
4431 'major-mode 4507 'major-mode
4432 'vip-device-type 4508 'viper-device-type
4433 'color-display-p 4509 'color-display-p
4434 'frame-parameters 4510 'frame-parameters
4435 'minibuffer-vi-face 4511 'minibuffer-vi-face
4436 'minibuffer-insert-face 4512 'minibuffer-insert-face
4437 'minibuffer-emacs-face 4513 'minibuffer-emacs-face
4440 Congratulations! You may have unearthed a bug in Viper! 4516 Congratulations! You may have unearthed a bug in Viper!
4441 Please mail a concise, accurate summary of the problem to the address above. 4517 Please mail a concise, accurate summary of the problem to the address above.
4442 4518
4443 -------------------------------------------------------------------") 4519 -------------------------------------------------------------------")
4444 (setq window-config (current-window-configuration)) 4520 (setq window-config (current-window-configuration))
4445 (with-output-to-temp-buffer " *vip-info*" 4521 (with-output-to-temp-buffer " *viper-info*"
4446 (switch-to-buffer " *vip-info*") 4522 (switch-to-buffer " *viper-info*")
4447 (delete-other-windows) 4523 (delete-other-windows)
4448 (princ " 4524 (princ "
4449 PLEASE FOLLOW THESE PROCEDURES 4525 PLEASE FOLLOW THESE PROCEDURES
4450 ------------------------------ 4526 ------------------------------
4451 4527
4484 4560
4485 (require 'reporter) 4561 (require 'reporter)
4486 (set-window-configuration window-config) 4562 (set-window-configuration window-config)
4487 4563
4488 (reporter-submit-bug-report "kifer@cs.sunysb.edu" 4564 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
4489 (vip-version) 4565 (viper-version)
4490 varlist 4566 varlist
4491 nil 'delete-other-windows 4567 nil 'delete-other-windows
4492 salutation) 4568 salutation)
4493 )) 4569 ))
4494 4570
4501 ;; 4577 ;;
4502 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event 4578 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
4503 ;; symbol in unread-command-events list may cause Emacs to turn this symbol 4579 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
4504 ;; into an event. Below, we delete nil from event lists, since nil is the most 4580 ;; into an event. Below, we delete nil from event lists, since nil is the most
4505 ;; common symbol that might appear in this wrong context. 4581 ;; common symbol that might appear in this wrong context.
4506 (defun vip-set-unread-command-events (arg) 4582 (defun viper-set-unread-command-events (arg)
4507 (if vip-emacs-p 4583 (if viper-emacs-p
4508 (setq 4584 (setq
4509 unread-command-events 4585 unread-command-events
4510 (let ((new-events 4586 (let ((new-events
4511 (cond ((eventp arg) (list arg)) 4587 (cond ((eventp arg) (list arg))
4512 ((listp arg) arg) 4588 ((listp arg) arg)
4513 ((sequencep arg) 4589 ((sequencep arg)
4514 (listify-key-sequence arg)) 4590 (listify-key-sequence arg))
4515 (t (error 4591 (t (error
4516 "vip-set-unread-command-events: Invalid argument, %S" 4592 "viper-set-unread-command-events: Invalid argument, %S"
4517 arg))))) 4593 arg)))))
4518 (if (not (eventp nil)) 4594 (if (not (eventp nil))
4519 (setq new-events (delq nil new-events))) 4595 (setq new-events (delq nil new-events)))
4520 (append new-events unread-command-events))) 4596 (append new-events unread-command-events)))
4521 ;; XEmacs 4597 ;; XEmacs
4522 (setq 4598 (setq
4523 unread-command-events 4599 unread-command-events
4524 (append 4600 (append
4525 (cond ((vip-characterp arg) (list (character-to-event arg))) 4601 (cond ((viper-characterp arg) (list (character-to-event arg)))
4526 ((eventp arg) (list arg)) 4602 ((eventp arg) (list arg))
4527 ((stringp arg) (mapcar 'character-to-event arg)) 4603 ((stringp arg) (mapcar 'character-to-event arg))
4528 ((vectorp arg) (append arg nil)) ; turn into list 4604 ((vectorp arg) (append arg nil)) ; turn into list
4529 ((listp arg) (vip-eventify-list-xemacs arg)) 4605 ((listp arg) (viper-eventify-list-xemacs arg))
4530 (t (error 4606 (t (error
4531 "vip-set-unread-command-events: Invalid argument, %S" arg))) 4607 "viper-set-unread-command-events: Invalid argument, %S" arg)))
4532 unread-command-events)))) 4608 unread-command-events))))
4533 4609
4534 ;; list is assumed to be a list of events of characters 4610 ;; list is assumed to be a list of events of characters
4535 (defun vip-eventify-list-xemacs (lis) 4611 (defun viper-eventify-list-xemacs (lis)
4536 (mapcar 4612 (mapcar
4537 (function (lambda (elt) 4613 (function (lambda (elt)
4538 (cond ((vip-characterp elt) (character-to-event elt)) 4614 (cond ((viper-characterp elt) (character-to-event elt))
4539 ((eventp elt) elt) 4615 ((eventp elt) elt)
4540 (t (error 4616 (t (error
4541 "vip-eventify-list-xemacs: can't convert to event, %S" 4617 "viper-eventify-list-xemacs: can't convert to event, %S"
4542 elt))))) 4618 elt)))))
4543 lis)) 4619 lis))
4544 4620
4545 4621
4546 4622