aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-06-09 00:11:23 +0000
committerKarl Heuer1995-06-09 00:11:23 +0000
commit8f2685cb0550e587d4e0ae6a16b1433a11ac9ff7 (patch)
tree84cc73f3dcbd5bf3463801ff78ef05295145ea0f
parent4af0c23b9f0b7fadd862060093217952d6617aa3 (diff)
downloademacs-8f2685cb0550e587d4e0ae6a16b1433a11ac9ff7.tar.gz
emacs-8f2685cb0550e587d4e0ae6a16b1433a11ac9ff7.zip
Fixed problems with yanking/deleting buffers.
Changed vip-*-frame-* to *-frame-*, incorporated overlay strings, unread-command-events, removed support for emacs versions 19.28 and xemacs 19.11 and earlier.
-rw-r--r--lisp/emulation/viper-ex.el157
1 files changed, 86 insertions, 71 deletions
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index 669d38a48f3..8eeb0c17917 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -24,6 +24,7 @@
24 24
25(defconst vip-ex-work-buf-name " *ex-working-space*") 25(defconst vip-ex-work-buf-name " *ex-working-space*")
26(defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) 26(defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
27(defconst vip-ex-tmp-buf-name " *ex-tmp*")
27 28
28 29
29;;; Variable completion in :set command 30;;; Variable completion in :set command
@@ -93,7 +94,8 @@
93 94
94;; `sh' doesn't seem to expand wildcards, like `*' 95;; `sh' doesn't seem to expand wildcards, like `*'
95(defconst ex-find-file-shell "csh" 96(defconst ex-find-file-shell "csh"
96 "Shell in which to interpret wildcards.") 97 "Shell in which to interpret wildcards. Must be csh, tcsh, or similar.
98Bourne shell doesn't seem to work here.")
97(defvar ex-find-file-shell-options "-f" 99(defvar ex-find-file-shell-options "-f"
98 "*Options to pass to `ex-find-file-shell'.") 100 "*Options to pass to `ex-find-file-shell'.")
99 101
@@ -140,16 +142,16 @@ reversed.")
140 142
141;;; Code 143;;; Code
142 144
145;; Check if ex-token is an initial segment of STR
143(defun vip-check-sub (str) 146(defun vip-check-sub (str)
144 "Check if ex-token is an initial segment of STR."
145 (let ((length (length ex-token))) 147 (let ((length (length ex-token)))
146 (if (and (<= length (length str)) 148 (if (and (<= length (length str))
147 (string= ex-token (substring str 0 length))) 149 (string= ex-token (substring str 0 length)))
148 (setq ex-token str) 150 (setq ex-token str)
149 (setq ex-token-type 'non-command)))) 151 (setq ex-token-type 'non-command))))
150 152
153;; Get a complete ex command
151(defun vip-get-ex-com-subr () 154(defun vip-get-ex-com-subr ()
152 "Get a complete ex command."
153 (let (case-fold-search) 155 (let (case-fold-search)
154 (set-mark (point)) 156 (set-mark (point))
155 (re-search-forward "[a-zA-Z][a-zA-Z]*") 157 (re-search-forward "[a-zA-Z][a-zA-Z]*")
@@ -237,9 +239,9 @@ reversed.")
237 (exchange-point-and-mark) 239 (exchange-point-and-mark)
238 )) 240 ))
239 241
242;; Get an ex-token which is either an address or a command.
243;; A token has a type, \(command, address, end-mark\), and a value
240(defun vip-get-ex-token () 244(defun vip-get-ex-token ()
241 "Get an ex-token which is either an address or a command.
242A token has a type, \(command, address, end-mark\), and a value."
243 (save-window-excursion 245 (save-window-excursion
244 (set-buffer vip-ex-work-buf) 246 (set-buffer vip-ex-work-buf)
245 (skip-chars-forward " \t|") 247 (skip-chars-forward " \t|")
@@ -418,8 +420,10 @@ A token has a type, \(command, address, end-mark\), and a value."
418 (vip-alist-to-list (reverse compl-list))))))) 420 (vip-alist-to-list (reverse compl-list)))))))
419 ))) 421 )))
420 422
423
424;; Read Ex commands
425;; Ex commands themselves are implemented in viper-ex.el
421(defun vip-ex (&optional string) 426(defun vip-ex (&optional string)
422 "Ex commands within Viper."
423 (interactive) 427 (interactive)
424 (or string 428 (or string
425 (setq ex-g-flag nil 429 (setq ex-g-flag nil
@@ -428,7 +432,7 @@ A token has a type, \(command, address, end-mark\), and a value."
428 (address nil) 432 (address nil)
429 (cont t) 433 (cont t)
430 (dot (point)) 434 (dot (point))
431 com-str) 435 prev-token-type com-str)
432 436
433 (vip-add-keymap vip-ex-cmd-map map) 437 (vip-add-keymap vip-ex-cmd-map map)
434 438
@@ -473,20 +477,29 @@ A token has a type, \(command, address, end-mark\), and a value."
473 ((eq ex-token-type 'non-command) 477 ((eq ex-token-type 'non-command)
474 (error (format "`%s': %s" ex-token vip-BadExCommand))) 478 (error (format "`%s': %s" ex-token vip-BadExCommand)))
475 ((eq ex-token-type 'whole) 479 ((eq ex-token-type 'whole)
480 (setq address nil)
476 (setq ex-addresses 481 (setq ex-addresses
477 (cons (point-max) (cons (point-min) ex-addresses)))) 482 (if ex-addresses
483 (cons (point-max) ex-addresses)
484 (cons (point-max) (cons (point-min) ex-addresses)))))
478 ((eq ex-token-type 'comma) 485 ((eq ex-token-type 'comma)
486 (if (eq prev-token-type 'whole)
487 (setq address (point-min)))
479 (setq ex-addresses 488 (setq ex-addresses
480 (cons (if (null address) (point) address) ex-addresses))) 489 (cons (if (null address) (point) address) ex-addresses)))
481 ((eq ex-token-type 'semi-colon) 490 ((eq ex-token-type 'semi-colon)
491 (if (eq prev-token-type 'whole)
492 (setq address (point-min)))
482 (if address (setq dot address)) 493 (if address (setq dot address))
483 (setq ex-addresses 494 (setq ex-addresses
484 (cons (if (null address) (point) address) ex-addresses))) 495 (cons (if (null address) (point) address) ex-addresses)))
485 (t (let ((ans (vip-get-ex-address-subr address dot))) 496 (t (let ((ans (vip-get-ex-address-subr address dot)))
486 (if ans (setq address ans)))))))) 497 (if ans (setq address ans)))))
498 (setq prev-token-type ex-token-type))))
499
487 500
501;; Get a regular expression and set `ex-variant', if found
488(defun vip-get-ex-pat () 502(defun vip-get-ex-pat ()
489 "Get a regular expression and set `ex-variant', if found."
490 (save-window-excursion 503 (save-window-excursion
491 (set-buffer vip-ex-work-buf) 504 (set-buffer vip-ex-work-buf)
492 (skip-chars-forward " \t") 505 (skip-chars-forward " \t")
@@ -521,8 +534,8 @@ A token has a type, \(command, address, end-mark\), and a value."
521 (setq ex-token nil)) 534 (setq ex-token nil))
522 c))) 535 c)))
523 536
537;; get an ex command
524(defun vip-get-ex-command () 538(defun vip-get-ex-command ()
525 "get an ex command"
526 (save-window-excursion 539 (save-window-excursion
527 (set-buffer vip-ex-work-buf) 540 (set-buffer vip-ex-work-buf)
528 (if (looking-at "/") (forward-char 1)) 541 (if (looking-at "/") (forward-char 1))
@@ -536,8 +549,8 @@ A token has a type, \(command, address, end-mark\), and a value."
536 (forward-char 1)) 549 (forward-char 1))
537 (t (error vip-BadExCommand))))) 550 (t (error vip-BadExCommand)))))
538 551
552;; Get an Ex option g or c
539(defun vip-get-ex-opt-gc (c) 553(defun vip-get-ex-opt-gc (c)
540 "Get an Ex option g or c."
541 (save-window-excursion 554 (save-window-excursion
542 (set-buffer vip-ex-work-buf) 555 (set-buffer vip-ex-work-buf)
543 (if (looking-at (format "%c" c)) (forward-char 1)) 556 (if (looking-at (format "%c" c)) (forward-char 1))
@@ -552,8 +565,8 @@ A token has a type, \(command, address, end-mark\), and a value."
552 t) 565 t)
553 (t nil)))) 566 (t nil))))
554 567
568;; Compute default addresses. WHOLE-FLAG means use the whole buffer
555(defun vip-default-ex-addresses (&optional whole-flag) 569(defun vip-default-ex-addresses (&optional whole-flag)
556 "Compute default addresses. WHOLE-FLAG means use the whole buffer."
557 (cond ((null ex-addresses) 570 (cond ((null ex-addresses)
558 (setq ex-addresses 571 (setq ex-addresses
559 (if whole-flag 572 (if whole-flag
@@ -563,8 +576,8 @@ A token has a type, \(command, address, end-mark\), and a value."
563 (setq ex-addresses 576 (setq ex-addresses
564 (cons (car ex-addresses) ex-addresses))))) 577 (cons (car ex-addresses) ex-addresses)))))
565 578
579;; Get an ex-address as a marker and set ex-flag if a flag is found
566(defun vip-get-ex-address () 580(defun vip-get-ex-address ()
567 "Get an ex-address as a marker and set ex-flag if a flag is found."
568 (let ((address (point-marker)) (cont t)) 581 (let ((address (point-marker)) (cont t))
569 (setq ex-token "") 582 (setq ex-token "")
570 (setq ex-flag nil) 583 (setq ex-flag nil)
@@ -586,8 +599,8 @@ A token has a type, \(command, address, end-mark\), and a value."
586 (if ans (setq address ans)))))) 599 (if ans (setq address ans))))))
587 address)) 600 address))
588 601
602;; Returns an address as a point
589(defun vip-get-ex-address-subr (old-address dot) 603(defun vip-get-ex-address-subr (old-address dot)
590 "Returns an address as a point."
591 (let ((address nil)) 604 (let ((address nil))
592 (if (null old-address) (setq old-address dot)) 605 (if (null old-address) (setq old-address dot))
593 (cond ((eq ex-token-type 'dot) 606 (cond ((eq ex-token-type 'dot)
@@ -630,8 +643,8 @@ A token has a type, \(command, address, end-mark\), and a value."
630 address)) 643 address))
631 644
632 645
646;; Search pattern and set address
633(defun ex-search-address (forward) 647(defun ex-search-address (forward)
634 "Search pattern and set address."
635 (if (string= ex-token "") 648 (if (string= ex-token "")
636 (if (null vip-s-string) 649 (if (null vip-s-string)
637 (error vip-NoPrevSearch) 650 (error vip-NoPrevSearch)
@@ -644,8 +657,8 @@ A token has a type, \(command, address, end-mark\), and a value."
644 (forward-line -1) 657 (forward-line -1)
645 (re-search-backward ex-token))) 658 (re-search-backward ex-token)))
646 659
660;; Get a buffer name and set `ex-count' and `ex-flag' if found
647(defun vip-get-ex-buffer () 661(defun vip-get-ex-buffer ()
648 "Get a buffer name and set `ex-count' and `ex-flag' if found."
649 (setq ex-buffer nil) 662 (setq ex-buffer nil)
650 (setq ex-count nil) 663 (setq ex-count nil)
651 (setq ex-flag nil) 664 (setq ex-flag nil)
@@ -696,8 +709,8 @@ A token has a type, \(command, address, end-mark\), and a value."
696 (error "`%s': %s" 709 (error "`%s': %s"
697 (buffer-substring (point-min) (1- (point-max))) vip-BadExCommand)))) 710 (buffer-substring (point-min) (1- (point-max))) vip-BadExCommand))))
698 711
712;; Expand \% and \# in ex command
699(defun ex-expand-filsyms (cmd buf) 713(defun ex-expand-filsyms (cmd buf)
700 "Expand \% and \# in ex command."
701 (let (cf pf ret) 714 (let (cf pf ret)
702 (save-excursion 715 (save-excursion
703 (set-buffer buf) 716 (set-buffer buf)
@@ -708,7 +721,7 @@ A token has a type, \(command, address, end-mark\), and a value."
708 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd)) 721 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
709 (error "No alternate file to substitute for `#'")) 722 (error "No alternate file to substitute for `#'"))
710 (save-excursion 723 (save-excursion
711 (set-buffer (get-buffer-create " *ex-tmp*")) 724 (set-buffer (get-buffer-create vip-ex-tmp-buf-name))
712 (erase-buffer) 725 (erase-buffer)
713 (insert cmd) 726 (insert cmd)
714 (goto-char (point-min)) 727 (goto-char (point-min))
@@ -726,8 +739,8 @@ A token has a type, \(command, address, end-mark\), and a value."
726 (message "%s" ret)) 739 (message "%s" ret))
727 ret)) 740 ret))
728 741
742;; Get a file name and set ex-variant, `ex-append' and `ex-offset' if found
729(defun vip-get-ex-file () 743(defun vip-get-ex-file ()
730 "Get a file name and set ex-variant, `ex-append' and `ex-offset' if found."
731 (let (prompt) 744 (let (prompt)
732 (setq ex-file nil 745 (setq ex-file nil
733 ex-variant nil 746 ex-variant nil
@@ -850,8 +863,8 @@ A token has a type, \(command, address, end-mark\), and a value."
850 (setq vip-last-ex-prompt (concat vip-last-ex-prompt " !"))))) 863 (setq vip-last-ex-prompt (concat vip-last-ex-prompt " !")))))
851 (substring str (or beg 0) end))) 864 (substring str (or beg 0) end)))
852 865
866;; Execute ex command using the value of addresses
853(defun vip-execute-ex-command () 867(defun vip-execute-ex-command ()
854 "Execute ex command using the value of addresses."
855 (vip-deactivate-mark) 868 (vip-deactivate-mark)
856 (cond ((string= ex-token "args") (ex-args)) 869 (cond ((string= ex-token "args") (ex-args))
857 ((string= ex-token "copy") (ex-copy nil)) 870 ((string= ex-token "copy") (ex-copy nil))
@@ -921,7 +934,7 @@ A token has a type, \(command, address, end-mark\), and a value."
921 (string= ex-token "unabbreviate")) 934 (string= ex-token "unabbreviate"))
922 (error 935 (error
923 (format 936 (format
924 "`%s': Vi's abbrevs are obsolete. Use more powerful Emacs' abbrevs" 937 "`%s': Vi-style abbrevs are obsolete. Use the more powerful Emacs abbrevs"
925 ex-token))) 938 ex-token)))
926 ((or (string= ex-token "list") 939 ((or (string= ex-token "list")
927 (string= ex-token "print") 940 (string= ex-token "print")
@@ -970,15 +983,15 @@ A token has a type, \(command, address, end-mark\), and a value."
970 (princ "\n\nPress any key to continue...\n\n")) 983 (princ "\n\nPress any key to continue...\n\n"))
971 (vip-read-event)))))) 984 (vip-read-event))))))
972 985
986;; Ex cd command. Default directory of this buffer changes
973(defun ex-cd () 987(defun ex-cd ()
974 "Ex cd command. Default directory of this buffer changes."
975 (vip-get-ex-file) 988 (vip-get-ex-file)
976 (if (string= ex-file "") 989 (if (string= ex-file "")
977 (setq ex-file "~")) 990 (setq ex-file "~"))
978 (setq default-directory (file-name-as-directory (expand-file-name ex-file)))) 991 (setq default-directory (file-name-as-directory (expand-file-name ex-file))))
979 992
993;; Ex copy and move command. DEL-FLAG means delete
980(defun ex-copy (del-flag) 994(defun ex-copy (del-flag)
981 "Ex copy and move command. DEL-FLAG means delete."
982 (vip-default-ex-addresses) 995 (vip-default-ex-addresses)
983 (let ((address (vip-get-ex-address)) 996 (let ((address (vip-get-ex-address))
984 (end (car ex-addresses)) (beg (car (cdr ex-addresses)))) 997 (end (car ex-addresses)) (beg (car (cdr ex-addresses))))
@@ -1008,8 +1021,8 @@ A token has a type, \(command, address, end-mark\), and a value."
1008 (forward-line 1)) 1021 (forward-line 1))
1009 (insert (current-kill 0)))) 1022 (insert (current-kill 0))))
1010 1023
1024;; Ex delete command
1011(defun ex-delete () 1025(defun ex-delete ()
1012 "Ex delete command."
1013 (vip-default-ex-addresses) 1026 (vip-default-ex-addresses)
1014 (vip-get-ex-buffer) 1027 (vip-get-ex-buffer)
1015 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) 1028 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
@@ -1045,12 +1058,12 @@ A token has a type, \(command, address, end-mark\), and a value."
1045 1058
1046 1059
1047 1060
1061;; Ex edit command
1062;; In Viper, `e' and `e!' behave identically. In both cases, the user is
1063;; asked if current buffer should really be discarded.
1064;; This command can take multiple file names. It replaces the current buffer
1065;; with the first file in its argument list
1048(defun ex-edit (&optional file) 1066(defun ex-edit (&optional file)
1049 "Ex edit command.
1050In Viper, `e' and `e!' behave identically. In both cases, the user is
1051asked if current buffer should really be discarded.
1052This command can take multiple file names. It replaces the current buffer
1053with the first file in its argument list."
1054 (if (not file) 1067 (if (not file)
1055 (vip-get-ex-file)) 1068 (vip-get-ex-file))
1056 (cond ((and (string= ex-file "") buffer-file-name) 1069 (cond ((and (string= ex-file "") buffer-file-name)
@@ -1100,11 +1113,11 @@ with the first file in its argument list."
1100;; splits the string FILESPEC into substrings separated by newlines `\012' 1113;; splits the string FILESPEC into substrings separated by newlines `\012'
1101;; each line assumed to be a file name. find-file's each file thus obtained. 1114;; each line assumed to be a file name. find-file's each file thus obtained.
1102(defun ex-find-file (filespec) 1115(defun ex-find-file (filespec)
1103 (let (s f filebuf status) 1116 (let (f filebuf tmp-buf status)
1104 (if (string-match "[^a-zA-Z0-9_.-/]" filespec) 1117 (if (string-match "[^a-zA-Z0-9_.-/]" filespec)
1105 (progn 1118 (progn
1106 (save-excursion 1119 (save-excursion
1107 (set-buffer (get-buffer-create " *ex-tmp*")) 1120 (set-buffer (setq tmp-buf (get-buffer-create vip-ex-tmp-buf-name)))
1108 (erase-buffer) 1121 (erase-buffer)
1109 (setq status 1122 (setq status
1110 (call-process ex-find-file-shell nil t nil 1123 (call-process ex-find-file-shell nil t nil
@@ -1112,7 +1125,7 @@ with the first file in its argument list."
1112 "-c" 1125 "-c"
1113 (format "echo %s | tr ' ' '\\012'" filespec))) 1126 (format "echo %s | tr ' ' '\\012'" filespec)))
1114 (goto-char (point-min)) 1127 (goto-char (point-min))
1115 ;; Give an error, if no match. 1128 ;; Issue an error, if no match.
1116 (if (> status 0) 1129 (if (> status 0)
1117 (save-excursion 1130 (save-excursion
1118 (skip-chars-forward " \t\n\j") 1131 (skip-chars-forward " \t\n\j")
@@ -1122,19 +1135,20 @@ with the first file in its argument list."
1122 filespec 1135 filespec
1123 (buffer-substring (point) (vip-line-pos 'end))) 1136 (buffer-substring (point) (vip-line-pos 'end)))
1124 )) 1137 ))
1138 (reverse-region (point-min) (point-max))
1139 (goto-char (point-min))
1125 (while (not (eobp)) 1140 (while (not (eobp))
1126 (setq s (point)) 1141 (setq f (buffer-substring (point) (vip-line-pos 'end)))
1127 (end-of-line) 1142 (setq filebuf (find-file f))
1128 (setq f (buffer-substring s (point))) 1143 (set-buffer tmp-buf) ; otherwise it'll be in f.
1129 (setq filebuf (find-file-noselect f))
1130 (forward-to-indentation 1)) 1144 (forward-to-indentation 1))
1131 )) 1145 ))
1132 (setq filebuf (find-file-noselect (setq f filespec)))) 1146 (setq filebuf (find-file-noselect (setq f filespec))))
1133 (switch-to-buffer filebuf) 1147 (switch-to-buffer filebuf)
1134 )) 1148 ))
1135 1149
1150;; Ex global command
1136(defun ex-global (variant) 1151(defun ex-global (variant)
1137 "Ex global command."
1138 (let ((gcommand ex-token)) 1152 (let ((gcommand ex-token))
1139 (if (or ex-g-flag ex-g-variant) 1153 (if (or ex-g-flag ex-g-variant)
1140 (error "`%s' within `global' is not allowed" gcommand) 1154 (error "`%s' within `global' is not allowed" gcommand)
@@ -1191,16 +1205,16 @@ with the first file in its argument list."
1191 (setq mark-count (1- mark-count)) 1205 (setq mark-count (1- mark-count))
1192 (setq marks (cdr marks))))) 1206 (setq marks (cdr marks)))))
1193 1207
1208;; Ex goto command
1194(defun ex-goto () 1209(defun ex-goto ()
1195 "Ex goto command."
1196 (if (null ex-addresses) 1210 (if (null ex-addresses)
1197 (setq ex-addresses (cons (point) nil))) 1211 (setq ex-addresses (cons (point) nil)))
1198 (push-mark (point) t) 1212 (push-mark (point) t)
1199 (goto-char (car ex-addresses)) 1213 (goto-char (car ex-addresses))
1200 (beginning-of-line)) 1214 (beginning-of-line))
1201 1215
1216;; Ex line commands. COM is join, shift-right or shift-left
1202(defun ex-line (com) 1217(defun ex-line (com)
1203 "Ex line commands. COM is join, shift-right or shift-left."
1204 (vip-default-ex-addresses) 1218 (vip-default-ex-addresses)
1205 (vip-get-ex-count) 1219 (vip-get-ex-count)
1206 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point) 1220 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point)
@@ -1247,8 +1261,8 @@ with the first file in its argument list."
1247 (vip-forward-char-carefully)))) 1261 (vip-forward-char-carefully))))
1248 1262
1249 1263
1264;; Ex mark command
1250(defun ex-mark () 1265(defun ex-mark ()
1251 "Ex mark command."
1252 (let (char) 1266 (let (char)
1253 (if (null ex-addresses) 1267 (if (null ex-addresses)
1254 (setq ex-addresses 1268 (setq ex-addresses
@@ -1349,10 +1363,10 @@ with the first file in its argument list."
1349 (setq wind (get-lru-window (if vip-xemacs-p nil 'visible))) 1363 (setq wind (get-lru-window (if vip-xemacs-p nil 'visible)))
1350 (set-window-buffer wind buf)) 1364 (set-window-buffer wind buf))
1351 1365
1352 (if window-system 1366 (if (vip-window-display-p)
1353 (progn 1367 (progn
1354 (vip-raise-frame (vip-window-frame wind)) 1368 (raise-frame (window-frame wind))
1355 (if (equal (vip-window-frame wind) (vip-window-frame old-win)) 1369 (if (equal (window-frame wind) (window-frame old-win))
1356 (save-window-excursion (select-window wind) (sit-for 1)) 1370 (save-window-excursion (select-window wind) (sit-for 1))
1357 (select-window wind))) 1371 (select-window wind)))
1358 (save-window-excursion (select-window wind) (sit-for 1))) 1372 (save-window-excursion (select-window wind) (sit-for 1)))
@@ -1365,32 +1379,36 @@ with the first file in its argument list."
1365 ))) 1379 )))
1366 1380
1367 1381
1382;; Force auto save
1368(defun ex-preserve () 1383(defun ex-preserve ()
1369 "Force auto save."
1370 (message "Autosaving all buffers that need to be saved...") 1384 (message "Autosaving all buffers that need to be saved...")
1371 (do-auto-save t)) 1385 (do-auto-save t))
1372 1386
1387;; Ex put
1373(defun ex-put () 1388(defun ex-put ()
1374 "Ex put."
1375 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))) 1389 (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
1376 (vip-get-ex-buffer) 1390 (vip-get-ex-buffer)
1377 (setq vip-use-register ex-buffer) 1391 (setq vip-use-register ex-buffer)
1378 (goto-char point) 1392 (goto-char point)
1379 (if (bobp) (vip-Put-back 1) (vip-put-back 1)))) 1393 (if (bobp) (vip-Put-back 1) (vip-put-back 1))))
1380 1394
1395;; Ex print working directory
1381(defun ex-pwd () 1396(defun ex-pwd ()
1382 "Ex print working directory."
1383 (message default-directory)) 1397 (message default-directory))
1384 1398
1399;; Ex quit command
1385(defun ex-quit () 1400(defun ex-quit ()
1386 "Ex quit command." 1401 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
1402 (save-excursion
1403 (set-buffer vip-ex-work-buf)
1404 (if (looking-at "!") (forward-char 1)))
1387 (if (< vip-expert-level 3) 1405 (if (< vip-expert-level 3)
1388 (save-buffers-kill-emacs) 1406 (save-buffers-kill-emacs)
1389 (kill-buffer (current-buffer)))) 1407 (kill-buffer (current-buffer))))
1390 1408
1391 1409
1410;; Ex read command
1392(defun ex-read () 1411(defun ex-read ()
1393 "Ex read command."
1394 (vip-get-ex-file) 1412 (vip-get-ex-file)
1395 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))) 1413 (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
1396 (goto-char point) 1414 (goto-char point)
@@ -1412,8 +1430,8 @@ with the first file in its argument list."
1412 (cons (mapconcat 'identity args " ") (cdr vip-ex-history)))) 1430 (cons (mapconcat 'identity args " ") (cdr vip-ex-history))))
1413 1431
1414 1432
1433;; Ex recover from emacs \#file\#
1415(defun ex-recover () 1434(defun ex-recover ()
1416 "Ex recover from emacs \#file\#."
1417 (vip-get-ex-file) 1435 (vip-get-ex-file)
1418 (if (or ex-append ex-offset) 1436 (if (or ex-append ex-offset)
1419 (error "`recover': %s" vip-SpuriousText)) 1437 (error "`recover': %s" vip-SpuriousText))
@@ -1429,8 +1447,8 @@ with the first file in its argument list."
1429 (error "No write since last change \(:rec! overrides\)")) 1447 (error "No write since last change \(:rec! overrides\)"))
1430 (recover-file ex-file)) 1448 (recover-file ex-file))
1431 1449
1450;; Tell that `rewind' is obsolete and to use `:next count' instead
1432(defun ex-rewind () 1451(defun ex-rewind ()
1433 "Tell that `rewind' is obsolete and that one should use `:next count'"
1434 (message 1452 (message
1435 "Use `:n <count>' instead. Counts are obtained from the `:args' command")) 1453 "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
1436 1454
@@ -1617,12 +1635,12 @@ with the first file in its argument list."
1617 (buffer-substring beg end)))) 1635 (buffer-substring beg end))))
1618 1636
1619 1637
1638;; Ex shell command
1620(defun ex-shell () 1639(defun ex-shell ()
1621 "Ex shell command."
1622 (shell)) 1640 (shell))
1623 1641
1642;; Viper help. Invokes Info
1624(defun ex-help () 1643(defun ex-help ()
1625 "Viper help. Invokes Info."
1626 (condition-case nil 1644 (condition-case nil
1627 (progn 1645 (progn
1628 (pop-to-buffer (get-buffer-create "*info*")) 1646 (pop-to-buffer (get-buffer-create "*info*"))
@@ -1630,27 +1648,24 @@ with the first file in its argument list."
1630 (message "Type `i' to search for a specific topic")) 1648 (message "Type `i' to search for a specific topic"))
1631 (error (beep 1) 1649 (error (beep 1)
1632 (with-output-to-temp-buffer " *vip-info*" 1650 (with-output-to-temp-buffer " *vip-info*"
1633 (princ "The Info file for Viper does not seem to be installed. 1651 (princ (format "
1652The Info file for Viper does not seem to be installed.
1634 1653
1635This file is part of the distribution of Viper. If you do not 1654This file is part of the standard distribution of %sEmacs.
1636have the full distribution, please obtain it from the `anonymous' 1655Please contact your system administrator. "
1637FTP account at `archive.cis.ohio-state.edu': 1656 (if vip-xemacs-p "X" "")
1638 1657 ))))))
1639 /pub/gnu/emacs/elisp-archive/modes/viper.shar
1640
1641The Info files for Viper should be installed as <name>, <name>-1, etc.,
1642where <name> is the value of `vip-info-file-name'.")))))
1643 1658
1659;; Ex source command. Loads the file specified as argument or `~/.vip'
1644(defun ex-source () 1660(defun ex-source ()
1645 "Ex source command. Loads the file specified as argument or `~/.vip'."
1646 (vip-get-ex-file) 1661 (vip-get-ex-file)
1647 (if (string= ex-file "") 1662 (if (string= ex-file "")
1648 (load vip-custom-file-name) 1663 (load vip-custom-file-name)
1649 (load ex-file))) 1664 (load ex-file)))
1650 1665
1666;; Ex substitute command
1667;; If REPEAT use previous regexp which is ex-reg-exp or vip-s-string
1651(defun ex-substitute (&optional repeat r-flag) 1668(defun ex-substitute (&optional repeat r-flag)
1652 "Ex substitute command.
1653If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1654 (let ((opt-g nil) 1669 (let ((opt-g nil)
1655 (opt-c nil) 1670 (opt-c nil)
1656 (matched-pos nil) 1671 (matched-pos nil)
@@ -1728,8 +1743,8 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1728 (beginning-of-line) 1743 (beginning-of-line)
1729 (if opt-c (message "done")))) 1744 (if opt-c (message "done"))))
1730 1745
1746;; Ex tag command
1731(defun ex-tag () 1747(defun ex-tag ()
1732 "Ex tag command."
1733 (let (tag) 1748 (let (tag)
1734 (save-window-excursion 1749 (save-window-excursion
1735 (set-buffer vip-ex-work-buf) 1750 (set-buffer vip-ex-work-buf)
@@ -1749,8 +1764,8 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1749 (vip-change-state-to-vi) 1764 (vip-change-state-to-vi)
1750 (vip-message-conditions conds))))) 1765 (vip-message-conditions conds)))))
1751 1766
1767;; Ex write command
1752(defun ex-write (q-flag) 1768(defun ex-write (q-flag)
1753 "Ex write command."
1754 (vip-default-ex-addresses t) 1769 (vip-default-ex-addresses t)
1755 (vip-get-ex-file) 1770 (vip-get-ex-file)
1756 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) 1771 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))
@@ -1826,8 +1841,8 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1826 (count-lines beg (min (1+ end) (point-max))) 1841 (count-lines beg (min (1+ end) (point-max)))
1827 (- end beg))) 1842 (- end beg)))
1828 1843
1844;; Ex yank command
1829(defun ex-yank () 1845(defun ex-yank ()
1830 "Ex yank command."
1831 (vip-default-ex-addresses) 1846 (vip-default-ex-addresses)
1832 (vip-get-ex-buffer) 1847 (vip-get-ex-buffer)
1833 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses)))) 1848 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
@@ -1853,8 +1868,8 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1853 (t (error vip-InvalidRegister ex-buffer)))) 1868 (t (error vip-InvalidRegister ex-buffer))))
1854 (copy-region-as-kill (point) (mark t))))) 1869 (copy-region-as-kill (point) (mark t)))))
1855 1870
1871;; Execute shell command
1856(defun ex-command () 1872(defun ex-command ()
1857 "Execute shell command."
1858 (let (command) 1873 (let (command)
1859 (save-window-excursion 1874 (save-window-excursion
1860 (set-buffer vip-ex-work-buf) 1875 (set-buffer vip-ex-work-buf)
@@ -1878,15 +1893,15 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1878 (shell-command-on-region (point) (mark t) command t)) 1893 (shell-command-on-region (point) (mark t) command t))
1879 (goto-char beg))))) 1894 (goto-char beg)))))
1880 1895
1896;; Print line number
1881(defun ex-line-no () 1897(defun ex-line-no ()
1882 "Print line number."
1883 (message "%d" 1898 (message "%d"
1884 (1+ (count-lines 1899 (1+ (count-lines
1885 (point-min) 1900 (point-min)
1886 (if (null ex-addresses) (point-max) (car ex-addresses)))))) 1901 (if (null ex-addresses) (point-max) (car ex-addresses))))))
1887 1902
1903;; Give information on the file visited by the current buffer
1888(defun vip-info-on-file () 1904(defun vip-info-on-file ()
1889 "Give information on the file visited by the current buffer."
1890 (interactive) 1905 (interactive)
1891 (let (file info) 1906 (let (file info)
1892 (setq file (if (buffer-file-name) 1907 (setq file (if (buffer-file-name)