Mercurial > hg > xemacs-beta
comparison lisp/viper/viper-ex.el @ 12:bcdc7deadc19 r19-15b7
Import from CVS: tag r19-15b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:48:16 +0200 |
parents | 376386a54a3c |
children | 9ee227acff29 |
comparison
equal
deleted
inserted
replaced
11:91ffe8bd52e4 | 12:bcdc7deadc19 |
---|---|
283 | 283 |
284 ;; Get an ex-token which is either an address or a command. | 284 ;; Get an ex-token which is either an address or a command. |
285 ;; A token has a type, \(command, address, end-mark\), and a value | 285 ;; A token has a type, \(command, address, end-mark\), and a value |
286 (defun vip-get-ex-token () | 286 (defun vip-get-ex-token () |
287 (save-window-excursion | 287 (save-window-excursion |
288 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
288 (set-buffer vip-ex-work-buf) | 289 (set-buffer vip-ex-work-buf) |
289 (skip-chars-forward " \t|") | 290 (skip-chars-forward " \t|") |
290 (cond ((looking-at "#") | 291 (cond ((looking-at "#") |
291 (setq ex-token-type 'command) | 292 (setq ex-token-type 'command) |
292 (setq ex-token (char-to-string (following-char))) | 293 (setq ex-token (char-to-string (following-char))) |
418 "\\|" "![ \t]*[a-zA-Z].*" | 419 "\\|" "![ \t]*[a-zA-Z].*" |
419 "\\)" | 420 "\\)" |
420 "!*"))) | 421 "!*"))) |
421 | 422 |
422 (save-window-excursion ;; put cursor at the end of the Ex working buffer | 423 (save-window-excursion ;; put cursor at the end of the Ex working buffer |
424 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
423 (set-buffer vip-ex-work-buf) | 425 (set-buffer vip-ex-work-buf) |
424 (goto-char (point-max))) | 426 (goto-char (point-max))) |
425 (cond ((vip-looking-back quit-regex1) (exit-minibuffer)) | 427 (cond ((vip-looking-back quit-regex1) (exit-minibuffer)) |
426 ((vip-looking-back stay-regex) (insert " ")) | 428 ((vip-looking-back stay-regex) (insert " ")) |
427 ((vip-looking-back quit-regex2) (exit-minibuffer)) | 429 ((vip-looking-back quit-regex2) (exit-minibuffer)) |
495 'vip-ex-history | 497 'vip-ex-history |
496 (car vip-ex-history) | 498 (car vip-ex-history) |
497 map))) | 499 map))) |
498 (save-window-excursion | 500 (save-window-excursion |
499 ;; just a precaution | 501 ;; just a precaution |
500 (or (vip-buffer-live-p vip-ex-work-buf) | 502 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) |
501 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name))) | |
502 (set-buffer vip-ex-work-buf) | 503 (set-buffer vip-ex-work-buf) |
503 (delete-region (point-min) (point-max)) | 504 (delete-region (point-min) (point-max)) |
504 (insert com-str "\n") | 505 (insert com-str "\n") |
505 (goto-char (point-min))) | 506 (goto-char (point-min))) |
506 (setq ex-token-type nil | 507 (setq ex-token-type nil |
516 (ex-global t) | 517 (ex-global t) |
517 (setq cont nil)) | 518 (setq cont nil)) |
518 (t | 519 (t |
519 (vip-execute-ex-command) | 520 (vip-execute-ex-command) |
520 (save-window-excursion | 521 (save-window-excursion |
522 (setq vip-ex-work-buf | |
523 (get-buffer-create vip-ex-work-buf-name)) | |
521 (set-buffer vip-ex-work-buf) | 524 (set-buffer vip-ex-work-buf) |
522 (skip-chars-forward " \t") | 525 (skip-chars-forward " \t") |
523 (cond ((looking-at "|") | 526 (cond ((looking-at "|") |
524 (forward-char 1)) | 527 (forward-char 1)) |
525 ((looking-at "\n") | 528 ((looking-at "\n") |
552 | 555 |
553 | 556 |
554 ;; Get a regular expression and set `ex-variant', if found | 557 ;; Get a regular expression and set `ex-variant', if found |
555 (defun vip-get-ex-pat () | 558 (defun vip-get-ex-pat () |
556 (save-window-excursion | 559 (save-window-excursion |
560 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
557 (set-buffer vip-ex-work-buf) | 561 (set-buffer vip-ex-work-buf) |
558 (skip-chars-forward " \t") | 562 (skip-chars-forward " \t") |
559 (if (looking-at "!") | 563 (if (looking-at "!") |
560 (progn | 564 (progn |
561 (setq ex-g-variant (not ex-g-variant) | 565 (setq ex-g-variant (not ex-g-variant) |
588 c))) | 592 c))) |
589 | 593 |
590 ;; get an ex command | 594 ;; get an ex command |
591 (defun vip-get-ex-command () | 595 (defun vip-get-ex-command () |
592 (save-window-excursion | 596 (save-window-excursion |
597 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
593 (set-buffer vip-ex-work-buf) | 598 (set-buffer vip-ex-work-buf) |
594 (if (looking-at "/") (forward-char 1)) | 599 (if (looking-at "/") (forward-char 1)) |
595 (skip-chars-forward " \t") | 600 (skip-chars-forward " \t") |
596 (cond ((looking-at "[a-z]") | 601 (cond ((looking-at "[a-z]") |
597 (vip-get-ex-com-subr) | 602 (vip-get-ex-com-subr) |
603 (t (error vip-BadExCommand))))) | 608 (t (error vip-BadExCommand))))) |
604 | 609 |
605 ;; Get an Ex option g or c | 610 ;; Get an Ex option g or c |
606 (defun vip-get-ex-opt-gc (c) | 611 (defun vip-get-ex-opt-gc (c) |
607 (save-window-excursion | 612 (save-window-excursion |
613 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
608 (set-buffer vip-ex-work-buf) | 614 (set-buffer vip-ex-work-buf) |
609 (if (looking-at (format "%c" c)) (forward-char 1)) | 615 (if (looking-at (format "%c" c)) (forward-char 1)) |
610 (skip-chars-forward " \t") | 616 (skip-chars-forward " \t") |
611 (cond ((looking-at "g") | 617 (cond ((looking-at "g") |
612 (setq ex-token "g") | 618 (setq ex-token "g") |
714 (defun vip-get-ex-buffer () | 720 (defun vip-get-ex-buffer () |
715 (setq ex-buffer nil) | 721 (setq ex-buffer nil) |
716 (setq ex-count nil) | 722 (setq ex-count nil) |
717 (setq ex-flag nil) | 723 (setq ex-flag nil) |
718 (save-window-excursion | 724 (save-window-excursion |
725 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
719 (set-buffer vip-ex-work-buf) | 726 (set-buffer vip-ex-work-buf) |
720 (skip-chars-forward " \t") | 727 (skip-chars-forward " \t") |
721 (if (looking-at "[a-zA-Z]") | 728 (if (looking-at "[a-zA-Z]") |
722 (progn | 729 (progn |
723 (setq ex-buffer (following-char)) | 730 (setq ex-buffer (following-char)) |
739 (defun vip-get-ex-count () | 746 (defun vip-get-ex-count () |
740 (setq ex-variant nil | 747 (setq ex-variant nil |
741 ex-count nil | 748 ex-count nil |
742 ex-flag nil) | 749 ex-flag nil) |
743 (save-window-excursion | 750 (save-window-excursion |
751 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
744 (set-buffer vip-ex-work-buf) | 752 (set-buffer vip-ex-work-buf) |
745 (skip-chars-forward " \t") | 753 (skip-chars-forward " \t") |
746 (if (looking-at "!") | 754 (if (looking-at "!") |
747 (progn | 755 (progn |
748 (setq ex-variant t) | 756 (setq ex-variant t) |
800 ex-append nil | 808 ex-append nil |
801 ex-offset nil | 809 ex-offset nil |
802 ex-cmdfile nil) | 810 ex-cmdfile nil) |
803 (save-excursion | 811 (save-excursion |
804 (save-window-excursion | 812 (save-window-excursion |
813 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
805 (set-buffer vip-ex-work-buf) | 814 (set-buffer vip-ex-work-buf) |
806 (skip-chars-forward " \t") | 815 (skip-chars-forward " \t") |
807 (if (looking-at "!") | 816 (if (looking-at "!") |
808 (if (and (not (vip-looking-back "[ \t]")) | 817 (if (and (not (vip-looking-back "[ \t]")) |
809 ;; read doesn't have a corresponding :r! form, so ! is | 818 ;; read doesn't have a corresponding :r! form, so ! is |
1165 ) ; let | 1174 ) ; let |
1166 | 1175 |
1167 (if (null (setq file (get-file-buffer ex-file))) | 1176 (if (null (setq file (get-file-buffer ex-file))) |
1168 (progn | 1177 (progn |
1169 (ex-find-file ex-file) | 1178 (ex-find-file ex-file) |
1170 (vip-change-state-to-vi) | 1179 (or (eq major-mode 'dired-mode) |
1180 (vip-change-state-to-vi)) | |
1171 (goto-char (point-min))) | 1181 (goto-char (point-min))) |
1172 (switch-to-buffer file)) | 1182 (switch-to-buffer file)) |
1173 (if ex-offset | 1183 (if ex-offset |
1174 (progn | 1184 (progn |
1175 (save-window-excursion | 1185 (save-window-excursion |
1186 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1176 (set-buffer vip-ex-work-buf) | 1187 (set-buffer vip-ex-work-buf) |
1177 (delete-region (point-min) (point-max)) | 1188 (delete-region (point-min) (point-max)) |
1178 (insert ex-offset "\n") | 1189 (insert ex-offset "\n") |
1179 (goto-char (point-min))) | 1190 (goto-char (point-min))) |
1180 (goto-char (vip-get-ex-address)) | 1191 (goto-char (vip-get-ex-address)) |
1181 (beginning-of-line))) | 1192 (beginning-of-line))) |
1182 (ex-fixup-history vip-last-ex-prompt ex-file)) | 1193 (ex-fixup-history vip-last-ex-prompt ex-file)) |
1183 | 1194 |
1184 ;; Splits the string FILESPEC into substrings separated by newlines. | 1195 ;; Find-file FILESPEC if it appears to specify a single file. |
1196 ;; Otherwise, assume that FILES{EC is a wildcard. | |
1197 ;; In this case, split it into substrings separated by newlines. | |
1185 ;; Each line is assumed to be a file name. find-file's each file thus obtained. | 1198 ;; Each line is assumed to be a file name. find-file's each file thus obtained. |
1186 (defun ex-find-file (filespec) | 1199 (defun ex-find-file (filespec) |
1187 (let ((nonstandard-filename-chars "[^a-zA-Z0-9_.-/,\\]")) | 1200 (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]")) |
1188 (if (string-match nonstandard-filename-chars filespec) | 1201 (cond ((file-exists-p filespec) (find-file filespec)) |
1189 (funcall ex-nontrivial-find-file-function filespec) | 1202 ((string-match nonstandard-filename-chars filespec) |
1190 (find-file filespec)) | 1203 (funcall ex-nontrivial-find-file-function filespec)) |
1204 (t (find-file filespec))) | |
1191 )) | 1205 )) |
1192 | 1206 |
1193 | 1207 |
1194 ;; Ex global command | 1208 ;; Ex global command |
1195 (defun ex-global (variant) | 1209 (defun ex-global (variant) |
1239 (beginning-of-line) | 1253 (beginning-of-line) |
1240 (if (bobp) (setq cont nil) | 1254 (if (bobp) (setq cont nil) |
1241 (forward-line -1) | 1255 (forward-line -1) |
1242 (end-of-line))))) | 1256 (end-of-line))))) |
1243 (save-window-excursion | 1257 (save-window-excursion |
1258 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1244 (set-buffer vip-ex-work-buf) | 1259 (set-buffer vip-ex-work-buf) |
1245 (setq com-str (buffer-substring (1+ (point)) (1- (point-max))))) | 1260 (setq com-str (buffer-substring (1+ (point)) (1- (point-max))))) |
1246 (while marks | 1261 (while marks |
1247 (goto-char (car marks)) | 1262 (goto-char (car marks)) |
1248 (vip-ex com-str) | 1263 (vip-ex com-str) |
1310 (let (char) | 1325 (let (char) |
1311 (if (null ex-addresses) | 1326 (if (null ex-addresses) |
1312 (setq ex-addresses | 1327 (setq ex-addresses |
1313 (cons (point) nil))) | 1328 (cons (point) nil))) |
1314 (save-window-excursion | 1329 (save-window-excursion |
1330 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1315 (set-buffer vip-ex-work-buf) | 1331 (set-buffer vip-ex-work-buf) |
1316 (skip-chars-forward " \t") | 1332 (skip-chars-forward " \t") |
1317 (if (looking-at "[a-z]") | 1333 (if (looking-at "[a-z]") |
1318 (progn | 1334 (progn |
1319 (setq char (following-char)) | 1335 (setq char (following-char)) |
1444 | 1460 |
1445 ;; Ex quit command | 1461 ;; Ex quit command |
1446 (defun ex-quit () | 1462 (defun ex-quit () |
1447 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc. | 1463 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc. |
1448 (save-excursion | 1464 (save-excursion |
1465 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1449 (set-buffer vip-ex-work-buf) | 1466 (set-buffer vip-ex-work-buf) |
1450 (if (looking-at "!") (forward-char 1))) | 1467 (if (looking-at "!") (forward-char 1))) |
1451 (if (< vip-expert-level 3) | 1468 (if (< vip-expert-level 3) |
1452 (save-buffers-kill-emacs) | 1469 (save-buffers-kill-emacs) |
1453 (kill-buffer (current-buffer)))) | 1470 (kill-buffer (current-buffer)))) |
1677 ;; In inline args, skip regex-forw and (optionally) chars-back. | 1694 ;; In inline args, skip regex-forw and (optionally) chars-back. |
1678 ;; Optional 3d arg is a string that should replace ' ' to prevent its | 1695 ;; Optional 3d arg is a string that should replace ' ' to prevent its |
1679 ;; special meaning | 1696 ;; special meaning |
1680 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str) | 1697 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str) |
1681 (save-excursion | 1698 (save-excursion |
1699 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1682 (set-buffer vip-ex-work-buf) | 1700 (set-buffer vip-ex-work-buf) |
1683 (goto-char (point-min)) | 1701 (goto-char (point-min)) |
1684 (re-search-forward regex-forw nil t) | 1702 (re-search-forward regex-forw nil t) |
1685 (let ((beg (point)) | 1703 (let ((beg (point)) |
1686 end) | 1704 end) |
1810 | 1828 |
1811 ;; Ex tag command | 1829 ;; Ex tag command |
1812 (defun ex-tag () | 1830 (defun ex-tag () |
1813 (let (tag) | 1831 (let (tag) |
1814 (save-window-excursion | 1832 (save-window-excursion |
1833 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1815 (set-buffer vip-ex-work-buf) | 1834 (set-buffer vip-ex-work-buf) |
1816 (skip-chars-forward " \t") | 1835 (skip-chars-forward " \t") |
1817 (set-mark (point)) | 1836 (set-mark (point)) |
1818 (skip-chars-forward "^ |\t\n") | 1837 (skip-chars-forward "^ |\t\n") |
1819 (setq tag (buffer-substring (mark t) (point)))) | 1838 (setq tag (buffer-substring (mark t) (point)))) |
1943 | 1962 |
1944 ;; Execute shell command | 1963 ;; Execute shell command |
1945 (defun ex-command () | 1964 (defun ex-command () |
1946 (let (command) | 1965 (let (command) |
1947 (save-window-excursion | 1966 (save-window-excursion |
1967 (setq vip-ex-work-buf (get-buffer-create vip-ex-work-buf-name)) | |
1948 (set-buffer vip-ex-work-buf) | 1968 (set-buffer vip-ex-work-buf) |
1949 (skip-chars-forward " \t") | 1969 (skip-chars-forward " \t") |
1950 (setq command (buffer-substring (point) (point-max))) | 1970 (setq command (buffer-substring (point) (point-max))) |
1951 (end-of-line)) | 1971 (end-of-line)) |
1952 (setq command (ex-expand-filsyms command (current-buffer))) | 1972 (setq command (ex-expand-filsyms command (current-buffer))) |