Mercurial > vim
comparison src/ex_docmd.c @ 167:c93c9cad9618
updated for version 7.0051
author | vimboss |
---|---|
date | Tue, 22 Feb 2005 08:39:57 +0000 |
parents | 8b0ee9d57d7f |
children | 8c60f65311fa |
comparison
equal
deleted
inserted
replaced
166:3a28ed993bbe | 167:c93c9cad9618 |
---|---|
126 # define ex_cwindow ex_ni | 126 # define ex_cwindow ex_ni |
127 #endif | 127 #endif |
128 | 128 |
129 static int check_more __ARGS((int, int)); | 129 static int check_more __ARGS((int, int)); |
130 static linenr_T get_address __ARGS((char_u **, int skip, int to_other_file)); | 130 static linenr_T get_address __ARGS((char_u **, int skip, int to_other_file)); |
131 static void get_flags __ARGS((exarg_T *eap)); | |
131 #if !defined(FEAT_PERL) || !defined(FEAT_PYTHON) || !defined(FEAT_TCL) \ | 132 #if !defined(FEAT_PERL) || !defined(FEAT_PYTHON) || !defined(FEAT_TCL) \ |
132 || !defined(FEAT_RUBY) || !defined(FEAT_MZSCHEME) | 133 || !defined(FEAT_RUBY) || !defined(FEAT_MZSCHEME) |
133 static void ex_script_ni __ARGS((exarg_T *eap)); | 134 static void ex_script_ni __ARGS((exarg_T *eap)); |
134 #endif | 135 #endif |
135 static char_u *invalid_range __ARGS((exarg_T *eap)); | 136 static char_u *invalid_range __ARGS((exarg_T *eap)); |
183 # define ex_listdo ex_ni | 184 # define ex_listdo ex_ni |
184 #endif | 185 #endif |
185 static void ex_mode __ARGS((exarg_T *eap)); | 186 static void ex_mode __ARGS((exarg_T *eap)); |
186 static void ex_wrongmodifier __ARGS((exarg_T *eap)); | 187 static void ex_wrongmodifier __ARGS((exarg_T *eap)); |
187 static void ex_find __ARGS((exarg_T *eap)); | 188 static void ex_find __ARGS((exarg_T *eap)); |
189 static void ex_open __ARGS((exarg_T *eap)); | |
188 static void ex_edit __ARGS((exarg_T *eap)); | 190 static void ex_edit __ARGS((exarg_T *eap)); |
189 #if !defined(FEAT_GUI) && !defined(FEAT_CLIENTSERVER) | 191 #if !defined(FEAT_GUI) && !defined(FEAT_CLIENTSERVER) |
190 # define ex_drop ex_ni | 192 # define ex_drop ex_ni |
191 #endif | 193 #endif |
192 #ifndef FEAT_GUI | 194 #ifndef FEAT_GUI |
269 # define ex_winpos ex_ni | 271 # define ex_winpos ex_ni |
270 #endif | 272 #endif |
271 static void ex_operators __ARGS((exarg_T *eap)); | 273 static void ex_operators __ARGS((exarg_T *eap)); |
272 static void ex_put __ARGS((exarg_T *eap)); | 274 static void ex_put __ARGS((exarg_T *eap)); |
273 static void ex_copymove __ARGS((exarg_T *eap)); | 275 static void ex_copymove __ARGS((exarg_T *eap)); |
276 static void ex_may_print __ARGS((exarg_T *eap)); | |
274 static void ex_submagic __ARGS((exarg_T *eap)); | 277 static void ex_submagic __ARGS((exarg_T *eap)); |
275 static void ex_join __ARGS((exarg_T *eap)); | 278 static void ex_join __ARGS((exarg_T *eap)); |
276 static void ex_at __ARGS((exarg_T *eap)); | 279 static void ex_at __ARGS((exarg_T *eap)); |
277 static void ex_bang __ARGS((exarg_T *eap)); | 280 static void ex_bang __ARGS((exarg_T *eap)); |
278 static void ex_undo __ARGS((exarg_T *eap)); | 281 static void ex_undo __ARGS((exarg_T *eap)); |
568 int improved; /* TRUE for "improved Ex" mode */ | 571 int improved; /* TRUE for "improved Ex" mode */ |
569 { | 572 { |
570 int save_msg_scroll; | 573 int save_msg_scroll; |
571 int prev_msg_row; | 574 int prev_msg_row; |
572 linenr_T prev_line; | 575 linenr_T prev_line; |
576 int changedtick; | |
577 | |
578 if (improved) | |
579 exmode_active = EXMODE_VIM; | |
580 else | |
581 exmode_active = EXMODE_NORMAL; | |
582 State = NORMAL; | |
583 | |
584 /* When using ":global /pat/ visual" and then "Q" we return to continue | |
585 * the :global command. */ | |
586 if (global_busy) | |
587 return; | |
573 | 588 |
574 save_msg_scroll = msg_scroll; | 589 save_msg_scroll = msg_scroll; |
575 ++RedrawingDisabled; /* don't redisplay the window */ | 590 ++RedrawingDisabled; /* don't redisplay the window */ |
576 ++no_wait_return; /* don't wait for return */ | 591 ++no_wait_return; /* don't wait for return */ |
577 if (improved) | |
578 exmode_active = EXMODE_VIM; | |
579 else | |
580 { | |
581 settmode(TMODE_COOK); | |
582 exmode_active = EXMODE_NORMAL; | |
583 } | |
584 | |
585 State = NORMAL; | |
586 #ifdef FEAT_GUI | 592 #ifdef FEAT_GUI |
587 /* Ignore scrollbar and mouse events in Ex mode */ | 593 /* Ignore scrollbar and mouse events in Ex mode */ |
588 ++hold_gui_events; | 594 ++hold_gui_events; |
589 #endif | 595 #endif |
590 #ifdef FEAT_SNIFF | 596 #ifdef FEAT_SNIFF |
604 #endif | 610 #endif |
605 msg_scroll = TRUE; | 611 msg_scroll = TRUE; |
606 need_wait_return = FALSE; | 612 need_wait_return = FALSE; |
607 ex_pressedreturn = FALSE; | 613 ex_pressedreturn = FALSE; |
608 ex_no_reprint = FALSE; | 614 ex_no_reprint = FALSE; |
615 changedtick = curbuf->b_changedtick; | |
609 prev_msg_row = msg_row; | 616 prev_msg_row = msg_row; |
610 prev_line = curwin->w_cursor.lnum; | 617 prev_line = curwin->w_cursor.lnum; |
611 #ifdef FEAT_SNIFF | 618 #ifdef FEAT_SNIFF |
612 ProcessSniffRequests(); | 619 ProcessSniffRequests(); |
613 #endif | 620 #endif |
618 } | 625 } |
619 else | 626 else |
620 do_cmdline(NULL, getexmodeline, NULL, DOCMD_NOWAIT); | 627 do_cmdline(NULL, getexmodeline, NULL, DOCMD_NOWAIT); |
621 lines_left = Rows - 1; | 628 lines_left = Rows - 1; |
622 | 629 |
623 if (prev_line != curwin->w_cursor.lnum && !ex_no_reprint) | 630 if ((prev_line != curwin->w_cursor.lnum |
624 { | 631 || changedtick != curbuf->b_changedtick) && !ex_no_reprint) |
625 if (ex_pressedreturn) | 632 { |
626 { | 633 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
627 /* go up one line, to overwrite the ":<CR>" line, so the | 634 EMSG(_(e_emptybuf)); |
628 * output doensn't contain empty lines. */ | 635 else |
629 msg_row = prev_msg_row; | 636 { |
630 if (prev_msg_row == Rows - 1) | 637 if (ex_pressedreturn) |
631 msg_row--; | 638 { |
632 } | 639 /* go up one line, to overwrite the ":<CR>" line, so the |
633 msg_col = 0; | 640 * output doensn't contain empty lines. */ |
634 print_line_no_prefix(curwin->w_cursor.lnum, FALSE); | 641 msg_row = prev_msg_row; |
635 msg_clr_eos(); | 642 if (prev_msg_row == Rows - 1) |
636 } | 643 msg_row--; |
637 else if (ex_pressedreturn) /* must be at EOF */ | 644 } |
638 EMSG(_("E501: At end-of-file")); | 645 msg_col = 0; |
646 print_line_no_prefix(curwin->w_cursor.lnum, FALSE, FALSE); | |
647 msg_clr_eos(); | |
648 } | |
649 } | |
650 else if (ex_pressedreturn && !ex_no_reprint) /* must be at EOF */ | |
651 { | |
652 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
653 EMSG(_(e_emptybuf)); | |
654 else | |
655 EMSG(_("E501: At end-of-file")); | |
656 } | |
639 } | 657 } |
640 | 658 |
641 #ifdef FEAT_GUI | 659 #ifdef FEAT_GUI |
642 --hold_gui_events; | 660 --hold_gui_events; |
643 #endif | 661 #endif |
644 if (!improved) | |
645 settmode(TMODE_RAW); | |
646 --RedrawingDisabled; | 662 --RedrawingDisabled; |
647 --no_wait_return; | 663 --no_wait_return; |
648 update_screen(CLEAR); | 664 update_screen(CLEAR); |
649 need_wait_return = FALSE; | 665 need_wait_return = FALSE; |
650 msg_scroll = save_msg_scroll; | 666 msg_scroll = save_msg_scroll; |
1661 ++ea.cmd; | 1677 ++ea.cmd; |
1662 | 1678 |
1663 /* in ex mode, an empty line works like :+ */ | 1679 /* in ex mode, an empty line works like :+ */ |
1664 if (*ea.cmd == NUL && exmode_active | 1680 if (*ea.cmd == NUL && exmode_active |
1665 && (getline_equal(getline, cookie, getexmodeline) | 1681 && (getline_equal(getline, cookie, getexmodeline) |
1666 || getline_equal(getline, cookie, getexline))) | 1682 || getline_equal(getline, cookie, getexline)) |
1683 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
1667 { | 1684 { |
1668 ea.cmd = (char_u *)"+"; | 1685 ea.cmd = (char_u *)"+"; |
1669 ex_pressedreturn = TRUE; | 1686 ex_pressedreturn = TRUE; |
1670 } | 1687 } |
1671 | 1688 |
1672 /* ignore comment and empty lines */ | 1689 /* ignore comment and empty lines */ |
1673 if (*ea.cmd == '"' || *ea.cmd == NUL) | 1690 if (*ea.cmd == '"' || *ea.cmd == NUL) |
1691 { | |
1692 ex_pressedreturn = TRUE; | |
1674 goto doend; | 1693 goto doend; |
1694 } | |
1675 | 1695 |
1676 /* | 1696 /* |
1677 * 2. handle command modifiers. | 1697 * 2. handle command modifiers. |
1678 */ | 1698 */ |
1679 p = ea.cmd; | 1699 p = ea.cmd; |
1934 * ":3|..." prints line 3 | 1954 * ":3|..." prints line 3 |
1935 * ":|" prints current line | 1955 * ":|" prints current line |
1936 */ | 1956 */ |
1937 if (ea.skip) /* skip this if inside :if */ | 1957 if (ea.skip) /* skip this if inside :if */ |
1938 goto doend; | 1958 goto doend; |
1939 if (*ea.cmd == '|') | 1959 if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) |
1940 { | 1960 { |
1941 ea.cmdidx = CMD_print; | 1961 ea.cmdidx = CMD_print; |
1942 ea.argt = RANGE+COUNT+TRLBAR; | 1962 ea.argt = RANGE+COUNT+TRLBAR; |
1943 if ((errormsg = invalid_range(&ea)) == NULL) | 1963 if ((errormsg = invalid_range(&ea)) == NULL) |
1944 { | 1964 { |
1946 ex_print(&ea); | 1966 ex_print(&ea); |
1947 } | 1967 } |
1948 } | 1968 } |
1949 else if (ea.addr_count != 0) | 1969 else if (ea.addr_count != 0) |
1950 { | 1970 { |
1951 if (ea.line2 < 0) | 1971 if (ea.line2 < 0 || ea.line2 > curbuf->b_ml.ml_line_count) |
1952 errormsg = invalid_range(&ea); | 1972 errormsg = (char_u *)_(e_invrange); |
1953 else | 1973 else |
1954 { | 1974 { |
1955 if (ea.line2 == 0) | 1975 if (ea.line2 == 0) |
1956 curwin->w_cursor.lnum = 1; | 1976 curwin->w_cursor.lnum = 1; |
1957 else if (ea.line2 > curbuf->b_ml.ml_line_count) | |
1958 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1959 else | 1977 else |
1960 curwin->w_cursor.lnum = ea.line2; | 1978 curwin->w_cursor.lnum = ea.line2; |
1961 beginline(BL_SOL | BL_FIX); | 1979 beginline(BL_SOL | BL_FIX); |
1962 } | 1980 } |
1963 } | 1981 } |
2088 * ea.line1 & ea.line2 so it's forwards again. | 2106 * ea.line1 & ea.line2 so it's forwards again. |
2089 * When global command is busy, don't ask, will fail below. | 2107 * When global command is busy, don't ask, will fail below. |
2090 */ | 2108 */ |
2091 if (!global_busy && ea.line1 > ea.line2) | 2109 if (!global_busy && ea.line1 > ea.line2) |
2092 { | 2110 { |
2093 if (sourcing) | 2111 if (sourcing || exmode_active) |
2094 { | 2112 { |
2095 errormsg = (char_u *)_("E493: Backwards range given"); | 2113 errormsg = (char_u *)_("E493: Backwards range given"); |
2096 goto doend; | 2114 goto doend; |
2097 } | 2115 } |
2098 else | 2116 else |
2278 if ((ea.argt & TRLBAR) && !ea.usefilter) | 2296 if ((ea.argt & TRLBAR) && !ea.usefilter) |
2279 separate_nextcmd(&ea); | 2297 separate_nextcmd(&ea); |
2280 | 2298 |
2281 /* | 2299 /* |
2282 * Check for <newline> to end a shell command. | 2300 * Check for <newline> to end a shell command. |
2283 * Also do this for ":read !cmd" and ":write !cmd". | 2301 * Also do this for ":read !cmd", ":write !cmd" and ":global". |
2302 * Any others? | |
2284 */ | 2303 */ |
2285 else if (ea.cmdidx == CMD_bang || ea.usefilter) | 2304 else if (ea.cmdidx == CMD_bang |
2305 || ea.cmdidx == CMD_global | |
2306 || ea.cmdidx == CMD_vglobal | |
2307 || ea.usefilter) | |
2286 { | 2308 { |
2287 for (p = ea.arg; *p; ++p) | 2309 for (p = ea.arg; *p; ++p) |
2288 { | 2310 { |
2289 /* Remove one backslash before a newline, so that it's possible to | 2311 /* Remove one backslash before a newline, so that it's possible to |
2290 * pass a newline to the shell and also a newline that is preceded | 2312 * pass a newline to the shell and also a newline that is preceded |
2365 */ | 2387 */ |
2366 if (ea.line2 > curbuf->b_ml.ml_line_count) | 2388 if (ea.line2 > curbuf->b_ml.ml_line_count) |
2367 ea.line2 = curbuf->b_ml.ml_line_count; | 2389 ea.line2 = curbuf->b_ml.ml_line_count; |
2368 } | 2390 } |
2369 } | 2391 } |
2392 | |
2393 /* | |
2394 * Check for flags: 'l', 'p' and '#'. | |
2395 */ | |
2396 if (ea.argt & EXFLAGS) | |
2397 get_flags(&ea); | |
2370 /* no arguments allowed */ | 2398 /* no arguments allowed */ |
2371 if (!ni && !(ea.argt & EXTRA) && *ea.arg != NUL | 2399 if (!ni && !(ea.argt & EXTRA) && *ea.arg != NUL |
2372 && vim_strchr((char_u *)"|\"", *ea.arg) == NULL) | 2400 && vim_strchr((char_u *)"|\"", *ea.arg) == NULL) |
2373 { | 2401 { |
2374 errormsg = (char_u *)_(e_trailing); | 2402 errormsg = (char_u *)_(e_trailing); |
2659 exarg_T *eap; | 2687 exarg_T *eap; |
2660 int *full; | 2688 int *full; |
2661 { | 2689 { |
2662 int len; | 2690 int len; |
2663 char_u *p; | 2691 char_u *p; |
2692 int i; | |
2664 | 2693 |
2665 /* | 2694 /* |
2666 * Isolate the command and search for it in the command table. | 2695 * Isolate the command and search for it in the command table. |
2667 * Exeptions: | 2696 * Exeptions: |
2668 * - the 'k' command can directly be followed by any character. | 2697 * - the 'k' command can directly be followed by any character. |
2669 * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r' | 2698 * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r' |
2670 * but :sre[wind] is another command, as are :scrip[tnames], | 2699 * but :sre[wind] is another command, as are :scrip[tnames], |
2671 * :scs[cope], :sim[alt], :sig[ns] and :sil[ent]. | 2700 * :scs[cope], :sim[alt], :sig[ns] and :sil[ent]. |
2701 * - the "d" command can directly be followed by 'l' or 'p' flag. | |
2672 */ | 2702 */ |
2673 p = eap->cmd; | 2703 p = eap->cmd; |
2674 if (*p == 'k') | 2704 if (*p == 'k') |
2675 { | 2705 { |
2676 eap->cmdidx = CMD_k; | 2706 eap->cmdidx = CMD_k; |
2692 ++p; | 2722 ++p; |
2693 /* check for non-alpha command */ | 2723 /* check for non-alpha command */ |
2694 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) | 2724 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) |
2695 ++p; | 2725 ++p; |
2696 len = (int)(p - eap->cmd); | 2726 len = (int)(p - eap->cmd); |
2727 if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) | |
2728 { | |
2729 /* Check for ":dl", ":dell", etc. to ":deletel": that's | |
2730 * :delete with the 'l' flag. Same for 'p'. */ | |
2731 for (i = 0; i < len; ++i) | |
2732 if (eap->cmd[i] != "delete"[i]) | |
2733 break; | |
2734 if (i == len - 1) | |
2735 { | |
2736 --len; | |
2737 if (p[-1] == 'l') | |
2738 eap->flags |= EXFLAG_LIST; | |
2739 else | |
2740 eap->flags |= EXFLAG_PRINT; | |
2741 } | |
2742 } | |
2697 | 2743 |
2698 if (ASCII_ISLOWER(*eap->cmd)) | 2744 if (ASCII_ISLOWER(*eap->cmd)) |
2699 eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)]; | 2745 eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)]; |
2700 else | 2746 else |
2701 eap->cmdidx = cmdidxs[26]; | 2747 eap->cmdidx = cmdidxs[26]; |
2926 cmd = skip_range(cmd, &xp->xp_context); | 2972 cmd = skip_range(cmd, &xp->xp_context); |
2927 | 2973 |
2928 /* | 2974 /* |
2929 * 4. parse command | 2975 * 4. parse command |
2930 */ | 2976 */ |
2931 | |
2932 cmd = skipwhite(cmd); | |
2933 xp->xp_pattern = cmd; | 2977 xp->xp_pattern = cmd; |
2934 if (*cmd == NUL) | 2978 if (*cmd == NUL) |
2935 return NULL; | 2979 return NULL; |
2936 if (*cmd == '"') | 2980 if (*cmd == '"') |
2937 { | 2981 { |
3279 case CMD_aboveleft: | 3323 case CMD_aboveleft: |
3280 case CMD_belowright: | 3324 case CMD_belowright: |
3281 case CMD_botright: | 3325 case CMD_botright: |
3282 case CMD_browse: | 3326 case CMD_browse: |
3283 case CMD_confirm: | 3327 case CMD_confirm: |
3328 case CMD_debug: | |
3284 case CMD_folddoclosed: | 3329 case CMD_folddoclosed: |
3285 case CMD_folddoopen: | 3330 case CMD_folddoopen: |
3286 case CMD_hide: | 3331 case CMD_hide: |
3287 case CMD_keepalt: | 3332 case CMD_keepalt: |
3288 case CMD_keepjumps: | 3333 case CMD_keepjumps: |
3631 * skip a range specifier of the form: addr [,addr] [;addr] .. | 3676 * skip a range specifier of the form: addr [,addr] [;addr] .. |
3632 * | 3677 * |
3633 * Backslashed delimiters after / or ? will be skipped, and commands will | 3678 * Backslashed delimiters after / or ? will be skipped, and commands will |
3634 * not be expanded between /'s and ?'s or after "'". | 3679 * not be expanded between /'s and ?'s or after "'". |
3635 * | 3680 * |
3681 * Also skip white space and ":" characters. | |
3636 * Returns the "cmd" pointer advanced to beyond the range. | 3682 * Returns the "cmd" pointer advanced to beyond the range. |
3637 */ | 3683 */ |
3638 char_u * | 3684 char_u * |
3639 skip_range(cmd, ctx) | 3685 skip_range(cmd, ctx) |
3640 char_u *cmd; | 3686 char_u *cmd; |
3641 int *ctx; /* pointer to xp_context or NULL */ | 3687 int *ctx; /* pointer to xp_context or NULL */ |
3642 { | 3688 { |
3643 int delim; | 3689 int delim; |
3644 | 3690 |
3645 while (*cmd != NUL && (vim_isspace(*cmd) || VIM_ISDIGIT(*cmd) || | 3691 while (vim_strchr((char_u *)" \t0123456789.$%'/?-+,;", *cmd) != NULL) |
3646 vim_strchr((char_u *)".$%'/?-+,;", *cmd) != NULL)) | |
3647 { | 3692 { |
3648 if (*cmd == '\'') | 3693 if (*cmd == '\'') |
3649 { | 3694 { |
3650 if (*++cmd == NUL && ctx != NULL) | 3695 if (*++cmd == NUL && ctx != NULL) |
3651 *ctx = EXPAND_NOTHING; | 3696 *ctx = EXPAND_NOTHING; |
3660 *ctx = EXPAND_NOTHING; | 3705 *ctx = EXPAND_NOTHING; |
3661 } | 3706 } |
3662 if (*cmd != NUL) | 3707 if (*cmd != NUL) |
3663 ++cmd; | 3708 ++cmd; |
3664 } | 3709 } |
3710 | |
3711 /* Skip ":" and white space. */ | |
3712 while (*cmd == ':') | |
3713 cmd = skipwhite(cmd + 1); | |
3714 | |
3665 return cmd; | 3715 return cmd; |
3666 } | 3716 } |
3667 | 3717 |
3668 /* | 3718 /* |
3669 * get a single EX address | 3719 * get a single EX address |
3854 *ptr = cmd; | 3904 *ptr = cmd; |
3855 return lnum; | 3905 return lnum; |
3856 } | 3906 } |
3857 | 3907 |
3858 /* | 3908 /* |
3909 * Get flags from an Ex command argument. | |
3910 */ | |
3911 static void | |
3912 get_flags(eap) | |
3913 exarg_T *eap; | |
3914 { | |
3915 while (vim_strchr((char_u *)"lp#", *eap->arg) != NULL) | |
3916 { | |
3917 if (*eap->arg == 'l') | |
3918 eap->flags |= EXFLAG_LIST; | |
3919 else if (*eap->arg == 'p') | |
3920 eap->flags |= EXFLAG_PRINT; | |
3921 else | |
3922 eap->flags |= EXFLAG_NR; | |
3923 eap->arg = skipwhite(eap->arg + 1); | |
3924 } | |
3925 } | |
3926 | |
3927 /* | |
3859 * Function called for command which is Not Implemented. NI! | 3928 * Function called for command which is Not Implemented. NI! |
3860 */ | 3929 */ |
3861 void | 3930 void |
3862 ex_ni(eap) | 3931 ex_ni(eap) |
3863 exarg_T *eap; | 3932 exarg_T *eap; |
4278 break; | 4347 break; |
4279 } | 4348 } |
4280 | 4349 |
4281 #ifdef FEAT_EVAL | 4350 #ifdef FEAT_EVAL |
4282 /* Skip over `=expr` when wildcards are expanded. */ | 4351 /* Skip over `=expr` when wildcards are expanded. */ |
4283 else if (p[0] == '`' && p[1] == '=') | 4352 else if (p[0] == '`' && p[1] == '=' && (eap->argt & XFILE)) |
4284 { | 4353 { |
4285 p += 2; | 4354 p += 2; |
4286 (void)skip_expr(&p); | 4355 (void)skip_expr(&p); |
4287 } | 4356 } |
4288 #endif | 4357 #endif |
6114 */ | 6183 */ |
6115 static void | 6184 static void |
6116 ex_print(eap) | 6185 ex_print(eap) |
6117 exarg_T *eap; | 6186 exarg_T *eap; |
6118 { | 6187 { |
6119 int save_list = 0; /* init for GCC */ | 6188 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
6120 | 6189 EMSG(_(e_emptybuf)); |
6121 if (eap->cmdidx == CMD_list) | 6190 else |
6122 { | 6191 { |
6123 save_list = curwin->w_p_list; | 6192 for ( ;!got_int; ui_breakcheck()) |
6124 curwin->w_p_list = 1; | 6193 { |
6125 } | 6194 print_line(eap->line1, |
6126 | 6195 (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound |
6127 for ( ;!got_int; ui_breakcheck()) | 6196 || (eap->flags & EXFLAG_NR)), |
6128 { | 6197 eap->cmdidx == CMD_list || (eap->flags & EXFLAG_LIST)); |
6129 print_line(eap->line1, | 6198 if (++eap->line1 > eap->line2) |
6130 (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound)); | 6199 break; |
6131 if (++eap->line1 > eap->line2) | 6200 out_flush(); /* show one line at a time */ |
6132 break; | 6201 } |
6133 out_flush(); /* show one line at a time */ | 6202 setpcmark(); |
6134 } | 6203 /* put cursor at last line */ |
6135 setpcmark(); | 6204 curwin->w_cursor.lnum = eap->line2; |
6136 /* put cursor at last line */ | 6205 beginline(BL_SOL | BL_FIX); |
6137 curwin->w_cursor.lnum = eap->line2; | 6206 } |
6138 beginline(BL_SOL | BL_FIX); | |
6139 | 6207 |
6140 ex_no_reprint = TRUE; | 6208 ex_no_reprint = TRUE; |
6141 | |
6142 if (eap->cmdidx == CMD_list) | |
6143 curwin->w_p_list = save_list; | |
6144 } | 6209 } |
6145 | 6210 |
6146 #ifdef FEAT_BYTEOFF | 6211 #ifdef FEAT_BYTEOFF |
6147 static void | 6212 static void |
6148 ex_goto(eap) | 6213 ex_goto(eap) |
6687 } | 6752 } |
6688 #endif | 6753 #endif |
6689 } | 6754 } |
6690 | 6755 |
6691 /* | 6756 /* |
6692 * ":edit", ":badd". | 6757 * ":open" simulation: for now just work like ":visual". |
6758 */ | |
6759 static void | |
6760 ex_open(eap) | |
6761 exarg_T *eap; | |
6762 { | |
6763 regmatch_T regmatch; | |
6764 char_u *p; | |
6765 | |
6766 curwin->w_cursor.lnum = eap->line2; | |
6767 beginline(BL_SOL | BL_FIX); | |
6768 if (*eap->arg == '/') | |
6769 { | |
6770 /* ":open /pattern/": put cursor in column found with pattern */ | |
6771 ++eap->arg; | |
6772 p = skip_regexp(eap->arg, '/', p_magic, NULL); | |
6773 *p = NUL; | |
6774 regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0); | |
6775 if (regmatch.regprog != NULL) | |
6776 { | |
6777 regmatch.rm_ic = p_ic; | |
6778 p = ml_get_curline(); | |
6779 if (vim_regexec(®match, p, (colnr_T)0)) | |
6780 curwin->w_cursor.col = regmatch.startp[0] - p; | |
6781 else | |
6782 EMSG(_(e_nomatch)); | |
6783 vim_free(regmatch.regprog); | |
6784 } | |
6785 /* Move to the NUL, ignore any other arguments. */ | |
6786 eap->arg += STRLEN(eap->arg); | |
6787 } | |
6788 check_cursor(); | |
6789 | |
6790 eap->cmdidx = CMD_visual; | |
6791 do_exedit(eap, NULL); | |
6792 } | |
6793 | |
6794 /* | |
6795 * ":edit", ":badd", ":visual". | |
6693 */ | 6796 */ |
6694 static void | 6797 static void |
6695 ex_edit(eap) | 6798 ex_edit(eap) |
6696 exarg_T *eap; | 6799 exarg_T *eap; |
6697 { | 6800 { |
6709 { | 6812 { |
6710 int n; | 6813 int n; |
6711 #ifdef FEAT_WINDOWS | 6814 #ifdef FEAT_WINDOWS |
6712 int need_hide; | 6815 int need_hide; |
6713 #endif | 6816 #endif |
6817 int exmode_was = exmode_active; | |
6714 | 6818 |
6715 /* | 6819 /* |
6716 * ":vi" command ends Ex mode. | 6820 * ":vi" command ends Ex mode. |
6717 */ | 6821 */ |
6718 if (exmode_active && (eap->cmdidx == CMD_visual | 6822 if (exmode_active && (eap->cmdidx == CMD_visual |
6719 || eap->cmdidx == CMD_view)) | 6823 || eap->cmdidx == CMD_view)) |
6720 { | 6824 { |
6721 exmode_active = FALSE; | 6825 exmode_active = FALSE; |
6722 if (*eap->arg == NUL) | 6826 if (*eap->arg == NUL) |
6827 { | |
6828 /* Special case: ":global/pat/visual\NLvi-commands" */ | |
6829 if (global_busy) | |
6830 { | |
6831 int rd = RedrawingDisabled; | |
6832 int nwr = no_wait_return; | |
6833 int ms = msg_scroll; | |
6834 #ifdef FEAT_GUI | |
6835 int he = hold_gui_events; | |
6836 #endif | |
6837 | |
6838 if (eap->nextcmd != NULL) | |
6839 { | |
6840 stuffReadbuff(eap->nextcmd); | |
6841 eap->nextcmd = NULL; | |
6842 } | |
6843 | |
6844 if (exmode_was != EXMODE_VIM) | |
6845 settmode(TMODE_RAW); | |
6846 RedrawingDisabled = 0; | |
6847 no_wait_return = 0; | |
6848 need_wait_return = FALSE; | |
6849 msg_scroll = 0; | |
6850 #ifdef FEAT_GUI | |
6851 hold_gui_events = 0; | |
6852 #endif | |
6853 must_redraw = CLEAR; | |
6854 | |
6855 main_loop(FALSE, TRUE); | |
6856 | |
6857 RedrawingDisabled = rd; | |
6858 no_wait_return = nwr; | |
6859 msg_scroll = ms; | |
6860 #ifdef FEAT_GUI | |
6861 hold_gui_events = he; | |
6862 #endif | |
6863 } | |
6723 return; | 6864 return; |
6865 } | |
6724 } | 6866 } |
6725 | 6867 |
6726 if ((eap->cmdidx == CMD_new | 6868 if ((eap->cmdidx == CMD_new |
6727 #ifdef FEAT_VERTSPLIT | 6869 #ifdef FEAT_VERTSPLIT |
6728 || eap->cmdidx == CMD_vnew | 6870 || eap->cmdidx == CMD_vnew |
6959 | 7101 |
6960 static void | 7102 static void |
6961 ex_read(eap) | 7103 ex_read(eap) |
6962 exarg_T *eap; | 7104 exarg_T *eap; |
6963 { | 7105 { |
6964 int i; | 7106 int i; |
7107 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | |
7108 linenr_T lnum; | |
6965 | 7109 |
6966 if (eap->usefilter) /* :r!cmd */ | 7110 if (eap->usefilter) /* :r!cmd */ |
6967 do_bang(1, eap, FALSE, FALSE, TRUE); | 7111 do_bang(1, eap, FALSE, FALSE, TRUE); |
6968 else | 7112 else |
6969 { | 7113 { |
7009 if (!aborting()) | 7153 if (!aborting()) |
7010 #endif | 7154 #endif |
7011 EMSG2(_(e_notopen), eap->arg); | 7155 EMSG2(_(e_notopen), eap->arg); |
7012 } | 7156 } |
7013 else | 7157 else |
7158 { | |
7159 if (empty && exmode_active) | |
7160 { | |
7161 /* Delete the empty line that remains. Historically ex does | |
7162 * this but vi doesn't. */ | |
7163 if (eap->line2 == 0) | |
7164 lnum = curbuf->b_ml.ml_line_count; | |
7165 else | |
7166 lnum = 1; | |
7167 if (*ml_get(lnum) == NUL) | |
7168 { | |
7169 ml_delete(lnum, FALSE); | |
7170 deleted_lines_mark(lnum, 1L); | |
7171 if (curwin->w_cursor.lnum >= lnum) | |
7172 --curwin->w_cursor.lnum; | |
7173 } | |
7174 } | |
7014 redraw_curbuf_later(VALID); | 7175 redraw_curbuf_later(VALID); |
7176 } | |
7015 } | 7177 } |
7016 } | 7178 } |
7017 | 7179 |
7018 /* | 7180 /* |
7019 * ":cd", ":lcd", ":chdir" and ":lchdir". | 7181 * ":cd", ":lcd", ":chdir" and ":lchdir". |
7032 if (*new_dir == NUL) | 7194 if (*new_dir == NUL) |
7033 ex_pwd(NULL); | 7195 ex_pwd(NULL); |
7034 else | 7196 else |
7035 #endif | 7197 #endif |
7036 { | 7198 { |
7199 if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged() | |
7200 && !eap->forceit) | |
7201 { | |
7202 EMSG(_("E747: Cannot change directory, buffer is modifed (add ! to override)")); | |
7203 return; | |
7204 } | |
7205 | |
7037 /* ":cd -": Change to previous directory */ | 7206 /* ":cd -": Change to previous directory */ |
7038 if (STRCMP(new_dir, "-") == 0) | 7207 if (STRCMP(new_dir, "-") == 0) |
7039 { | 7208 { |
7040 if (prev_dir == NULL) | 7209 if (prev_dir == NULL) |
7041 { | 7210 { |
7130 static void | 7299 static void |
7131 ex_equal(eap) | 7300 ex_equal(eap) |
7132 exarg_T *eap; | 7301 exarg_T *eap; |
7133 { | 7302 { |
7134 smsg((char_u *)"%ld", (long)eap->line2); | 7303 smsg((char_u *)"%ld", (long)eap->line2); |
7304 ex_may_print(eap); | |
7135 } | 7305 } |
7136 | 7306 |
7137 static void | 7307 static void |
7138 ex_sleep(eap) | 7308 ex_sleep(eap) |
7139 exarg_T *eap; | 7309 exarg_T *eap; |
7359 break; | 7529 break; |
7360 } | 7530 } |
7361 #ifdef FEAT_VIRTUALEDIT | 7531 #ifdef FEAT_VIRTUALEDIT |
7362 virtual_op = MAYBE; | 7532 virtual_op = MAYBE; |
7363 #endif | 7533 #endif |
7534 ex_may_print(eap); | |
7364 } | 7535 } |
7365 | 7536 |
7366 /* | 7537 /* |
7367 * ":put". | 7538 * ":put". |
7368 */ | 7539 */ |
7375 { | 7546 { |
7376 eap->line2 = 1; | 7547 eap->line2 = 1; |
7377 eap->forceit = TRUE; | 7548 eap->forceit = TRUE; |
7378 } | 7549 } |
7379 curwin->w_cursor.lnum = eap->line2; | 7550 curwin->w_cursor.lnum = eap->line2; |
7380 do_put(eap->regname, eap->forceit ? BACKWARD : FORWARD, 1L, PUT_LINE); | 7551 do_put(eap->regname, eap->forceit ? BACKWARD : FORWARD, 1L, |
7552 PUT_LINE|PUT_CURSLINE); | |
7381 } | 7553 } |
7382 | 7554 |
7383 /* | 7555 /* |
7384 * Handle ":copy" and ":move". | 7556 * Handle ":copy" and ":move". |
7385 */ | 7557 */ |
7393 if (eap->arg == NULL) /* error detected */ | 7565 if (eap->arg == NULL) /* error detected */ |
7394 { | 7566 { |
7395 eap->nextcmd = NULL; | 7567 eap->nextcmd = NULL; |
7396 return; | 7568 return; |
7397 } | 7569 } |
7570 get_flags(eap); | |
7398 | 7571 |
7399 /* | 7572 /* |
7400 * move or copy lines from 'eap->line1'-'eap->line2' to below line 'n' | 7573 * move or copy lines from 'eap->line1'-'eap->line2' to below line 'n' |
7401 */ | 7574 */ |
7402 if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count) | 7575 if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count) |
7412 } | 7585 } |
7413 else | 7586 else |
7414 ex_copy(eap->line1, eap->line2, n); | 7587 ex_copy(eap->line1, eap->line2, n); |
7415 u_clearline(); | 7588 u_clearline(); |
7416 beginline(BL_SOL | BL_FIX); | 7589 beginline(BL_SOL | BL_FIX); |
7590 ex_may_print(eap); | |
7591 } | |
7592 | |
7593 /* | |
7594 * Print the current line if flags were given to the Ex command. | |
7595 */ | |
7596 static void | |
7597 ex_may_print(eap) | |
7598 exarg_T *eap; | |
7599 { | |
7600 if (eap->flags != 0) | |
7601 { | |
7602 print_line(curwin->w_cursor.lnum, (eap->flags & EXFLAG_NR), | |
7603 (eap->flags & EXFLAG_LIST)); | |
7604 ex_no_reprint = TRUE; | |
7605 } | |
7417 } | 7606 } |
7418 | 7607 |
7419 /* | 7608 /* |
7420 * ":smagic" and ":snomagic". | 7609 * ":smagic" and ":snomagic". |
7421 */ | 7610 */ |
7449 } | 7638 } |
7450 ++eap->line2; | 7639 ++eap->line2; |
7451 } | 7640 } |
7452 do_do_join(eap->line2 - eap->line1 + 1, !eap->forceit); | 7641 do_do_join(eap->line2 - eap->line1 + 1, !eap->forceit); |
7453 beginline(BL_WHITE | BL_FIX); | 7642 beginline(BL_WHITE | BL_FIX); |
7643 ex_may_print(eap); | |
7454 } | 7644 } |
7455 | 7645 |
7456 /* | 7646 /* |
7457 * ":[addr]@r" or ":[addr]*r": execute register | 7647 * ":[addr]@r" or ":[addr]*r": execute register |
7458 */ | 7648 */ |
7472 c = *eap->arg; | 7662 c = *eap->arg; |
7473 if (c == NUL || (c == '*' && *eap->cmd == '*')) | 7663 if (c == NUL || (c == '*' && *eap->cmd == '*')) |
7474 c = '@'; | 7664 c = '@'; |
7475 /* put the register in mapbuf */ | 7665 /* put the register in mapbuf */ |
7476 if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL) == FAIL) | 7666 if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL) == FAIL) |
7667 { | |
7477 beep_flush(); | 7668 beep_flush(); |
7669 } | |
7478 else | 7670 else |
7479 { | 7671 { |
7480 int save_efr = exec_from_reg; | 7672 int save_efr = exec_from_reg; |
7481 | 7673 |
7482 exec_from_reg = TRUE; | 7674 exec_from_reg = TRUE; |
7600 || redir_reg == '"')) | 7792 || redir_reg == '"')) |
7601 { | 7793 { |
7602 /* make register empty */ | 7794 /* make register empty */ |
7603 write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); | 7795 write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); |
7604 } | 7796 } |
7605 if (*arg != NUL) | 7797 } |
7606 EMSG2(_(e_invarg2), eap->arg); | 7798 if (*arg != NUL) |
7799 { | |
7800 EMSG2(_(e_invarg2), eap->arg); | |
7801 redir_reg = 0; | |
7802 } | |
7803 } | |
7804 else if (*arg == '=' && arg[1] == '>') | |
7805 { | |
7806 int append; | |
7807 | |
7808 /* redirect to a variable */ | |
7809 close_redir(); | |
7810 arg += 2; | |
7811 | |
7812 if (*arg == '>') | |
7813 { | |
7814 ++arg; | |
7815 append = TRUE; | |
7607 } | 7816 } |
7608 else | 7817 else |
7609 EMSG2(_(e_invarg2), eap->arg); | 7818 append = FALSE; |
7819 | |
7820 if (var_redir_start(skipwhite(arg), append) == OK) | |
7821 redir_vname = 1; | |
7610 } | 7822 } |
7611 #endif | 7823 #endif |
7612 | 7824 |
7613 /* TODO: redirect to a buffer */ | 7825 /* TODO: redirect to a buffer */ |
7614 | |
7615 /* TODO: redirect to an internal variable */ | |
7616 | 7826 |
7617 else | 7827 else |
7618 EMSG2(_(e_invarg2), eap->arg); | 7828 EMSG2(_(e_invarg2), eap->arg); |
7619 } | 7829 } |
7620 } | 7830 } |
7688 fclose(redir_fd); | 7898 fclose(redir_fd); |
7689 redir_fd = NULL; | 7899 redir_fd = NULL; |
7690 } | 7900 } |
7691 #ifdef FEAT_EVAL | 7901 #ifdef FEAT_EVAL |
7692 redir_reg = 0; | 7902 redir_reg = 0; |
7903 if (redir_vname) | |
7904 { | |
7905 var_redir_stop(); | |
7906 redir_vname = 0; | |
7907 } | |
7693 #endif | 7908 #endif |
7694 } | 7909 } |
7695 | 7910 |
7696 #if defined(FEAT_SESSION) && defined(USE_CRNL) | 7911 #if defined(FEAT_SESSION) && defined(USE_CRNL) |
7697 # define MKSESSION_NL | 7912 # define MKSESSION_NL |
7772 #endif | 7987 #endif |
7773 | 7988 |
7774 #if defined(FEAT_SESSION) && defined(vim_mkdir) | 7989 #if defined(FEAT_SESSION) && defined(vim_mkdir) |
7775 /* When using 'viewdir' may have to create the directory. */ | 7990 /* When using 'viewdir' may have to create the directory. */ |
7776 if (using_vdir && !mch_isdir(p_vdir)) | 7991 if (using_vdir && !mch_isdir(p_vdir)) |
7777 if (vim_mkdir(p_vdir, 0755) != 0) | 7992 vim_mkdir_emsg(p_vdir, 0755); |
7778 EMSG2(_("E739: Cannot create directory: %s"), p_vdir); | |
7779 #endif | 7993 #endif |
7780 | 7994 |
7781 fd = open_exfile(fname, eap->forceit, WRITEBIN); | 7995 fd = open_exfile(fname, eap->forceit, WRITEBIN); |
7782 if (fd != NULL) | 7996 if (fd != NULL) |
7783 { | 7997 { |
7890 #endif | 8104 #endif |
7891 #ifdef FEAT_SESSION | 8105 #ifdef FEAT_SESSION |
7892 vim_free(viewFile); | 8106 vim_free(viewFile); |
7893 #endif | 8107 #endif |
7894 } | 8108 } |
8109 | |
8110 #if ((defined(FEAT_SESSION) || defined(FEAT_EVAL)) && defined(vim_mkdir)) \ | |
8111 || defined(PROTO) | |
8112 int | |
8113 vim_mkdir_emsg(name, prot) | |
8114 char_u *name; | |
8115 int prot; | |
8116 { | |
8117 if (vim_mkdir(name, prot) != 0) | |
8118 { | |
8119 EMSG2(_("E739: Cannot create directory: %s"), name); | |
8120 return FAIL; | |
8121 } | |
8122 return OK; | |
8123 } | |
8124 #endif | |
7895 | 8125 |
7896 /* | 8126 /* |
7897 * Open a file for writing for an Ex command, with some checks. | 8127 * Open a file for writing for an Ex command, with some checks. |
7898 * Return file descriptor, or NULL on failure. | 8128 * Return file descriptor, or NULL on failure. |
7899 */ | 8129 */ |