Mercurial > emacs
comparison lisp/emulation/viper-ex.el @ 10793:b3ff28388976
New version from the author.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 22 Feb 1995 00:38:59 +0000 |
parents | af7c0bb1059f |
children | c1372b3306b7 |
comparison
equal
deleted
inserted
replaced
10792:70977216c215 | 10793:b3ff28388976 |
---|---|
23 | 23 |
24 (defconst vip-ex-work-buf-name " *ex-working-space*") | 24 (defconst vip-ex-work-buf-name " *ex-working-space*") |
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 |
32 '(("!") ("=") (">") ("&") ("~") | 32 '(("!") ("=") (">") ("&") ("~") |
33 ("yank") ("xit") ("WWrite") ("Write") ("write") ("wq") ("visual") | 33 ("yank") ("xit") ("WWrite") ("Write") ("write") ("wq") ("visual") |
181 ((looking-at "mar") (vip-check-sub "mark")) | 181 ((looking-at "mar") (vip-check-sub "mark")) |
182 (t (vip-check-sub "move")))) | 182 (t (vip-check-sub "move")))) |
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") |
191 (vip-check-sub "next"))) | 191 (vip-check-sub "next"))) |
192 ((looking-at "N") (vip-check-sub "Next")) | 192 ((looking-at "N") (vip-check-sub "Next")) |
397 ;; Preceding chars may be part of a command name | 397 ;; Preceding chars may be part of a command name |
398 (setq string-to-complete (buffer-substring save-pos (point))) | 398 (setq string-to-complete (buffer-substring save-pos (point))) |
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)")) |
406 (t ;; partial completion | 406 (t ;; partial completion |
407 (goto-char save-pos) | 407 (goto-char save-pos) |
607 (if (= ex-token 0) (setq address 0) | 607 (if (= ex-token 0) (setq address 0) |
608 (forward-line (1- ex-token)) | 608 (forward-line (1- ex-token)) |
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) |
617 (setq address (point-marker)))) | 617 (setq address (point-marker)))) |
618 ((eq ex-token-type 'search-backward) | 618 ((eq ex-token-type 'search-backward) |
699 "Expand \% and \# in ex command." | 699 "Expand \% and \# in ex command." |
700 (let (cf pf ret) | 700 (let (cf pf ret) |
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) |
714 (let ((data (match-data)) | 715 (let ((data (match-data)) |
715 (char (buffer-substring (match-beginning 0) (match-end 0)))) | 716 (char (buffer-substring (match-beginning 0) (match-end 0)))) |
719 (if (string= char "%") | 720 (if (string= char "%") |
720 (replace-match cf) | 721 (replace-match cf) |
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 |
728 (defun vip-get-ex-file () | 728 (defun vip-get-ex-file () |
729 "Get a file name and set ex-variant, `ex-append' and `ex-offset' if found." | 729 "Get a file name and set ex-variant, `ex-append' and `ex-offset' if found." |
761 (setq ex-offset (buffer-substring (point) (mark t))) | 761 (setq ex-offset (buffer-substring (point) (mark t))) |
762 (forward-char 1) | 762 (forward-char 1) |
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 |
770 ;; For :e, match multiple non-white strings separated | 770 ;; For :e, match multiple non-white strings separated |
771 ;; by white. For others, find the first non-white string | 771 ;; by white. For others, find the first non-white string |
836 ;; bound to " " in ex-read-filename-map. | 836 ;; bound to " " in ex-read-filename-map. |
837 (setq cont (and vip-keep-reading-filename | 837 (setq cont (and vip-keep-reading-filename |
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 |
846 (progn | 846 (progn |
847 (setq ex-cmdfile t) | 847 (setq ex-cmdfile t) |
965 (princ "\n=============\n") | 965 (princ "\n=============\n") |
966 (princ args) | 966 (princ args) |
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." |
974 (vip-get-ex-file) | 974 (vip-get-ex-file) |
975 (if (string= ex-file "") | 975 (if (string= ex-file "") |
1097 (ex-fixup-history vip-last-ex-prompt ex-file)) | 1097 (ex-fixup-history vip-last-ex-prompt ex-file)) |
1098 | 1098 |
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 )) |
1122 | 1134 |
1123 (defun ex-global (variant) | 1135 (defun ex-global (variant) |
1263 (let (count l) | 1275 (let (count l) |
1264 (if (not find-alt-file) | 1276 (if (not find-alt-file) |
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)) |
1274 (setq count (string-to-int ex-file)) | 1285 (setq count (string-to-int ex-file)) |
1275 (if (= count 0) (setq count 1)) | 1286 (if (= count 0) (setq count 1)) |
1287 (if (car l) | 1298 (if (car l) |
1288 (let* ((w (if cycle-other-window | 1299 (let* ((w (if cycle-other-window |
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 |
1296 (defun ex-next-related-buffer (direction &optional no-recursion) | 1309 (defun ex-next-related-buffer (direction &optional no-recursion) |
1297 | 1310 |
1493 (setq var "vip-search-wrap-around-t" | 1506 (setq var "vip-search-wrap-around-t" |
1494 val "t")) | 1507 val "t")) |
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 |
1502 (or (vip-set-unread-command-events "") (sit-for 2)) | 1515 (or (vip-set-unread-command-events "") (sit-for 2)) |
1503 (setq val (read-string (format ":set %s = " var))) | 1516 (setq val (read-string (format ":set %s = " var))) |
1642 (matched-pos nil) | 1655 (matched-pos nil) |
1643 (case-fold-search vip-case-fold-search) | 1656 (case-fold-search vip-case-fold-search) |
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) |
1653 (setq delim (vip-get-ex-pat)) | 1669 (setq delim (vip-get-ex-pat)) |
1654 (if (null ex-token) | 1670 (if (null ex-token) |
1869 (if (null ex-addresses) (point-max) (car ex-addresses)))))) | 1885 (if (null ex-addresses) (point-max) (car ex-addresses)))))) |
1870 | 1886 |
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) |
1887 | 1913 |
1888 ;;; viper-ex.el ends here | 1914 ;;; viper-ex.el ends here |