Mercurial > hg > xemacs-beta
comparison lisp/viper/viper-ex.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 |
---|---|
23 | 23 |
24 (provide 'viper-ex) | 24 (provide 'viper-ex) |
25 | 25 |
26 ;; Compiler pacifier | 26 ;; Compiler pacifier |
27 (defvar read-file-name-map) | 27 (defvar read-file-name-map) |
28 (defvar vip-use-register) | 28 (defvar viper-use-register) |
29 (defvar vip-s-string) | 29 (defvar viper-s-string) |
30 (defvar vip-shift-width) | 30 (defvar viper-shift-width) |
31 (defvar vip-ex-history) | 31 (defvar viper-ex-history) |
32 (defvar vip-related-files-and-buffers-ring) | 32 (defvar viper-related-files-and-buffers-ring) |
33 (defvar vip-local-search-start-marker) | 33 (defvar viper-local-search-start-marker) |
34 (defvar viper-expert-level) | 34 (defvar viper-expert-level) |
35 (defvar vip-custom-file-name) | 35 (defvar viper-custom-file-name) |
36 (defvar vip-case-fold-search) | 36 (defvar viper-case-fold-search) |
37 (defvar explicit-shell-file-name) | 37 (defvar explicit-shell-file-name) |
38 | 38 |
39 ;; loading happens only in non-interactive compilation | 39 ;; loading happens only in non-interactive compilation |
40 ;; in order to spare non-viperized emacs from being viperized | 40 ;; in order to spare non-viperized emacs from being viperized |
41 (if noninteractive | 41 (if noninteractive |
59 | 59 |
60 | 60 |
61 | 61 |
62 ;;; Variables | 62 ;;; Variables |
63 | 63 |
64 (defconst vip-ex-work-buf-name " *ex-working-space*") | 64 (defconst viper-ex-work-buf-name " *ex-working-space*") |
65 (defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 65 (defconst viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
66 (defconst vip-ex-tmp-buf-name " *ex-tmp*") | 66 (defconst viper-ex-tmp-buf-name " *ex-tmp*") |
67 | 67 |
68 | 68 |
69 ;;; Variable completion in :set command | 69 ;;; Variable completion in :set command |
70 | 70 |
71 ;; The list of Ex commands. Used for completing command names. | 71 ;; The list of Ex commands. Used for completing command names. |
166 Don't put `-c' here, as it is added automatically." | 166 Don't put `-c' here, as it is added automatically." |
167 :type 'string | 167 :type 'string |
168 :group 'viper-ex) | 168 :group 'viper-ex) |
169 | 169 |
170 (defvar ex-nontrivial-find-file-function | 170 (defvar ex-nontrivial-find-file-function |
171 (cond (ex-unix-type-shell 'vip-ex-nontrivial-find-file-unix) | 171 (cond (ex-unix-type-shell 'viper-ex-nontrivial-find-file-unix) |
172 ((eq system-type 'emx) 'vip-ex-nontrivial-find-file-ms) ; OS/2 | 172 ((eq system-type 'emx) 'viper-ex-nontrivial-find-file-ms) ; OS/2 |
173 (vip-ms-style-os-p 'vip-ex-nontrivial-find-file-ms) ; a Microsoft OS | 173 (viper-ms-style-os-p 'viper-ex-nontrivial-find-file-ms) ; Microsoft OS |
174 (vip-vms-os-p 'vip-ex-nontrivial-find-file-unix) ; VMS | 174 (viper-vms-os-p 'viper-ex-nontrivial-find-file-unix) ; VMS |
175 (t 'vip-ex-nontrivial-find-file-unix) ; presumably UNIX | 175 (t 'viper-ex-nontrivial-find-file-unix) ; presumably UNIX |
176 )) | 176 )) |
177 | 177 |
178 ;; Remembers the previous Ex tag. | 178 ;; Remembers the previous Ex tag. |
179 (defvar ex-tag nil) | 179 (defvar ex-tag nil) |
180 | 180 |
192 | 192 |
193 ;; File containing the shell command to be executed at Ex prompt, | 193 ;; File containing the shell command to be executed at Ex prompt, |
194 ;; e.g., :r !date | 194 ;; e.g., :r !date |
195 (defvar ex-cmdfile nil) | 195 (defvar ex-cmdfile nil) |
196 | 196 |
197 ;; flag used in vip-ex-read-file-name to indicate that we may be reading | 197 ;; flag used in viper-ex-read-file-name to indicate that we may be reading |
198 ;; multiple file names. Used for :edit and :next | 198 ;; multiple file names. Used for :edit and :next |
199 (defvar vip-keep-reading-filename nil) | 199 (defvar viper-keep-reading-filename nil) |
200 | 200 |
201 (defcustom ex-cycle-other-window t | 201 (defcustom ex-cycle-other-window t |
202 "*If t, :n and :b cycles through files and buffers in other window. | 202 "*If t, :n and :b cycles through files and buffers in other window. |
203 Then :N and :B cycles in the current window. If nil, this behavior is | 203 Then :N and :B cycles in the current window. If nil, this behavior is |
204 reversed." | 204 reversed." |
209 "*Cycle through *scratch* and other buffers that don't visit any file." | 209 "*Cycle through *scratch* and other buffers that don't visit any file." |
210 :type 'boolean | 210 :type 'boolean |
211 :group 'viper-ex) | 211 :group 'viper-ex) |
212 | 212 |
213 ;; Last shell command executed with :! command. | 213 ;; Last shell command executed with :! command. |
214 (defvar vip-ex-last-shell-com nil) | 214 (defvar viper-ex-last-shell-com nil) |
215 | 215 |
216 ;; Indicates if Minibuffer was exited temporarily in Ex-command. | 216 ;; Indicates if Minibuffer was exited temporarily in Ex-command. |
217 (defvar vip-incomplete-ex-cmd nil) | 217 (defvar viper-incomplete-ex-cmd nil) |
218 | 218 |
219 ;; Remembers the last ex-command prompt. | 219 ;; Remembers the last ex-command prompt. |
220 (defvar vip-last-ex-prompt "") | 220 (defvar viper-last-ex-prompt "") |
221 | 221 |
222 | 222 |
223 ;;; Code | 223 ;;; Code |
224 | 224 |
225 ;; Check if ex-token is an initial segment of STR | 225 ;; Check if ex-token is an initial segment of STR |
226 (defun vip-check-sub (str) | 226 (defun viper-check-sub (str) |
227 (let ((length (length ex-token))) | 227 (let ((length (length ex-token))) |
228 (if (and (<= length (length str)) | 228 (if (and (<= length (length str)) |
229 (string= ex-token (substring str 0 length))) | 229 (string= ex-token (substring str 0 length))) |
230 (setq ex-token str) | 230 (setq ex-token str) |
231 (setq ex-token-type 'non-command)))) | 231 (setq ex-token-type 'non-command)))) |
232 | 232 |
233 ;; Get a complete ex command | 233 ;; Get a complete ex command |
234 (defun vip-get-ex-com-subr () | 234 (defun viper-get-ex-com-subr () |
235 (let (case-fold-search) | 235 (let (case-fold-search) |
236 (set-mark (point)) | 236 (set-mark (point)) |
237 (re-search-forward "[a-zA-Z][a-zA-Z]*") | 237 (re-search-forward "[a-zA-Z][a-zA-Z]*") |
238 (setq ex-token-type 'command) | 238 (setq ex-token-type 'command) |
239 (setq ex-token (buffer-substring (point) (mark t))) | 239 (setq ex-token (buffer-substring (point) (mark t))) |
240 (exchange-point-and-mark) | 240 (exchange-point-and-mark) |
241 (cond ((looking-at "a") | 241 (cond ((looking-at "a") |
242 (cond ((looking-at "ab") (vip-check-sub "abbreviate")) | 242 (cond ((looking-at "ab") (viper-check-sub "abbreviate")) |
243 ((looking-at "ar") (vip-check-sub "args")) | 243 ((looking-at "ar") (viper-check-sub "args")) |
244 (t (vip-check-sub "append")))) | 244 (t (viper-check-sub "append")))) |
245 ((looking-at "h") (vip-check-sub "help")) | 245 ((looking-at "h") (viper-check-sub "help")) |
246 ((looking-at "c") | 246 ((looking-at "c") |
247 (cond ((looking-at "cd") (vip-check-sub "cd")) | 247 (cond ((looking-at "cd") (viper-check-sub "cd")) |
248 ((looking-at "ch") (vip-check-sub "chdir")) | 248 ((looking-at "ch") (viper-check-sub "chdir")) |
249 ((looking-at "co") (vip-check-sub "copy")) | 249 ((looking-at "co") (viper-check-sub "copy")) |
250 (t (vip-check-sub "change")))) | 250 (t (viper-check-sub "change")))) |
251 ((looking-at "d") (vip-check-sub "delete")) | 251 ((looking-at "d") (viper-check-sub "delete")) |
252 ((looking-at "b") (vip-check-sub "buffer")) | 252 ((looking-at "b") (viper-check-sub "buffer")) |
253 ((looking-at "B") (vip-check-sub "Buffer")) | 253 ((looking-at "B") (viper-check-sub "Buffer")) |
254 ((looking-at "e") | 254 ((looking-at "e") |
255 (if (looking-at "ex") (vip-check-sub "ex") | 255 (if (looking-at "ex") (viper-check-sub "ex") |
256 (vip-check-sub "edit"))) | 256 (viper-check-sub "edit"))) |
257 ((looking-at "f") (vip-check-sub "file")) | 257 ((looking-at "f") (viper-check-sub "file")) |
258 ((looking-at "g") (vip-check-sub "global")) | 258 ((looking-at "g") (viper-check-sub "global")) |
259 ((looking-at "i") (vip-check-sub "insert")) | 259 ((looking-at "i") (viper-check-sub "insert")) |
260 ((looking-at "j") (vip-check-sub "join")) | 260 ((looking-at "j") (viper-check-sub "join")) |
261 ((looking-at "l") (vip-check-sub "list")) | 261 ((looking-at "l") (viper-check-sub "list")) |
262 ((looking-at "m") | 262 ((looking-at "m") |
263 (cond ((looking-at "map") (vip-check-sub "map")) | 263 (cond ((looking-at "map") (viper-check-sub "map")) |
264 ((looking-at "mar") (vip-check-sub "mark")) | 264 ((looking-at "mar") (viper-check-sub "mark")) |
265 (t (vip-check-sub "move")))) | 265 (t (viper-check-sub "move")))) |
266 ((looking-at "k[a-z][^a-z]") | 266 ((looking-at "k[a-z][^a-z]") |
267 (setq ex-token "kmark") | 267 (setq ex-token "kmark") |
268 (forward-char 1) | 268 (forward-char 1) |
269 (exchange-point-and-mark)) ; this is canceled out by another | 269 (exchange-point-and-mark)) ; this is canceled out by another |
270 ; exchange-point-and-mark at the end | 270 ; exchange-point-and-mark at the end |
271 ((looking-at "k") (vip-check-sub "kmark")) | 271 ((looking-at "k") (viper-check-sub "kmark")) |
272 ((looking-at "n") (if (looking-at "nu") | 272 ((looking-at "n") (if (looking-at "nu") |
273 (vip-check-sub "number") | 273 (viper-check-sub "number") |
274 (vip-check-sub "next"))) | 274 (viper-check-sub "next"))) |
275 ((looking-at "N") (vip-check-sub "Next")) | 275 ((looking-at "N") (viper-check-sub "Next")) |
276 ((looking-at "o") (vip-check-sub "open")) | 276 ((looking-at "o") (viper-check-sub "open")) |
277 ((looking-at "p") | 277 ((looking-at "p") |
278 (cond ((looking-at "pre") (vip-check-sub "preserve")) | 278 (cond ((looking-at "pre") (viper-check-sub "preserve")) |
279 ((looking-at "pu") (vip-check-sub "put")) | 279 ((looking-at "pu") (viper-check-sub "put")) |
280 ((looking-at "pw") (vip-check-sub "pwd")) | 280 ((looking-at "pw") (viper-check-sub "pwd")) |
281 (t (vip-check-sub "print")))) | 281 (t (viper-check-sub "print")))) |
282 ((looking-at "P") (vip-check-sub "PreviousRelatedFile")) | 282 ((looking-at "P") (viper-check-sub "PreviousRelatedFile")) |
283 ((looking-at "R") (vip-check-sub "RelatedFile")) | 283 ((looking-at "R") (viper-check-sub "RelatedFile")) |
284 ((looking-at "q") (vip-check-sub "quit")) | 284 ((looking-at "q") (viper-check-sub "quit")) |
285 ((looking-at "r") | 285 ((looking-at "r") |
286 (cond ((looking-at "rec") (vip-check-sub "recover")) | 286 (cond ((looking-at "rec") (viper-check-sub "recover")) |
287 ((looking-at "rew") (vip-check-sub "rewind")) | 287 ((looking-at "rew") (viper-check-sub "rewind")) |
288 (t (vip-check-sub "read")))) | 288 (t (viper-check-sub "read")))) |
289 ((looking-at "s") | 289 ((looking-at "s") |
290 (cond ((looking-at "se") (vip-check-sub "set")) | 290 (cond ((looking-at "se") (viper-check-sub "set")) |
291 ((looking-at "sh") (vip-check-sub "shell")) | 291 ((looking-at "sh") (viper-check-sub "shell")) |
292 ((looking-at "so") (vip-check-sub "source")) | 292 ((looking-at "so") (viper-check-sub "source")) |
293 ((looking-at "sr") (vip-check-sub "sr")) | 293 ((looking-at "sr") (viper-check-sub "sr")) |
294 ((looking-at "st") (vip-check-sub "stop")) | 294 ((looking-at "st") (viper-check-sub "stop")) |
295 ((looking-at "sus") (vip-check-sub "suspend")) | 295 ((looking-at "sus") (viper-check-sub "suspend")) |
296 ((looking-at "subm") (vip-check-sub "submitReport")) | 296 ((looking-at "subm") (viper-check-sub "submitReport")) |
297 (t (vip-check-sub "substitute")))) | 297 (t (viper-check-sub "substitute")))) |
298 ((looking-at "t") | 298 ((looking-at "t") |
299 (if (looking-at "ta") (vip-check-sub "tag") | 299 (if (looking-at "ta") (viper-check-sub "tag") |
300 (vip-check-sub "transfer"))) | 300 (viper-check-sub "transfer"))) |
301 ((looking-at "u") | 301 ((looking-at "u") |
302 (cond ((looking-at "una") (vip-check-sub "unabbreviate")) | 302 (cond ((looking-at "una") (viper-check-sub "unabbreviate")) |
303 ((looking-at "unm") (vip-check-sub "unmap")) | 303 ((looking-at "unm") (viper-check-sub "unmap")) |
304 (t (vip-check-sub "undo")))) | 304 (t (viper-check-sub "undo")))) |
305 ((looking-at "v") | 305 ((looking-at "v") |
306 (cond ((looking-at "ve") (vip-check-sub "version")) | 306 (cond ((looking-at "ve") (viper-check-sub "version")) |
307 ((looking-at "vi") (vip-check-sub "visual")) | 307 ((looking-at "vi") (viper-check-sub "visual")) |
308 (t (vip-check-sub "vglobal")))) | 308 (t (viper-check-sub "vglobal")))) |
309 ((looking-at "w") | 309 ((looking-at "w") |
310 (if (looking-at "wq") (vip-check-sub "wq") | 310 (if (looking-at "wq") (viper-check-sub "wq") |
311 (vip-check-sub "write"))) | 311 (viper-check-sub "write"))) |
312 ((looking-at "W") | 312 ((looking-at "W") |
313 (if (looking-at "WW") | 313 (if (looking-at "WW") |
314 (vip-check-sub "WWrite") | 314 (viper-check-sub "WWrite") |
315 (vip-check-sub "Write"))) | 315 (viper-check-sub "Write"))) |
316 ((looking-at "x") (vip-check-sub "xit")) | 316 ((looking-at "x") (viper-check-sub "xit")) |
317 ((looking-at "y") (vip-check-sub "yank")) | 317 ((looking-at "y") (viper-check-sub "yank")) |
318 ((looking-at "z") (vip-check-sub "z"))) | 318 ((looking-at "z") (viper-check-sub "z"))) |
319 (exchange-point-and-mark) | 319 (exchange-point-and-mark) |
320 )) | 320 )) |
321 | 321 |
322 ;; Get an ex-token which is either an address or a command. | 322 ;; Get an ex-token which is either an address or a command. |
323 ;; A token has a type, \(command, address, end-mark\), and a value | 323 ;; A token has a type, \(command, address, end-mark\), and a value |
324 (defun vip-get-ex-token () | 324 (defun viper-get-ex-token () |
325 (save-window-excursion | 325 (save-window-excursion |
326 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 326 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
327 (set-buffer vip-ex-work-buf) | 327 (set-buffer viper-ex-work-buf) |
328 (skip-chars-forward " \t|") | 328 (skip-chars-forward " \t|") |
329 (cond ((looking-at "#") | 329 (cond ((looking-at "#") |
330 (setq ex-token-type 'command) | 330 (setq ex-token-type 'command) |
331 (setq ex-token (char-to-string (following-char))) | 331 (setq ex-token (char-to-string (following-char))) |
332 (forward-char 1)) | 332 (forward-char 1)) |
333 ((looking-at "[a-z]") (vip-get-ex-com-subr)) | 333 ((looking-at "[a-z]") (viper-get-ex-com-subr)) |
334 ((looking-at "\\.") | 334 ((looking-at "\\.") |
335 (forward-char 1) | 335 (forward-char 1) |
336 (setq ex-token-type 'dot)) | 336 (setq ex-token-type 'dot)) |
337 ((looking-at "[0-9]") | 337 ((looking-at "[0-9]") |
338 (set-mark (point)) | 338 (set-mark (point)) |
356 (setq ex-token-type 'plus)) | 356 (setq ex-token-type 'plus)) |
357 ((looking-at "+[0-9]") | 357 ((looking-at "+[0-9]") |
358 (forward-char 1) | 358 (forward-char 1) |
359 (setq ex-token-type 'plus)) | 359 (setq ex-token-type 'plus)) |
360 (t | 360 (t |
361 (error vip-BadAddress)))) | 361 (error viper-BadAddress)))) |
362 ((looking-at "-") | 362 ((looking-at "-") |
363 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]")) | 363 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]")) |
364 (forward-char 1) | 364 (forward-char 1) |
365 (insert "1") | 365 (insert "1") |
366 (backward-char 1) | 366 (backward-char 1) |
367 (setq ex-token-type 'minus)) | 367 (setq ex-token-type 'minus)) |
368 ((looking-at "-[0-9]") | 368 ((looking-at "-[0-9]") |
369 (forward-char 1) | 369 (forward-char 1) |
370 (setq ex-token-type 'minus)) | 370 (setq ex-token-type 'minus)) |
371 (t | 371 (t |
372 (error vip-BadAddress)))) | 372 (error viper-BadAddress)))) |
373 ((looking-at "/") | 373 ((looking-at "/") |
374 (forward-char 1) | 374 (forward-char 1) |
375 (set-mark (point)) | 375 (set-mark (point)) |
376 (let ((cont t)) | 376 (let ((cont t)) |
377 (while (and (not (eolp)) cont) | 377 (while (and (not (eolp)) cont) |
378 ;;(re-search-forward "[^/]*/") | 378 ;;(re-search-forward "[^/]*/") |
379 (re-search-forward "[^/]*\\(/\\|\n\\)") | 379 (re-search-forward "[^/]*\\(/\\|\n\\)") |
380 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/")) | 380 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/")) |
381 (setq cont nil)))) | 381 (setq cont nil)))) |
382 (backward-char 1) | 382 (backward-char 1) |
383 (setq ex-token (buffer-substring (point) (mark t))) | 383 (setq ex-token (buffer-substring (point) (mark t))) |
384 (if (looking-at "/") (forward-char 1)) | 384 (if (looking-at "/") (forward-char 1)) |
385 (setq ex-token-type 'search-forward)) | 385 (setq ex-token-type 'search-forward)) |
388 (set-mark (point)) | 388 (set-mark (point)) |
389 (let ((cont t)) | 389 (let ((cont t)) |
390 (while (and (not (eolp)) cont) | 390 (while (and (not (eolp)) cont) |
391 ;;(re-search-forward "[^\\?]*\\?") | 391 ;;(re-search-forward "[^\\?]*\\?") |
392 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)") | 392 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)") |
393 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?")) | 393 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?")) |
394 (setq cont nil)) | 394 (setq cont nil)) |
395 (backward-char 1) | 395 (backward-char 1) |
396 (if (not (looking-at "\n")) (forward-char 1)))) | 396 (if (not (looking-at "\n")) (forward-char 1)))) |
397 (setq ex-token-type 'search-backward) | 397 (setq ex-token-type 'search-backward) |
398 (setq ex-token (buffer-substring (1- (point)) (mark t)))) | 398 (setq ex-token (buffer-substring (1- (point)) (mark t)))) |
415 (forward-char 1)) | 415 (forward-char 1)) |
416 ((looking-at "\n") | 416 ((looking-at "\n") |
417 (setq ex-token-type 'end-mark) | 417 (setq ex-token-type 'end-mark) |
418 (setq ex-token "goto")) | 418 (setq ex-token "goto")) |
419 (t | 419 (t |
420 (error vip-BadExCommand))))) | 420 (error viper-BadExCommand))))) |
421 | 421 |
422 ;; Reads Ex command. Tries to determine if it has to exit because command | 422 ;; Reads Ex command. Tries to determine if it has to exit because command |
423 ;; is complete or invalid. If not, keeps reading command. | 423 ;; is complete or invalid. If not, keeps reading command. |
424 (defun ex-cmd-read-exit () | 424 (defun ex-cmd-read-exit () |
425 (interactive) | 425 (interactive) |
426 (setq vip-incomplete-ex-cmd t) | 426 (setq viper-incomplete-ex-cmd t) |
427 (let ((quit-regex1 (concat | 427 (let ((quit-regex1 (concat |
428 "\\(" "set[ \t]*" | 428 "\\(" "set[ \t]*" |
429 "\\|" "edit[ \t]*" | 429 "\\|" "edit[ \t]*" |
430 "\\|" "[nN]ext[ \t]*" | 430 "\\|" "[nN]ext[ \t]*" |
431 "\\|" "unm[ \t]*" | 431 "\\|" "unm[ \t]*" |
457 "\\|" "![ \t]*[a-zA-Z].*" | 457 "\\|" "![ \t]*[a-zA-Z].*" |
458 "\\)" | 458 "\\)" |
459 "!*"))) | 459 "!*"))) |
460 | 460 |
461 (save-window-excursion ;; put cursor at the end of the Ex working buffer | 461 (save-window-excursion ;; put cursor at the end of the Ex working buffer |
462 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 462 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
463 (set-buffer vip-ex-work-buf) | 463 (set-buffer viper-ex-work-buf) |
464 (goto-char (point-max))) | 464 (goto-char (point-max))) |
465 (cond ((vip-looking-back quit-regex1) (exit-minibuffer)) | 465 (cond ((viper-looking-back quit-regex1) (exit-minibuffer)) |
466 ((vip-looking-back stay-regex) (insert " ")) | 466 ((viper-looking-back stay-regex) (insert " ")) |
467 ((vip-looking-back quit-regex2) (exit-minibuffer)) | 467 ((viper-looking-back quit-regex2) (exit-minibuffer)) |
468 (t (insert " "))))) | 468 (t (insert " "))))) |
469 | 469 |
470 ;; complete Ex command | 470 ;; complete Ex command |
471 (defun ex-cmd-complete () | 471 (defun ex-cmd-complete () |
472 (interactive) | 472 (interactive) |
475 (save-excursion | 475 (save-excursion |
476 (setq dist (skip-chars-backward "[a-zA-Z!=>&~]") | 476 (setq dist (skip-chars-backward "[a-zA-Z!=>&~]") |
477 save-pos (point))) | 477 save-pos (point))) |
478 | 478 |
479 (if (or (= dist 0) | 479 (if (or (= dist 0) |
480 (vip-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)") | 480 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)") |
481 (vip-looking-back | 481 (viper-looking-back |
482 "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*+[ \t]+[a-zA-Z!=>&~]+")) | 482 "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*+[ \t]+[a-zA-Z!=>&~]+")) |
483 ;; Preceding characters are not the ones allowed in an Ex command | 483 ;; Preceding characters are not the ones allowed in an Ex command |
484 ;; or we have typed past command name. | 484 ;; or we have typed past command name. |
485 ;; Note: we didn't do parsing, so there may be surprises. | 485 ;; Note: we didn't do parsing, so there may be surprises. |
486 (if (or (vip-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*") | 486 (if (or (viper-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*") |
487 (vip-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)") | 487 (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)") |
488 (looking-at "[^ \t\n\C-m]")) | 488 (looking-at "[^ \t\n\C-m]")) |
489 nil | 489 nil |
490 (with-output-to-temp-buffer "*Completions*" | 490 (with-output-to-temp-buffer "*Completions*" |
491 (display-completion-list | 491 (display-completion-list |
492 (vip-alist-to-list ex-token-alist)))) | 492 (viper-alist-to-list ex-token-alist)))) |
493 ;; Preceding chars may be part of a command name | 493 ;; Preceding chars may be part of a command name |
494 (setq string-to-complete (buffer-substring save-pos (point))) | 494 (setq string-to-complete (buffer-substring save-pos (point))) |
495 (setq completion-result | 495 (setq completion-result |
496 (try-completion string-to-complete ex-token-alist)) | 496 (try-completion string-to-complete ex-token-alist)) |
497 | 497 |
498 (cond ((eq completion-result t) ; exact match--do nothing | 498 (cond ((eq completion-result t) ; exact match--do nothing |
499 (vip-tmp-insert-at-eob " (Sole completion)")) | 499 (viper-tmp-insert-at-eob " (Sole completion)")) |
500 ((eq completion-result nil) | 500 ((eq completion-result nil) |
501 (vip-tmp-insert-at-eob " (No match)")) | 501 (viper-tmp-insert-at-eob " (No match)")) |
502 (t ;; partial completion | 502 (t ;; partial completion |
503 (goto-char save-pos) | 503 (goto-char save-pos) |
504 (delete-region (point) (point-max)) | 504 (delete-region (point) (point-max)) |
505 (insert completion-result) | 505 (insert completion-result) |
506 (let (case-fold-search) | 506 (let (case-fold-search) |
507 (setq compl-list | 507 (setq compl-list |
508 (vip-filter-alist (concat "^" completion-result) | 508 (viper-filter-alist (concat "^" completion-result) |
509 ex-token-alist))) | 509 ex-token-alist))) |
510 (if (> (length compl-list) 1) | 510 (if (> (length compl-list) 1) |
511 (with-output-to-temp-buffer "*Completions*" | 511 (with-output-to-temp-buffer "*Completions*" |
512 (display-completion-list | 512 (display-completion-list |
513 (vip-alist-to-list (reverse compl-list))))))) | 513 (viper-alist-to-list (reverse compl-list))))))) |
514 ))) | 514 ))) |
515 | 515 |
516 | 516 |
517 ;; Read Ex commands | 517 ;; Read Ex commands |
518 (defun vip-ex (&optional string) | 518 (defun viper-ex (&optional string) |
519 (interactive) | 519 (interactive) |
520 (or string | 520 (or string |
521 (setq ex-g-flag nil | 521 (setq ex-g-flag nil |
522 ex-g-variant nil)) | 522 ex-g-variant nil)) |
523 (let* ((map (copy-keymap minibuffer-local-map)) | 523 (let* ((map (copy-keymap minibuffer-local-map)) |
524 (address nil) | 524 (address nil) |
525 (cont t) | 525 (cont t) |
526 (dot (point)) | 526 (dot (point)) |
527 prev-token-type com-str) | 527 prev-token-type com-str) |
528 | 528 |
529 (vip-add-keymap vip-ex-cmd-map map) | 529 (viper-add-keymap viper-ex-cmd-map map) |
530 | 530 |
531 (setq com-str (or string (vip-read-string-with-history | 531 (setq com-str (or string (viper-read-string-with-history |
532 ":" | 532 ":" |
533 nil | 533 nil |
534 'vip-ex-history | 534 'viper-ex-history |
535 (car vip-ex-history) | 535 (car viper-ex-history) |
536 map))) | 536 map))) |
537 (save-window-excursion | 537 (save-window-excursion |
538 ;; just a precaution | 538 ;; just a precaution |
539 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 539 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
540 (set-buffer vip-ex-work-buf) | 540 (set-buffer viper-ex-work-buf) |
541 (delete-region (point-min) (point-max)) | 541 (delete-region (point-min) (point-max)) |
542 (insert com-str "\n") | 542 (insert com-str "\n") |
543 (goto-char (point-min))) | 543 (goto-char (point-min))) |
544 (setq ex-token-type nil | 544 (setq ex-token-type nil |
545 ex-addresses nil) | 545 ex-addresses nil) |
546 (while cont | 546 (while cont |
547 (vip-get-ex-token) | 547 (viper-get-ex-token) |
548 (cond ((memq ex-token-type '(command end-mark)) | 548 (cond ((memq ex-token-type '(command end-mark)) |
549 (if address (setq ex-addresses (cons address ex-addresses))) | 549 (if address (setq ex-addresses (cons address ex-addresses))) |
550 (cond ((string= ex-token "global") | 550 (cond ((string= ex-token "global") |
551 (ex-global nil) | 551 (ex-global nil) |
552 (setq cont nil)) | 552 (setq cont nil)) |
553 ((string= ex-token "vglobal") | 553 ((string= ex-token "vglobal") |
554 (ex-global t) | 554 (ex-global t) |
555 (setq cont nil)) | 555 (setq cont nil)) |
556 (t | 556 (t |
557 (vip-execute-ex-command) | 557 (viper-execute-ex-command) |
558 (save-window-excursion | 558 (save-window-excursion |
559 (setq vip-ex-work-buf | 559 (setq viper-ex-work-buf |
560 (get-buffer-create vip-ex-work-buf-name)) | 560 (get-buffer-create viper-ex-work-buf-name)) |
561 (set-buffer vip-ex-work-buf) | 561 (set-buffer viper-ex-work-buf) |
562 (skip-chars-forward " \t") | 562 (skip-chars-forward " \t") |
563 (cond ((looking-at "|") | 563 (cond ((looking-at "|") |
564 (forward-char 1)) | 564 (forward-char 1)) |
565 ((looking-at "\n") | 565 ((looking-at "\n") |
566 (setq cont nil)) | 566 (setq cont nil)) |
567 (t (error "`%s': %s" ex-token vip-SpuriousText))) | 567 (t (error "`%s': %s" ex-token viper-SpuriousText))) |
568 )) | 568 )) |
569 )) | 569 )) |
570 ((eq ex-token-type 'non-command) | 570 ((eq ex-token-type 'non-command) |
571 (error "`%s': %s" ex-token vip-BadExCommand)) | 571 (error "`%s': %s" ex-token viper-BadExCommand)) |
572 ((eq ex-token-type 'whole) | 572 ((eq ex-token-type 'whole) |
573 (setq address nil) | 573 (setq address nil) |
574 (setq ex-addresses | 574 (setq ex-addresses |
575 (if ex-addresses | 575 (if ex-addresses |
576 (cons (point-max) ex-addresses) | 576 (cons (point-max) ex-addresses) |
584 (if (eq prev-token-type 'whole) | 584 (if (eq prev-token-type 'whole) |
585 (setq address (point-min))) | 585 (setq address (point-min))) |
586 (if address (setq dot address)) | 586 (if address (setq dot address)) |
587 (setq ex-addresses | 587 (setq ex-addresses |
588 (cons (if (null address) (point) address) ex-addresses))) | 588 (cons (if (null address) (point) address) ex-addresses))) |
589 (t (let ((ans (vip-get-ex-address-subr address dot))) | 589 (t (let ((ans (viper-get-ex-address-subr address dot))) |
590 (if ans (setq address ans))))) | 590 (if ans (setq address ans))))) |
591 (setq prev-token-type ex-token-type)))) | 591 (setq prev-token-type ex-token-type)))) |
592 | 592 |
593 | 593 |
594 ;; Get a regular expression and set `ex-variant', if found | 594 ;; Get a regular expression and set `ex-variant', if found |
595 (defun vip-get-ex-pat () | 595 (defun viper-get-ex-pat () |
596 (save-window-excursion | 596 (save-window-excursion |
597 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 597 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
598 (set-buffer vip-ex-work-buf) | 598 (set-buffer viper-ex-work-buf) |
599 (skip-chars-forward " \t") | 599 (skip-chars-forward " \t") |
600 (if (looking-at "!") | 600 (if (looking-at "!") |
601 (progn | 601 (progn |
602 (setq ex-g-variant (not ex-g-variant) | 602 (setq ex-g-variant (not ex-g-variant) |
603 ex-g-flag (not ex-g-flag)) | 603 ex-g-flag (not ex-g-flag)) |
616 (if (not (re-search-forward (format "[^%c]*%c" c c) nil t)) | 616 (if (not (re-search-forward (format "[^%c]*%c" c c) nil t)) |
617 (if (member ex-token '("global" "vglobal")) | 617 (if (member ex-token '("global" "vglobal")) |
618 (error | 618 (error |
619 "Missing closing delimiter for global regexp") | 619 "Missing closing delimiter for global regexp") |
620 (goto-char (point-max)))) | 620 (goto-char (point-max)))) |
621 (if (not (vip-looking-back | 621 (if (not (viper-looking-back |
622 (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c))) | 622 (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c))) |
623 (setq cont nil)))) | 623 (setq cont nil)))) |
624 (setq ex-token | 624 (setq ex-token |
625 (if (= (mark t) (point)) "" | 625 (if (= (mark t) (point)) "" |
626 (buffer-substring (1- (point)) (mark t)))) | 626 (buffer-substring (1- (point)) (mark t)))) |
635 ) | 635 ) |
636 (setq ex-token nil)) | 636 (setq ex-token nil)) |
637 c))) | 637 c))) |
638 | 638 |
639 ;; get an ex command | 639 ;; get an ex command |
640 (defun vip-get-ex-command () | 640 (defun viper-get-ex-command () |
641 (save-window-excursion | 641 (save-window-excursion |
642 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 642 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
643 (set-buffer vip-ex-work-buf) | 643 (set-buffer viper-ex-work-buf) |
644 (if (looking-at "/") (forward-char 1)) | 644 (if (looking-at "/") (forward-char 1)) |
645 (skip-chars-forward " \t") | 645 (skip-chars-forward " \t") |
646 (cond ((looking-at "[a-z]") | 646 (cond ((looking-at "[a-z]") |
647 (vip-get-ex-com-subr) | 647 (viper-get-ex-com-subr) |
648 (if (eq ex-token-type 'non-command) | 648 (if (eq ex-token-type 'non-command) |
649 (error "`%s': %s" ex-token vip-BadExCommand))) | 649 (error "`%s': %s" ex-token viper-BadExCommand))) |
650 ((looking-at "[!=><&~]") | 650 ((looking-at "[!=><&~]") |
651 (setq ex-token (char-to-string (following-char))) | 651 (setq ex-token (char-to-string (following-char))) |
652 (forward-char 1)) | 652 (forward-char 1)) |
653 (t (error vip-BadExCommand))))) | 653 (t (error viper-BadExCommand))))) |
654 | 654 |
655 ;; Get an Ex option g or c | 655 ;; Get an Ex option g or c |
656 (defun vip-get-ex-opt-gc (c) | 656 (defun viper-get-ex-opt-gc (c) |
657 (save-window-excursion | 657 (save-window-excursion |
658 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 658 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
659 (set-buffer vip-ex-work-buf) | 659 (set-buffer viper-ex-work-buf) |
660 (if (looking-at (format "%c" c)) (forward-char 1)) | 660 (if (looking-at (format "%c" c)) (forward-char 1)) |
661 (skip-chars-forward " \t") | 661 (skip-chars-forward " \t") |
662 (cond ((looking-at "g") | 662 (cond ((looking-at "g") |
663 (setq ex-token "g") | 663 (setq ex-token "g") |
664 (forward-char 1) | 664 (forward-char 1) |
668 (forward-char 1) | 668 (forward-char 1) |
669 t) | 669 t) |
670 (t nil)))) | 670 (t nil)))) |
671 | 671 |
672 ;; Compute default addresses. WHOLE-FLAG means use the whole buffer | 672 ;; Compute default addresses. WHOLE-FLAG means use the whole buffer |
673 (defun vip-default-ex-addresses (&optional whole-flag) | 673 (defun viper-default-ex-addresses (&optional whole-flag) |
674 (cond ((null ex-addresses) | 674 (cond ((null ex-addresses) |
675 (setq ex-addresses | 675 (setq ex-addresses |
676 (if whole-flag | 676 (if whole-flag |
677 (cons (point-max) (cons (point-min) nil)) | 677 (cons (point-max) (cons (point-min) nil)) |
678 (cons (point) (cons (point) nil))))) | 678 (cons (point) (cons (point) nil))))) |
679 ((null (cdr ex-addresses)) | 679 ((null (cdr ex-addresses)) |
680 (setq ex-addresses | 680 (setq ex-addresses |
681 (cons (car ex-addresses) ex-addresses))))) | 681 (cons (car ex-addresses) ex-addresses))))) |
682 | 682 |
683 ;; Get an ex-address as a marker and set ex-flag if a flag is found | 683 ;; Get an ex-address as a marker and set ex-flag if a flag is found |
684 (defun vip-get-ex-address () | 684 (defun viper-get-ex-address () |
685 (let ((address (point-marker)) | 685 (let ((address (point-marker)) |
686 (cont t)) | 686 (cont t)) |
687 (setq ex-token "") | 687 (setq ex-token "") |
688 (setq ex-flag nil) | 688 (setq ex-flag nil) |
689 (while cont | 689 (while cont |
690 (vip-get-ex-token) | 690 (viper-get-ex-token) |
691 (cond ((eq ex-token-type 'command) | 691 (cond ((eq ex-token-type 'command) |
692 (if (member ex-token '("print" "list" "#")) | 692 (if (member ex-token '("print" "list" "#")) |
693 (progn | 693 (progn |
694 (setq ex-flag t | 694 (setq ex-flag t |
695 cont nil)) | 695 cont nil)) |
697 ((eq ex-token-type 'end-mark) | 697 ((eq ex-token-type 'end-mark) |
698 (setq cont nil)) | 698 (setq cont nil)) |
699 ((eq ex-token-type 'whole) | 699 ((eq ex-token-type 'whole) |
700 (error "Trailing address expected")) | 700 (error "Trailing address expected")) |
701 ((eq ex-token-type 'comma) | 701 ((eq ex-token-type 'comma) |
702 (error "`%s': %s" ex-token vip-SpuriousText)) | 702 (error "`%s': %s" ex-token viper-SpuriousText)) |
703 (t (let ((ans (vip-get-ex-address-subr address (point-marker)))) | 703 (t (let ((ans (viper-get-ex-address-subr address (point-marker)))) |
704 (if ans (setq address ans)))))) | 704 (if ans (setq address ans)))))) |
705 address)) | 705 address)) |
706 | 706 |
707 ;; Returns an address as a point | 707 ;; Returns an address as a point |
708 (defun vip-get-ex-address-subr (old-address dot) | 708 (defun viper-get-ex-address-subr (old-address dot) |
709 (let ((address nil)) | 709 (let ((address nil)) |
710 (if (null old-address) (setq old-address dot)) | 710 (if (null old-address) (setq old-address dot)) |
711 (cond ((eq ex-token-type 'dot) | 711 (cond ((eq ex-token-type 'dot) |
712 (setq address dot)) | 712 (setq address dot)) |
713 ((eq ex-token-type 'add-number) | 713 ((eq ex-token-type 'add-number) |
740 (setq address (point-marker)))) | 740 (setq address (point-marker)))) |
741 ((eq ex-token-type 'goto-mark) | 741 ((eq ex-token-type 'goto-mark) |
742 (save-excursion | 742 (save-excursion |
743 (if (null ex-token) | 743 (if (null ex-token) |
744 (exchange-point-and-mark) | 744 (exchange-point-and-mark) |
745 (goto-char (vip-register-to-point | 745 (goto-char (viper-register-to-point |
746 (1+ (- ex-token ?a)) 'enforce-buffer))) | 746 (1+ (- ex-token ?a)) 'enforce-buffer))) |
747 (setq address (point-marker))))) | 747 (setq address (point-marker))))) |
748 address)) | 748 address)) |
749 | 749 |
750 | 750 |
751 ;; Search pattern and set address | 751 ;; Search pattern and set address |
752 (defun ex-search-address (forward) | 752 (defun ex-search-address (forward) |
753 (if (string= ex-token "") | 753 (if (string= ex-token "") |
754 (if (null vip-s-string) | 754 (if (null viper-s-string) |
755 (error vip-NoPrevSearch) | 755 (error viper-NoPrevSearch) |
756 (setq ex-token vip-s-string)) | 756 (setq ex-token viper-s-string)) |
757 (setq vip-s-string ex-token)) | 757 (setq viper-s-string ex-token)) |
758 (if forward | 758 (if forward |
759 (progn | 759 (progn |
760 (forward-line 1) | 760 (forward-line 1) |
761 (re-search-forward ex-token)) | 761 (re-search-forward ex-token)) |
762 (forward-line -1) | 762 (forward-line -1) |
763 (re-search-backward ex-token))) | 763 (re-search-backward ex-token))) |
764 | 764 |
765 ;; Get a buffer name and set `ex-count' and `ex-flag' if found | 765 ;; Get a buffer name and set `ex-count' and `ex-flag' if found |
766 (defun vip-get-ex-buffer () | 766 (defun viper-get-ex-buffer () |
767 (setq ex-buffer nil) | 767 (setq ex-buffer nil) |
768 (setq ex-count nil) | 768 (setq ex-count nil) |
769 (setq ex-flag nil) | 769 (setq ex-flag nil) |
770 (save-window-excursion | 770 (save-window-excursion |
771 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 771 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
772 (set-buffer vip-ex-work-buf) | 772 (set-buffer viper-ex-work-buf) |
773 (skip-chars-forward " \t") | 773 (skip-chars-forward " \t") |
774 (if (looking-at "[a-zA-Z]") | 774 (if (looking-at "[a-zA-Z]") |
775 (progn | 775 (progn |
776 (setq ex-buffer (following-char)) | 776 (setq ex-buffer (following-char)) |
777 (forward-char 1) | 777 (forward-char 1) |
785 (if (looking-at "[pl#]") | 785 (if (looking-at "[pl#]") |
786 (progn | 786 (progn |
787 (setq ex-flag t) | 787 (setq ex-flag t) |
788 (forward-char 1))) | 788 (forward-char 1))) |
789 (if (not (looking-at "[\n|]")) | 789 (if (not (looking-at "[\n|]")) |
790 (error "`%s': %s" ex-token vip-SpuriousText)))) | 790 (error "`%s': %s" ex-token viper-SpuriousText)))) |
791 | 791 |
792 (defun vip-get-ex-count () | 792 (defun viper-get-ex-count () |
793 (setq ex-variant nil | 793 (setq ex-variant nil |
794 ex-count nil | 794 ex-count nil |
795 ex-flag nil) | 795 ex-flag nil) |
796 (save-window-excursion | 796 (save-window-excursion |
797 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 797 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
798 (set-buffer vip-ex-work-buf) | 798 (set-buffer viper-ex-work-buf) |
799 (skip-chars-forward " \t") | 799 (skip-chars-forward " \t") |
800 (if (looking-at "!") | 800 (if (looking-at "!") |
801 (progn | 801 (progn |
802 (setq ex-variant t) | 802 (setq ex-variant t) |
803 (forward-char 1))) | 803 (forward-char 1))) |
812 (progn | 812 (progn |
813 (setq ex-flag t) | 813 (setq ex-flag t) |
814 (forward-char 1))) | 814 (forward-char 1))) |
815 (if (not (looking-at "[\n|]")) | 815 (if (not (looking-at "[\n|]")) |
816 (error "`%s': %s" | 816 (error "`%s': %s" |
817 (buffer-substring (point-min) (1- (point-max))) vip-BadExCommand)))) | 817 (buffer-substring |
818 (point-min) (1- (point-max))) viper-BadExCommand)))) | |
818 | 819 |
819 ;; Expand \% and \# in ex command | 820 ;; Expand \% and \# in ex command |
820 (defun ex-expand-filsyms (cmd buf) | 821 (defun ex-expand-filsyms (cmd buf) |
821 (let (cf pf ret) | 822 (let (cf pf ret) |
822 (save-excursion | 823 (save-excursion |
826 (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd)) | 827 (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd)) |
827 (error "No current file to substitute for `%%'")) | 828 (error "No current file to substitute for `%%'")) |
828 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd)) | 829 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd)) |
829 (error "No alternate file to substitute for `#'")) | 830 (error "No alternate file to substitute for `#'")) |
830 (save-excursion | 831 (save-excursion |
831 (set-buffer (get-buffer-create vip-ex-tmp-buf-name)) | 832 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) |
832 (erase-buffer) | 833 (erase-buffer) |
833 (insert cmd) | 834 (insert cmd) |
834 (goto-char (point-min)) | 835 (goto-char (point-min)) |
835 (while (re-search-forward "%\\|#" nil t) | 836 (while (re-search-forward "%\\|#" nil t) |
836 (let ((data (match-data)) | 837 (let ((data (match-data)) |
837 (char (buffer-substring (match-beginning 0) (match-end 0)))) | 838 (char (buffer-substring (match-beginning 0) (match-end 0)))) |
838 (if (vip-looking-back (concat "\\\\" char)) | 839 (if (viper-looking-back (concat "\\\\" char)) |
839 (replace-match char) | 840 (replace-match char) |
840 (store-match-data data) | 841 (store-match-data data) |
841 (if (string= char "%") | 842 (if (string= char "%") |
842 (replace-match cf) | 843 (replace-match cf) |
843 (replace-match pf))))) | 844 (replace-match pf))))) |
845 (setq ret (buffer-substring (point-min) (point))) | 846 (setq ret (buffer-substring (point-min) (point))) |
846 (message "%s" ret)) | 847 (message "%s" ret)) |
847 ret)) | 848 ret)) |
848 | 849 |
849 ;; Get a file name and set ex-variant, `ex-append' and `ex-offset' if found | 850 ;; Get a file name and set ex-variant, `ex-append' and `ex-offset' if found |
850 (defun vip-get-ex-file () | 851 (defun viper-get-ex-file () |
851 (let (prompt) | 852 (let (prompt) |
852 (setq ex-file nil | 853 (setq ex-file nil |
853 ex-variant nil | 854 ex-variant nil |
854 ex-append nil | 855 ex-append nil |
855 ex-offset nil | 856 ex-offset nil |
856 ex-cmdfile nil) | 857 ex-cmdfile nil) |
857 (save-excursion | 858 (save-excursion |
858 (save-window-excursion | 859 (save-window-excursion |
859 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 860 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
860 (set-buffer vip-ex-work-buf) | 861 (set-buffer viper-ex-work-buf) |
861 (skip-chars-forward " \t") | 862 (skip-chars-forward " \t") |
862 (if (looking-at "!") | 863 (if (looking-at "!") |
863 (if (and (not (vip-looking-back "[ \t]")) | 864 (if (and (not (viper-looking-back "[ \t]")) |
864 ;; read doesn't have a corresponding :r! form, so ! is | 865 ;; read doesn't have a corresponding :r! form, so ! is |
865 ;; immediately interpreted as a shell command. | 866 ;; immediately interpreted as a shell command. |
866 (not (string= ex-token "read"))) | 867 (not (string= ex-token "read"))) |
867 (progn | 868 (progn |
868 (setq ex-variant t) | 869 (setq ex-variant t) |
900 "[^ \t\n]+") | 901 "[^ \t\n]+") |
901 ex-file) | 902 ex-file) |
902 (progn | 903 (progn |
903 ;; if file name comes from history, don't leave | 904 ;; if file name comes from history, don't leave |
904 ;; minibuffer when the user types space | 905 ;; minibuffer when the user types space |
905 (setq vip-incomplete-ex-cmd nil) | 906 (setq viper-incomplete-ex-cmd nil) |
906 ;; this must be the last clause in this progn | 907 ;; this must be the last clause in this progn |
907 (substring ex-file (match-beginning 0) (match-end 0)) | 908 (substring ex-file (match-beginning 0) (match-end 0)) |
908 ) | 909 ) |
909 "")) | 910 "")) |
910 ;; this leaves only the command name in the work area | 911 ;; this leaves only the command name in the work area |
914 (goto-char (point-max)) | 915 (goto-char (point-max)) |
915 (skip-chars-backward " \t\n") | 916 (skip-chars-backward " \t\n") |
916 (setq prompt (buffer-substring (point-min) (point))) | 917 (setq prompt (buffer-substring (point-min) (point))) |
917 )) | 918 )) |
918 | 919 |
919 (setq vip-last-ex-prompt prompt) | 920 (setq viper-last-ex-prompt prompt) |
920 | 921 |
921 ;; If we just finished reading command, redisplay prompt | 922 ;; If we just finished reading command, redisplay prompt |
922 (if vip-incomplete-ex-cmd | 923 (if viper-incomplete-ex-cmd |
923 (setq ex-file (vip-ex-read-file-name (format ":%s " prompt))) | 924 (setq ex-file (viper-ex-read-file-name (format ":%s " prompt))) |
924 ;; file was typed in-line | 925 ;; file was typed in-line |
925 (setq ex-file (or ex-file ""))) | 926 (setq ex-file (or ex-file ""))) |
926 )) | 927 )) |
927 | 928 |
928 | 929 |
929 ;; Completes file name or exits minibuffer. If Ex command accepts multiple | 930 ;; Completes file name or exits minibuffer. If Ex command accepts multiple |
930 ;; file names, arranges to re-enter the minibuffer. | 931 ;; file names, arranges to re-enter the minibuffer. |
931 (defun vip-complete-filename-or-exit () | 932 (defun viper-complete-filename-or-exit () |
932 (interactive) | 933 (interactive) |
933 (setq vip-keep-reading-filename t) | 934 (setq viper-keep-reading-filename t) |
934 ;; don't exit if directory---ex-commands don't | 935 ;; don't exit if directory---ex-commands don't |
935 (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer)) | 936 (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer)) |
936 ;; apparently the argument to an Ex command is | 937 ;; apparently the argument to an Ex command is |
937 ;; supposed to be a shell command | 938 ;; supposed to be a shell command |
938 ((vip-looking-back "^[ \t]*!.*") | 939 ((viper-looking-back "^[ \t]*!.*") |
939 (setq ex-cmdfile t) | 940 (setq ex-cmdfile t) |
940 (insert " ")) | 941 (insert " ")) |
941 (t | 942 (t |
942 (setq ex-cmdfile nil) | 943 (setq ex-cmdfile nil) |
943 (minibuffer-complete-word)))) | 944 (minibuffer-complete-word)))) |
944 | 945 |
945 (defun vip-handle-! () | 946 (defun viper-handle-! () |
946 (interactive) | 947 (interactive) |
947 (if (and (string= | 948 (if (and (string= |
948 (buffer-string) (vip-abbreviate-file-name default-directory)) | 949 (buffer-string) (viper-abbreviate-file-name default-directory)) |
949 (member ex-token '("read" "write"))) | 950 (member ex-token '("read" "write"))) |
950 (erase-buffer)) | 951 (erase-buffer)) |
951 (insert "!")) | 952 (insert "!")) |
952 | 953 |
953 (defun ex-cmd-accepts-multiple-files-p (token) | 954 (defun ex-cmd-accepts-multiple-files-p (token) |
954 (member token '("edit" "next" "Next"))) | 955 (member token '("edit" "next" "Next"))) |
955 | 956 |
956 ;; If user doesn't enter anything, then "" is returned, i.e., the | 957 ;; If user doesn't enter anything, then "" is returned, i.e., the |
957 ;; prompt-directory is not returned. | 958 ;; prompt-directory is not returned. |
958 (defun vip-ex-read-file-name (prompt) | 959 (defun viper-ex-read-file-name (prompt) |
959 (let* ((str "") | 960 (let* ((str "") |
960 (minibuffer-local-completion-map | 961 (minibuffer-local-completion-map |
961 (copy-keymap minibuffer-local-completion-map)) | 962 (copy-keymap minibuffer-local-completion-map)) |
962 beg end cont val) | 963 beg end cont val) |
963 | 964 |
964 (vip-add-keymap ex-read-filename-map | 965 (viper-add-keymap ex-read-filename-map |
965 (if vip-emacs-p | 966 (if viper-emacs-p |
966 minibuffer-local-completion-map | 967 minibuffer-local-completion-map |
967 read-file-name-map)) | 968 read-file-name-map)) |
968 | 969 |
969 (setq cont (setq vip-keep-reading-filename t)) | 970 (setq cont (setq viper-keep-reading-filename t)) |
970 (while cont | 971 (while cont |
971 (setq vip-keep-reading-filename nil | 972 (setq viper-keep-reading-filename nil |
972 val (read-file-name (concat prompt str) nil default-directory)) | 973 val (read-file-name (concat prompt str) nil default-directory)) |
973 (if (string-match " " val) | 974 (if (string-match " " val) |
974 (setq val (concat "\\\"" val "\\\""))) | 975 (setq val (concat "\\\"" val "\\\""))) |
975 (setq str (concat str (if (equal val "") "" " ") | 976 (setq str (concat str (if (equal val "") "" " ") |
976 val (if (equal val "") "" " "))) | 977 val (if (equal val "") "" " "))) |
977 | 978 |
978 ;; Only edit, next, and Next commands accept multiple files. | 979 ;; Only edit, next, and Next commands accept multiple files. |
979 ;; vip-keep-reading-filename is set in the anonymous function that is | 980 ;; viper-keep-reading-filename is set in the anonymous function that is |
980 ;; bound to " " in ex-read-filename-map. | 981 ;; bound to " " in ex-read-filename-map. |
981 (setq cont (and vip-keep-reading-filename | 982 (setq cont (and viper-keep-reading-filename |
982 (ex-cmd-accepts-multiple-files-p ex-token))) | 983 (ex-cmd-accepts-multiple-files-p ex-token))) |
983 ) | 984 ) |
984 | 985 |
985 (setq beg (string-match "[^ \t]" str) ; delete leading blanks | 986 (setq beg (string-match "[^ \t]" str) ; delete leading blanks |
986 end (string-match "[ \t]*$" str)) ; delete trailing blanks | 987 end (string-match "[ \t]*$" str)) ; delete trailing blanks |
988 (if (string-match "[\t ]*!" str) | 989 (if (string-match "[\t ]*!" str) |
989 ;; this is actually a shell command | 990 ;; this is actually a shell command |
990 (progn | 991 (progn |
991 (setq ex-cmdfile t) | 992 (setq ex-cmdfile t) |
992 (setq beg (1+ beg)) | 993 (setq beg (1+ beg)) |
993 (setq vip-last-ex-prompt (concat vip-last-ex-prompt " !"))))) | 994 (setq viper-last-ex-prompt |
995 (concat viper-last-ex-prompt " !"))))) | |
994 (substring str (or beg 0) end))) | 996 (substring str (or beg 0) end))) |
995 | 997 |
996 ;; Execute ex command using the value of addresses | 998 ;; Execute ex command using the value of addresses |
997 (defun vip-execute-ex-command () | 999 (defun viper-execute-ex-command () |
998 (vip-deactivate-mark) | 1000 (viper-deactivate-mark) |
999 (cond ((string= ex-token "args") (ex-args)) | 1001 (cond ((string= ex-token "args") (ex-args)) |
1000 ((string= ex-token "copy") (ex-copy nil)) | 1002 ((string= ex-token "copy") (ex-copy nil)) |
1001 ((string= ex-token "cd") (ex-cd)) | 1003 ((string= ex-token "cd") (ex-cd)) |
1002 ((string= ex-token "chdir") (ex-cd)) | 1004 ((string= ex-token "chdir") (ex-cd)) |
1003 ((string= ex-token "delete") (ex-delete)) | 1005 ((string= ex-token "delete") (ex-delete)) |
1004 ((string= ex-token "edit") (ex-edit)) | 1006 ((string= ex-token "edit") (ex-edit)) |
1005 ((string= ex-token "file") (vip-info-on-file)) | 1007 ((string= ex-token "file") (viper-info-on-file)) |
1006 ((string= ex-token "goto") (ex-goto)) | 1008 ((string= ex-token "goto") (ex-goto)) |
1007 ((string= ex-token "help") (ex-help)) | 1009 ((string= ex-token "help") (ex-help)) |
1008 ((string= ex-token "join") (ex-line "join")) | 1010 ((string= ex-token "join") (ex-line "join")) |
1009 ((string= ex-token "kmark") (ex-mark)) | 1011 ((string= ex-token "kmark") (ex-mark)) |
1010 ((string= ex-token "mark") (ex-mark)) | 1012 ((string= ex-token "mark") (ex-mark)) |
1019 ((string= ex-token "PreviousRelatedFile") (ex-next-related-buffer -1)) | 1021 ((string= ex-token "PreviousRelatedFile") (ex-next-related-buffer -1)) |
1020 ((string= ex-token "quit") (ex-quit)) | 1022 ((string= ex-token "quit") (ex-quit)) |
1021 ((string= ex-token "read") (ex-read)) | 1023 ((string= ex-token "read") (ex-read)) |
1022 ((string= ex-token "recover") (ex-recover)) | 1024 ((string= ex-token "recover") (ex-recover)) |
1023 ((string= ex-token "rewind") (ex-rewind)) | 1025 ((string= ex-token "rewind") (ex-rewind)) |
1024 ((string= ex-token "submitReport") (vip-submit-report)) | 1026 ((string= ex-token "submitReport") (viper-submit-report)) |
1025 ((string= ex-token "set") (ex-set)) | 1027 ((string= ex-token "set") (ex-set)) |
1026 ((string= ex-token "shell") (ex-shell)) | 1028 ((string= ex-token "shell") (ex-shell)) |
1027 ((string= ex-token "source") (ex-source)) | 1029 ((string= ex-token "source") (ex-source)) |
1028 ((string= ex-token "sr") (ex-substitute t t)) | 1030 ((string= ex-token "sr") (ex-substitute t t)) |
1029 ((string= ex-token "substitute") (ex-substitute)) | 1031 ((string= ex-token "substitute") (ex-substitute)) |
1030 ((string= ex-token "suspend") (suspend-emacs)) | 1032 ((string= ex-token "suspend") (suspend-emacs)) |
1031 ((string= ex-token "stop") (suspend-emacs)) | 1033 ((string= ex-token "stop") (suspend-emacs)) |
1032 ((string= ex-token "transfer") (ex-copy nil)) | 1034 ((string= ex-token "transfer") (ex-copy nil)) |
1033 ((string= ex-token "buffer") (if ex-cycle-other-window | 1035 ((string= ex-token "buffer") (if ex-cycle-other-window |
1034 (vip-switch-to-buffer-other-window) | 1036 (viper-switch-to-buffer-other-window) |
1035 (vip-switch-to-buffer))) | 1037 (viper-switch-to-buffer))) |
1036 ((string= ex-token "Buffer") (if ex-cycle-other-window | 1038 ((string= ex-token "Buffer") (if ex-cycle-other-window |
1037 (vip-switch-to-buffer) | 1039 (viper-switch-to-buffer) |
1038 (vip-switch-to-buffer-other-window))) | 1040 (viper-switch-to-buffer-other-window))) |
1039 ((string= ex-token "tag") (ex-tag)) | 1041 ((string= ex-token "tag") (ex-tag)) |
1040 ((string= ex-token "undo") (vip-undo)) | 1042 ((string= ex-token "undo") (viper-undo)) |
1041 ((string= ex-token "unmap") (ex-unmap)) | 1043 ((string= ex-token "unmap") (ex-unmap)) |
1042 ((string= ex-token "version") (vip-version)) | 1044 ((string= ex-token "version") (viper-version)) |
1043 ((string= ex-token "visual") (ex-edit)) | 1045 ((string= ex-token "visual") (ex-edit)) |
1044 ((string= ex-token "write") (ex-write nil)) | 1046 ((string= ex-token "write") (ex-write nil)) |
1045 ((string= ex-token "Write") (save-some-buffers)) | 1047 ((string= ex-token "Write") (save-some-buffers)) |
1046 ((string= ex-token "wq") (ex-write t)) | 1048 ((string= ex-token "wq") (ex-write t)) |
1047 ((string= ex-token "WWrite") (save-some-buffers t)) ; don't ask | 1049 ((string= ex-token "WWrite") (save-some-buffers t)) ; don't ask |
1066 ((or (string= ex-token "list") | 1068 ((or (string= ex-token "list") |
1067 (string= ex-token "print") | 1069 (string= ex-token "print") |
1068 (string= ex-token "z") | 1070 (string= ex-token "z") |
1069 (string= ex-token "#")) | 1071 (string= ex-token "#")) |
1070 (error "`%s': Command not implemented in Viper" ex-token)) | 1072 (error "`%s': Command not implemented in Viper" ex-token)) |
1071 (t (error "`%s': %s" ex-token vip-BadExCommand)))) | 1073 (t (error "`%s': %s" ex-token viper-BadExCommand)))) |
1072 | 1074 |
1073 (defun vip-undisplayed-files () | 1075 (defun viper-undisplayed-files () |
1074 (mapcar | 1076 (mapcar |
1075 (function | 1077 (function |
1076 (lambda (b) | 1078 (lambda (b) |
1077 (if (null (get-buffer-window b)) | 1079 (if (null (get-buffer-window b)) |
1078 (let ((f (buffer-file-name b))) | 1080 (let ((f (buffer-file-name b))) |
1086 nil))) | 1088 nil))) |
1087 (buffer-list))) | 1089 (buffer-list))) |
1088 | 1090 |
1089 | 1091 |
1090 (defun ex-args () | 1092 (defun ex-args () |
1091 (let ((l (vip-undisplayed-files)) | 1093 (let ((l (viper-undisplayed-files)) |
1092 (args "") | 1094 (args "") |
1093 (file-count 1)) | 1095 (file-count 1)) |
1094 (while (not (null l)) | 1096 (while (not (null l)) |
1095 (if (car l) | 1097 (if (car l) |
1096 (setq args (format "%s %d) %s\n" args file-count (car l)) | 1098 (setq args (format "%s %d) %s\n" args file-count (car l)) |
1098 (setq l (cdr l))) | 1100 (setq l (cdr l))) |
1099 (if (string= args "") | 1101 (if (string= args "") |
1100 (message "All files are already displayed") | 1102 (message "All files are already displayed") |
1101 (save-excursion | 1103 (save-excursion |
1102 (save-window-excursion | 1104 (save-window-excursion |
1103 (with-output-to-temp-buffer " *vip-info*" | 1105 (with-output-to-temp-buffer " *viper-info*" |
1104 (princ "\n\nThese files are not displayed in any window.\n") | 1106 (princ "\n\nThese files are not displayed in any window.\n") |
1105 (princ "\n=============\n") | 1107 (princ "\n=============\n") |
1106 (princ args) | 1108 (princ args) |
1107 (princ "\n=============\n") | 1109 (princ "\n=============\n") |
1108 (princ "\nThe numbers can be given as counts to :next. ") | 1110 (princ "\nThe numbers can be given as counts to :next. ") |
1109 (princ "\n\nPress any key to continue...\n\n")) | 1111 (princ "\n\nPress any key to continue...\n\n")) |
1110 (vip-read-event)))))) | 1112 (viper-read-event)))))) |
1111 | 1113 |
1112 ;; Ex cd command. Default directory of this buffer changes | 1114 ;; Ex cd command. Default directory of this buffer changes |
1113 (defun ex-cd () | 1115 (defun ex-cd () |
1114 (vip-get-ex-file) | 1116 (viper-get-ex-file) |
1115 (if (string= ex-file "") | 1117 (if (string= ex-file "") |
1116 (setq ex-file "~")) | 1118 (setq ex-file "~")) |
1117 (setq default-directory (file-name-as-directory (expand-file-name ex-file)))) | 1119 (setq default-directory (file-name-as-directory (expand-file-name ex-file)))) |
1118 | 1120 |
1119 ;; Ex copy and move command. DEL-FLAG means delete | 1121 ;; Ex copy and move command. DEL-FLAG means delete |
1120 (defun ex-copy (del-flag) | 1122 (defun ex-copy (del-flag) |
1121 (vip-default-ex-addresses) | 1123 (viper-default-ex-addresses) |
1122 (let ((address (vip-get-ex-address)) | 1124 (let ((address (viper-get-ex-address)) |
1123 (end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | 1125 (end (car ex-addresses)) (beg (car (cdr ex-addresses)))) |
1124 (goto-char end) | 1126 (goto-char end) |
1125 (save-excursion | 1127 (save-excursion |
1126 (push-mark beg t) | 1128 (push-mark beg t) |
1127 (vip-enlarge-region (mark t) (point)) | 1129 (viper-enlarge-region (mark t) (point)) |
1128 (if del-flag | 1130 (if del-flag |
1129 (kill-region (point) (mark t)) | 1131 (kill-region (point) (mark t)) |
1130 (copy-region-as-kill (point) (mark t))) | 1132 (copy-region-as-kill (point) (mark t))) |
1131 (if ex-flag | 1133 (if ex-flag |
1132 (progn | 1134 (progn |
1147 (forward-line 1)) | 1149 (forward-line 1)) |
1148 (insert (current-kill 0)))) | 1150 (insert (current-kill 0)))) |
1149 | 1151 |
1150 ;; Ex delete command | 1152 ;; Ex delete command |
1151 (defun ex-delete () | 1153 (defun ex-delete () |
1152 (vip-default-ex-addresses) | 1154 (viper-default-ex-addresses) |
1153 (vip-get-ex-buffer) | 1155 (viper-get-ex-buffer) |
1154 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | 1156 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) |
1155 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 1157 (if (> beg end) (error viper-FirstAddrExceedsSecond)) |
1156 (save-excursion | 1158 (save-excursion |
1157 (vip-enlarge-region beg end) | 1159 (viper-enlarge-region beg end) |
1158 (exchange-point-and-mark) | 1160 (exchange-point-and-mark) |
1159 (if ex-count | 1161 (if ex-count |
1160 (progn | 1162 (progn |
1161 (set-mark (point)) | 1163 (set-mark (point)) |
1162 (forward-line (1- ex-count))) | 1164 (forward-line (1- ex-count))) |
1163 (set-mark end)) | 1165 (set-mark end)) |
1164 (vip-enlarge-region (point) (mark t)) | 1166 (viper-enlarge-region (point) (mark t)) |
1165 (if ex-flag | 1167 (if ex-flag |
1166 ;; show text to be deleted and ask for confirmation | 1168 ;; show text to be deleted and ask for confirmation |
1167 (progn | 1169 (progn |
1168 (with-output-to-temp-buffer " *delete text*" | 1170 (with-output-to-temp-buffer " *delete text*" |
1169 (princ (buffer-substring (point) (mark t)))) | 1171 (princ (buffer-substring (point) (mark t)))) |
1172 (quit | 1174 (quit |
1173 (save-excursion (kill-buffer " *delete text*")) | 1175 (save-excursion (kill-buffer " *delete text*")) |
1174 (error ""))) | 1176 (error ""))) |
1175 (save-excursion (kill-buffer " *delete text*"))) | 1177 (save-excursion (kill-buffer " *delete text*"))) |
1176 (if ex-buffer | 1178 (if ex-buffer |
1177 (cond ((vip-valid-register ex-buffer '(Letter)) | 1179 (cond ((viper-valid-register ex-buffer '(Letter)) |
1178 (vip-append-to-register | 1180 (viper-append-to-register |
1179 (downcase ex-buffer) (point) (mark t))) | 1181 (downcase ex-buffer) (point) (mark t))) |
1180 ((vip-valid-register ex-buffer) | 1182 ((viper-valid-register ex-buffer) |
1181 (copy-to-register ex-buffer (point) (mark t) nil)) | 1183 (copy-to-register ex-buffer (point) (mark t) nil)) |
1182 (t (error vip-InvalidRegister ex-buffer)))) | 1184 (t (error viper-InvalidRegister ex-buffer)))) |
1183 (kill-region (point) (mark t)))))) | 1185 (kill-region (point) (mark t)))))) |
1184 | 1186 |
1185 | 1187 |
1186 | 1188 |
1187 ;; Ex edit command | 1189 ;; Ex edit command |
1189 ;; asked if current buffer should really be discarded. | 1191 ;; asked if current buffer should really be discarded. |
1190 ;; This command can take multiple file names. It replaces the current buffer | 1192 ;; This command can take multiple file names. It replaces the current buffer |
1191 ;; with the first file in its argument list | 1193 ;; with the first file in its argument list |
1192 (defun ex-edit (&optional file) | 1194 (defun ex-edit (&optional file) |
1193 (if (not file) | 1195 (if (not file) |
1194 (vip-get-ex-file)) | 1196 (viper-get-ex-file)) |
1195 (cond ((and (string= ex-file "") buffer-file-name) | 1197 (cond ((and (string= ex-file "") buffer-file-name) |
1196 (setq ex-file (vip-abbreviate-file-name (buffer-file-name)))) | 1198 (setq ex-file (viper-abbreviate-file-name (buffer-file-name)))) |
1197 ((string= ex-file "") | 1199 ((string= ex-file "") |
1198 (error vip-NoFileSpecified))) | 1200 (error viper-NoFileSpecified))) |
1199 | 1201 |
1200 (let (msg do-edit) | 1202 (let (msg do-edit) |
1201 (if buffer-file-name | 1203 (if buffer-file-name |
1202 (cond ((buffer-modified-p) | 1204 (cond ((buffer-modified-p) |
1203 (setq msg | 1205 (setq msg |
1221 | 1223 |
1222 (if (null (setq file (get-file-buffer ex-file))) | 1224 (if (null (setq file (get-file-buffer ex-file))) |
1223 (progn | 1225 (progn |
1224 (ex-find-file ex-file) | 1226 (ex-find-file ex-file) |
1225 (or (eq major-mode 'dired-mode) | 1227 (or (eq major-mode 'dired-mode) |
1226 (vip-change-state-to-vi)) | 1228 (viper-change-state-to-vi)) |
1227 (goto-char (point-min))) | 1229 (goto-char (point-min))) |
1228 (switch-to-buffer file)) | 1230 (switch-to-buffer file)) |
1229 (if ex-offset | 1231 (if ex-offset |
1230 (progn | 1232 (progn |
1231 (save-window-excursion | 1233 (save-window-excursion |
1232 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1234 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1233 (set-buffer vip-ex-work-buf) | 1235 (set-buffer viper-ex-work-buf) |
1234 (delete-region (point-min) (point-max)) | 1236 (delete-region (point-min) (point-max)) |
1235 (insert ex-offset "\n") | 1237 (insert ex-offset "\n") |
1236 (goto-char (point-min))) | 1238 (goto-char (point-min))) |
1237 (goto-char (vip-get-ex-address)) | 1239 (goto-char (viper-get-ex-address)) |
1238 (beginning-of-line))) | 1240 (beginning-of-line))) |
1239 (ex-fixup-history vip-last-ex-prompt ex-file)) | 1241 (ex-fixup-history viper-last-ex-prompt ex-file)) |
1240 | 1242 |
1241 ;; Find-file FILESPEC if it appears to specify a single file. | 1243 ;; Find-file FILESPEC if it appears to specify a single file. |
1242 ;; Otherwise, assume that FILES{EC is a wildcard. | 1244 ;; Otherwise, assume that FILES{EC is a wildcard. |
1243 ;; In this case, split it into substrings separated by newlines. | 1245 ;; In this case, split it into substrings separated by newlines. |
1244 ;; Each line is assumed to be a file name. find-file's each file thus obtained. | 1246 ;; Each line is assumed to be a file name. find-file's each file thus obtained. |
1267 (if variant | 1269 (if variant |
1268 (setq ex-g-flag nil | 1270 (setq ex-g-flag nil |
1269 ex-g-variant t) | 1271 ex-g-variant t) |
1270 (setq ex-g-flag t | 1272 (setq ex-g-flag t |
1271 ex-g-variant nil))) | 1273 ex-g-variant nil))) |
1272 (vip-get-ex-pat) | 1274 (viper-get-ex-pat) |
1273 (if (null ex-token) | 1275 (if (null ex-token) |
1274 (error "`%s': Missing regular expression" gcommand))) | 1276 (error "`%s': Missing regular expression" gcommand))) |
1275 | 1277 |
1276 (if (string= ex-token "") | 1278 (if (string= ex-token "") |
1277 (if (null vip-s-string) | 1279 (if (null viper-s-string) |
1278 (error vip-NoPrevSearch) | 1280 (error viper-NoPrevSearch) |
1279 (setq ex-g-pat vip-s-string)) | 1281 (setq ex-g-pat viper-s-string)) |
1280 (setq ex-g-pat ex-token | 1282 (setq ex-g-pat ex-token |
1281 vip-s-string ex-token)) | 1283 viper-s-string ex-token)) |
1282 (if (null ex-addresses) | 1284 (if (null ex-addresses) |
1283 (setq ex-addresses (list (point-max) (point-min))) | 1285 (setq ex-addresses (list (point-max) (point-min))) |
1284 (vip-default-ex-addresses)) | 1286 (viper-default-ex-addresses)) |
1285 (let ((marks nil) | 1287 (let ((marks nil) |
1286 (mark-count 0) | 1288 (mark-count 0) |
1287 (end (car ex-addresses)) | 1289 (end (car ex-addresses)) |
1288 (beg (car (cdr ex-addresses))) | 1290 (beg (car (cdr ex-addresses))) |
1289 com-str) | 1291 com-str) |
1290 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 1292 (if (> beg end) (error viper-FirstAddrExceedsSecond)) |
1291 (save-excursion | 1293 (save-excursion |
1292 (vip-enlarge-region beg end) | 1294 (viper-enlarge-region beg end) |
1293 (exchange-point-and-mark) | 1295 (exchange-point-and-mark) |
1294 (let ((cont t) (limit (point-marker))) | 1296 (let ((cont t) (limit (point-marker))) |
1295 (exchange-point-and-mark) | 1297 (exchange-point-and-mark) |
1296 ;; skip the last line if empty | 1298 ;; skip the last line if empty |
1297 (beginning-of-line) | 1299 (beginning-of-line) |
1298 (if (eobp) (vip-backward-char-carefully)) | 1300 (if (eobp) (viper-backward-char-carefully)) |
1299 (while (and cont (not (bobp)) (>= (point) limit)) | 1301 (while (and cont (not (bobp)) (>= (point) limit)) |
1300 (beginning-of-line) | 1302 (beginning-of-line) |
1301 (set-mark (point)) | 1303 (set-mark (point)) |
1302 (end-of-line) | 1304 (end-of-line) |
1303 (let ((found (re-search-backward ex-g-pat (mark t) t))) | 1305 (let ((found (re-search-backward ex-g-pat (mark t) t))) |
1310 (beginning-of-line) | 1312 (beginning-of-line) |
1311 (if (bobp) (setq cont nil) | 1313 (if (bobp) (setq cont nil) |
1312 (forward-line -1) | 1314 (forward-line -1) |
1313 (end-of-line))))) | 1315 (end-of-line))))) |
1314 (save-window-excursion | 1316 (save-window-excursion |
1315 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1317 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1316 (set-buffer vip-ex-work-buf) | 1318 (set-buffer viper-ex-work-buf) |
1317 (setq com-str (buffer-substring (1+ (point)) (1- (point-max))))) | 1319 (setq com-str (buffer-substring (1+ (point)) (1- (point-max))))) |
1318 (while marks | 1320 (while marks |
1319 (goto-char (car marks)) | 1321 (goto-char (car marks)) |
1320 (vip-ex com-str) | 1322 (viper-ex com-str) |
1321 (setq mark-count (1- mark-count)) | 1323 (setq mark-count (1- mark-count)) |
1322 (setq marks (cdr marks))))) | 1324 (setq marks (cdr marks))))) |
1323 | 1325 |
1324 ;; Ex goto command | 1326 ;; Ex goto command |
1325 (defun ex-goto () | 1327 (defun ex-goto () |
1329 (goto-char (car ex-addresses)) | 1331 (goto-char (car ex-addresses)) |
1330 (beginning-of-line)) | 1332 (beginning-of-line)) |
1331 | 1333 |
1332 ;; Ex line commands. COM is join, shift-right or shift-left | 1334 ;; Ex line commands. COM is join, shift-right or shift-left |
1333 (defun ex-line (com) | 1335 (defun ex-line (com) |
1334 (vip-default-ex-addresses) | 1336 (viper-default-ex-addresses) |
1335 (vip-get-ex-count) | 1337 (viper-get-ex-count) |
1336 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point) | 1338 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point) |
1337 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 1339 (if (> beg end) (error viper-FirstAddrExceedsSecond)) |
1338 (save-excursion | 1340 (save-excursion |
1339 (vip-enlarge-region beg end) | 1341 (viper-enlarge-region beg end) |
1340 (exchange-point-and-mark) | 1342 (exchange-point-and-mark) |
1341 (if ex-count | 1343 (if ex-count |
1342 (progn | 1344 (progn |
1343 (set-mark (point)) | 1345 (set-mark (point)) |
1344 (forward-line ex-count))) | 1346 (forward-line ex-count))) |
1369 (delete-region (point) (1- (point))) | 1371 (delete-region (point) (1- (point))) |
1370 (if (not ex-variant) (fixup-whitespace)))))) | 1372 (if (not ex-variant) (fixup-whitespace)))))) |
1371 ((or (string= com "right") (string= com "left")) | 1373 ((or (string= com "right") (string= com "left")) |
1372 (indent-rigidly | 1374 (indent-rigidly |
1373 (min beg end) (max beg end) | 1375 (min beg end) (max beg end) |
1374 (if (string= com "right") vip-shift-width (- vip-shift-width))) | 1376 (if (string= com "right") viper-shift-width (- viper-shift-width))) |
1375 (goto-char (max beg end)) | 1377 (goto-char (max beg end)) |
1376 (end-of-line) | 1378 (end-of-line) |
1377 (vip-forward-char-carefully)))) | 1379 (viper-forward-char-carefully)))) |
1378 | 1380 |
1379 | 1381 |
1380 ;; Ex mark command | 1382 ;; Ex mark command |
1381 (defun ex-mark () | 1383 (defun ex-mark () |
1382 (let (char) | 1384 (let (char) |
1383 (if (null ex-addresses) | 1385 (if (null ex-addresses) |
1384 (setq ex-addresses | 1386 (setq ex-addresses |
1385 (cons (point) nil))) | 1387 (cons (point) nil))) |
1386 (save-window-excursion | 1388 (save-window-excursion |
1387 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1389 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1388 (set-buffer vip-ex-work-buf) | 1390 (set-buffer viper-ex-work-buf) |
1389 (skip-chars-forward " \t") | 1391 (skip-chars-forward " \t") |
1390 (if (looking-at "[a-z]") | 1392 (if (looking-at "[a-z]") |
1391 (progn | 1393 (progn |
1392 (setq char (following-char)) | 1394 (setq char (following-char)) |
1393 (forward-char 1) | 1395 (forward-char 1) |
1394 (skip-chars-forward " \t") | 1396 (skip-chars-forward " \t") |
1395 (if (not (looking-at "[\n|]")) | 1397 (if (not (looking-at "[\n|]")) |
1396 (error "`%s': %s" ex-token vip-SpuriousText))) | 1398 (error "`%s': %s" ex-token viper-SpuriousText))) |
1397 (error "`%s' requires a following letter" ex-token))) | 1399 (error "`%s' requires a following letter" ex-token))) |
1398 (save-excursion | 1400 (save-excursion |
1399 (goto-char (car ex-addresses)) | 1401 (goto-char (car ex-addresses)) |
1400 (point-to-register (1+ (- char ?a)))))) | 1402 (point-to-register (1+ (- char ?a)))))) |
1401 | 1403 |
1405 (defun ex-next (cycle-other-window &optional find-alt-file) | 1407 (defun ex-next (cycle-other-window &optional find-alt-file) |
1406 (catch 'ex-edit | 1408 (catch 'ex-edit |
1407 (let (count l) | 1409 (let (count l) |
1408 (if (not find-alt-file) | 1410 (if (not find-alt-file) |
1409 (progn | 1411 (progn |
1410 (vip-get-ex-file) | 1412 (viper-get-ex-file) |
1411 (if (or (char-or-string-p ex-offset) | 1413 (if (or (char-or-string-p ex-offset) |
1412 (and (not (string= "" ex-file)) | 1414 (and (not (string= "" ex-file)) |
1413 (not (string-match "^[0-9]+$" ex-file)))) | 1415 (not (string-match "^[0-9]+$" ex-file)))) |
1414 (progn | 1416 (progn |
1415 (ex-edit t) | 1417 (ex-edit t) |
1416 (throw 'ex-edit nil)) | 1418 (throw 'ex-edit nil)) |
1417 (setq count (string-to-int ex-file)) | 1419 (setq count (string-to-int ex-file)) |
1418 (if (= count 0) (setq count 1)) | 1420 (if (= count 0) (setq count 1)) |
1419 (if (< count 0) (error "Usage: `next <count>' (count >= 0)")))) | 1421 (if (< count 0) (error "Usage: `next <count>' (count >= 0)")))) |
1420 (setq count 1)) | 1422 (setq count 1)) |
1421 (setq l (vip-undisplayed-files)) | 1423 (setq l (viper-undisplayed-files)) |
1422 (while (> count 0) | 1424 (while (> count 0) |
1423 (while (and (not (null l)) (null (car l))) | 1425 (while (and (not (null l)) (null (car l))) |
1424 (setq l (cdr l))) | 1426 (setq l (cdr l))) |
1425 (setq count (1- count)) | 1427 (setq count (1- count)) |
1426 (if (> count 0) | 1428 (if (> count 0) |
1432 (get-lru-window) (selected-window))) | 1434 (get-lru-window) (selected-window))) |
1433 (b (window-buffer w))) | 1435 (b (window-buffer w))) |
1434 (set-window-buffer w (get-file-buffer (car l))) | 1436 (set-window-buffer w (get-file-buffer (car l))) |
1435 (bury-buffer b) | 1437 (bury-buffer b) |
1436 ;; this puts "next <count>" in the ex-command history | 1438 ;; this puts "next <count>" in the ex-command history |
1437 (ex-fixup-history vip-last-ex-prompt ex-file)) | 1439 (ex-fixup-history viper-last-ex-prompt ex-file)) |
1438 (error "Not that many undisplayed files"))))))) | 1440 (error "Not that many undisplayed files"))))))) |
1439 | 1441 |
1440 | 1442 |
1441 (defun ex-next-related-buffer (direction &optional no-recursion) | 1443 (defun ex-next-related-buffer (direction &optional no-recursion) |
1442 | 1444 |
1443 (vip-ring-rotate1 vip-related-files-and-buffers-ring direction) | 1445 (viper-ring-rotate1 viper-related-files-and-buffers-ring direction) |
1444 | 1446 |
1445 (let ((file-or-buffer-name | 1447 (let ((file-or-buffer-name |
1446 (vip-current-ring-item vip-related-files-and-buffers-ring)) | 1448 (viper-current-ring-item viper-related-files-and-buffers-ring)) |
1447 (old-ring vip-related-files-and-buffers-ring) | 1449 (old-ring viper-related-files-and-buffers-ring) |
1448 (old-win (selected-window)) | 1450 (old-win (selected-window)) |
1449 skip-rest buf wind) | 1451 skip-rest buf wind) |
1450 | 1452 |
1451 (or (and (ring-p vip-related-files-and-buffers-ring) | 1453 (or (and (ring-p viper-related-files-and-buffers-ring) |
1452 (> (ring-length vip-related-files-and-buffers-ring) 0)) | 1454 (> (ring-length viper-related-files-and-buffers-ring) 0)) |
1453 (error "This buffer has no related files or buffers")) | 1455 (error "This buffer has no related files or buffers")) |
1454 | 1456 |
1455 (or (stringp file-or-buffer-name) | 1457 (or (stringp file-or-buffer-name) |
1456 (error | 1458 (error |
1457 "File and buffer names must be strings, %S" file-or-buffer-name)) | 1459 "File and buffer names must be strings, %S" file-or-buffer-name)) |
1459 (setq buf (cond ((get-buffer file-or-buffer-name)) | 1461 (setq buf (cond ((get-buffer file-or-buffer-name)) |
1460 ((file-exists-p file-or-buffer-name) | 1462 ((file-exists-p file-or-buffer-name) |
1461 (find-file-noselect file-or-buffer-name)) | 1463 (find-file-noselect file-or-buffer-name)) |
1462 )) | 1464 )) |
1463 | 1465 |
1464 (if (not (vip-buffer-live-p buf)) | 1466 (if (not (viper-buffer-live-p buf)) |
1465 (error "Didn't find buffer %S or file %S" | 1467 (error "Didn't find buffer %S or file %S" |
1466 file-or-buffer-name | 1468 file-or-buffer-name |
1467 (vip-abbreviate-file-name | 1469 (viper-abbreviate-file-name |
1468 (expand-file-name file-or-buffer-name)))) | 1470 (expand-file-name file-or-buffer-name)))) |
1469 | 1471 |
1470 (if (equal buf (current-buffer)) | 1472 (if (equal buf (current-buffer)) |
1471 (or no-recursion | 1473 (or no-recursion |
1472 ;; try again | 1474 ;; try again |
1475 (ex-next-related-buffer direction 'norecursion)))) | 1477 (ex-next-related-buffer direction 'norecursion)))) |
1476 | 1478 |
1477 (if skip-rest | 1479 (if skip-rest |
1478 () | 1480 () |
1479 ;; setup buffer | 1481 ;; setup buffer |
1480 (if (setq wind (vip-get-visible-buffer-window buf)) | 1482 (if (setq wind (viper-get-visible-buffer-window buf)) |
1481 () | 1483 () |
1482 (setq wind (get-lru-window (if vip-xemacs-p nil 'visible))) | 1484 (setq wind (get-lru-window (if viper-xemacs-p nil 'visible))) |
1483 (set-window-buffer wind buf)) | 1485 (set-window-buffer wind buf)) |
1484 | 1486 |
1485 (if (vip-window-display-p) | 1487 (if (viper-window-display-p) |
1486 (progn | 1488 (progn |
1487 (raise-frame (window-frame wind)) | 1489 (raise-frame (window-frame wind)) |
1488 (if (equal (window-frame wind) (window-frame old-win)) | 1490 (if (equal (window-frame wind) (window-frame old-win)) |
1489 (save-window-excursion (select-window wind) (sit-for 1)) | 1491 (save-window-excursion (select-window wind) (sit-for 1)) |
1490 (select-window wind))) | 1492 (select-window wind))) |
1491 (save-window-excursion (select-window wind) (sit-for 1))) | 1493 (save-window-excursion (select-window wind) (sit-for 1))) |
1492 | 1494 |
1493 (save-excursion | 1495 (save-excursion |
1494 (set-buffer buf) | 1496 (set-buffer buf) |
1495 (setq vip-related-files-and-buffers-ring old-ring)) | 1497 (setq viper-related-files-and-buffers-ring old-ring)) |
1496 | 1498 |
1497 (setq vip-local-search-start-marker (point-marker)) | 1499 (setq viper-local-search-start-marker (point-marker)) |
1498 ))) | 1500 ))) |
1499 | 1501 |
1500 | 1502 |
1501 ;; Force auto save | 1503 ;; Force auto save |
1502 (defun ex-preserve () | 1504 (defun ex-preserve () |
1504 (do-auto-save t)) | 1506 (do-auto-save t)) |
1505 | 1507 |
1506 ;; Ex put | 1508 ;; Ex put |
1507 (defun ex-put () | 1509 (defun ex-put () |
1508 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))) | 1510 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))) |
1509 (vip-get-ex-buffer) | 1511 (viper-get-ex-buffer) |
1510 (setq vip-use-register ex-buffer) | 1512 (setq viper-use-register ex-buffer) |
1511 (goto-char point) | 1513 (goto-char point) |
1512 (if (bobp) (vip-Put-back 1) (vip-put-back 1)))) | 1514 (if (bobp) (viper-Put-back 1) (viper-put-back 1)))) |
1513 | 1515 |
1514 ;; Ex print working directory | 1516 ;; Ex print working directory |
1515 (defun ex-pwd () | 1517 (defun ex-pwd () |
1516 (message default-directory)) | 1518 (message default-directory)) |
1517 | 1519 |
1518 ;; Ex quit command | 1520 ;; Ex quit command |
1519 (defun ex-quit () | 1521 (defun ex-quit () |
1520 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc. | 1522 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc. |
1521 (save-excursion | 1523 (save-excursion |
1522 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1524 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1523 (set-buffer vip-ex-work-buf) | 1525 (set-buffer viper-ex-work-buf) |
1524 (if (looking-at "!") (forward-char 1))) | 1526 (if (looking-at "!") (forward-char 1))) |
1525 (if (< viper-expert-level 3) | 1527 (if (< viper-expert-level 3) |
1526 (save-buffers-kill-emacs) | 1528 (save-buffers-kill-emacs) |
1527 (kill-buffer (current-buffer)))) | 1529 (kill-buffer (current-buffer)))) |
1528 | 1530 |
1529 | 1531 |
1530 ;; Ex read command | 1532 ;; Ex read command |
1531 (defun ex-read () | 1533 (defun ex-read () |
1532 (vip-get-ex-file) | 1534 (viper-get-ex-file) |
1533 (let ((point (if (null ex-addresses) (point) (car ex-addresses))) | 1535 (let ((point (if (null ex-addresses) (point) (car ex-addresses))) |
1534 command) | 1536 command) |
1535 (goto-char point) | 1537 (goto-char point) |
1536 (vip-add-newline-at-eob-if-necessary) | 1538 (viper-add-newline-at-eob-if-necessary) |
1537 (if (not (or (bobp) (eobp))) (forward-line 1)) | 1539 (if (not (or (bobp) (eobp))) (forward-line 1)) |
1538 (if (and (not ex-variant) (string= ex-file "")) | 1540 (if (and (not ex-variant) (string= ex-file "")) |
1539 (progn | 1541 (progn |
1540 (if (null buffer-file-name) | 1542 (if (null buffer-file-name) |
1541 (error vip-NoFileSpecified)) | 1543 (error viper-NoFileSpecified)) |
1542 (setq ex-file buffer-file-name))) | 1544 (setq ex-file buffer-file-name))) |
1543 (if ex-cmdfile | 1545 (if ex-cmdfile |
1544 (progn | 1546 (progn |
1545 (setq command (ex-expand-filsyms ex-file (current-buffer))) | 1547 (setq command (ex-expand-filsyms ex-file (current-buffer))) |
1546 (shell-command command t)) | 1548 (shell-command command t)) |
1547 (insert-file-contents ex-file))) | 1549 (insert-file-contents ex-file))) |
1548 (ex-fixup-history vip-last-ex-prompt ex-file)) | 1550 (ex-fixup-history viper-last-ex-prompt ex-file)) |
1549 | 1551 |
1550 ;; this function fixes ex-history for some commands like ex-read, ex-edit | 1552 ;; this function fixes ex-history for some commands like ex-read, ex-edit |
1551 (defun ex-fixup-history (&rest args) | 1553 (defun ex-fixup-history (&rest args) |
1552 (setq vip-ex-history | 1554 (setq viper-ex-history |
1553 (cons (mapconcat 'identity args " ") (cdr vip-ex-history)))) | 1555 (cons (mapconcat 'identity args " ") (cdr viper-ex-history)))) |
1554 | 1556 |
1555 | 1557 |
1556 ;; Ex recover from emacs \#file\# | 1558 ;; Ex recover from emacs \#file\# |
1557 (defun ex-recover () | 1559 (defun ex-recover () |
1558 (vip-get-ex-file) | 1560 (viper-get-ex-file) |
1559 (if (or ex-append ex-offset) | 1561 (if (or ex-append ex-offset) |
1560 (error "`recover': %s" vip-SpuriousText)) | 1562 (error "`recover': %s" viper-SpuriousText)) |
1561 (if (string= ex-file "") | 1563 (if (string= ex-file "") |
1562 (progn | 1564 (progn |
1563 (if (null buffer-file-name) | 1565 (if (null buffer-file-name) |
1564 (error "This buffer isn't visiting any file")) | 1566 (error "This buffer isn't visiting any file")) |
1565 (setq ex-file buffer-file-name)) | 1567 (setq ex-file buffer-file-name)) |
1583 (cursor-in-echo-area t) | 1585 (cursor-in-echo-area t) |
1584 str batch) | 1586 str batch) |
1585 (define-key | 1587 (define-key |
1586 minibuffer-local-completion-map " " 'minibuffer-complete-and-exit) | 1588 minibuffer-local-completion-map " " 'minibuffer-complete-and-exit) |
1587 (define-key minibuffer-local-completion-map "=" 'exit-minibuffer) | 1589 (define-key minibuffer-local-completion-map "=" 'exit-minibuffer) |
1588 (if (vip-set-unread-command-events | 1590 (if (viper-set-unread-command-events |
1589 (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil "\C-m")) | 1591 (ex-get-inline-cmd-args "[ \t]*[a-zA-Z]*[ \t]*" nil "\C-m")) |
1590 (progn | 1592 (progn |
1591 (setq batch t) | 1593 (setq batch t) |
1592 (vip-set-unread-command-events ?\C-m))) | 1594 (viper-set-unread-command-events ?\C-m))) |
1593 (message ":set <Variable> [= <Value>]") | 1595 (message ":set <Variable> [= <Value>]") |
1594 (or batch (sit-for 2)) | 1596 (or batch (sit-for 2)) |
1595 | 1597 |
1596 (while (string-match "^[ \\t\\n]*$" | 1598 (while (string-match "^[ \\t\\n]*$" |
1597 (setq str | 1599 (setq str |
1598 (completing-read ":set " ex-variable-alist))) | 1600 (completing-read ":set " ex-variable-alist))) |
1599 (message ":set <Variable> [= <Value>]") | 1601 (message ":set <Variable> [= <Value>]") |
1600 ;; if there are unread events, don't wait | 1602 ;; if there are unread events, don't wait |
1601 (or (vip-set-unread-command-events "") (sit-for 2)) | 1603 (or (viper-set-unread-command-events "") (sit-for 2)) |
1602 ) ; while | 1604 ) ; while |
1603 str)) | 1605 str)) |
1604 | 1606 |
1605 | 1607 |
1606 (defun ex-set () | 1608 (defun ex-set () |
1608 (val 0) | 1610 (val 0) |
1609 (set-cmd "setq") | 1611 (set-cmd "setq") |
1610 (ask-if-save t) | 1612 (ask-if-save t) |
1611 (auto-cmd-label "; don't touch or else...") | 1613 (auto-cmd-label "; don't touch or else...") |
1612 (delete-turn-on-auto-fill-pattern | 1614 (delete-turn-on-auto-fill-pattern |
1613 "([ \t]*add-hook[ \t]+'vip-insert-state-hooks[ \t]+'turn-on-auto-fill.*)") | 1615 "([ \t]*add-hook[ \t]+'viper-insert-state-hooks[ \t]+'turn-on-auto-fill.*)") |
1614 actual-lisp-cmd lisp-cmd-del-pattern | 1616 actual-lisp-cmd lisp-cmd-del-pattern |
1615 val2 orig-var) | 1617 val2 orig-var) |
1616 (setq orig-var var) | 1618 (setq orig-var var) |
1617 (cond ((string= var "all") | 1619 (cond ((string= var "all") |
1618 (setq ask-if-save nil | 1620 (setq ask-if-save nil |
1619 set-cmd nil)) | 1621 set-cmd nil)) |
1620 ((member var '("ai" "autoindent")) | 1622 ((member var '("ai" "autoindent")) |
1621 (setq var "vip-auto-indent" | 1623 (setq var "viper-auto-indent" |
1622 set-cmd "setq" | 1624 set-cmd "setq" |
1623 ask-if-save nil | 1625 ask-if-save nil |
1624 val "t")) | 1626 val "t")) |
1625 ((member var '("ai-g" "autoindent-global")) | 1627 ((member var '("ai-g" "autoindent-global")) |
1626 (kill-local-variable 'vip-auto-indent) | 1628 (kill-local-variable 'viper-auto-indent) |
1627 (setq var "vip-auto-indent" | 1629 (setq var "viper-auto-indent" |
1628 set-cmd "setq-default" | 1630 set-cmd "setq-default" |
1629 val "t")) | 1631 val "t")) |
1630 ((member var '("noai" "noautoindent")) | 1632 ((member var '("noai" "noautoindent")) |
1631 (setq var "vip-auto-indent" | 1633 (setq var "viper-auto-indent" |
1632 ask-if-save nil | 1634 ask-if-save nil |
1633 val "nil")) | 1635 val "nil")) |
1634 ((member var '("noai-g" "noautoindent-global")) | 1636 ((member var '("noai-g" "noautoindent-global")) |
1635 (kill-local-variable 'vip-auto-indent) | 1637 (kill-local-variable 'viper-auto-indent) |
1636 (setq var "vip-auto-indent" | 1638 (setq var "viper-auto-indent" |
1637 set-cmd "setq-default" | 1639 set-cmd "setq-default" |
1638 val "nil")) | 1640 val "nil")) |
1639 ((member var '("ic" "ignorecase")) | 1641 ((member var '("ic" "ignorecase")) |
1640 (setq var "vip-case-fold-search" | 1642 (setq var "viper-case-fold-search" |
1641 val "t")) | 1643 val "t")) |
1642 ((member var '("noic" "noignorecase")) | 1644 ((member var '("noic" "noignorecase")) |
1643 (setq var "vip-case-fold-search" | 1645 (setq var "viper-case-fold-search" |
1644 val "nil")) | 1646 val "nil")) |
1645 ((member var '("ma" "magic")) | 1647 ((member var '("ma" "magic")) |
1646 (setq var "vip-re-search" | 1648 (setq var "viper-re-search" |
1647 val "t")) | 1649 val "t")) |
1648 ((member var '("noma" "nomagic")) | 1650 ((member var '("noma" "nomagic")) |
1649 (setq var "vip-re-search" | 1651 (setq var "viper-re-search" |
1650 val "nil")) | 1652 val "nil")) |
1651 ((member var '("ro" "readonly")) | 1653 ((member var '("ro" "readonly")) |
1652 (setq var "buffer-read-only" | 1654 (setq var "buffer-read-only" |
1653 val "t")) | 1655 val "t")) |
1654 ((member var '("noro" "noreadonly")) | 1656 ((member var '("noro" "noreadonly")) |
1659 val "t")) | 1661 val "t")) |
1660 ((member var '("nosm" "noshowmatch")) | 1662 ((member var '("nosm" "noshowmatch")) |
1661 (setq var "blink-matching-paren" | 1663 (setq var "blink-matching-paren" |
1662 val "nil")) | 1664 val "nil")) |
1663 ((member var '("ws" "wrapscan")) | 1665 ((member var '("ws" "wrapscan")) |
1664 (setq var "vip-search-wrap-around-t" | 1666 (setq var "viper-search-wrap-around-t" |
1665 val "t")) | 1667 val "t")) |
1666 ((member var '("nows" "nowrapscan")) | 1668 ((member var '("nows" "nowrapscan")) |
1667 (setq var "vip-search-wrap-around-t" | 1669 (setq var "viper-search-wrap-around-t" |
1668 val "nil"))) | 1670 val "nil"))) |
1669 (if (and set-cmd (eq val 0)) ; value must be set by the user | 1671 (if (and set-cmd (eq val 0)) ; value must be set by the user |
1670 (let ((cursor-in-echo-area t)) | 1672 (let ((cursor-in-echo-area t)) |
1671 (message ":set %s = <Value>" var) | 1673 (message ":set %s = <Value>" var) |
1672 ;; if there are unread events, don't wait | 1674 ;; if there are unread events, don't wait |
1673 (or (vip-set-unread-command-events "") (sit-for 2)) | 1675 (or (viper-set-unread-command-events "") (sit-for 2)) |
1674 (setq val (read-string (format ":set %s = " var))) | 1676 (setq val (read-string (format ":set %s = " var))) |
1675 (ex-fixup-history "set" orig-var val) | 1677 (ex-fixup-history "set" orig-var val) |
1676 | 1678 |
1677 ;; check numerical values | 1679 ;; check numerical values |
1678 (if (member var | 1680 (if (member var |
1686 (error | 1688 (error |
1687 (error "%s: Invalid value, numberp, %S" var val)))) | 1689 (error "%s: Invalid value, numberp, %S" var val)))) |
1688 | 1690 |
1689 (cond | 1691 (cond |
1690 ((member var '("sw" "shiftwidth")) | 1692 ((member var '("sw" "shiftwidth")) |
1691 (setq var "vip-shift-width")) | 1693 (setq var "viper-shift-width")) |
1692 ((member var '("ts" "tabstop")) | 1694 ((member var '("ts" "tabstop")) |
1693 ;; make it take effect in curr buff and new bufs | 1695 ;; make it take effect in curr buff and new bufs |
1694 (setq var "tab-width" | 1696 (setq var "tab-width" |
1695 set-cmd "setq" | 1697 set-cmd "setq" |
1696 ask-if-save nil)) | 1698 ask-if-save nil)) |
1716 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s" | 1718 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s" |
1717 set-cmd var auto-cmd-label))) | 1719 set-cmd var auto-cmd-label))) |
1718 | 1720 |
1719 (if (and ask-if-save | 1721 (if (and ask-if-save |
1720 (y-or-n-p (format "Do you want to save this setting in %s " | 1722 (y-or-n-p (format "Do you want to save this setting in %s " |
1721 vip-custom-file-name))) | 1723 viper-custom-file-name))) |
1722 (progn | 1724 (progn |
1723 (vip-save-string-in-file | 1725 (viper-save-string-in-file |
1724 actual-lisp-cmd vip-custom-file-name | 1726 actual-lisp-cmd viper-custom-file-name |
1725 ;; del pattern | 1727 ;; del pattern |
1726 lisp-cmd-del-pattern) | 1728 lisp-cmd-del-pattern) |
1727 (if (string= var "fill-column") | 1729 (if (string= var "fill-column") |
1728 (if (> val2 0) | 1730 (if (> val2 0) |
1729 (vip-save-string-in-file | 1731 (viper-save-string-in-file |
1730 (concat | 1732 (concat |
1731 "(add-hook 'vip-insert-state-hooks 'turn-on-auto-fill) " | 1733 "(add-hook 'viper-insert-state-hooks 'turn-on-auto-fill) " |
1732 auto-cmd-label) | 1734 auto-cmd-label) |
1733 vip-custom-file-name | 1735 viper-custom-file-name |
1734 delete-turn-on-auto-fill-pattern) | 1736 delete-turn-on-auto-fill-pattern) |
1735 (vip-save-string-in-file | 1737 (viper-save-string-in-file |
1736 nil vip-custom-file-name delete-turn-on-auto-fill-pattern) | 1738 nil viper-custom-file-name delete-turn-on-auto-fill-pattern) |
1737 (vip-save-string-in-file | 1739 (viper-save-string-in-file |
1738 nil vip-custom-file-name | 1740 nil viper-custom-file-name |
1739 ;; del pattern | 1741 ;; del pattern |
1740 lisp-cmd-del-pattern) | 1742 lisp-cmd-del-pattern) |
1741 )) | 1743 )) |
1742 )) | 1744 )) |
1743 | 1745 |
1759 ;; In inline args, skip regex-forw and (optionally) chars-back. | 1761 ;; In inline args, skip regex-forw and (optionally) chars-back. |
1760 ;; Optional 3d arg is a string that should replace ' ' to prevent its | 1762 ;; Optional 3d arg is a string that should replace ' ' to prevent its |
1761 ;; special meaning | 1763 ;; special meaning |
1762 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str) | 1764 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str) |
1763 (save-excursion | 1765 (save-excursion |
1764 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1766 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1765 (set-buffer vip-ex-work-buf) | 1767 (set-buffer viper-ex-work-buf) |
1766 (goto-char (point-min)) | 1768 (goto-char (point-min)) |
1767 (re-search-forward regex-forw nil t) | 1769 (re-search-forward regex-forw nil t) |
1768 (let ((beg (point)) | 1770 (let ((beg (point)) |
1769 end) | 1771 end) |
1770 (goto-char (point-max)) | 1772 (goto-char (point-max)) |
1776 ;; in Ex commands | 1778 ;; in Ex commands |
1777 (goto-char beg) | 1779 (goto-char beg) |
1778 (if replace-str | 1780 (if replace-str |
1779 (while (re-search-forward " +" nil t) | 1781 (while (re-search-forward " +" nil t) |
1780 (replace-match replace-str nil t) | 1782 (replace-match replace-str nil t) |
1781 (vip-forward-char-carefully))) | 1783 (viper-forward-char-carefully))) |
1782 (goto-char end) | 1784 (goto-char end) |
1783 (buffer-substring beg end)))) | 1785 (buffer-substring beg end)))) |
1784 | 1786 |
1785 | 1787 |
1786 ;; Ex shell command | 1788 ;; Ex shell command |
1790 ;; Viper help. Invokes Info | 1792 ;; Viper help. Invokes Info |
1791 (defun ex-help () | 1793 (defun ex-help () |
1792 (condition-case nil | 1794 (condition-case nil |
1793 (progn | 1795 (progn |
1794 (pop-to-buffer (get-buffer-create "*info*")) | 1796 (pop-to-buffer (get-buffer-create "*info*")) |
1795 (info (if vip-xemacs-p "viper.info" "viper")) | 1797 (info (if viper-xemacs-p "viper.info" "viper")) |
1796 (message "Type `i' to search for a specific topic")) | 1798 (message "Type `i' to search for a specific topic")) |
1797 (error (beep 1) | 1799 (error (beep 1) |
1798 (with-output-to-temp-buffer " *vip-info*" | 1800 (with-output-to-temp-buffer " *viper-info*" |
1799 (princ (format " | 1801 (princ (format " |
1800 The Info file for Viper does not seem to be installed. | 1802 The Info file for Viper does not seem to be installed. |
1801 | 1803 |
1802 This file is part of the standard distribution of %sEmacs. | 1804 This file is part of the standard distribution of %sEmacs. |
1803 Please contact your system administrator. " | 1805 Please contact your system administrator. " |
1804 (if vip-xemacs-p "X" "") | 1806 (if viper-xemacs-p "X" "") |
1805 )))))) | 1807 )))))) |
1806 | 1808 |
1807 ;; Ex source command. Loads the file specified as argument or `~/.vip' | 1809 ;; Ex source command. Loads the file specified as argument or `~/.viper' |
1808 (defun ex-source () | 1810 (defun ex-source () |
1809 (vip-get-ex-file) | 1811 (viper-get-ex-file) |
1810 (if (string= ex-file "") | 1812 (if (string= ex-file "") |
1811 (load vip-custom-file-name) | 1813 (load viper-custom-file-name) |
1812 (load ex-file))) | 1814 (load ex-file))) |
1813 | 1815 |
1814 ;; Ex substitute command | 1816 ;; Ex substitute command |
1815 ;; If REPEAT use previous regexp which is ex-reg-exp or vip-s-string | 1817 ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string |
1816 (defun ex-substitute (&optional repeat r-flag) | 1818 (defun ex-substitute (&optional repeat r-flag) |
1817 (let ((opt-g nil) | 1819 (let ((opt-g nil) |
1818 (opt-c nil) | 1820 (opt-c nil) |
1819 (matched-pos nil) | 1821 (matched-pos nil) |
1820 (case-fold-search vip-case-fold-search) | 1822 (case-fold-search viper-case-fold-search) |
1821 delim pat repl) | 1823 delim pat repl) |
1822 (if repeat (setq ex-token nil) (setq delim (vip-get-ex-pat))) | 1824 (if repeat (setq ex-token nil) (setq delim (viper-get-ex-pat))) |
1823 (if (null ex-token) | 1825 (if (null ex-token) |
1824 (progn | 1826 (progn |
1825 (setq pat (if r-flag vip-s-string ex-reg-exp)) | 1827 (setq pat (if r-flag viper-s-string ex-reg-exp)) |
1826 (or (stringp pat) | 1828 (or (stringp pat) |
1827 (error "No previous pattern to use in substitution")) | 1829 (error "No previous pattern to use in substitution")) |
1828 (setq repl ex-repl | 1830 (setq repl ex-repl |
1829 delim (string-to-char pat))) | 1831 delim (string-to-char pat))) |
1830 (setq pat (if (string= ex-token "") vip-s-string ex-token)) | 1832 (setq pat (if (string= ex-token "") viper-s-string ex-token)) |
1831 (setq vip-s-string pat | 1833 (setq viper-s-string pat |
1832 ex-reg-exp pat) | 1834 ex-reg-exp pat) |
1833 (setq delim (vip-get-ex-pat)) | 1835 (setq delim (viper-get-ex-pat)) |
1834 (if (null ex-token) | 1836 (if (null ex-token) |
1835 (setq ex-token "" | 1837 (setq ex-token "" |
1836 ex-repl "") | 1838 ex-repl "") |
1837 (setq repl ex-token | 1839 (setq repl ex-token |
1838 ex-repl ex-token))) | 1840 ex-repl ex-token))) |
1839 (while (vip-get-ex-opt-gc delim) | 1841 (while (viper-get-ex-opt-gc delim) |
1840 (if (string= ex-token "g") (setq opt-g t) (setq opt-c t))) | 1842 (if (string= ex-token "g") (setq opt-g t) (setq opt-c t))) |
1841 (vip-get-ex-count) | 1843 (viper-get-ex-count) |
1842 (if ex-count | 1844 (if ex-count |
1843 (save-excursion | 1845 (save-excursion |
1844 (if ex-addresses (goto-char (car ex-addresses))) | 1846 (if ex-addresses (goto-char (car ex-addresses))) |
1845 (set-mark (point)) | 1847 (set-mark (point)) |
1846 (forward-line (1- ex-count)) | 1848 (forward-line (1- ex-count)) |
1852 ;(setq G opt-g) | 1854 ;(setq G opt-g) |
1853 (let ((beg (car ex-addresses)) | 1855 (let ((beg (car ex-addresses)) |
1854 (end (car (cdr ex-addresses))) | 1856 (end (car (cdr ex-addresses))) |
1855 eol-mark) | 1857 eol-mark) |
1856 (save-excursion | 1858 (save-excursion |
1857 (vip-enlarge-region beg end) | 1859 (viper-enlarge-region beg end) |
1858 (let ((limit (save-excursion | 1860 (let ((limit (save-excursion |
1859 (goto-char (max (point) (mark t))) | 1861 (goto-char (max (point) (mark t))) |
1860 (point-marker)))) | 1862 (point-marker)))) |
1861 (goto-char (min (point) (mark t))) | 1863 (goto-char (min (point) (mark t))) |
1862 (while (< (point) limit) | 1864 (while (< (point) limit) |
1872 (setq matched-pos (point)) | 1874 (setq matched-pos (point)) |
1873 (if (not (stringp repl)) | 1875 (if (not (stringp repl)) |
1874 (error "Can't perform Ex substitution: No previous replacement pattern")) | 1876 (error "Can't perform Ex substitution: No previous replacement pattern")) |
1875 (replace-match repl t)))) | 1877 (replace-match repl t)))) |
1876 (end-of-line) | 1878 (end-of-line) |
1877 (vip-forward-char-carefully)) | 1879 (viper-forward-char-carefully)) |
1878 (if (null pat) | 1880 (if (null pat) |
1879 (error | 1881 (error |
1880 "Can't repeat Ex substitution: No previous regular expression")) | 1882 "Can't repeat Ex substitution: No previous regular expression")) |
1881 (if (and (re-search-forward pat eol-mark t) | 1883 (if (and (re-search-forward pat eol-mark t) |
1882 (or (not opt-c) (y-or-n-p "Replace? "))) | 1884 (or (not opt-c) (y-or-n-p "Replace? "))) |
1884 (setq matched-pos (point)) | 1886 (setq matched-pos (point)) |
1885 (if (not (stringp repl)) | 1887 (if (not (stringp repl)) |
1886 (error "Can't perform Ex substitution: No previous replacement pattern")) | 1888 (error "Can't perform Ex substitution: No previous replacement pattern")) |
1887 (replace-match repl t))) | 1889 (replace-match repl t))) |
1888 (end-of-line) | 1890 (end-of-line) |
1889 (vip-forward-char-carefully)))))) | 1891 (viper-forward-char-carefully)))))) |
1890 (if matched-pos (goto-char matched-pos)) | 1892 (if matched-pos (goto-char matched-pos)) |
1891 (beginning-of-line) | 1893 (beginning-of-line) |
1892 (if opt-c (message "done")))) | 1894 (if opt-c (message "done")))) |
1893 | 1895 |
1894 ;; Ex tag command | 1896 ;; Ex tag command |
1895 (defun ex-tag () | 1897 (defun ex-tag () |
1896 (let (tag) | 1898 (let (tag) |
1897 (save-window-excursion | 1899 (save-window-excursion |
1898 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 1900 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
1899 (set-buffer vip-ex-work-buf) | 1901 (set-buffer viper-ex-work-buf) |
1900 (skip-chars-forward " \t") | 1902 (skip-chars-forward " \t") |
1901 (set-mark (point)) | 1903 (set-mark (point)) |
1902 (skip-chars-forward "^ |\t\n") | 1904 (skip-chars-forward "^ |\t\n") |
1903 (setq tag (buffer-substring (mark t) (point)))) | 1905 (setq tag (buffer-substring (mark t) (point)))) |
1904 (if (not (string= tag "")) (setq ex-tag tag)) | 1906 (if (not (string= tag "")) (setq ex-tag tag)) |
1905 (vip-change-state-to-emacs) | 1907 (viper-change-state-to-emacs) |
1906 (condition-case conds | 1908 (condition-case conds |
1907 (progn | 1909 (progn |
1908 (if (string= tag "") | 1910 (if (string= tag "") |
1909 (find-tag ex-tag t) | 1911 (find-tag ex-tag t) |
1910 (find-tag-other-window ex-tag)) | 1912 (find-tag-other-window ex-tag)) |
1911 (vip-change-state-to-vi)) | 1913 (viper-change-state-to-vi)) |
1912 (error | 1914 (error |
1913 (vip-change-state-to-vi) | 1915 (viper-change-state-to-vi) |
1914 (vip-message-conditions conds))))) | 1916 (viper-message-conditions conds))))) |
1915 | 1917 |
1916 ;; Ex write command | 1918 ;; Ex write command |
1917 (defun ex-write (q-flag) | 1919 (defun ex-write (q-flag) |
1918 (vip-default-ex-addresses t) | 1920 (viper-default-ex-addresses t) |
1919 (vip-get-ex-file) | 1921 (viper-get-ex-file) |
1920 (let ((end (car ex-addresses)) | 1922 (let ((end (car ex-addresses)) |
1921 (beg (car (cdr ex-addresses))) | 1923 (beg (car (cdr ex-addresses))) |
1922 (orig-buf (current-buffer)) | 1924 (orig-buf (current-buffer)) |
1923 (orig-buf-file-name (buffer-file-name)) | 1925 (orig-buf-file-name (buffer-file-name)) |
1924 (orig-buf-name (buffer-name)) | 1926 (orig-buf-name (buffer-name)) |
1925 (buff-changed-p (buffer-modified-p)) | 1927 (buff-changed-p (buffer-modified-p)) |
1926 temp-buf writing-same-file region | 1928 temp-buf writing-same-file region |
1927 file-exists writing-whole-file) | 1929 file-exists writing-whole-file) |
1928 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 1930 (if (> beg end) (error viper-FirstAddrExceedsSecond)) |
1929 (if ex-cmdfile | 1931 (if ex-cmdfile |
1930 (progn | 1932 (progn |
1931 (vip-enlarge-region beg end) | 1933 (viper-enlarge-region beg end) |
1932 (shell-command-on-region (point) (mark t) ex-file)) | 1934 (shell-command-on-region (point) (mark t) ex-file)) |
1933 (if (and (string= ex-file "") (not (buffer-file-name))) | 1935 (if (and (string= ex-file "") (not (buffer-file-name))) |
1934 (setq ex-file | 1936 (setq ex-file |
1935 (read-file-name | 1937 (read-file-name |
1936 (format "Buffer %s isn't visiting any file. File to save in: " | 1938 (format "Buffer %s isn't visiting any file. File to save in: " |
1985 (ex-write-info | 1987 (ex-write-info |
1986 file-exists ex-file (point-min) (point-max)))) | 1988 file-exists ex-file (point-min) (point-max)))) |
1987 (t ; writing a region | 1989 (t ; writing a region |
1988 (unwind-protect | 1990 (unwind-protect |
1989 (save-excursion | 1991 (save-excursion |
1990 (vip-enlarge-region beg end) | 1992 (viper-enlarge-region beg end) |
1991 (setq region (buffer-substring (point) (mark t))) | 1993 (setq region (buffer-substring (point) (mark t))) |
1992 ;; create temp buffer for the region | 1994 ;; create temp buffer for the region |
1993 (setq temp-buf (get-buffer-create " *ex-write*")) | 1995 (setq temp-buf (get-buffer-create " *ex-write*")) |
1994 (set-buffer temp-buf) | 1996 (set-buffer temp-buf) |
1995 (set-visited-file-name ex-file 'noquerry) | 1997 (set-visited-file-name ex-file 'noquerry) |
2020 ))) | 2022 ))) |
2021 | 2023 |
2022 | 2024 |
2023 (defun ex-write-info (exists file-name beg end) | 2025 (defun ex-write-info (exists file-name beg end) |
2024 (message "`%s'%s %d lines, %d characters" | 2026 (message "`%s'%s %d lines, %d characters" |
2025 (vip-abbreviate-file-name file-name) | 2027 (viper-abbreviate-file-name file-name) |
2026 (if exists "" " [New file]") | 2028 (if exists "" " [New file]") |
2027 (count-lines beg (min (1+ end) (point-max))) | 2029 (count-lines beg (min (1+ end) (point-max))) |
2028 (- end beg))) | 2030 (- end beg))) |
2029 | 2031 |
2030 ;; Ex yank command | 2032 ;; Ex yank command |
2031 (defun ex-yank () | 2033 (defun ex-yank () |
2032 (vip-default-ex-addresses) | 2034 (viper-default-ex-addresses) |
2033 (vip-get-ex-buffer) | 2035 (viper-get-ex-buffer) |
2034 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | 2036 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) |
2035 (if (> beg end) (error vip-FirstAddrExceedsSecond)) | 2037 (if (> beg end) (error viper-FirstAddrExceedsSecond)) |
2036 (save-excursion | 2038 (save-excursion |
2037 (vip-enlarge-region beg end) | 2039 (viper-enlarge-region beg end) |
2038 (exchange-point-and-mark) | 2040 (exchange-point-and-mark) |
2039 (if (or ex-g-flag ex-g-variant) | 2041 (if (or ex-g-flag ex-g-variant) |
2040 (error "Can't execute `yank' within `global'")) | 2042 (error "Can't execute `yank' within `global'")) |
2041 (if ex-count | 2043 (if ex-count |
2042 (progn | 2044 (progn |
2043 (set-mark (point)) | 2045 (set-mark (point)) |
2044 (forward-line (1- ex-count))) | 2046 (forward-line (1- ex-count))) |
2045 (set-mark end)) | 2047 (set-mark end)) |
2046 (vip-enlarge-region (point) (mark t)) | 2048 (viper-enlarge-region (point) (mark t)) |
2047 (if ex-flag (error "`yank': %s" vip-SpuriousText)) | 2049 (if ex-flag (error "`yank': %s" viper-SpuriousText)) |
2048 (if ex-buffer | 2050 (if ex-buffer |
2049 (cond ((vip-valid-register ex-buffer '(Letter)) | 2051 (cond ((viper-valid-register ex-buffer '(Letter)) |
2050 (vip-append-to-register | 2052 (viper-append-to-register |
2051 (downcase ex-buffer) (point) (mark t))) | 2053 (downcase ex-buffer) (point) (mark t))) |
2052 ((vip-valid-register ex-buffer) | 2054 ((viper-valid-register ex-buffer) |
2053 (copy-to-register ex-buffer (point) (mark t) nil)) | 2055 (copy-to-register ex-buffer (point) (mark t) nil)) |
2054 (t (error vip-InvalidRegister ex-buffer)))) | 2056 (t (error viper-InvalidRegister ex-buffer)))) |
2055 (copy-region-as-kill (point) (mark t))))) | 2057 (copy-region-as-kill (point) (mark t))))) |
2056 | 2058 |
2057 ;; Execute shell command | 2059 ;; Execute shell command |
2058 (defun ex-command () | 2060 (defun ex-command () |
2059 (let (command) | 2061 (let (command) |
2060 (save-window-excursion | 2062 (save-window-excursion |
2061 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | 2063 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) |
2062 (set-buffer vip-ex-work-buf) | 2064 (set-buffer viper-ex-work-buf) |
2063 (skip-chars-forward " \t") | 2065 (skip-chars-forward " \t") |
2064 (setq command (buffer-substring (point) (point-max))) | 2066 (setq command (buffer-substring (point) (point-max))) |
2065 (end-of-line)) | 2067 (end-of-line)) |
2066 (setq command (ex-expand-filsyms command (current-buffer))) | 2068 (setq command (ex-expand-filsyms command (current-buffer))) |
2067 (if (and (> (length command) 0) (string= "!" (substring command 0 1))) | 2069 (if (and (> (length command) 0) (string= "!" (substring command 0 1))) |
2068 (if vip-ex-last-shell-com | 2070 (if viper-ex-last-shell-com |
2069 (setq command (concat vip-ex-last-shell-com (substring command 1))) | 2071 (setq command |
2072 (concat viper-ex-last-shell-com (substring command 1))) | |
2070 (error "No previous shell command"))) | 2073 (error "No previous shell command"))) |
2071 (setq vip-ex-last-shell-com command) | 2074 (setq viper-ex-last-shell-com command) |
2072 (if (null ex-addresses) | 2075 (if (null ex-addresses) |
2073 (shell-command command) | 2076 (shell-command command) |
2074 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) | 2077 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) |
2075 (if (null beg) (setq beg end)) | 2078 (if (null beg) (setq beg end)) |
2076 (save-excursion | 2079 (save-excursion |
2077 (goto-char beg) | 2080 (goto-char beg) |
2078 (set-mark end) | 2081 (set-mark end) |
2079 (vip-enlarge-region (point) (mark t)) | 2082 (viper-enlarge-region (point) (mark t)) |
2080 (shell-command-on-region (point) (mark t) command t)) | 2083 (shell-command-on-region (point) (mark t) command t)) |
2081 (goto-char beg))))) | 2084 (goto-char beg))))) |
2082 | 2085 |
2083 ;; Print line number | 2086 ;; Print line number |
2084 (defun ex-line-no () | 2087 (defun ex-line-no () |
2086 (1+ (count-lines | 2089 (1+ (count-lines |
2087 (point-min) | 2090 (point-min) |
2088 (if (null ex-addresses) (point-max) (car ex-addresses)))))) | 2091 (if (null ex-addresses) (point-max) (car ex-addresses)))))) |
2089 | 2092 |
2090 ;; Give information on the file visited by the current buffer | 2093 ;; Give information on the file visited by the current buffer |
2091 (defun vip-info-on-file () | 2094 (defun viper-info-on-file () |
2092 (interactive) | 2095 (interactive) |
2093 (let ((pos1 (vip-line-pos 'start)) | 2096 (let ((pos1 (viper-line-pos 'start)) |
2094 (pos2 (vip-line-pos 'end)) | 2097 (pos2 (viper-line-pos 'end)) |
2095 lines file info) | 2098 lines file info) |
2096 (setq lines (count-lines (point-min) (vip-line-pos 'end)) | 2099 (setq lines (count-lines (point-min) (viper-line-pos 'end)) |
2097 file (if (buffer-file-name) | 2100 file (if (buffer-file-name) |
2098 (concat (vip-abbreviate-file-name (buffer-file-name)) ":") | 2101 (concat (viper-abbreviate-file-name (buffer-file-name)) ":") |
2099 (concat (buffer-name) " [Not visiting any file]:")) | 2102 (concat (buffer-name) " [Not visiting any file]:")) |
2100 info (format "line=%d/%d pos=%d/%d col=%d %s" | 2103 info (format "line=%d/%d pos=%d/%d col=%d %s" |
2101 (if (= pos1 pos2) | 2104 (if (= pos1 pos2) |
2102 (1+ lines) | 2105 (1+ lines) |
2103 lines) | 2106 lines) |
2107 (if (buffer-modified-p) "[Modified]" "[Unchanged]"))) | 2110 (if (buffer-modified-p) "[Modified]" "[Unchanged]"))) |
2108 (if (< (+ 1 (length info) (length file)) | 2111 (if (< (+ 1 (length info) (length file)) |
2109 (window-width (minibuffer-window))) | 2112 (window-width (minibuffer-window))) |
2110 (message (concat file " " info)) | 2113 (message (concat file " " info)) |
2111 (save-window-excursion | 2114 (save-window-excursion |
2112 (with-output-to-temp-buffer " *vip-info*" | 2115 (with-output-to-temp-buffer " *viper-info*" |
2113 (princ (concat "\n" | 2116 (princ (concat "\n" |
2114 file "\n\n\t" info | 2117 file "\n\n\t" info |
2115 "\n\n\nPress any key to continue...\n\n"))) | 2118 "\n\n\nPress any key to continue...\n\n"))) |
2116 (vip-read-event) | 2119 (viper-read-event) |
2117 (kill-buffer " *vip-info*"))) | 2120 (kill-buffer " *viper-info*"))) |
2118 )) | 2121 )) |
2119 | 2122 |
2120 ;; display all variables set through :set | 2123 ;; display all variables set through :set |
2121 (defun ex-show-vars () | 2124 (defun ex-show-vars () |
2122 (with-output-to-temp-buffer " *vip-info*" | 2125 (with-output-to-temp-buffer " *viper-info*" |
2123 (princ (if vip-auto-indent | 2126 (princ (if viper-auto-indent |
2124 "autoindent (local)\n" "noautoindent (local)\n")) | 2127 "autoindent (local)\n" "noautoindent (local)\n")) |
2125 (princ (if (default-value 'vip-auto-indent) | 2128 (princ (if (default-value 'viper-auto-indent) |
2126 "autoindent (global) \n" "noautoindent (global) \n")) | 2129 "autoindent (global) \n" "noautoindent (global) \n")) |
2127 (princ (if vip-case-fold-search "ignorecase\n" "noignorecase\n")) | 2130 (princ (if viper-case-fold-search "ignorecase\n" "noignorecase\n")) |
2128 (princ (if vip-re-search "magic\n" "nomagic\n")) | 2131 (princ (if viper-re-search "magic\n" "nomagic\n")) |
2129 (princ (if buffer-read-only "readonly\n" "noreadonly\n")) | 2132 (princ (if buffer-read-only "readonly\n" "noreadonly\n")) |
2130 (princ (if blink-matching-paren "showmatch\n" "noshowmatch\n")) | 2133 (princ (if blink-matching-paren "showmatch\n" "noshowmatch\n")) |
2131 (princ (if vip-search-wrap-around-t "wrapscan\n" "nowrapscan\n")) | 2134 (princ (if viper-search-wrap-around-t "wrapscan\n" "nowrapscan\n")) |
2132 (princ (format "shiftwidth \t\t= %S\n" vip-shift-width)) | 2135 (princ (format "shiftwidth \t\t= %S\n" viper-shift-width)) |
2133 (princ (format "tabstop (local) \t= %S\n" tab-width)) | 2136 (princ (format "tabstop (local) \t= %S\n" tab-width)) |
2134 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width))) | 2137 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width))) |
2135 (princ (format "wrapmargin (local) \t= %S\n" | 2138 (princ (format "wrapmargin (local) \t= %S\n" |
2136 (- (window-width) fill-column))) | 2139 (- (window-width) fill-column))) |
2137 (princ (format "wrapmargin (global) \t= %S\n" | 2140 (princ (format "wrapmargin (global) \t= %S\n" |