aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-02-22 00:38:59 +0000
committerKarl Heuer1995-02-22 00:38:59 +0000
commitfad2477b8090d98f8df9223d2ac38c7fee3f1c2c (patch)
treef686c12a3fff0e517c7b8091f9003b9d26f64434
parent15d90a400bd975087a1a76c0284e657f86f26537 (diff)
downloademacs-fad2477b8090d98f8df9223d2ac38c7fee3f1c2c.tar.gz
emacs-fad2477b8090d98f8df9223d2ac38c7fee3f1c2c.zip
New version from the author.
-rw-r--r--lisp/emulation/viper-ex.el102
1 files changed, 64 insertions, 38 deletions
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index 3cd5c9f3986..81f73c65b23 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -25,7 +25,7 @@
25(defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) 25(defconst vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))
26 26
27 27
28;;; Completion in :set command 28;;; Variable completion in :set command
29 29
30;; The list of Ex commands. Used for completing command names. 30;; The list of Ex commands. Used for completing command names.
31(defconst ex-token-alist 31(defconst ex-token-alist
@@ -183,8 +183,8 @@ reversed.")
183 ((looking-at "k[a-z][^a-z]") 183 ((looking-at "k[a-z][^a-z]")
184 (setq ex-token "kmark") 184 (setq ex-token "kmark")
185 (forward-char 1) 185 (forward-char 1)
186 (exchange-point-and-mark)) ;; this is canceled out by another 186 (exchange-point-and-mark)) ; this is canceled out by another
187 ;; exchange-point-and-mark at the end 187 ; exchange-point-and-mark at the end
188 ((looking-at "k") (vip-check-sub "kmark")) 188 ((looking-at "k") (vip-check-sub "kmark"))
189 ((looking-at "n") (if (looking-at "nu") 189 ((looking-at "n") (if (looking-at "nu")
190 (vip-check-sub "number") 190 (vip-check-sub "number")
@@ -399,7 +399,7 @@ A token has a type, \(command, address, end-mark\), and a value."
399 (setq completion-result 399 (setq completion-result
400 (try-completion string-to-complete ex-token-alist)) 400 (try-completion string-to-complete ex-token-alist))
401 401
402 (cond ((eq completion-result t) ;; exact match--do nothing 402 (cond ((eq completion-result t) ; exact match--do nothing
403 (vip-tmp-insert-at-eob " (Sole completion)")) 403 (vip-tmp-insert-at-eob " (Sole completion)"))
404 ((eq completion-result nil) 404 ((eq completion-result nil)
405 (vip-tmp-insert-at-eob " (No match)")) 405 (vip-tmp-insert-at-eob " (No match)"))
@@ -609,8 +609,8 @@ A token has a type, \(command, address, end-mark\), and a value."
609 (setq address (point-marker))))) 609 (setq address (point-marker)))))
610 ((eq ex-token-type 'end) 610 ((eq ex-token-type 'end)
611 (setq address (point-max-marker))) 611 (setq address (point-max-marker)))
612 ((eq ex-token-type 'plus) t);; do nothing 612 ((eq ex-token-type 'plus) t) ; do nothing
613 ((eq ex-token-type 'minus) t);; do nothing 613 ((eq ex-token-type 'minus) t) ; do nothing
614 ((eq ex-token-type 'search-forward) 614 ((eq ex-token-type 'search-forward)
615 (save-excursion 615 (save-excursion
616 (ex-search-address t) 616 (ex-search-address t)
@@ -701,13 +701,14 @@ A token has a type, \(command, address, end-mark\), and a value."
701 (save-excursion 701 (save-excursion
702 (set-buffer buf) 702 (set-buffer buf)
703 (setq cf buffer-file-name) 703 (setq cf buffer-file-name)
704 (setq pf (ex-next nil t))) ;; this finds alternative file name 704 (setq pf (ex-next nil t))) ; this finds alternative file name
705 (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd)) 705 (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
706 (error "No current file to substitute for `\%'")) 706 (error "No current file to substitute for `\%'"))
707 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd)) 707 (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
708 (error "No alternate file to substitute for `#'")) 708 (error "No alternate file to substitute for `#'"))
709 (save-excursion 709 (save-excursion
710 (set-buffer (get-buffer-create " ex-tmp")) 710 (set-buffer (get-buffer-create " *ex-tmp*"))
711 (erase-buffer)
711 (insert cmd) 712 (insert cmd)
712 (goto-char (point-min)) 713 (goto-char (point-min))
713 (while (re-search-forward "%\\|#" nil t) 714 (while (re-search-forward "%\\|#" nil t)
@@ -721,7 +722,6 @@ A token has a type, \(command, address, end-mark\), and a value."
721 (replace-match pf))))) 722 (replace-match pf)))))
722 (end-of-line) 723 (end-of-line)
723 (setq ret (buffer-substring (point-min) (point))) 724 (setq ret (buffer-substring (point-min) (point)))
724 (kill-buffer (current-buffer))
725 (message "%s" ret)) 725 (message "%s" ret))
726 ret)) 726 ret))
727 727
@@ -763,7 +763,7 @@ A token has a type, \(command, address, end-mark\), and a value."
763 (skip-chars-forward " \t"))) 763 (skip-chars-forward " \t")))
764 ;; this takes care of :r, :w, etc., when they get file names 764 ;; this takes care of :r, :w, etc., when they get file names
765 ;; from the history list 765 ;; from the history list
766 (if (member ex-token '("read" "write" "edit" "visual")) 766 (if (member ex-token '("read" "write" "edit" "visual" "next"))
767 (progn 767 (progn
768 (setq ex-file (buffer-substring (point) (1- (point-max)))) 768 (setq ex-file (buffer-substring (point) (1- (point-max))))
769 (setq ex-file 769 (setq ex-file
@@ -838,8 +838,8 @@ A token has a type, \(command, address, end-mark\), and a value."
838 (ex-cmd-accepts-multiple-files-p ex-token))) 838 (ex-cmd-accepts-multiple-files-p ex-token)))
839 ) 839 )
840 840
841 (setq beg (string-match "[^ \t]" str) ;; delete leading blanks 841 (setq beg (string-match "[^ \t]" str) ; delete leading blanks
842 end (string-match "[ \t]*$" str)) ;; delete trailing blanks 842 end (string-match "[ \t]*$" str)) ; delete trailing blanks
843 (if (member ex-token '("read" "write")) 843 (if (member ex-token '("read" "write"))
844 (if (string-match "[\t ]*!" str) 844 (if (string-match "[\t ]*!" str)
845 ;; this is actually a shell command 845 ;; this is actually a shell command
@@ -967,7 +967,7 @@ A token has a type, \(command, address, end-mark\), and a value."
967 (princ "\n=============\n") 967 (princ "\n=============\n")
968 (princ "\nThe numbers can be given as counts to :next. ") 968 (princ "\nThe numbers can be given as counts to :next. ")
969 (princ "\n\nPress any key to continue...\n\n")) 969 (princ "\n\nPress any key to continue...\n\n"))
970 (vip-read-char-exclusive)))))) 970 (vip-read-event))))))
971 971
972(defun ex-cd () 972(defun ex-cd ()
973 "Ex cd command. Default directory of this buffer changes." 973 "Ex cd command. Default directory of this buffer changes."
@@ -1099,23 +1099,35 @@ with the first file in its argument list."
1099;; splits the string FILESPEC into substrings separated by newlines `\012' 1099;; splits the string FILESPEC into substrings separated by newlines `\012'
1100;; each line assumed to be a file name. find-file's each file thus obtained. 1100;; each line assumed to be a file name. find-file's each file thus obtained.
1101(defun ex-find-file (filespec) 1101(defun ex-find-file (filespec)
1102 (let (s f filebuf) 1102 (let (s f filebuf status)
1103 (if (string-match "[^a-zA-Z0-9_.-/]" filespec) 1103 (if (string-match "[^a-zA-Z0-9_.-/]" filespec)
1104 (progn 1104 (progn
1105 (save-excursion 1105 (save-excursion
1106 (set-buffer (get-buffer-create " ex-tmp")) 1106 (set-buffer (get-buffer-create " *ex-tmp*"))
1107 (call-process ex-find-file-shell nil t nil 1107 (erase-buffer)
1108 ex-find-file-shell-options 1108 (setq status
1109 "-c" 1109 (call-process ex-find-file-shell nil t nil
1110 (format "echo %s | tr ' ' '\\012'" filespec)) 1110 ex-find-file-shell-options
1111 "-c"
1112 (format "echo %s | tr ' ' '\\012'" filespec)))
1111 (goto-char (point-min)) 1113 (goto-char (point-min))
1114 ;; Give an error, if no match.
1115 (if (> status 0)
1116 (save-excursion
1117 (skip-chars-forward " \t\n\j")
1118 (if (looking-at "echo:")
1119 (vip-forward-word 1))
1120 (error "%S%s"
1121 filespec
1122 (buffer-substring (point) (vip-line-pos 'end)))
1123 ))
1112 (while (not (eobp)) 1124 (while (not (eobp))
1113 (setq s (point)) 1125 (setq s (point))
1114 (end-of-line) 1126 (end-of-line)
1115 (setq f (buffer-substring s (point))) 1127 (setq f (buffer-substring s (point)))
1116 (setq filebuf (find-file-noselect f)) 1128 (setq filebuf (find-file-noselect f))
1117 (forward-to-indentation 1)) 1129 (forward-to-indentation 1))
1118 (kill-buffer (current-buffer)))) 1130 ))
1119 (setq filebuf (find-file-noselect (setq f filespec)))) 1131 (setq filebuf (find-file-noselect (setq f filespec))))
1120 (switch-to-buffer filebuf) 1132 (switch-to-buffer filebuf)
1121 )) 1133 ))
@@ -1265,9 +1277,8 @@ with the first file in its argument list."
1265 (progn 1277 (progn
1266 (vip-get-ex-file) 1278 (vip-get-ex-file)
1267 (if (or (char-or-string-p ex-offset) 1279 (if (or (char-or-string-p ex-offset)
1268 (not (string= "" ex-file))) 1280 (and (not (string= "" ex-file))
1269 ;(and (not (string= "" ex-file)) 1281 (not (string-match "^[0-9]+$" ex-file))))
1270 ; (not (string-match "[0-9]+" ex-file))))
1271 (progn 1282 (progn
1272 (ex-edit t) 1283 (ex-edit t)
1273 (throw 'ex-edit nil)) 1284 (throw 'ex-edit nil))
@@ -1289,7 +1300,9 @@ with the first file in its argument list."
1289 (get-lru-window) (selected-window))) 1300 (get-lru-window) (selected-window)))
1290 (b (window-buffer w))) 1301 (b (window-buffer w)))
1291 (set-window-buffer w (get-file-buffer (car l))) 1302 (set-window-buffer w (get-file-buffer (car l)))
1292 (bury-buffer b)) 1303 (bury-buffer b)
1304 ;; this puts "next <count>" in the ex-command history
1305 (ex-fixup-history vip-last-ex-prompt ex-file))
1293 (error "Not that many undisplayed files"))))))) 1306 (error "Not that many undisplayed files")))))))
1294 1307
1295 1308
@@ -1495,7 +1508,7 @@ with the first file in its argument list."
1495 ((member var '("nows" "nowrapscan")) 1508 ((member var '("nows" "nowrapscan"))
1496 (setq var "vip-search-wrap-around-t" 1509 (setq var "vip-search-wrap-around-t"
1497 val "nil"))) 1510 val "nil")))
1498 (if (eq val 0) ;; value must be set by the user 1511 (if (eq val 0) ; value must be set by the user
1499 (let ((cursor-in-echo-area t)) 1512 (let ((cursor-in-echo-area t))
1500 (message (format ":set %s = <Value>" var)) 1513 (message (format ":set %s = <Value>" var))
1501 ;; if there are unread events, don't wait 1514 ;; if there are unread events, don't wait
@@ -1644,9 +1657,12 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1644 delim pat repl) 1657 delim pat repl)
1645 (if repeat (setq ex-token nil) (setq delim (vip-get-ex-pat))) 1658 (if repeat (setq ex-token nil) (setq delim (vip-get-ex-pat)))
1646 (if (null ex-token) 1659 (if (null ex-token)
1647 (setq pat (if r-flag vip-s-string ex-reg-exp) 1660 (progn
1648 repl ex-repl 1661 (setq pat (if r-flag vip-s-string ex-reg-exp))
1649 delim (string-to-char pat)) 1662 (or (stringp pat)
1663 (error "No previous pattern to use in substitution"))
1664 (setq repl ex-repl
1665 delim (string-to-char pat)))
1650 (setq pat (if (string= ex-token "") vip-s-string ex-token)) 1666 (setq pat (if (string= ex-token "") vip-s-string ex-token))
1651 (setq vip-s-string pat 1667 (setq vip-s-string pat
1652 ex-reg-exp pat) 1668 ex-reg-exp pat)
@@ -1871,16 +1887,26 @@ If REPEAT use previous regexp which is ex-reg-exp or vip-s-string"
1871(defun vip-info-on-file () 1887(defun vip-info-on-file ()
1872 "Give information on the file visited by the current buffer." 1888 "Give information on the file visited by the current buffer."
1873 (interactive) 1889 (interactive)
1874 (message "%s: pos=%d(%d) line=%d(%d) col=%d %s" 1890 (let (file info)
1875 (if (buffer-file-name) 1891 (setq file (if (buffer-file-name)
1876 (abbreviate-file-name (buffer-file-name)) 1892 (concat (abbreviate-file-name (buffer-file-name)) ":")
1877 "[No visited file]") 1893 (concat (buffer-name) " [Not visiting any file]:"))
1878 (point) (1- (point-max)) 1894 info (format "line=%d/%d pos=%d/%d col=%d %s"
1879 (count-lines (point-min) (vip-line-pos 'end)) 1895 (count-lines (point-min) (vip-line-pos 'end))
1880 (count-lines (point-min) (point-max)) 1896 (count-lines (point-min) (point-max))
1881 (1+ (current-column)) 1897 (point) (1- (point-max))
1882 (if (buffer-modified-p) "[Modified]" "[Unchanged]") 1898 (1+ (current-column))
1883 )) 1899 (if (buffer-modified-p) "[Modified]" "[Unchanged]")))
1900 (if (< (+ 1 (length info) (length file))
1901 (window-width (minibuffer-window)))
1902 (message (concat file " " info))
1903 (save-window-excursion
1904 (with-output-to-temp-buffer " *vip-info*"
1905 (princ (concat "\n"
1906 file "\n\n\t" info
1907 "\n\n\nPress any key to continue...\n\n")))
1908 (vip-read-event)))
1909 ))
1884 1910
1885 1911
1886(provide 'viper-ex) 1912(provide 'viper-ex)