Mercurial > vim
comparison src/ex_docmd.c @ 18779:8f05b3cf8557 v8.1.2379
patch 8.1.2379: using old C style comments
Commit: https://github.com/vim/vim/commit/217e1b8359447f5550dcb0d1ee43380a90c253c5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 21:41:28 2019 +0100
patch 8.1.2379: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 21:45:04 +0100 |
parents | 49b78d6465e5 |
children | b77ef4b8af7c |
comparison
equal
deleted
inserted
replaced
18778:2182f82b04e4 | 18779:8f05b3cf8557 |
---|---|
21 | 21 |
22 #ifdef FEAT_EVAL | 22 #ifdef FEAT_EVAL |
23 static char_u *do_one_cmd(char_u **, int, struct condstack *, char_u *(*fgetline)(int, void *, int, int), void *cookie); | 23 static char_u *do_one_cmd(char_u **, int, struct condstack *, char_u *(*fgetline)(int, void *, int, int), void *cookie); |
24 #else | 24 #else |
25 static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie); | 25 static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie); |
26 static int if_level = 0; /* depth in :if */ | 26 static int if_level = 0; // depth in :if |
27 #endif | 27 #endif |
28 static void free_cmdmod(void); | 28 static void free_cmdmod(void); |
29 static void append_command(char_u *cmd); | 29 static void append_command(char_u *cmd); |
30 static char_u *find_command(exarg_T *eap, int *full); | 30 static char_u *find_command(exarg_T *eap, int *full); |
31 | 31 |
381 | 381 |
382 static char_u dollar_command[2] = {'$', 0}; | 382 static char_u dollar_command[2] = {'$', 0}; |
383 | 383 |
384 | 384 |
385 #ifdef FEAT_EVAL | 385 #ifdef FEAT_EVAL |
386 /* Struct for storing a line inside a while/for loop */ | 386 // Struct for storing a line inside a while/for loop |
387 typedef struct | 387 typedef struct |
388 { | 388 { |
389 char_u *line; /* command line */ | 389 char_u *line; // command line |
390 linenr_T lnum; /* sourcing_lnum of the line */ | 390 linenr_T lnum; // sourcing_lnum of the line |
391 } wcmd_T; | 391 } wcmd_T; |
392 | 392 |
393 /* | 393 /* |
394 * Structure used to store info for line position in a while or for loop. | 394 * Structure used to store info for line position in a while or for loop. |
395 * This is required, because do_one_cmd() may invoke ex_function(), which | 395 * This is required, because do_one_cmd() may invoke ex_function(), which |
396 * reads more lines that may come from the while/for loop. | 396 * reads more lines that may come from the while/for loop. |
397 */ | 397 */ |
398 struct loop_cookie | 398 struct loop_cookie |
399 { | 399 { |
400 garray_T *lines_gap; /* growarray with line info */ | 400 garray_T *lines_gap; // growarray with line info |
401 int current_line; /* last read line from growarray */ | 401 int current_line; // last read line from growarray |
402 int repeating; /* TRUE when looping a second time */ | 402 int repeating; // TRUE when looping a second time |
403 /* When "repeating" is FALSE use "getline" and "cookie" to get lines */ | 403 // When "repeating" is FALSE use "getline" and "cookie" to get lines |
404 char_u *(*getline)(int, void *, int, int); | 404 char_u *(*getline)(int, void *, int, int); |
405 void *cookie; | 405 void *cookie; |
406 }; | 406 }; |
407 | 407 |
408 static char_u *get_loop_line(int c, void *cookie, int indent, int do_concat); | 408 static char_u *get_loop_line(int c, void *cookie, int indent, int do_concat); |
409 static int store_loop_line(garray_T *gap, char_u *line); | 409 static int store_loop_line(garray_T *gap, char_u *line); |
410 static void free_cmdlines(garray_T *gap); | 410 static void free_cmdlines(garray_T *gap); |
411 | 411 |
412 /* Struct to save a few things while debugging. Used in do_cmdline() only. */ | 412 // Struct to save a few things while debugging. Used in do_cmdline() only. |
413 struct dbg_stuff | 413 struct dbg_stuff |
414 { | 414 { |
415 int trylevel; | 415 int trylevel; |
416 int force_abort; | 416 int force_abort; |
417 except_T *caught_stack; | 417 except_T *caught_stack; |
432 dsp->force_abort = force_abort; force_abort = FALSE; | 432 dsp->force_abort = force_abort; force_abort = FALSE; |
433 dsp->caught_stack = caught_stack; caught_stack = NULL; | 433 dsp->caught_stack = caught_stack; caught_stack = NULL; |
434 dsp->vv_exception = v_exception(NULL); | 434 dsp->vv_exception = v_exception(NULL); |
435 dsp->vv_throwpoint = v_throwpoint(NULL); | 435 dsp->vv_throwpoint = v_throwpoint(NULL); |
436 | 436 |
437 /* Necessary for debugging an inactive ":catch", ":finally", ":endtry" */ | 437 // Necessary for debugging an inactive ":catch", ":finally", ":endtry" |
438 dsp->did_emsg = did_emsg; did_emsg = FALSE; | 438 dsp->did_emsg = did_emsg; did_emsg = FALSE; |
439 dsp->got_int = got_int; got_int = FALSE; | 439 dsp->got_int = got_int; got_int = FALSE; |
440 dsp->did_throw = did_throw; did_throw = FALSE; | 440 dsp->did_throw = did_throw; did_throw = FALSE; |
441 dsp->need_rethrow = need_rethrow; need_rethrow = FALSE; | 441 dsp->need_rethrow = need_rethrow; need_rethrow = FALSE; |
442 dsp->check_cstack = check_cstack; check_cstack = FALSE; | 442 dsp->check_cstack = check_cstack; check_cstack = FALSE; |
465 * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi" | 465 * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi" |
466 * command is given. | 466 * command is given. |
467 */ | 467 */ |
468 void | 468 void |
469 do_exmode( | 469 do_exmode( |
470 int improved) /* TRUE for "improved Ex" mode */ | 470 int improved) // TRUE for "improved Ex" mode |
471 { | 471 { |
472 int save_msg_scroll; | 472 int save_msg_scroll; |
473 int prev_msg_row; | 473 int prev_msg_row; |
474 linenr_T prev_line; | 474 linenr_T prev_line; |
475 varnumber_T changedtick; | 475 varnumber_T changedtick; |
478 exmode_active = EXMODE_VIM; | 478 exmode_active = EXMODE_VIM; |
479 else | 479 else |
480 exmode_active = EXMODE_NORMAL; | 480 exmode_active = EXMODE_NORMAL; |
481 State = NORMAL; | 481 State = NORMAL; |
482 | 482 |
483 /* When using ":global /pat/ visual" and then "Q" we return to continue | 483 // When using ":global /pat/ visual" and then "Q" we return to continue |
484 * the :global command. */ | 484 // the :global command. |
485 if (global_busy) | 485 if (global_busy) |
486 return; | 486 return; |
487 | 487 |
488 save_msg_scroll = msg_scroll; | 488 save_msg_scroll = msg_scroll; |
489 ++RedrawingDisabled; /* don't redisplay the window */ | 489 ++RedrawingDisabled; // don't redisplay the window |
490 ++no_wait_return; /* don't wait for return */ | 490 ++no_wait_return; // don't wait for return |
491 #ifdef FEAT_GUI | 491 #ifdef FEAT_GUI |
492 /* Ignore scrollbar and mouse events in Ex mode */ | 492 // Ignore scrollbar and mouse events in Ex mode |
493 ++hold_gui_events; | 493 ++hold_gui_events; |
494 #endif | 494 #endif |
495 | 495 |
496 msg(_("Entering Ex mode. Type \"visual\" to go to Normal mode.")); | 496 msg(_("Entering Ex mode. Type \"visual\" to go to Normal mode.")); |
497 while (exmode_active) | 497 while (exmode_active) |
498 { | 498 { |
499 /* Check for a ":normal" command and no more characters left. */ | 499 // Check for a ":normal" command and no more characters left. |
500 if (ex_normal_busy > 0 && typebuf.tb_len == 0) | 500 if (ex_normal_busy > 0 && typebuf.tb_len == 0) |
501 { | 501 { |
502 exmode_active = FALSE; | 502 exmode_active = FALSE; |
503 break; | 503 break; |
504 } | 504 } |
525 emsg(_(e_emptybuf)); | 525 emsg(_(e_emptybuf)); |
526 else | 526 else |
527 { | 527 { |
528 if (ex_pressedreturn) | 528 if (ex_pressedreturn) |
529 { | 529 { |
530 /* go up one line, to overwrite the ":<CR>" line, so the | 530 // go up one line, to overwrite the ":<CR>" line, so the |
531 * output doesn't contain empty lines. */ | 531 // output doesn't contain empty lines. |
532 msg_row = prev_msg_row; | 532 msg_row = prev_msg_row; |
533 if (prev_msg_row == Rows - 1) | 533 if (prev_msg_row == Rows - 1) |
534 msg_row--; | 534 msg_row--; |
535 } | 535 } |
536 msg_col = 0; | 536 msg_col = 0; |
537 print_line_no_prefix(curwin->w_cursor.lnum, FALSE, FALSE); | 537 print_line_no_prefix(curwin->w_cursor.lnum, FALSE, FALSE); |
538 msg_clr_eos(); | 538 msg_clr_eos(); |
539 } | 539 } |
540 } | 540 } |
541 else if (ex_pressedreturn && !ex_no_reprint) /* must be at EOF */ | 541 else if (ex_pressedreturn && !ex_no_reprint) // must be at EOF |
542 { | 542 { |
543 if (curbuf->b_ml.ml_flags & ML_EMPTY) | 543 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
544 emsg(_(e_emptybuf)); | 544 emsg(_(e_emptybuf)); |
545 else | 545 else |
546 emsg(_("E501: At end-of-file")); | 546 emsg(_("E501: At end-of-file")); |
609 */ | 609 */ |
610 int | 610 int |
611 do_cmdline( | 611 do_cmdline( |
612 char_u *cmdline, | 612 char_u *cmdline, |
613 char_u *(*fgetline)(int, void *, int, int), | 613 char_u *(*fgetline)(int, void *, int, int), |
614 void *cookie, /* argument for fgetline() */ | 614 void *cookie, // argument for fgetline() |
615 int flags) | 615 int flags) |
616 { | 616 { |
617 char_u *next_cmdline; /* next cmd to execute */ | 617 char_u *next_cmdline; // next cmd to execute |
618 char_u *cmdline_copy = NULL; /* copy of cmd line */ | 618 char_u *cmdline_copy = NULL; // copy of cmd line |
619 int used_getline = FALSE; /* used "fgetline" to obtain command */ | 619 int used_getline = FALSE; // used "fgetline" to obtain command |
620 static int recursive = 0; /* recursive depth */ | 620 static int recursive = 0; // recursive depth |
621 int msg_didout_before_start = 0; | 621 int msg_didout_before_start = 0; |
622 int count = 0; /* line number count */ | 622 int count = 0; // line number count |
623 int did_inc = FALSE; /* incremented RedrawingDisabled */ | 623 int did_inc = FALSE; // incremented RedrawingDisabled |
624 int retval = OK; | 624 int retval = OK; |
625 #ifdef FEAT_EVAL | 625 #ifdef FEAT_EVAL |
626 struct condstack cstack; /* conditional stack */ | 626 struct condstack cstack; // conditional stack |
627 garray_T lines_ga; /* keep lines for ":while"/":for" */ | 627 garray_T lines_ga; // keep lines for ":while"/":for" |
628 int current_line = 0; /* active line in lines_ga */ | 628 int current_line = 0; // active line in lines_ga |
629 char_u *fname = NULL; /* function or script name */ | 629 char_u *fname = NULL; // function or script name |
630 linenr_T *breakpoint = NULL; /* ptr to breakpoint field in cookie */ | 630 linenr_T *breakpoint = NULL; // ptr to breakpoint field in cookie |
631 int *dbg_tick = NULL; /* ptr to dbg_tick field in cookie */ | 631 int *dbg_tick = NULL; // ptr to dbg_tick field in cookie |
632 struct dbg_stuff debug_saved; /* saved things for debug mode */ | 632 struct dbg_stuff debug_saved; // saved things for debug mode |
633 int initial_trylevel; | 633 int initial_trylevel; |
634 struct msglist **saved_msg_list = NULL; | 634 struct msglist **saved_msg_list = NULL; |
635 struct msglist *private_msg_list; | 635 struct msglist *private_msg_list; |
636 | 636 |
637 /* "fgetline" and "cookie" passed to do_one_cmd() */ | 637 // "fgetline" and "cookie" passed to do_one_cmd() |
638 char_u *(*cmd_getline)(int, void *, int, int); | 638 char_u *(*cmd_getline)(int, void *, int, int); |
639 void *cmd_cookie; | 639 void *cmd_cookie; |
640 struct loop_cookie cmd_loop_cookie; | 640 struct loop_cookie cmd_loop_cookie; |
641 void *real_cookie; | 641 void *real_cookie; |
642 int getline_is_func; | 642 int getline_is_func; |
643 #else | 643 #else |
644 # define cmd_getline fgetline | 644 # define cmd_getline fgetline |
645 # define cmd_cookie cookie | 645 # define cmd_cookie cookie |
646 #endif | 646 #endif |
647 static int call_depth = 0; /* recursiveness */ | 647 static int call_depth = 0; // recursiveness |
648 | 648 |
649 #ifdef FEAT_EVAL | 649 #ifdef FEAT_EVAL |
650 /* For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory | 650 // For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory |
651 * location for storing error messages to be converted to an exception. | 651 // location for storing error messages to be converted to an exception. |
652 * This ensures that the do_errthrow() call in do_one_cmd() does not | 652 // This ensures that the do_errthrow() call in do_one_cmd() does not |
653 * combine the messages stored by an earlier invocation of do_one_cmd() | 653 // combine the messages stored by an earlier invocation of do_one_cmd() |
654 * with the command name of the later one. This would happen when | 654 // with the command name of the later one. This would happen when |
655 * BufWritePost autocommands are executed after a write error. */ | 655 // BufWritePost autocommands are executed after a write error. |
656 saved_msg_list = msg_list; | 656 saved_msg_list = msg_list; |
657 msg_list = &private_msg_list; | 657 msg_list = &private_msg_list; |
658 private_msg_list = NULL; | 658 private_msg_list = NULL; |
659 #endif | 659 #endif |
660 | 660 |
661 /* It's possible to create an endless loop with ":execute", catch that | 661 // It's possible to create an endless loop with ":execute", catch that |
662 * here. The value of 200 allows nested function calls, ":source", etc. | 662 // here. The value of 200 allows nested function calls, ":source", etc. |
663 * Allow 200 or 'maxfuncdepth', whatever is larger. */ | 663 // Allow 200 or 'maxfuncdepth', whatever is larger. |
664 if (call_depth >= 200 | 664 if (call_depth >= 200 |
665 #ifdef FEAT_EVAL | 665 #ifdef FEAT_EVAL |
666 && call_depth >= p_mfd | 666 && call_depth >= p_mfd |
667 #endif | 667 #endif |
668 ) | 668 ) |
669 { | 669 { |
670 emsg(_("E169: Command too recursive")); | 670 emsg(_("E169: Command too recursive")); |
671 #ifdef FEAT_EVAL | 671 #ifdef FEAT_EVAL |
672 /* When converting to an exception, we do not include the command name | 672 // When converting to an exception, we do not include the command name |
673 * since this is not an error of the specific command. */ | 673 // since this is not an error of the specific command. |
674 do_errthrow((struct condstack *)NULL, (char_u *)NULL); | 674 do_errthrow((struct condstack *)NULL, (char_u *)NULL); |
675 msg_list = saved_msg_list; | 675 msg_list = saved_msg_list; |
676 #endif | 676 #endif |
677 return FAIL; | 677 return FAIL; |
678 } | 678 } |
686 cstack.cs_lflags = 0; | 686 cstack.cs_lflags = 0; |
687 ga_init2(&lines_ga, (int)sizeof(wcmd_T), 10); | 687 ga_init2(&lines_ga, (int)sizeof(wcmd_T), 10); |
688 | 688 |
689 real_cookie = getline_cookie(fgetline, cookie); | 689 real_cookie = getline_cookie(fgetline, cookie); |
690 | 690 |
691 /* Inside a function use a higher nesting level. */ | 691 // Inside a function use a higher nesting level. |
692 getline_is_func = getline_equal(fgetline, cookie, get_func_line); | 692 getline_is_func = getline_equal(fgetline, cookie, get_func_line); |
693 if (getline_is_func && ex_nesting_level == func_level(real_cookie)) | 693 if (getline_is_func && ex_nesting_level == func_level(real_cookie)) |
694 ++ex_nesting_level; | 694 ++ex_nesting_level; |
695 | 695 |
696 /* Get the function or script name and the address where the next breakpoint | 696 // Get the function or script name and the address where the next breakpoint |
697 * line and the debug tick for a function or script are stored. */ | 697 // line and the debug tick for a function or script are stored. |
698 if (getline_is_func) | 698 if (getline_is_func) |
699 { | 699 { |
700 fname = func_name(real_cookie); | 700 fname = func_name(real_cookie); |
701 breakpoint = func_breakpoint(real_cookie); | 701 breakpoint = func_breakpoint(real_cookie); |
702 dbg_tick = func_dbg_tick(real_cookie); | 702 dbg_tick = func_dbg_tick(real_cookie); |
760 { | 760 { |
761 #ifdef FEAT_EVAL | 761 #ifdef FEAT_EVAL |
762 getline_is_func = getline_equal(fgetline, cookie, get_func_line); | 762 getline_is_func = getline_equal(fgetline, cookie, get_func_line); |
763 #endif | 763 #endif |
764 | 764 |
765 /* stop skipping cmds for an error msg after all endif/while/for */ | 765 // stop skipping cmds for an error msg after all endif/while/for |
766 if (next_cmdline == NULL | 766 if (next_cmdline == NULL |
767 #ifdef FEAT_EVAL | 767 #ifdef FEAT_EVAL |
768 && !force_abort | 768 && !force_abort |
769 && cstack.cs_idx < 0 | 769 && cstack.cs_idx < 0 |
770 && !(getline_is_func && func_has_abort(real_cookie)) | 770 && !(getline_is_func && func_has_abort(real_cookie)) |
777 * 2. If no line given: Get an allocated line with fgetline(). | 777 * 2. If no line given: Get an allocated line with fgetline(). |
778 * 3. If a line is given: Make a copy, so we can mess with it. | 778 * 3. If a line is given: Make a copy, so we can mess with it. |
779 */ | 779 */ |
780 | 780 |
781 #ifdef FEAT_EVAL | 781 #ifdef FEAT_EVAL |
782 /* 1. If repeating, get a previous line from lines_ga. */ | 782 // 1. If repeating, get a previous line from lines_ga. |
783 if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) | 783 if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) |
784 { | 784 { |
785 /* Each '|' separated command is stored separately in lines_ga, to | 785 // Each '|' separated command is stored separately in lines_ga, to |
786 * be able to jump to it. Don't use next_cmdline now. */ | 786 // be able to jump to it. Don't use next_cmdline now. |
787 VIM_CLEAR(cmdline_copy); | 787 VIM_CLEAR(cmdline_copy); |
788 | 788 |
789 /* Check if a function has returned or, unless it has an unclosed | 789 // Check if a function has returned or, unless it has an unclosed |
790 * try conditional, aborted. */ | 790 // try conditional, aborted. |
791 if (getline_is_func) | 791 if (getline_is_func) |
792 { | 792 { |
793 # ifdef FEAT_PROFILE | 793 # ifdef FEAT_PROFILE |
794 if (do_profiling == PROF_YES) | 794 if (do_profiling == PROF_YES) |
795 func_line_end(real_cookie); | 795 func_line_end(real_cookie); |
804 else if (do_profiling == PROF_YES | 804 else if (do_profiling == PROF_YES |
805 && getline_equal(fgetline, cookie, getsourceline)) | 805 && getline_equal(fgetline, cookie, getsourceline)) |
806 script_line_end(); | 806 script_line_end(); |
807 #endif | 807 #endif |
808 | 808 |
809 /* Check if a sourced file hit a ":finish" command. */ | 809 // Check if a sourced file hit a ":finish" command. |
810 if (source_finished(fgetline, cookie)) | 810 if (source_finished(fgetline, cookie)) |
811 { | 811 { |
812 retval = FAIL; | 812 retval = FAIL; |
813 break; | 813 break; |
814 } | 814 } |
815 | 815 |
816 /* If breakpoints have been added/deleted need to check for it. */ | 816 // If breakpoints have been added/deleted need to check for it. |
817 if (breakpoint != NULL && dbg_tick != NULL | 817 if (breakpoint != NULL && dbg_tick != NULL |
818 && *dbg_tick != debug_tick) | 818 && *dbg_tick != debug_tick) |
819 { | 819 { |
820 *breakpoint = dbg_find_breakpoint( | 820 *breakpoint = dbg_find_breakpoint( |
821 getline_equal(fgetline, cookie, getsourceline), | 821 getline_equal(fgetline, cookie, getsourceline), |
824 } | 824 } |
825 | 825 |
826 next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line; | 826 next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line; |
827 sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum; | 827 sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum; |
828 | 828 |
829 /* Did we encounter a breakpoint? */ | 829 // Did we encounter a breakpoint? |
830 if (breakpoint != NULL && *breakpoint != 0 | 830 if (breakpoint != NULL && *breakpoint != 0 |
831 && *breakpoint <= sourcing_lnum) | 831 && *breakpoint <= sourcing_lnum) |
832 { | 832 { |
833 dbg_breakpoint(fname, sourcing_lnum); | 833 dbg_breakpoint(fname, sourcing_lnum); |
834 /* Find next breakpoint. */ | 834 // Find next breakpoint. |
835 *breakpoint = dbg_find_breakpoint( | 835 *breakpoint = dbg_find_breakpoint( |
836 getline_equal(fgetline, cookie, getsourceline), | 836 getline_equal(fgetline, cookie, getsourceline), |
837 fname, sourcing_lnum); | 837 fname, sourcing_lnum); |
838 *dbg_tick = debug_tick; | 838 *dbg_tick = debug_tick; |
839 } | 839 } |
848 # endif | 848 # endif |
849 } | 849 } |
850 | 850 |
851 if (cstack.cs_looplevel > 0) | 851 if (cstack.cs_looplevel > 0) |
852 { | 852 { |
853 /* Inside a while/for loop we need to store the lines and use them | 853 // Inside a while/for loop we need to store the lines and use them |
854 * again. Pass a different "fgetline" function to do_one_cmd() | 854 // again. Pass a different "fgetline" function to do_one_cmd() |
855 * below, so that it stores lines in or reads them from | 855 // below, so that it stores lines in or reads them from |
856 * "lines_ga". Makes it possible to define a function inside a | 856 // "lines_ga". Makes it possible to define a function inside a |
857 * while/for loop. */ | 857 // while/for loop. |
858 cmd_getline = get_loop_line; | 858 cmd_getline = get_loop_line; |
859 cmd_cookie = (void *)&cmd_loop_cookie; | 859 cmd_cookie = (void *)&cmd_loop_cookie; |
860 cmd_loop_cookie.lines_gap = &lines_ga; | 860 cmd_loop_cookie.lines_gap = &lines_ga; |
861 cmd_loop_cookie.current_line = current_line; | 861 cmd_loop_cookie.current_line = current_line; |
862 cmd_loop_cookie.getline = fgetline; | 862 cmd_loop_cookie.getline = fgetline; |
868 cmd_getline = fgetline; | 868 cmd_getline = fgetline; |
869 cmd_cookie = cookie; | 869 cmd_cookie = cookie; |
870 } | 870 } |
871 #endif | 871 #endif |
872 | 872 |
873 /* 2. If no line given, get an allocated line with fgetline(). */ | 873 // 2. If no line given, get an allocated line with fgetline(). |
874 if (next_cmdline == NULL) | 874 if (next_cmdline == NULL) |
875 { | 875 { |
876 /* | 876 /* |
877 * Need to set msg_didout for the first line after an ":if", | 877 * Need to set msg_didout for the first line after an ":if", |
878 * otherwise the ":if" will be overwritten. | 878 * otherwise the ":if" will be overwritten. |
885 #else | 885 #else |
886 0 | 886 0 |
887 #endif | 887 #endif |
888 , TRUE)) == NULL) | 888 , TRUE)) == NULL) |
889 { | 889 { |
890 /* Don't call wait_return for aborted command line. The NULL | 890 // Don't call wait_return for aborted command line. The NULL |
891 * returned for the end of a sourced file or executed function | 891 // returned for the end of a sourced file or executed function |
892 * doesn't do this. */ | 892 // doesn't do this. |
893 if (KeyTyped && !(flags & DOCMD_REPEAT)) | 893 if (KeyTyped && !(flags & DOCMD_REPEAT)) |
894 need_wait_return = FALSE; | 894 need_wait_return = FALSE; |
895 retval = FAIL; | 895 retval = FAIL; |
896 break; | 896 break; |
897 } | 897 } |
908 else | 908 else |
909 repeat_cmdline = NULL; | 909 repeat_cmdline = NULL; |
910 } | 910 } |
911 } | 911 } |
912 | 912 |
913 /* 3. Make a copy of the command so we can mess with it. */ | 913 // 3. Make a copy of the command so we can mess with it. |
914 else if (cmdline_copy == NULL) | 914 else if (cmdline_copy == NULL) |
915 { | 915 { |
916 next_cmdline = vim_strsave(next_cmdline); | 916 next_cmdline = vim_strsave(next_cmdline); |
917 if (next_cmdline == NULL) | 917 if (next_cmdline == NULL) |
918 { | 918 { |
952 * +command file"). | 952 * +command file"). |
953 */ | 953 */ |
954 if (!(flags & DOCMD_NOWAIT) && !recursive) | 954 if (!(flags & DOCMD_NOWAIT) && !recursive) |
955 { | 955 { |
956 msg_didout_before_start = msg_didout; | 956 msg_didout_before_start = msg_didout; |
957 msg_didany = FALSE; /* no output yet */ | 957 msg_didany = FALSE; // no output yet |
958 msg_start(); | 958 msg_start(); |
959 msg_scroll = TRUE; /* put messages below each other */ | 959 msg_scroll = TRUE; // put messages below each other |
960 ++no_wait_return; /* don't wait for return until finished */ | 960 ++no_wait_return; // don't wait for return until finished |
961 ++RedrawingDisabled; | 961 ++RedrawingDisabled; |
962 did_inc = TRUE; | 962 did_inc = TRUE; |
963 } | 963 } |
964 } | 964 } |
965 | 965 |
979 cmd_getline, cmd_cookie); | 979 cmd_getline, cmd_cookie); |
980 --recursive; | 980 --recursive; |
981 | 981 |
982 #ifdef FEAT_EVAL | 982 #ifdef FEAT_EVAL |
983 if (cmd_cookie == (void *)&cmd_loop_cookie) | 983 if (cmd_cookie == (void *)&cmd_loop_cookie) |
984 /* Use "current_line" from "cmd_loop_cookie", it may have been | 984 // Use "current_line" from "cmd_loop_cookie", it may have been |
985 * incremented when defining a function. */ | 985 // incremented when defining a function. |
986 current_line = cmd_loop_cookie.current_line; | 986 current_line = cmd_loop_cookie.current_line; |
987 #endif | 987 #endif |
988 | 988 |
989 if (next_cmdline == NULL) | 989 if (next_cmdline == NULL) |
990 { | 990 { |
1002 new_last_cmdline = NULL; | 1002 new_last_cmdline = NULL; |
1003 } | 1003 } |
1004 } | 1004 } |
1005 else | 1005 else |
1006 { | 1006 { |
1007 /* need to copy the command after the '|' to cmdline_copy, for the | 1007 // need to copy the command after the '|' to cmdline_copy, for the |
1008 * next do_one_cmd() */ | 1008 // next do_one_cmd() |
1009 STRMOVE(cmdline_copy, next_cmdline); | 1009 STRMOVE(cmdline_copy, next_cmdline); |
1010 next_cmdline = cmdline_copy; | 1010 next_cmdline = cmdline_copy; |
1011 } | 1011 } |
1012 | 1012 |
1013 | 1013 |
1014 #ifdef FEAT_EVAL | 1014 #ifdef FEAT_EVAL |
1015 /* reset did_emsg for a function that is not aborted by an error */ | 1015 // reset did_emsg for a function that is not aborted by an error |
1016 if (did_emsg && !force_abort | 1016 if (did_emsg && !force_abort |
1017 && getline_equal(fgetline, cookie, get_func_line) | 1017 && getline_equal(fgetline, cookie, get_func_line) |
1018 && !func_has_abort(real_cookie)) | 1018 && !func_has_abort(real_cookie)) |
1019 did_emsg = FALSE; | 1019 did_emsg = FALSE; |
1020 | 1020 |
1030 */ | 1030 */ |
1031 if (cstack.cs_lflags & (CSL_HAD_CONT | CSL_HAD_ENDLOOP)) | 1031 if (cstack.cs_lflags & (CSL_HAD_CONT | CSL_HAD_ENDLOOP)) |
1032 { | 1032 { |
1033 cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP); | 1033 cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP); |
1034 | 1034 |
1035 /* Jump back to the matching ":while" or ":for". Be careful | 1035 // Jump back to the matching ":while" or ":for". Be careful |
1036 * not to use a cs_line[] from an entry that isn't a ":while" | 1036 // not to use a cs_line[] from an entry that isn't a ":while" |
1037 * or ":for": It would make "current_line" invalid and can | 1037 // or ":for": It would make "current_line" invalid and can |
1038 * cause a crash. */ | 1038 // cause a crash. |
1039 if (!did_emsg && !got_int && !did_throw | 1039 if (!did_emsg && !got_int && !did_throw |
1040 && cstack.cs_idx >= 0 | 1040 && cstack.cs_idx >= 0 |
1041 && (cstack.cs_flags[cstack.cs_idx] | 1041 && (cstack.cs_flags[cstack.cs_idx] |
1042 & (CSF_WHILE | CSF_FOR)) | 1042 & (CSF_WHILE | CSF_FOR)) |
1043 && cstack.cs_line[cstack.cs_idx] >= 0 | 1043 && cstack.cs_line[cstack.cs_idx] >= 0 |
1044 && (cstack.cs_flags[cstack.cs_idx] & CSF_ACTIVE)) | 1044 && (cstack.cs_flags[cstack.cs_idx] & CSF_ACTIVE)) |
1045 { | 1045 { |
1046 current_line = cstack.cs_line[cstack.cs_idx]; | 1046 current_line = cstack.cs_line[cstack.cs_idx]; |
1047 /* remember we jumped there */ | 1047 // remember we jumped there |
1048 cstack.cs_lflags |= CSL_HAD_LOOP; | 1048 cstack.cs_lflags |= CSL_HAD_LOOP; |
1049 line_breakcheck(); /* check if CTRL-C typed */ | 1049 line_breakcheck(); // check if CTRL-C typed |
1050 | 1050 |
1051 /* Check for the next breakpoint at or after the ":while" | 1051 // Check for the next breakpoint at or after the ":while" |
1052 * or ":for". */ | 1052 // or ":for". |
1053 if (breakpoint != NULL) | 1053 if (breakpoint != NULL) |
1054 { | 1054 { |
1055 *breakpoint = dbg_find_breakpoint( | 1055 *breakpoint = dbg_find_breakpoint( |
1056 getline_equal(fgetline, cookie, getsourceline), | 1056 getline_equal(fgetline, cookie, getsourceline), |
1057 fname, | 1057 fname, |
1059 *dbg_tick = debug_tick; | 1059 *dbg_tick = debug_tick; |
1060 } | 1060 } |
1061 } | 1061 } |
1062 else | 1062 else |
1063 { | 1063 { |
1064 /* can only get here with ":endwhile" or ":endfor" */ | 1064 // can only get here with ":endwhile" or ":endfor" |
1065 if (cstack.cs_idx >= 0) | 1065 if (cstack.cs_idx >= 0) |
1066 rewind_conditionals(&cstack, cstack.cs_idx - 1, | 1066 rewind_conditionals(&cstack, cstack.cs_idx - 1, |
1067 CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); | 1067 CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); |
1068 } | 1068 } |
1069 } | 1069 } |
1076 cstack.cs_lflags &= ~CSL_HAD_LOOP; | 1076 cstack.cs_lflags &= ~CSL_HAD_LOOP; |
1077 cstack.cs_line[cstack.cs_idx] = current_line - 1; | 1077 cstack.cs_line[cstack.cs_idx] = current_line - 1; |
1078 } | 1078 } |
1079 } | 1079 } |
1080 | 1080 |
1081 /* Check for the next breakpoint after a watchexpression */ | 1081 // Check for the next breakpoint after a watchexpression |
1082 if (breakpoint != NULL && has_watchexpr()) | 1082 if (breakpoint != NULL && has_watchexpr()) |
1083 { | 1083 { |
1084 *breakpoint = dbg_find_breakpoint(FALSE, fname, sourcing_lnum); | 1084 *breakpoint = dbg_find_breakpoint(FALSE, fname, sourcing_lnum); |
1085 *dbg_tick = debug_tick; | 1085 *dbg_tick = debug_tick; |
1086 } | 1086 } |
1114 did_throw ? (void *)current_exception : NULL); | 1114 did_throw ? (void *)current_exception : NULL); |
1115 did_emsg = got_int = did_throw = FALSE; | 1115 did_emsg = got_int = did_throw = FALSE; |
1116 cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY; | 1116 cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY; |
1117 } | 1117 } |
1118 | 1118 |
1119 /* Update global "trylevel" for recursive calls to do_cmdline() from | 1119 // Update global "trylevel" for recursive calls to do_cmdline() from |
1120 * within this loop. */ | 1120 // within this loop. |
1121 trylevel = initial_trylevel + cstack.cs_trylevel; | 1121 trylevel = initial_trylevel + cstack.cs_trylevel; |
1122 | 1122 |
1123 /* | 1123 /* |
1124 * If the outermost try conditional (across function calls and sourced | 1124 * If the outermost try conditional (across function calls and sourced |
1125 * files) is aborted because of an error, an interrupt, or an uncaught | 1125 * files) is aborted because of an error, an interrupt, or an uncaught |
1128 * the rest of the script. | 1128 * the rest of the script. |
1129 */ | 1129 */ |
1130 if (trylevel == 0 && !did_emsg && !got_int && !did_throw) | 1130 if (trylevel == 0 && !did_emsg && !got_int && !did_throw) |
1131 force_abort = FALSE; | 1131 force_abort = FALSE; |
1132 | 1132 |
1133 /* Convert an interrupt to an exception if appropriate. */ | 1133 // Convert an interrupt to an exception if appropriate. |
1134 (void)do_intthrow(&cstack); | 1134 (void)do_intthrow(&cstack); |
1135 #endif /* FEAT_EVAL */ | 1135 #endif // FEAT_EVAL |
1136 | 1136 |
1137 } | 1137 } |
1138 /* | 1138 /* |
1139 * Continue executing command lines when: | 1139 * Continue executing command lines when: |
1140 * - no CTRL-C typed, no aborting error, no exception thrown or try | 1140 * - no CTRL-C typed, no aborting error, no exception thrown or try |
1153 && cstack.cs_trylevel == 0 | 1153 && cstack.cs_trylevel == 0 |
1154 #endif | 1154 #endif |
1155 ) | 1155 ) |
1156 && !(did_emsg | 1156 && !(did_emsg |
1157 #ifdef FEAT_EVAL | 1157 #ifdef FEAT_EVAL |
1158 /* Keep going when inside try/catch, so that the error can be | 1158 // Keep going when inside try/catch, so that the error can be |
1159 * deal with, except when it is a syntax error, it may cause | 1159 // deal with, except when it is a syntax error, it may cause |
1160 * the :endtry to be missed. */ | 1160 // the :endtry to be missed. |
1161 && (cstack.cs_trylevel == 0 || did_emsg_syntax) | 1161 && (cstack.cs_trylevel == 0 || did_emsg_syntax) |
1162 #endif | 1162 #endif |
1163 && used_getline | 1163 && used_getline |
1164 && (getline_equal(fgetline, cookie, getexmodeline) | 1164 && (getline_equal(fgetline, cookie, getexmodeline) |
1165 || getline_equal(fgetline, cookie, getexline))) | 1165 || getline_equal(fgetline, cookie, getexline))) |
1207 do | 1207 do |
1208 { | 1208 { |
1209 int idx = cleanup_conditionals(&cstack, 0, TRUE); | 1209 int idx = cleanup_conditionals(&cstack, 0, TRUE); |
1210 | 1210 |
1211 if (idx >= 0) | 1211 if (idx >= 0) |
1212 --idx; /* remove try block not in its finally clause */ | 1212 --idx; // remove try block not in its finally clause |
1213 rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR, | 1213 rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR, |
1214 &cstack.cs_looplevel); | 1214 &cstack.cs_looplevel); |
1215 } | 1215 } |
1216 while (cstack.cs_idx >= 0); | 1216 while (cstack.cs_idx >= 0); |
1217 trylevel = initial_trylevel; | 1217 trylevel = initial_trylevel; |
1218 } | 1218 } |
1219 | 1219 |
1220 /* If a missing ":endtry", ":endwhile", ":endfor", or ":endif" or a memory | 1220 // If a missing ":endtry", ":endwhile", ":endfor", or ":endif" or a memory |
1221 * lack was reported above and the error message is to be converted to an | 1221 // lack was reported above and the error message is to be converted to an |
1222 * exception, do this now after rewinding the cstack. */ | 1222 // exception, do this now after rewinding the cstack. |
1223 do_errthrow(&cstack, getline_equal(fgetline, cookie, get_func_line) | 1223 do_errthrow(&cstack, getline_equal(fgetline, cookie, get_func_line) |
1224 ? (char_u *)"endfunction" : (char_u *)NULL); | 1224 ? (char_u *)"endfunction" : (char_u *)NULL); |
1225 | 1225 |
1226 if (trylevel == 0) | 1226 if (trylevel == 0) |
1227 { | 1227 { |
1264 saved_sourcing_lnum = sourcing_lnum; | 1264 saved_sourcing_lnum = sourcing_lnum; |
1265 sourcing_name = current_exception->throw_name; | 1265 sourcing_name = current_exception->throw_name; |
1266 sourcing_lnum = current_exception->throw_lnum; | 1266 sourcing_lnum = current_exception->throw_lnum; |
1267 current_exception->throw_name = NULL; | 1267 current_exception->throw_name = NULL; |
1268 | 1268 |
1269 discard_current_exception(); /* uses IObuff if 'verbose' */ | 1269 discard_current_exception(); // uses IObuff if 'verbose' |
1270 suppress_errthrow = TRUE; | 1270 suppress_errthrow = TRUE; |
1271 force_abort = TRUE; | 1271 force_abort = TRUE; |
1272 | 1272 |
1273 if (messages != NULL) | 1273 if (messages != NULL) |
1274 { | 1274 { |
1321 if (!did_throw) | 1321 if (!did_throw) |
1322 check_cstack = TRUE; | 1322 check_cstack = TRUE; |
1323 } | 1323 } |
1324 else | 1324 else |
1325 { | 1325 { |
1326 /* When leaving a function, reduce nesting level. */ | 1326 // When leaving a function, reduce nesting level. |
1327 if (getline_equal(fgetline, cookie, get_func_line)) | 1327 if (getline_equal(fgetline, cookie, get_func_line)) |
1328 --ex_nesting_level; | 1328 --ex_nesting_level; |
1329 /* | 1329 /* |
1330 * Go to debug mode when returning from a function in which we are | 1330 * Go to debug mode when returning from a function in which we are |
1331 * single-stepping. | 1331 * single-stepping. |
1344 */ | 1344 */ |
1345 if (flags & DOCMD_EXCRESET) | 1345 if (flags & DOCMD_EXCRESET) |
1346 restore_dbg_stuff(&debug_saved); | 1346 restore_dbg_stuff(&debug_saved); |
1347 | 1347 |
1348 msg_list = saved_msg_list; | 1348 msg_list = saved_msg_list; |
1349 #endif /* FEAT_EVAL */ | 1349 #endif // FEAT_EVAL |
1350 | 1350 |
1351 /* | 1351 /* |
1352 * If there was too much output to fit on the command line, ask the user to | 1352 * If there was too much output to fit on the command line, ask the user to |
1353 * hit return before redrawing the screen. With the ":global" command we do | 1353 * hit return before redrawing the screen. With the ":global" command we do |
1354 * this only once after the command is finished. | 1354 * this only once after the command is finished. |
1368 || (did_endif && KeyTyped && !did_emsg) | 1368 || (did_endif && KeyTyped && !did_emsg) |
1369 #endif | 1369 #endif |
1370 ) | 1370 ) |
1371 { | 1371 { |
1372 need_wait_return = FALSE; | 1372 need_wait_return = FALSE; |
1373 msg_didany = FALSE; /* don't wait when restarting edit */ | 1373 msg_didany = FALSE; // don't wait when restarting edit |
1374 } | 1374 } |
1375 else if (need_wait_return) | 1375 else if (need_wait_return) |
1376 { | 1376 { |
1377 /* | 1377 /* |
1378 * The msg_start() above clears msg_didout. The wait_return we do | 1378 * The msg_start() above clears msg_didout. The wait_return we do |
1383 wait_return(FALSE); | 1383 wait_return(FALSE); |
1384 } | 1384 } |
1385 } | 1385 } |
1386 | 1386 |
1387 #ifdef FEAT_EVAL | 1387 #ifdef FEAT_EVAL |
1388 did_endif = FALSE; /* in case do_cmdline used recursively */ | 1388 did_endif = FALSE; // in case do_cmdline used recursively |
1389 #else | 1389 #else |
1390 /* | 1390 /* |
1391 * Reset if_level, in case a sourced script file contains more ":if" than | 1391 * Reset if_level, in case a sourced script file contains more ":if" than |
1392 * ":endif" (could be ":if x | foo | endif"). | 1392 * ":endif" (could be ":if x | foo | endif"). |
1393 */ | 1393 */ |
1410 char_u *line; | 1410 char_u *line; |
1411 | 1411 |
1412 if (cp->current_line + 1 >= cp->lines_gap->ga_len) | 1412 if (cp->current_line + 1 >= cp->lines_gap->ga_len) |
1413 { | 1413 { |
1414 if (cp->repeating) | 1414 if (cp->repeating) |
1415 return NULL; /* trying to read past ":endwhile"/":endfor" */ | 1415 return NULL; // trying to read past ":endwhile"/":endfor" |
1416 | 1416 |
1417 /* First time inside the ":while"/":for": get line normally. */ | 1417 // First time inside the ":while"/":for": get line normally. |
1418 if (cp->getline == NULL) | 1418 if (cp->getline == NULL) |
1419 line = getcmdline(c, 0L, indent, do_concat); | 1419 line = getcmdline(c, 0L, indent, do_concat); |
1420 else | 1420 else |
1421 line = cp->getline(c, cp->cookie, indent, do_concat); | 1421 line = cp->getline(c, cp->cookie, indent, do_concat); |
1422 if (line != NULL && store_loop_line(cp->lines_gap, line) == OK) | 1422 if (line != NULL && store_loop_line(cp->lines_gap, line) == OK) |
1465 * "func". * Otherwise return TRUE when "fgetline" equals "func". | 1465 * "func". * Otherwise return TRUE when "fgetline" equals "func". |
1466 */ | 1466 */ |
1467 int | 1467 int |
1468 getline_equal( | 1468 getline_equal( |
1469 char_u *(*fgetline)(int, void *, int, int), | 1469 char_u *(*fgetline)(int, void *, int, int), |
1470 void *cookie UNUSED, /* argument for fgetline() */ | 1470 void *cookie UNUSED, // argument for fgetline() |
1471 char_u *(*func)(int, void *, int, int)) | 1471 char_u *(*func)(int, void *, int, int)) |
1472 { | 1472 { |
1473 #ifdef FEAT_EVAL | 1473 #ifdef FEAT_EVAL |
1474 char_u *(*gp)(int, void *, int, int); | 1474 char_u *(*gp)(int, void *, int, int); |
1475 struct loop_cookie *cp; | 1475 struct loop_cookie *cp; |
1476 | 1476 |
1477 /* When "fgetline" is "get_loop_line()" use the "cookie" to find the | 1477 // When "fgetline" is "get_loop_line()" use the "cookie" to find the |
1478 * function that's originally used to obtain the lines. This may be | 1478 // function that's originally used to obtain the lines. This may be |
1479 * nested several levels. */ | 1479 // nested several levels. |
1480 gp = fgetline; | 1480 gp = fgetline; |
1481 cp = (struct loop_cookie *)cookie; | 1481 cp = (struct loop_cookie *)cookie; |
1482 while (gp == get_loop_line) | 1482 while (gp == get_loop_line) |
1483 { | 1483 { |
1484 gp = cp->getline; | 1484 gp = cp->getline; |
1495 * getline function. Otherwise return "cookie". | 1495 * getline function. Otherwise return "cookie". |
1496 */ | 1496 */ |
1497 void * | 1497 void * |
1498 getline_cookie( | 1498 getline_cookie( |
1499 char_u *(*fgetline)(int, void *, int, int) UNUSED, | 1499 char_u *(*fgetline)(int, void *, int, int) UNUSED, |
1500 void *cookie) /* argument for fgetline() */ | 1500 void *cookie) // argument for fgetline() |
1501 { | 1501 { |
1502 #ifdef FEAT_EVAL | 1502 #ifdef FEAT_EVAL |
1503 char_u *(*gp)(int, void *, int, int); | 1503 char_u *(*gp)(int, void *, int, int); |
1504 struct loop_cookie *cp; | 1504 struct loop_cookie *cp; |
1505 | 1505 |
1506 /* When "fgetline" is "get_loop_line()" use the "cookie" to find the | 1506 // When "fgetline" is "get_loop_line()" use the "cookie" to find the |
1507 * cookie that's originally used to obtain the lines. This may be nested | 1507 // cookie that's originally used to obtain the lines. This may be nested |
1508 * several levels. */ | 1508 // several levels. |
1509 gp = fgetline; | 1509 gp = fgetline; |
1510 cp = (struct loop_cookie *)cookie; | 1510 cp = (struct loop_cookie *)cookie; |
1511 while (gp == get_loop_line) | 1511 while (gp == get_loop_line) |
1512 { | 1512 { |
1513 gp = cp->getline; | 1513 gp = cp->getline; |
1541 nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; | 1541 nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; |
1542 if (nextbuf == NULL) | 1542 if (nextbuf == NULL) |
1543 break; | 1543 break; |
1544 buf = nextbuf; | 1544 buf = nextbuf; |
1545 if (addr_type == ADDR_LOADED_BUFFERS) | 1545 if (addr_type == ADDR_LOADED_BUFFERS) |
1546 /* skip over unloaded buffers */ | 1546 // skip over unloaded buffers |
1547 while (buf->b_ml.ml_mfp == NULL) | 1547 while (buf->b_ml.ml_mfp == NULL) |
1548 { | 1548 { |
1549 nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; | 1549 nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; |
1550 if (nextbuf == NULL) | 1550 if (nextbuf == NULL) |
1551 break; | 1551 break; |
1552 buf = nextbuf; | 1552 buf = nextbuf; |
1553 } | 1553 } |
1554 } | 1554 } |
1555 /* we might have gone too far, last buffer is not loadedd */ | 1555 // we might have gone too far, last buffer is not loadedd |
1556 if (addr_type == ADDR_LOADED_BUFFERS) | 1556 if (addr_type == ADDR_LOADED_BUFFERS) |
1557 while (buf->b_ml.ml_mfp == NULL) | 1557 while (buf->b_ml.ml_mfp == NULL) |
1558 { | 1558 { |
1559 nextbuf = (offset >= 0) ? buf->b_prev : buf->b_next; | 1559 nextbuf = (offset >= 0) ? buf->b_prev : buf->b_next; |
1560 if (nextbuf == NULL) | 1560 if (nextbuf == NULL) |
1632 int sourcing, | 1632 int sourcing, |
1633 #ifdef FEAT_EVAL | 1633 #ifdef FEAT_EVAL |
1634 struct condstack *cstack, | 1634 struct condstack *cstack, |
1635 #endif | 1635 #endif |
1636 char_u *(*fgetline)(int, void *, int, int), | 1636 char_u *(*fgetline)(int, void *, int, int), |
1637 void *cookie) /* argument for fgetline() */ | 1637 void *cookie) // argument for fgetline() |
1638 { | 1638 { |
1639 char_u *p; | 1639 char_u *p; |
1640 linenr_T lnum; | 1640 linenr_T lnum; |
1641 long n; | 1641 long n; |
1642 char *errormsg = NULL; /* error message */ | 1642 char *errormsg = NULL; // error message |
1643 char_u *after_modifier = NULL; | 1643 char_u *after_modifier = NULL; |
1644 exarg_T ea; /* Ex command arguments */ | 1644 exarg_T ea; // Ex command arguments |
1645 int save_msg_scroll = msg_scroll; | 1645 int save_msg_scroll = msg_scroll; |
1646 cmdmod_T save_cmdmod; | 1646 cmdmod_T save_cmdmod; |
1647 int save_reg_executing = reg_executing; | 1647 int save_reg_executing = reg_executing; |
1648 int ni; /* set when Not Implemented */ | 1648 int ni; // set when Not Implemented |
1649 char_u *cmd; | 1649 char_u *cmd; |
1650 | 1650 |
1651 vim_memset(&ea, 0, sizeof(ea)); | 1651 vim_memset(&ea, 0, sizeof(ea)); |
1652 ea.line1 = 1; | 1652 ea.line1 = 1; |
1653 ea.line2 = 1; | 1653 ea.line2 = 1; |
1654 #ifdef FEAT_EVAL | 1654 #ifdef FEAT_EVAL |
1655 ++ex_nesting_level; | 1655 ++ex_nesting_level; |
1656 #endif | 1656 #endif |
1657 | 1657 |
1658 /* When the last file has not been edited :q has to be typed twice. */ | 1658 // When the last file has not been edited :q has to be typed twice. |
1659 if (quitmore | 1659 if (quitmore |
1660 #ifdef FEAT_EVAL | 1660 #ifdef FEAT_EVAL |
1661 /* avoid that a function call in 'statusline' does this */ | 1661 // avoid that a function call in 'statusline' does this |
1662 && !getline_equal(fgetline, cookie, get_func_line) | 1662 && !getline_equal(fgetline, cookie, get_func_line) |
1663 #endif | 1663 #endif |
1664 /* avoid that an autocommand, e.g. QuitPre, does this */ | 1664 // avoid that an autocommand, e.g. QuitPre, does this |
1665 && !getline_equal(fgetline, cookie, getnextac)) | 1665 && !getline_equal(fgetline, cookie, getnextac)) |
1666 --quitmore; | 1666 --quitmore; |
1667 | 1667 |
1668 /* | 1668 /* |
1669 * Reset browse, confirm, etc.. They are restored when returning, for | 1669 * Reset browse, confirm, etc.. They are restored when returning, for |
1670 * recursive calls. | 1670 * recursive calls. |
1671 */ | 1671 */ |
1672 save_cmdmod = cmdmod; | 1672 save_cmdmod = cmdmod; |
1673 | 1673 |
1674 /* "#!anything" is handled like a comment. */ | 1674 // "#!anything" is handled like a comment. |
1675 if ((*cmdlinep)[0] == '#' && (*cmdlinep)[1] == '!') | 1675 if ((*cmdlinep)[0] == '#' && (*cmdlinep)[1] == '!') |
1676 goto doend; | 1676 goto doend; |
1677 | 1677 |
1678 if (p_verbose >= 16) | 1678 if (p_verbose >= 16) |
1679 msg_verbose_cmd(0, *cmdlinep); | 1679 msg_verbose_cmd(0, *cmdlinep); |
1746 script_line_exec(); | 1746 script_line_exec(); |
1747 } | 1747 } |
1748 } | 1748 } |
1749 # endif | 1749 # endif |
1750 | 1750 |
1751 /* May go to debug mode. If this happens and the ">quit" debug command is | 1751 // May go to debug mode. If this happens and the ">quit" debug command is |
1752 * used, throw an interrupt exception and skip the next command. */ | 1752 // used, throw an interrupt exception and skip the next command. |
1753 dbg_check_breakpoint(&ea); | 1753 dbg_check_breakpoint(&ea); |
1754 if (!ea.skip && got_int) | 1754 if (!ea.skip && got_int) |
1755 { | 1755 { |
1756 ea.skip = TRUE; | 1756 ea.skip = TRUE; |
1757 (void)do_intthrow(cstack); | 1757 (void)do_intthrow(cstack); |
1819 * strange vi behaviour: | 1819 * strange vi behaviour: |
1820 * ":3" jumps to line 3 | 1820 * ":3" jumps to line 3 |
1821 * ":3|..." prints line 3 | 1821 * ":3|..." prints line 3 |
1822 * ":|" prints current line | 1822 * ":|" prints current line |
1823 */ | 1823 */ |
1824 if (ea.skip) /* skip this if inside :if */ | 1824 if (ea.skip) // skip this if inside :if |
1825 goto doend; | 1825 goto doend; |
1826 if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) | 1826 if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) |
1827 { | 1827 { |
1828 ea.cmdidx = CMD_print; | 1828 ea.cmdidx = CMD_print; |
1829 ea.argt = EX_RANGE+EX_COUNT+EX_TRLBAR; | 1829 ea.argt = EX_RANGE+EX_COUNT+EX_TRLBAR; |
1835 } | 1835 } |
1836 else if (ea.addr_count != 0) | 1836 else if (ea.addr_count != 0) |
1837 { | 1837 { |
1838 if (ea.line2 > curbuf->b_ml.ml_line_count) | 1838 if (ea.line2 > curbuf->b_ml.ml_line_count) |
1839 { | 1839 { |
1840 /* With '-' in 'cpoptions' a line number past the file is an | 1840 // With '-' in 'cpoptions' a line number past the file is an |
1841 * error, otherwise put it at the end of the file. */ | 1841 // error, otherwise put it at the end of the file. |
1842 if (vim_strchr(p_cpo, CPO_MINUS) != NULL) | 1842 if (vim_strchr(p_cpo, CPO_MINUS) != NULL) |
1843 ea.line2 = -1; | 1843 ea.line2 = -1; |
1844 else | 1844 else |
1845 ea.line2 = curbuf->b_ml.ml_line_count; | 1845 ea.line2 = curbuf->b_ml.ml_line_count; |
1846 } | 1846 } |
1857 } | 1857 } |
1858 } | 1858 } |
1859 goto doend; | 1859 goto doend; |
1860 } | 1860 } |
1861 | 1861 |
1862 /* If this looks like an undefined user command and there are CmdUndefined | 1862 // If this looks like an undefined user command and there are CmdUndefined |
1863 * autocommands defined, trigger the matching autocommands. */ | 1863 // autocommands defined, trigger the matching autocommands. |
1864 if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip | 1864 if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip |
1865 && ASCII_ISUPPER(*ea.cmd) | 1865 && ASCII_ISUPPER(*ea.cmd) |
1866 && has_cmdundefined()) | 1866 && has_cmdundefined()) |
1867 { | 1867 { |
1868 int ret; | 1868 int ret; |
1871 while (ASCII_ISALNUM(*p)) | 1871 while (ASCII_ISALNUM(*p)) |
1872 ++p; | 1872 ++p; |
1873 p = vim_strnsave(ea.cmd, (int)(p - ea.cmd)); | 1873 p = vim_strnsave(ea.cmd, (int)(p - ea.cmd)); |
1874 ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); | 1874 ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); |
1875 vim_free(p); | 1875 vim_free(p); |
1876 /* If the autocommands did something and didn't cause an error, try | 1876 // If the autocommands did something and didn't cause an error, try |
1877 * finding the command again. */ | 1877 // finding the command again. |
1878 p = (ret | 1878 p = (ret |
1879 #ifdef FEAT_EVAL | 1879 #ifdef FEAT_EVAL |
1880 && !aborting() | 1880 && !aborting() |
1881 #endif | 1881 #endif |
1882 ) ? find_command(&ea, NULL) : ea.cmd; | 1882 ) ? find_command(&ea, NULL) : ea.cmd; |
1901 if (!ea.skip) | 1901 if (!ea.skip) |
1902 { | 1902 { |
1903 STRCPY(IObuff, _("E492: Not an editor command")); | 1903 STRCPY(IObuff, _("E492: Not an editor command")); |
1904 if (!sourcing) | 1904 if (!sourcing) |
1905 { | 1905 { |
1906 /* If the modifier was parsed OK the error must be in the | 1906 // If the modifier was parsed OK the error must be in the |
1907 * following command */ | 1907 // following command |
1908 if (after_modifier != NULL) | 1908 if (after_modifier != NULL) |
1909 append_command(after_modifier); | 1909 append_command(after_modifier); |
1910 else | 1910 else |
1911 append_command(*cmdlinep); | 1911 append_command(*cmdlinep); |
1912 } | 1912 } |
1937 goto doend; | 1937 goto doend; |
1938 } | 1938 } |
1939 | 1939 |
1940 #endif | 1940 #endif |
1941 | 1941 |
1942 /* forced commands */ | 1942 // forced commands |
1943 if (*p == '!' && ea.cmdidx != CMD_substitute | 1943 if (*p == '!' && ea.cmdidx != CMD_substitute |
1944 && ea.cmdidx != CMD_smagic && ea.cmdidx != CMD_snomagic) | 1944 && ea.cmdidx != CMD_smagic && ea.cmdidx != CMD_snomagic) |
1945 { | 1945 { |
1946 ++p; | 1946 ++p; |
1947 ea.forceit = TRUE; | 1947 ea.forceit = TRUE; |
1970 errormsg = _("E981: Command not allowed in rvim"); | 1970 errormsg = _("E981: Command not allowed in rvim"); |
1971 goto doend; | 1971 goto doend; |
1972 } | 1972 } |
1973 if (!curbuf->b_p_ma && (ea.argt & EX_MODIFY)) | 1973 if (!curbuf->b_p_ma && (ea.argt & EX_MODIFY)) |
1974 { | 1974 { |
1975 /* Command not allowed in non-'modifiable' buffer */ | 1975 // Command not allowed in non-'modifiable' buffer |
1976 errormsg = _(e_modifiable); | 1976 errormsg = _(e_modifiable); |
1977 goto doend; | 1977 goto doend; |
1978 } | 1978 } |
1979 | 1979 |
1980 if (text_locked() && !(ea.argt & EX_CMDWIN) | 1980 if (text_locked() && !(ea.argt & EX_CMDWIN) |
1981 && !IS_USER_CMDIDX(ea.cmdidx)) | 1981 && !IS_USER_CMDIDX(ea.cmdidx)) |
1982 { | 1982 { |
1983 /* Command not allowed when editing the command line. */ | 1983 // Command not allowed when editing the command line. |
1984 errormsg = _(get_text_locked_msg()); | 1984 errormsg = _(get_text_locked_msg()); |
1985 goto doend; | 1985 goto doend; |
1986 } | 1986 } |
1987 | 1987 |
1988 /* Disallow editing another buffer when "curbuf_lock" is set. | 1988 // Disallow editing another buffer when "curbuf_lock" is set. |
1989 * Do allow ":checktime" (it is postponed). | 1989 // Do allow ":checktime" (it is postponed). |
1990 * Do allow ":edit" (check for an argument later). | 1990 // Do allow ":edit" (check for an argument later). |
1991 * Do allow ":file" with no arguments (check for an argument later). */ | 1991 // Do allow ":file" with no arguments (check for an argument later). |
1992 if (!(ea.argt & EX_CMDWIN) | 1992 if (!(ea.argt & EX_CMDWIN) |
1993 && ea.cmdidx != CMD_checktime | 1993 && ea.cmdidx != CMD_checktime |
1994 && ea.cmdidx != CMD_edit | 1994 && ea.cmdidx != CMD_edit |
1995 && ea.cmdidx != CMD_file | 1995 && ea.cmdidx != CMD_file |
1996 && !IS_USER_CMDIDX(ea.cmdidx) | 1996 && !IS_USER_CMDIDX(ea.cmdidx) |
1997 && curbuf_locked()) | 1997 && curbuf_locked()) |
1998 goto doend; | 1998 goto doend; |
1999 | 1999 |
2000 if (!ni && !(ea.argt & EX_RANGE) && ea.addr_count > 0) | 2000 if (!ni && !(ea.argt & EX_RANGE) && ea.addr_count > 0) |
2001 { | 2001 { |
2002 /* no range allowed */ | 2002 // no range allowed |
2003 errormsg = _(e_norange); | 2003 errormsg = _(e_norange); |
2004 goto doend; | 2004 goto doend; |
2005 } | 2005 } |
2006 } | 2006 } |
2007 | 2007 |
2051 | 2051 |
2052 #ifdef FEAT_FOLDING | 2052 #ifdef FEAT_FOLDING |
2053 if (((ea.argt & EX_WHOLEFOLD) || ea.addr_count >= 2) && !global_busy | 2053 if (((ea.argt & EX_WHOLEFOLD) || ea.addr_count >= 2) && !global_busy |
2054 && ea.addr_type == ADDR_LINES) | 2054 && ea.addr_type == ADDR_LINES) |
2055 { | 2055 { |
2056 /* Put the first line at the start of a closed fold, put the last line | 2056 // Put the first line at the start of a closed fold, put the last line |
2057 * at the end of a closed fold. */ | 2057 // at the end of a closed fold. |
2058 (void)hasFolding(ea.line1, &ea.line1, NULL); | 2058 (void)hasFolding(ea.line1, &ea.line1, NULL); |
2059 (void)hasFolding(ea.line2, NULL, &ea.line2); | 2059 (void)hasFolding(ea.line2, NULL, &ea.line2); |
2060 } | 2060 } |
2061 #endif | 2061 #endif |
2062 | 2062 |
2095 goto doend; | 2095 goto doend; |
2096 } | 2096 } |
2097 | 2097 |
2098 if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) | 2098 if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) |
2099 { | 2099 { |
2100 if (*ea.arg == '>') /* append */ | 2100 if (*ea.arg == '>') // append |
2101 { | 2101 { |
2102 if (*++ea.arg != '>') /* typed wrong */ | 2102 if (*++ea.arg != '>') // typed wrong |
2103 { | 2103 { |
2104 errormsg = _("E494: Use w or w>>"); | 2104 errormsg = _("E494: Use w or w>>"); |
2105 goto doend; | 2105 goto doend; |
2106 } | 2106 } |
2107 ea.arg = skipwhite(ea.arg + 1); | 2107 ea.arg = skipwhite(ea.arg + 1); |
2108 ea.append = TRUE; | 2108 ea.append = TRUE; |
2109 } | 2109 } |
2110 else if (*ea.arg == '!' && ea.cmdidx == CMD_write) /* :w !filter */ | 2110 else if (*ea.arg == '!' && ea.cmdidx == CMD_write) // :w !filter |
2111 { | 2111 { |
2112 ++ea.arg; | 2112 ++ea.arg; |
2113 ea.usefilter = TRUE; | 2113 ea.usefilter = TRUE; |
2114 } | 2114 } |
2115 } | 2115 } |
2116 | 2116 |
2117 if (ea.cmdidx == CMD_read) | 2117 if (ea.cmdidx == CMD_read) |
2118 { | 2118 { |
2119 if (ea.forceit) | 2119 if (ea.forceit) |
2120 { | 2120 { |
2121 ea.usefilter = TRUE; /* :r! filter if ea.forceit */ | 2121 ea.usefilter = TRUE; // :r! filter if ea.forceit |
2122 ea.forceit = FALSE; | 2122 ea.forceit = FALSE; |
2123 } | 2123 } |
2124 else if (*ea.arg == '!') /* :r !filter */ | 2124 else if (*ea.arg == '!') // :r !filter |
2125 { | 2125 { |
2126 ++ea.arg; | 2126 ++ea.arg; |
2127 ea.usefilter = TRUE; | 2127 ea.usefilter = TRUE; |
2128 } | 2128 } |
2129 } | 2129 } |
2130 | 2130 |
2131 if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) | 2131 if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) |
2132 { | 2132 { |
2133 ea.amount = 1; | 2133 ea.amount = 1; |
2134 while (*ea.arg == *ea.cmd) /* count number of '>' or '<' */ | 2134 while (*ea.arg == *ea.cmd) // count number of '>' or '<' |
2135 { | 2135 { |
2136 ++ea.arg; | 2136 ++ea.arg; |
2137 ++ea.amount; | 2137 ++ea.amount; |
2138 } | 2138 } |
2139 ea.arg = skipwhite(ea.arg); | 2139 ea.arg = skipwhite(ea.arg); |
2164 || ea.cmdidx == CMD_vglobal | 2164 || ea.cmdidx == CMD_vglobal |
2165 || ea.usefilter) | 2165 || ea.usefilter) |
2166 { | 2166 { |
2167 for (p = ea.arg; *p; ++p) | 2167 for (p = ea.arg; *p; ++p) |
2168 { | 2168 { |
2169 /* Remove one backslash before a newline, so that it's possible to | 2169 // Remove one backslash before a newline, so that it's possible to |
2170 * pass a newline to the shell and also a newline that is preceded | 2170 // pass a newline to the shell and also a newline that is preceded |
2171 * with a backslash. This makes it impossible to end a shell | 2171 // with a backslash. This makes it impossible to end a shell |
2172 * command in a backslash, but that doesn't appear useful. | 2172 // command in a backslash, but that doesn't appear useful. |
2173 * Halving the number of backslashes is incompatible with previous | 2173 // Halving the number of backslashes is incompatible with previous |
2174 * versions. */ | 2174 // versions. |
2175 if (*p == '\\' && p[1] == '\n') | 2175 if (*p == '\\' && p[1] == '\n') |
2176 STRMOVE(p, p + 1); | 2176 STRMOVE(p, p + 1); |
2177 else if (*p == '\n') | 2177 else if (*p == '\n') |
2178 { | 2178 { |
2179 ea.nextcmd = p + 1; | 2179 ea.nextcmd = p + 1; |
2236 iemsg(_("INTERNAL: Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); | 2236 iemsg(_("INTERNAL: Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); |
2237 break; | 2237 break; |
2238 } | 2238 } |
2239 } | 2239 } |
2240 | 2240 |
2241 /* accept numbered register only when no count allowed (:put) */ | 2241 // accept numbered register only when no count allowed (:put) |
2242 if ( (ea.argt & EX_REGSTR) | 2242 if ( (ea.argt & EX_REGSTR) |
2243 && *ea.arg != NUL | 2243 && *ea.arg != NUL |
2244 /* Do not allow register = for user commands */ | 2244 // Do not allow register = for user commands |
2245 && (!IS_USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') | 2245 && (!IS_USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') |
2246 && !((ea.argt & EX_COUNT) && VIM_ISDIGIT(*ea.arg))) | 2246 && !((ea.argt & EX_COUNT) && VIM_ISDIGIT(*ea.arg))) |
2247 { | 2247 { |
2248 #ifndef FEAT_CLIPBOARD | 2248 #ifndef FEAT_CLIPBOARD |
2249 /* check these explicitly for a more specific error message */ | 2249 // check these explicitly for a more specific error message |
2250 if (*ea.arg == '*' || *ea.arg == '+') | 2250 if (*ea.arg == '*' || *ea.arg == '+') |
2251 { | 2251 { |
2252 errormsg = _(e_invalidreg); | 2252 errormsg = _(e_invalidreg); |
2253 goto doend; | 2253 goto doend; |
2254 } | 2254 } |
2256 if (valid_yank_reg(*ea.arg, (ea.cmdidx != CMD_put | 2256 if (valid_yank_reg(*ea.arg, (ea.cmdidx != CMD_put |
2257 && !IS_USER_CMDIDX(ea.cmdidx)))) | 2257 && !IS_USER_CMDIDX(ea.cmdidx)))) |
2258 { | 2258 { |
2259 ea.regname = *ea.arg++; | 2259 ea.regname = *ea.arg++; |
2260 #ifdef FEAT_EVAL | 2260 #ifdef FEAT_EVAL |
2261 /* for '=' register: accept the rest of the line as an expression */ | 2261 // for '=' register: accept the rest of the line as an expression |
2262 if (ea.arg[-1] == '=' && ea.arg[0] != NUL) | 2262 if (ea.arg[-1] == '=' && ea.arg[0] != NUL) |
2263 { | 2263 { |
2264 set_expr_line(vim_strsave(ea.arg)); | 2264 set_expr_line(vim_strsave(ea.arg)); |
2265 ea.arg += STRLEN(ea.arg); | 2265 ea.arg += STRLEN(ea.arg); |
2266 } | 2266 } |
2331 */ | 2331 */ |
2332 if (ea.skip) | 2332 if (ea.skip) |
2333 { | 2333 { |
2334 switch (ea.cmdidx) | 2334 switch (ea.cmdidx) |
2335 { | 2335 { |
2336 /* commands that need evaluation */ | 2336 // commands that need evaluation |
2337 case CMD_while: | 2337 case CMD_while: |
2338 case CMD_endwhile: | 2338 case CMD_endwhile: |
2339 case CMD_for: | 2339 case CMD_for: |
2340 case CMD_endfor: | 2340 case CMD_endfor: |
2341 case CMD_if: | 2341 case CMD_if: |
2347 case CMD_finally: | 2347 case CMD_finally: |
2348 case CMD_endtry: | 2348 case CMD_endtry: |
2349 case CMD_function: | 2349 case CMD_function: |
2350 break; | 2350 break; |
2351 | 2351 |
2352 /* Commands that handle '|' themselves. Check: A command should | 2352 // Commands that handle '|' themselves. Check: A command should |
2353 * either have the EX_TRLBAR flag, appear in this list or appear in | 2353 // either have the EX_TRLBAR flag, appear in this list or appear in |
2354 * the list at ":help :bar". */ | 2354 // the list at ":help :bar". |
2355 case CMD_aboveleft: | 2355 case CMD_aboveleft: |
2356 case CMD_and: | 2356 case CMD_and: |
2357 case CMD_belowright: | 2357 case CMD_belowright: |
2358 case CMD_botright: | 2358 case CMD_botright: |
2359 case CMD_browse: | 2359 case CMD_browse: |
2447 while (p > ea.arg && VIM_ISWHITE(p[-1])) | 2447 while (p > ea.arg && VIM_ISWHITE(p[-1])) |
2448 --p; | 2448 --p; |
2449 } | 2449 } |
2450 ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & EX_BUFUNL) != 0, | 2450 ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & EX_BUFUNL) != 0, |
2451 FALSE, FALSE); | 2451 FALSE, FALSE); |
2452 if (ea.line2 < 0) /* failed */ | 2452 if (ea.line2 < 0) // failed |
2453 goto doend; | 2453 goto doend; |
2454 ea.addr_count = 1; | 2454 ea.addr_count = 1; |
2455 ea.arg = skipwhite(p); | 2455 ea.arg = skipwhite(p); |
2456 } | 2456 } |
2457 | 2457 |
2458 /* The :try command saves the emsg_silent flag, reset it here when | 2458 // The :try command saves the emsg_silent flag, reset it here when |
2459 * ":silent! try" was used, it should only apply to :try itself. */ | 2459 // ":silent! try" was used, it should only apply to :try itself. |
2460 if (ea.cmdidx == CMD_try && ea.did_esilent > 0) | 2460 if (ea.cmdidx == CMD_try && ea.did_esilent > 0) |
2461 { | 2461 { |
2462 emsg_silent -= ea.did_esilent; | 2462 emsg_silent -= ea.did_esilent; |
2463 if (emsg_silent < 0) | 2463 if (emsg_silent < 0) |
2464 emsg_silent = 0; | 2464 emsg_silent = 0; |
2507 } | 2507 } |
2508 need_rethrow = check_cstack = FALSE; | 2508 need_rethrow = check_cstack = FALSE; |
2509 #endif | 2509 #endif |
2510 | 2510 |
2511 doend: | 2511 doend: |
2512 if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */ | 2512 if (curwin->w_cursor.lnum == 0) // can happen with zero line number |
2513 { | 2513 { |
2514 curwin->w_cursor.lnum = 1; | 2514 curwin->w_cursor.lnum = 1; |
2515 curwin->w_cursor.col = 0; | 2515 curwin->w_cursor.col = 0; |
2516 } | 2516 } |
2517 | 2517 |
2541 cmdmod = save_cmdmod; | 2541 cmdmod = save_cmdmod; |
2542 reg_executing = save_reg_executing; | 2542 reg_executing = save_reg_executing; |
2543 | 2543 |
2544 if (ea.save_msg_silent != -1) | 2544 if (ea.save_msg_silent != -1) |
2545 { | 2545 { |
2546 /* messages could be enabled for a serious error, need to check if the | 2546 // messages could be enabled for a serious error, need to check if the |
2547 * counters don't become negative */ | 2547 // counters don't become negative |
2548 if (!did_emsg || msg_silent > ea.save_msg_silent) | 2548 if (!did_emsg || msg_silent > ea.save_msg_silent) |
2549 msg_silent = ea.save_msg_silent; | 2549 msg_silent = ea.save_msg_silent; |
2550 emsg_silent -= ea.did_esilent; | 2550 emsg_silent -= ea.did_esilent; |
2551 if (emsg_silent < 0) | 2551 if (emsg_silent < 0) |
2552 emsg_silent = 0; | 2552 emsg_silent = 0; |
2553 /* Restore msg_scroll, it's set by file I/O commands, even when no | 2553 // Restore msg_scroll, it's set by file I/O commands, even when no |
2554 * message is actually displayed. */ | 2554 // message is actually displayed. |
2555 msg_scroll = save_msg_scroll; | 2555 msg_scroll = save_msg_scroll; |
2556 | 2556 |
2557 /* "silent reg" or "silent echo x" inside "redir" leaves msg_col | 2557 // "silent reg" or "silent echo x" inside "redir" leaves msg_col |
2558 * somewhere in the line. Put it back in the first column. */ | 2558 // somewhere in the line. Put it back in the first column. |
2559 if (redirecting()) | 2559 if (redirecting()) |
2560 msg_col = 0; | 2560 msg_col = 0; |
2561 } | 2561 } |
2562 | 2562 |
2563 #ifdef HAVE_SANDBOX | 2563 #ifdef HAVE_SANDBOX |
2564 if (ea.did_sandbox) | 2564 if (ea.did_sandbox) |
2565 --sandbox; | 2565 --sandbox; |
2566 #endif | 2566 #endif |
2567 | 2567 |
2568 if (ea.nextcmd && *ea.nextcmd == NUL) /* not really a next command */ | 2568 if (ea.nextcmd && *ea.nextcmd == NUL) // not really a next command |
2569 ea.nextcmd = NULL; | 2569 ea.nextcmd = NULL; |
2570 | 2570 |
2571 #ifdef FEAT_EVAL | 2571 #ifdef FEAT_EVAL |
2572 --ex_nesting_level; | 2572 --ex_nesting_level; |
2573 #endif | 2573 #endif |
2605 for (;;) | 2605 for (;;) |
2606 { | 2606 { |
2607 while (*eap->cmd == ' ' || *eap->cmd == '\t' || *eap->cmd == ':') | 2607 while (*eap->cmd == ' ' || *eap->cmd == '\t' || *eap->cmd == ':') |
2608 ++eap->cmd; | 2608 ++eap->cmd; |
2609 | 2609 |
2610 /* in ex mode, an empty line works like :+ */ | 2610 // in ex mode, an empty line works like :+ |
2611 if (*eap->cmd == NUL && exmode_active | 2611 if (*eap->cmd == NUL && exmode_active |
2612 && (getline_equal(eap->getline, eap->cookie, getexmodeline) | 2612 && (getline_equal(eap->getline, eap->cookie, getexmodeline) |
2613 || getline_equal(eap->getline, eap->cookie, getexline)) | 2613 || getline_equal(eap->getline, eap->cookie, getexline)) |
2614 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | 2614 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
2615 { | 2615 { |
2616 eap->cmd = (char_u *)"+"; | 2616 eap->cmd = (char_u *)"+"; |
2617 if (!skip_only) | 2617 if (!skip_only) |
2618 ex_pressedreturn = TRUE; | 2618 ex_pressedreturn = TRUE; |
2619 } | 2619 } |
2620 | 2620 |
2621 /* ignore comment and empty lines */ | 2621 // ignore comment and empty lines |
2622 if (*eap->cmd == '"') | 2622 if (*eap->cmd == '"') |
2623 return FAIL; | 2623 return FAIL; |
2624 if (*eap->cmd == NUL) | 2624 if (*eap->cmd == NUL) |
2625 { | 2625 { |
2626 if (!skip_only) | 2626 if (!skip_only) |
2629 } | 2629 } |
2630 | 2630 |
2631 p = skip_range(eap->cmd, NULL); | 2631 p = skip_range(eap->cmd, NULL); |
2632 switch (*p) | 2632 switch (*p) |
2633 { | 2633 { |
2634 /* When adding an entry, also modify cmd_exists(). */ | 2634 // When adding an entry, also modify cmd_exists(). |
2635 case 'a': if (!checkforcmd(&eap->cmd, "aboveleft", 3)) | 2635 case 'a': if (!checkforcmd(&eap->cmd, "aboveleft", 3)) |
2636 break; | 2636 break; |
2637 cmdmod.split |= WSP_ABOVE; | 2637 cmdmod.split |= WSP_ABOVE; |
2638 continue; | 2638 continue; |
2639 | 2639 |
2679 if (!checkforcmd(&eap->cmd, "keepjumps", 5)) | 2679 if (!checkforcmd(&eap->cmd, "keepjumps", 5)) |
2680 break; | 2680 break; |
2681 cmdmod.keepjumps = TRUE; | 2681 cmdmod.keepjumps = TRUE; |
2682 continue; | 2682 continue; |
2683 | 2683 |
2684 case 'f': /* only accept ":filter {pat} cmd" */ | 2684 case 'f': // only accept ":filter {pat} cmd" |
2685 { | 2685 { |
2686 char_u *reg_pat; | 2686 char_u *reg_pat; |
2687 | 2687 |
2688 if (!checkforcmd(&p, "filter", 4) | 2688 if (!checkforcmd(&p, "filter", 4) |
2689 || *p == NUL || ends_excmd(*p)) | 2689 || *p == NUL || ends_excmd(*p)) |
2711 } | 2711 } |
2712 eap->cmd = p; | 2712 eap->cmd = p; |
2713 continue; | 2713 continue; |
2714 } | 2714 } |
2715 | 2715 |
2716 /* ":hide" and ":hide | cmd" are not modifiers */ | 2716 // ":hide" and ":hide | cmd" are not modifiers |
2717 case 'h': if (p != eap->cmd || !checkforcmd(&p, "hide", 3) | 2717 case 'h': if (p != eap->cmd || !checkforcmd(&p, "hide", 3) |
2718 || *p == NUL || ends_excmd(*p)) | 2718 || *p == NUL || ends_excmd(*p)) |
2719 break; | 2719 break; |
2720 eap->cmd = p; | 2720 eap->cmd = p; |
2721 cmdmod.hide = TRUE; | 2721 cmdmod.hide = TRUE; |
2734 | 2734 |
2735 case 'n': if (checkforcmd(&eap->cmd, "noautocmd", 3)) | 2735 case 'n': if (checkforcmd(&eap->cmd, "noautocmd", 3)) |
2736 { | 2736 { |
2737 if (cmdmod.save_ei == NULL && !skip_only) | 2737 if (cmdmod.save_ei == NULL && !skip_only) |
2738 { | 2738 { |
2739 /* Set 'eventignore' to "all". Restore the | 2739 // Set 'eventignore' to "all". Restore the |
2740 * existing option value later. */ | 2740 // existing option value later. |
2741 cmdmod.save_ei = vim_strsave(p_ei); | 2741 cmdmod.save_ei = vim_strsave(p_ei); |
2742 set_string_option_direct((char_u *)"ei", -1, | 2742 set_string_option_direct((char_u *)"ei", -1, |
2743 (char_u *)"all", OPT_FREE, SID_NONE); | 2743 (char_u *)"all", OPT_FREE, SID_NONE); |
2744 } | 2744 } |
2745 continue; | 2745 continue; |
2774 eap->save_msg_silent = msg_silent; | 2774 eap->save_msg_silent = msg_silent; |
2775 ++msg_silent; | 2775 ++msg_silent; |
2776 } | 2776 } |
2777 if (*eap->cmd == '!' && !VIM_ISWHITE(eap->cmd[-1])) | 2777 if (*eap->cmd == '!' && !VIM_ISWHITE(eap->cmd[-1])) |
2778 { | 2778 { |
2779 /* ":silent!", but not "silent !cmd" */ | 2779 // ":silent!", but not "silent !cmd" |
2780 eap->cmd = skipwhite(eap->cmd + 1); | 2780 eap->cmd = skipwhite(eap->cmd + 1); |
2781 if (!skip_only) | 2781 if (!skip_only) |
2782 { | 2782 { |
2783 ++emsg_silent; | 2783 ++emsg_silent; |
2784 ++eap->did_esilent; | 2784 ++eap->did_esilent; |
2854 static void | 2854 static void |
2855 free_cmdmod(void) | 2855 free_cmdmod(void) |
2856 { | 2856 { |
2857 if (cmdmod.save_ei != NULL) | 2857 if (cmdmod.save_ei != NULL) |
2858 { | 2858 { |
2859 /* Restore 'eventignore' to the value before ":noautocmd". */ | 2859 // Restore 'eventignore' to the value before ":noautocmd". |
2860 set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei, | 2860 set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei, |
2861 OPT_FREE, SID_NONE); | 2861 OPT_FREE, SID_NONE); |
2862 free_string_option(cmdmod.save_ei); | 2862 free_string_option(cmdmod.save_ei); |
2863 } | 2863 } |
2864 | 2864 |
3060 * Check for an Ex command with optional tail. | 3060 * Check for an Ex command with optional tail. |
3061 * If there is a match advance "pp" to the argument and return TRUE. | 3061 * If there is a match advance "pp" to the argument and return TRUE. |
3062 */ | 3062 */ |
3063 int | 3063 int |
3064 checkforcmd( | 3064 checkforcmd( |
3065 char_u **pp, /* start of command */ | 3065 char_u **pp, // start of command |
3066 char *cmd, /* name of command */ | 3066 char *cmd, // name of command |
3067 int len) /* required length */ | 3067 int len) // required length |
3068 { | 3068 { |
3069 int i; | 3069 int i; |
3070 | 3070 |
3071 for (i = 0; cmd[i] != NUL; ++i) | 3071 for (i = 0; cmd[i] != NUL; ++i) |
3072 if (((char_u *)cmd)[i] != (*pp)[i]) | 3072 if (((char_u *)cmd)[i] != (*pp)[i]) |
3148 } | 3148 } |
3149 else | 3149 else |
3150 { | 3150 { |
3151 while (ASCII_ISALPHA(*p)) | 3151 while (ASCII_ISALPHA(*p)) |
3152 ++p; | 3152 ++p; |
3153 /* for python 3.x support ":py3", ":python3", ":py3file", etc. */ | 3153 // for python 3.x support ":py3", ":python3", ":py3file", etc. |
3154 if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y') | 3154 if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y') |
3155 while (ASCII_ISALNUM(*p)) | 3155 while (ASCII_ISALNUM(*p)) |
3156 ++p; | 3156 ++p; |
3157 | 3157 |
3158 /* check for non-alpha command */ | 3158 // check for non-alpha command |
3159 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) | 3159 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) |
3160 ++p; | 3160 ++p; |
3161 len = (int)(p - eap->cmd); | 3161 len = (int)(p - eap->cmd); |
3162 if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) | 3162 if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) |
3163 { | 3163 { |
3164 /* Check for ":dl", ":dell", etc. to ":deletel": that's | 3164 // Check for ":dl", ":dell", etc. to ":deletel": that's |
3165 * :delete with the 'l' flag. Same for 'p'. */ | 3165 // :delete with the 'l' flag. Same for 'p'. |
3166 for (i = 0; i < len; ++i) | 3166 for (i = 0; i < len; ++i) |
3167 if (eap->cmd[i] != ((char_u *)"delete")[i]) | 3167 if (eap->cmd[i] != ((char_u *)"delete")[i]) |
3168 break; | 3168 break; |
3169 if (i == len - 1) | 3169 if (i == len - 1) |
3170 { | 3170 { |
3185 { | 3185 { |
3186 iemsg(_("E943: Command table needs to be updated, run 'make cmdidxs'")); | 3186 iemsg(_("E943: Command table needs to be updated, run 'make cmdidxs'")); |
3187 getout(1); | 3187 getout(1); |
3188 } | 3188 } |
3189 | 3189 |
3190 /* Use a precomputed index for fast look-up in cmdnames[] | 3190 // Use a precomputed index for fast look-up in cmdnames[] |
3191 * taking into account the first 2 letters of eap->cmd. */ | 3191 // taking into account the first 2 letters of eap->cmd. |
3192 eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; | 3192 eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; |
3193 if (ASCII_ISLOWER(c2)) | 3193 if (ASCII_ISLOWER(c2)) |
3194 eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; | 3194 eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; |
3195 } | 3195 } |
3196 else | 3196 else |
3229 #if defined(FEAT_EVAL) || defined(PROTO) | 3229 #if defined(FEAT_EVAL) || defined(PROTO) |
3230 static struct cmdmod | 3230 static struct cmdmod |
3231 { | 3231 { |
3232 char *name; | 3232 char *name; |
3233 int minlen; | 3233 int minlen; |
3234 int has_count; /* :123verbose :3tab */ | 3234 int has_count; // :123verbose :3tab |
3235 } cmdmods[] = { | 3235 } cmdmods[] = { |
3236 {"aboveleft", 3, FALSE}, | 3236 {"aboveleft", 3, FALSE}, |
3237 {"belowright", 3, FALSE}, | 3237 {"belowright", 3, FALSE}, |
3238 {"botright", 2, FALSE}, | 3238 {"botright", 2, FALSE}, |
3239 {"browse", 3, FALSE}, | 3239 {"browse", 3, FALSE}, |
3294 int full = FALSE; | 3294 int full = FALSE; |
3295 int i; | 3295 int i; |
3296 int j; | 3296 int j; |
3297 char_u *p; | 3297 char_u *p; |
3298 | 3298 |
3299 /* Check command modifiers. */ | 3299 // Check command modifiers. |
3300 for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i) | 3300 for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i) |
3301 { | 3301 { |
3302 for (j = 0; name[j] != NUL; ++j) | 3302 for (j = 0; name[j] != NUL; ++j) |
3303 if (name[j] != cmdmods[i].name[j]) | 3303 if (name[j] != cmdmods[i].name[j]) |
3304 break; | 3304 break; |
3305 if (name[j] == NUL && j >= cmdmods[i].minlen) | 3305 if (name[j] == NUL && j >= cmdmods[i].minlen) |
3306 return (cmdmods[i].name[j] == NUL ? 2 : 1); | 3306 return (cmdmods[i].name[j] == NUL ? 2 : 1); |
3307 } | 3307 } |
3308 | 3308 |
3309 /* Check built-in commands and user defined commands. | 3309 // Check built-in commands and user defined commands. |
3310 * For ":2match" and ":3match" we need to skip the number. */ | 3310 // For ":2match" and ":3match" we need to skip the number. |
3311 ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; | 3311 ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; |
3312 ea.cmdidx = (cmdidx_T)0; | 3312 ea.cmdidx = (cmdidx_T)0; |
3313 p = find_command(&ea, &full); | 3313 p = find_command(&ea, &full); |
3314 if (p == NULL) | 3314 if (p == NULL) |
3315 return 3; | 3315 return 3; |
3316 if (vim_isdigit(*name) && ea.cmdidx != CMD_match) | 3316 if (vim_isdigit(*name) && ea.cmdidx != CMD_match) |
3317 return 0; | 3317 return 0; |
3318 if (*skipwhite(p) != NUL) | 3318 if (*skipwhite(p) != NUL) |
3319 return 0; /* trailing garbage */ | 3319 return 0; // trailing garbage |
3320 return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1)); | 3320 return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1)); |
3321 } | 3321 } |
3322 #endif | 3322 #endif |
3323 | 3323 |
3324 cmdidx_T | 3324 cmdidx_T |
3350 * Returns the "cmd" pointer advanced to beyond the range. | 3350 * Returns the "cmd" pointer advanced to beyond the range. |
3351 */ | 3351 */ |
3352 char_u * | 3352 char_u * |
3353 skip_range( | 3353 skip_range( |
3354 char_u *cmd, | 3354 char_u *cmd, |
3355 int *ctx) /* pointer to xp_context or NULL */ | 3355 int *ctx) // pointer to xp_context or NULL |
3356 { | 3356 { |
3357 unsigned delim; | 3357 unsigned delim; |
3358 | 3358 |
3359 while (vim_strchr((char_u *)" \t0123456789.$%'/?-+,;\\", *cmd) != NULL) | 3359 while (vim_strchr((char_u *)" \t0123456789.$%'/?-+,;\\", *cmd) != NULL) |
3360 { | 3360 { |
3381 } | 3381 } |
3382 if (*cmd != NUL) | 3382 if (*cmd != NUL) |
3383 ++cmd; | 3383 ++cmd; |
3384 } | 3384 } |
3385 | 3385 |
3386 /* Skip ":" and white space. */ | 3386 // Skip ":" and white space. |
3387 while (*cmd == ':') | 3387 while (*cmd == ':') |
3388 cmd = skipwhite(cmd + 1); | 3388 cmd = skipwhite(cmd + 1); |
3389 | 3389 |
3390 return cmd; | 3390 return cmd; |
3391 } | 3391 } |
3432 lnum = MAXLNUM; | 3432 lnum = MAXLNUM; |
3433 do | 3433 do |
3434 { | 3434 { |
3435 switch (*cmd) | 3435 switch (*cmd) |
3436 { | 3436 { |
3437 case '.': /* '.' - Cursor position */ | 3437 case '.': // '.' - Cursor position |
3438 ++cmd; | 3438 ++cmd; |
3439 switch (addr_type) | 3439 switch (addr_type) |
3440 { | 3440 { |
3441 case ADDR_LINES: | 3441 case ADDR_LINES: |
3442 case ADDR_OTHER: | 3442 case ADDR_OTHER: |
3473 #endif | 3473 #endif |
3474 break; | 3474 break; |
3475 } | 3475 } |
3476 break; | 3476 break; |
3477 | 3477 |
3478 case '$': /* '$' - last line */ | 3478 case '$': // '$' - last line |
3479 ++cmd; | 3479 ++cmd; |
3480 switch (addr_type) | 3480 switch (addr_type) |
3481 { | 3481 { |
3482 case ADDR_LINES: | 3482 case ADDR_LINES: |
3483 case ADDR_OTHER: | 3483 case ADDR_OTHER: |
3527 #endif | 3527 #endif |
3528 break; | 3528 break; |
3529 } | 3529 } |
3530 break; | 3530 break; |
3531 | 3531 |
3532 case '\'': /* ''' - mark */ | 3532 case '\'': // ''' - mark |
3533 if (*++cmd == NUL) | 3533 if (*++cmd == NUL) |
3534 { | 3534 { |
3535 cmd = NULL; | 3535 cmd = NULL; |
3536 goto error; | 3536 goto error; |
3537 } | 3537 } |
3543 } | 3543 } |
3544 if (skip) | 3544 if (skip) |
3545 ++cmd; | 3545 ++cmd; |
3546 else | 3546 else |
3547 { | 3547 { |
3548 /* Only accept a mark in another file when it is | 3548 // Only accept a mark in another file when it is |
3549 * used by itself: ":'M". */ | 3549 // used by itself: ":'M". |
3550 fp = getmark(*cmd, to_other_file && cmd[1] == NUL); | 3550 fp = getmark(*cmd, to_other_file && cmd[1] == NUL); |
3551 ++cmd; | 3551 ++cmd; |
3552 if (fp == (pos_T *)-1) | 3552 if (fp == (pos_T *)-1) |
3553 /* Jumped to another file. */ | 3553 // Jumped to another file. |
3554 lnum = curwin->w_cursor.lnum; | 3554 lnum = curwin->w_cursor.lnum; |
3555 else | 3555 else |
3556 { | 3556 { |
3557 if (check_mark(fp) == FAIL) | 3557 if (check_mark(fp) == FAIL) |
3558 { | 3558 { |
3563 } | 3563 } |
3564 } | 3564 } |
3565 break; | 3565 break; |
3566 | 3566 |
3567 case '/': | 3567 case '/': |
3568 case '?': /* '/' or '?' - search */ | 3568 case '?': // '/' or '?' - search |
3569 c = *cmd++; | 3569 c = *cmd++; |
3570 if (addr_type != ADDR_LINES) | 3570 if (addr_type != ADDR_LINES) |
3571 { | 3571 { |
3572 addr_error(addr_type); | 3572 addr_error(addr_type); |
3573 cmd = NULL; | 3573 cmd = NULL; |
3574 goto error; | 3574 goto error; |
3575 } | 3575 } |
3576 if (skip) /* skip "/pat/" */ | 3576 if (skip) // skip "/pat/" |
3577 { | 3577 { |
3578 cmd = skip_regexp(cmd, c, (int)p_magic, NULL); | 3578 cmd = skip_regexp(cmd, c, (int)p_magic, NULL); |
3579 if (*cmd == c) | 3579 if (*cmd == c) |
3580 ++cmd; | 3580 ++cmd; |
3581 } | 3581 } |
3608 cmd = NULL; | 3608 cmd = NULL; |
3609 goto error; | 3609 goto error; |
3610 } | 3610 } |
3611 lnum = curwin->w_cursor.lnum; | 3611 lnum = curwin->w_cursor.lnum; |
3612 curwin->w_cursor = pos; | 3612 curwin->w_cursor = pos; |
3613 /* adjust command string pointer */ | 3613 // adjust command string pointer |
3614 cmd += searchcmdlen; | 3614 cmd += searchcmdlen; |
3615 } | 3615 } |
3616 break; | 3616 break; |
3617 | 3617 |
3618 case '\\': /* "\?", "\/" or "\&", repeat search */ | 3618 case '\\': // "\?", "\/" or "\&", repeat search |
3619 ++cmd; | 3619 ++cmd; |
3620 if (addr_type != ADDR_LINES) | 3620 if (addr_type != ADDR_LINES) |
3621 { | 3621 { |
3622 addr_error(addr_type); | 3622 addr_error(addr_type); |
3623 cmd = NULL; | 3623 cmd = NULL; |
3666 } | 3666 } |
3667 ++cmd; | 3667 ++cmd; |
3668 break; | 3668 break; |
3669 | 3669 |
3670 default: | 3670 default: |
3671 if (VIM_ISDIGIT(*cmd)) /* absolute line number */ | 3671 if (VIM_ISDIGIT(*cmd)) // absolute line number |
3672 lnum = getdigits(&cmd); | 3672 lnum = getdigits(&cmd); |
3673 } | 3673 } |
3674 | 3674 |
3675 for (;;) | 3675 for (;;) |
3676 { | 3676 { |
3719 break; | 3719 break; |
3720 } | 3720 } |
3721 } | 3721 } |
3722 | 3722 |
3723 if (VIM_ISDIGIT(*cmd)) | 3723 if (VIM_ISDIGIT(*cmd)) |
3724 i = '+'; /* "number" is same as "+number" */ | 3724 i = '+'; // "number" is same as "+number" |
3725 else | 3725 else |
3726 i = *cmd++; | 3726 i = *cmd++; |
3727 if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */ | 3727 if (!VIM_ISDIGIT(*cmd)) // '+' is '+1', but '+0' is not '+1' |
3728 n = 1; | 3728 n = 1; |
3729 else | 3729 else |
3730 n = getdigits(&cmd); | 3730 n = getdigits(&cmd); |
3731 | 3731 |
3732 if (addr_type == ADDR_TABS_RELATIVE) | 3732 if (addr_type == ADDR_TABS_RELATIVE) |
3740 lnum = compute_buffer_local_count( | 3740 lnum = compute_buffer_local_count( |
3741 addr_type, lnum, (i == '-') ? -1 * n : n); | 3741 addr_type, lnum, (i == '-') ? -1 * n : n); |
3742 else | 3742 else |
3743 { | 3743 { |
3744 #ifdef FEAT_FOLDING | 3744 #ifdef FEAT_FOLDING |
3745 /* Relative line addressing, need to adjust for folded lines | 3745 // Relative line addressing, need to adjust for folded lines |
3746 * now, but only do it after the first address. */ | 3746 // now, but only do it after the first address. |
3747 if (addr_type == ADDR_LINES && (i == '-' || i == '+') | 3747 if (addr_type == ADDR_LINES && (i == '-' || i == '+') |
3748 && address_count >= 2) | 3748 && address_count >= 2) |
3749 (void)hasFolding(lnum, NULL, &lnum); | 3749 (void)hasFolding(lnum, NULL, &lnum); |
3750 #endif | 3750 #endif |
3751 if (i == '-') | 3751 if (i == '-') |
3829 #endif | 3829 #endif |
3830 ) | 3830 ) |
3831 return _(e_invrange); | 3831 return _(e_invrange); |
3832 break; | 3832 break; |
3833 case ADDR_ARGUMENTS: | 3833 case ADDR_ARGUMENTS: |
3834 /* add 1 if ARGCOUNT is 0 */ | 3834 // add 1 if ARGCOUNT is 0 |
3835 if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) | 3835 if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) |
3836 return _(e_invrange); | 3836 return _(e_invrange); |
3837 break; | 3837 break; |
3838 case ADDR_BUFFERS: | 3838 case ADDR_BUFFERS: |
3839 // Only a boundary check, not whether the buffers actually | 3839 // Only a boundary check, not whether the buffers actually |
3977 | 3977 |
3978 p = skipwhite(p); | 3978 p = skipwhite(p); |
3979 | 3979 |
3980 if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) | 3980 if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) |
3981 { | 3981 { |
3982 /* replace $* by given arguments */ | 3982 // replace $* by given arguments |
3983 i = 1; | 3983 i = 1; |
3984 while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL) | 3984 while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL) |
3985 ++i; | 3985 ++i; |
3986 len = (int)STRLEN(p); | 3986 len = (int)STRLEN(p); |
3987 new_cmdline = alloc(STRLEN(program) + i * (len - 2) + 1); | 3987 new_cmdline = alloc(STRLEN(program) + i * (len - 2) + 1); |
3988 if (new_cmdline == NULL) | 3988 if (new_cmdline == NULL) |
3989 return NULL; /* out of memory */ | 3989 return NULL; // out of memory |
3990 ptr = new_cmdline; | 3990 ptr = new_cmdline; |
3991 while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) | 3991 while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) |
3992 { | 3992 { |
3993 i = (int)(pos - program); | 3993 i = (int)(pos - program); |
3994 STRNCPY(ptr, program, i); | 3994 STRNCPY(ptr, program, i); |
4000 } | 4000 } |
4001 else | 4001 else |
4002 { | 4002 { |
4003 new_cmdline = alloc(STRLEN(program) + STRLEN(p) + 2); | 4003 new_cmdline = alloc(STRLEN(program) + STRLEN(p) + 2); |
4004 if (new_cmdline == NULL) | 4004 if (new_cmdline == NULL) |
4005 return NULL; /* out of memory */ | 4005 return NULL; // out of memory |
4006 STRCPY(new_cmdline, program); | 4006 STRCPY(new_cmdline, program); |
4007 STRCAT(new_cmdline, " "); | 4007 STRCAT(new_cmdline, " "); |
4008 STRCAT(new_cmdline, p); | 4008 STRCAT(new_cmdline, p); |
4009 } | 4009 } |
4010 msg_make(p); | 4010 msg_make(p); |
4011 | 4011 |
4012 /* 'eap->cmd' is not set here, because it is not used at CMD_make */ | 4012 // 'eap->cmd' is not set here, because it is not used at CMD_make |
4013 vim_free(*cmdlinep); | 4013 vim_free(*cmdlinep); |
4014 *cmdlinep = new_cmdline; | 4014 *cmdlinep = new_cmdline; |
4015 p = new_cmdline; | 4015 p = new_cmdline; |
4016 } | 4016 } |
4017 return p; | 4017 return p; |
4027 expand_filename( | 4027 expand_filename( |
4028 exarg_T *eap, | 4028 exarg_T *eap, |
4029 char_u **cmdlinep, | 4029 char_u **cmdlinep, |
4030 char **errormsgp) | 4030 char **errormsgp) |
4031 { | 4031 { |
4032 int has_wildcards; /* need to expand wildcards */ | 4032 int has_wildcards; // need to expand wildcards |
4033 char_u *repl; | 4033 char_u *repl; |
4034 int srclen; | 4034 int srclen; |
4035 char_u *p; | 4035 char_u *p; |
4036 int n; | 4036 int n; |
4037 int escaped; | 4037 int escaped; |
4038 | 4038 |
4039 #ifdef FEAT_QUICKFIX | 4039 #ifdef FEAT_QUICKFIX |
4040 /* Skip a regexp pattern for ":vimgrep[add] pat file..." */ | 4040 // Skip a regexp pattern for ":vimgrep[add] pat file..." |
4041 p = skip_grep_pat(eap); | 4041 p = skip_grep_pat(eap); |
4042 #else | 4042 #else |
4043 p = eap->arg; | 4043 p = eap->arg; |
4044 #endif | 4044 #endif |
4045 | 4045 |
4050 */ | 4050 */ |
4051 has_wildcards = mch_has_wildcard(p); | 4051 has_wildcards = mch_has_wildcard(p); |
4052 while (*p != NUL) | 4052 while (*p != NUL) |
4053 { | 4053 { |
4054 #ifdef FEAT_EVAL | 4054 #ifdef FEAT_EVAL |
4055 /* Skip over `=expr`, wildcards in it are not expanded. */ | 4055 // Skip over `=expr`, wildcards in it are not expanded. |
4056 if (p[0] == '`' && p[1] == '=') | 4056 if (p[0] == '`' && p[1] == '=') |
4057 { | 4057 { |
4058 p += 2; | 4058 p += 2; |
4059 (void)skip_expr(&p); | 4059 (void)skip_expr(&p); |
4060 if (*p == '`') | 4060 if (*p == '`') |
4075 /* | 4075 /* |
4076 * Try to find a match at this position. | 4076 * Try to find a match at this position. |
4077 */ | 4077 */ |
4078 repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), | 4078 repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), |
4079 errormsgp, &escaped); | 4079 errormsgp, &escaped); |
4080 if (*errormsgp != NULL) /* error detected */ | 4080 if (*errormsgp != NULL) // error detected |
4081 return FAIL; | 4081 return FAIL; |
4082 if (repl == NULL) /* no match found */ | 4082 if (repl == NULL) // no match found |
4083 { | 4083 { |
4084 p += srclen; | 4084 p += srclen; |
4085 continue; | 4085 continue; |
4086 } | 4086 } |
4087 | 4087 |
4088 /* Wildcards won't be expanded below, the replacement is taken | 4088 // Wildcards won't be expanded below, the replacement is taken |
4089 * literally. But do expand "~/file", "~user/file" and "$HOME/file". */ | 4089 // literally. But do expand "~/file", "~user/file" and "$HOME/file". |
4090 if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL) | 4090 if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL) |
4091 { | 4091 { |
4092 char_u *l = repl; | 4092 char_u *l = repl; |
4093 | 4093 |
4094 repl = expand_env_save(repl); | 4094 repl = expand_env_save(repl); |
4095 vim_free(l); | 4095 vim_free(l); |
4096 } | 4096 } |
4097 | 4097 |
4098 /* Need to escape white space et al. with a backslash. | 4098 // Need to escape white space et al. with a backslash. |
4099 * Don't do this for: | 4099 // Don't do this for: |
4100 * - replacement that already has been escaped: "##" | 4100 // - replacement that already has been escaped: "##" |
4101 * - shell commands (may have to use quotes instead). | 4101 // - shell commands (may have to use quotes instead). |
4102 * - non-unix systems when there is a single argument (spaces don't | 4102 // - non-unix systems when there is a single argument (spaces don't |
4103 * separate arguments then). | 4103 // separate arguments then). |
4104 */ | |
4105 if (!eap->usefilter | 4104 if (!eap->usefilter |
4106 && !escaped | 4105 && !escaped |
4107 && eap->cmdidx != CMD_bang | 4106 && eap->cmdidx != CMD_bang |
4108 && eap->cmdidx != CMD_grep | 4107 && eap->cmdidx != CMD_grep |
4109 && eap->cmdidx != CMD_grepadd | 4108 && eap->cmdidx != CMD_grepadd |
4118 #endif | 4117 #endif |
4119 ) | 4118 ) |
4120 { | 4119 { |
4121 char_u *l; | 4120 char_u *l; |
4122 #ifdef BACKSLASH_IN_FILENAME | 4121 #ifdef BACKSLASH_IN_FILENAME |
4123 /* Don't escape a backslash here, because rem_backslash() doesn't | 4122 // Don't escape a backslash here, because rem_backslash() doesn't |
4124 * remove it later. */ | 4123 // remove it later. |
4125 static char_u *nobslash = (char_u *)" \t\"|"; | 4124 static char_u *nobslash = (char_u *)" \t\"|"; |
4126 # define ESCAPE_CHARS nobslash | 4125 # define ESCAPE_CHARS nobslash |
4127 #else | 4126 #else |
4128 # define ESCAPE_CHARS escape_chars | 4127 # define ESCAPE_CHARS escape_chars |
4129 #endif | 4128 #endif |
4139 } | 4138 } |
4140 break; | 4139 break; |
4141 } | 4140 } |
4142 } | 4141 } |
4143 | 4142 |
4144 /* For a shell command a '!' must be escaped. */ | 4143 // For a shell command a '!' must be escaped. |
4145 if ((eap->usefilter || eap->cmdidx == CMD_bang | 4144 if ((eap->usefilter || eap->cmdidx == CMD_bang |
4146 || eap->cmdidx == CMD_terminal) | 4145 || eap->cmdidx == CMD_terminal) |
4147 && vim_strpbrk(repl, (char_u *)"!") != NULL) | 4146 && vim_strpbrk(repl, (char_u *)"!") != NULL) |
4148 { | 4147 { |
4149 char_u *l; | 4148 char_u *l; |
4208 p = NameBuff; | 4207 p = NameBuff; |
4209 } | 4208 } |
4210 else | 4209 else |
4211 p = NULL; | 4210 p = NULL; |
4212 } | 4211 } |
4213 else /* n == 2 */ | 4212 else // n == 2 |
4214 { | 4213 { |
4215 expand_T xpc; | 4214 expand_T xpc; |
4216 int options = WILD_LIST_NOTFOUND | 4215 int options = WILD_LIST_NOTFOUND |
4217 | WILD_NOERROR | WILD_ADD_SLASH; | 4216 | WILD_NOERROR | WILD_ADD_SLASH; |
4218 | 4217 |
4227 } | 4226 } |
4228 if (p != NULL) | 4227 if (p != NULL) |
4229 { | 4228 { |
4230 (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), | 4229 (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), |
4231 p, cmdlinep); | 4230 p, cmdlinep); |
4232 if (n == 2) /* p came from ExpandOne() */ | 4231 if (n == 2) // p came from ExpandOne() |
4233 vim_free(p); | 4232 vim_free(p); |
4234 } | 4233 } |
4235 } | 4234 } |
4236 } | 4235 } |
4237 } | 4236 } |
4264 * Careful: a "+cmd" argument may have been NUL terminated. | 4263 * Careful: a "+cmd" argument may have been NUL terminated. |
4265 */ | 4264 */ |
4266 len = (int)STRLEN(repl); | 4265 len = (int)STRLEN(repl); |
4267 i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3; | 4266 i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3; |
4268 if (eap->nextcmd != NULL) | 4267 if (eap->nextcmd != NULL) |
4269 i += (int)STRLEN(eap->nextcmd);/* add space for next command */ | 4268 i += (int)STRLEN(eap->nextcmd);// add space for next command |
4270 if ((new_cmdline = alloc(i)) == NULL) | 4269 if ((new_cmdline = alloc(i)) == NULL) |
4271 return NULL; /* out of memory! */ | 4270 return NULL; // out of memory! |
4272 | 4271 |
4273 /* | 4272 /* |
4274 * Copy the stuff before the expanded part. | 4273 * Copy the stuff before the expanded part. |
4275 * Copy the expanded stuff. | 4274 * Copy the expanded stuff. |
4276 * Copy what came after the expanded part. | 4275 * Copy what came after the expanded part. |
4277 * Copy the next commands, if there are any. | 4276 * Copy the next commands, if there are any. |
4278 */ | 4277 */ |
4279 i = (int)(src - *cmdlinep); /* length of part before match */ | 4278 i = (int)(src - *cmdlinep); // length of part before match |
4280 mch_memmove(new_cmdline, *cmdlinep, (size_t)i); | 4279 mch_memmove(new_cmdline, *cmdlinep, (size_t)i); |
4281 | 4280 |
4282 mch_memmove(new_cmdline + i, repl, (size_t)len); | 4281 mch_memmove(new_cmdline + i, repl, (size_t)len); |
4283 i += len; /* remember the end of the string */ | 4282 i += len; // remember the end of the string |
4284 STRCPY(new_cmdline + i, src + srclen); | 4283 STRCPY(new_cmdline + i, src + srclen); |
4285 src = new_cmdline + i; /* remember where to continue */ | 4284 src = new_cmdline + i; // remember where to continue |
4286 | 4285 |
4287 if (eap->nextcmd != NULL) /* append next command */ | 4286 if (eap->nextcmd != NULL) // append next command |
4288 { | 4287 { |
4289 i = (int)STRLEN(new_cmdline) + 1; | 4288 i = (int)STRLEN(new_cmdline) + 1; |
4290 STRCPY(new_cmdline + i, eap->nextcmd); | 4289 STRCPY(new_cmdline + i, eap->nextcmd); |
4291 eap->nextcmd = new_cmdline + i; | 4290 eap->nextcmd = new_cmdline + i; |
4292 } | 4291 } |
4317 for ( ; *p; MB_PTR_ADV(p)) | 4316 for ( ; *p; MB_PTR_ADV(p)) |
4318 { | 4317 { |
4319 if (*p == Ctrl_V) | 4318 if (*p == Ctrl_V) |
4320 { | 4319 { |
4321 if (eap->argt & (EX_CTRLV | EX_XFILE)) | 4320 if (eap->argt & (EX_CTRLV | EX_XFILE)) |
4322 ++p; /* skip CTRL-V and next char */ | 4321 ++p; // skip CTRL-V and next char |
4323 else | 4322 else |
4324 /* remove CTRL-V and skip next char */ | 4323 // remove CTRL-V and skip next char |
4325 STRMOVE(p, p + 1); | 4324 STRMOVE(p, p + 1); |
4326 if (*p == NUL) /* stop at NUL after CTRL-V */ | 4325 if (*p == NUL) // stop at NUL after CTRL-V |
4327 break; | 4326 break; |
4328 } | 4327 } |
4329 | 4328 |
4330 #ifdef FEAT_EVAL | 4329 #ifdef FEAT_EVAL |
4331 /* Skip over `=expr` when wildcards are expanded. */ | 4330 // Skip over `=expr` when wildcards are expanded. |
4332 else if (p[0] == '`' && p[1] == '=' && (eap->argt & EX_XFILE)) | 4331 else if (p[0] == '`' && p[1] == '=' && (eap->argt & EX_XFILE)) |
4333 { | 4332 { |
4334 p += 2; | 4333 p += 2; |
4335 (void)skip_expr(&p); | 4334 (void)skip_expr(&p); |
4336 } | 4335 } |
4337 #endif | 4336 #endif |
4338 | 4337 |
4339 /* Check for '"': start of comment or '|': next command */ | 4338 // Check for '"': start of comment or '|': next command |
4340 /* :@" and :*" do not start a comment! | 4339 // :@" and :*" do not start a comment! |
4341 * :redir @" doesn't either. */ | 4340 // :redir @" doesn't either. |
4342 else if ((*p == '"' && !(eap->argt & EX_NOTRLCOM) | 4341 else if ((*p == '"' && !(eap->argt & EX_NOTRLCOM) |
4343 && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star) | 4342 && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star) |
4344 || p != eap->arg) | 4343 || p != eap->arg) |
4345 && (eap->cmdidx != CMD_redir | 4344 && (eap->cmdidx != CMD_redir |
4346 || p != eap->arg + 1 || p[-1] != '@')) | 4345 || p != eap->arg + 1 || p[-1] != '@')) |
4351 * AND 'b' is present in 'cpoptions'. | 4350 * AND 'b' is present in 'cpoptions'. |
4352 */ | 4351 */ |
4353 if ((vim_strchr(p_cpo, CPO_BAR) == NULL | 4352 if ((vim_strchr(p_cpo, CPO_BAR) == NULL |
4354 || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\') | 4353 || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\') |
4355 { | 4354 { |
4356 STRMOVE(p - 1, p); /* remove the '\' */ | 4355 STRMOVE(p - 1, p); // remove the '\' |
4357 --p; | 4356 --p; |
4358 } | 4357 } |
4359 else | 4358 else |
4360 { | 4359 { |
4361 eap->nextcmd = check_nextcmd(p); | 4360 eap->nextcmd = check_nextcmd(p); |
4363 break; | 4362 break; |
4364 } | 4363 } |
4365 } | 4364 } |
4366 } | 4365 } |
4367 | 4366 |
4368 if (!(eap->argt & EX_NOTRLCOM)) /* remove trailing spaces */ | 4367 if (!(eap->argt & EX_NOTRLCOM)) // remove trailing spaces |
4369 del_trailing_spaces(eap->arg); | 4368 del_trailing_spaces(eap->arg); |
4370 } | 4369 } |
4371 | 4370 |
4372 /* | 4371 /* |
4373 * get + command from ex argument | 4372 * get + command from ex argument |
4376 getargcmd(char_u **argp) | 4375 getargcmd(char_u **argp) |
4377 { | 4376 { |
4378 char_u *arg = *argp; | 4377 char_u *arg = *argp; |
4379 char_u *command = NULL; | 4378 char_u *command = NULL; |
4380 | 4379 |
4381 if (*arg == '+') /* +[command] */ | 4380 if (*arg == '+') // +[command] |
4382 { | 4381 { |
4383 ++arg; | 4382 ++arg; |
4384 if (vim_isspace(*arg) || *arg == NUL) | 4383 if (vim_isspace(*arg) || *arg == NUL) |
4385 command = dollar_command; | 4384 command = dollar_command; |
4386 else | 4385 else |
4387 { | 4386 { |
4388 command = arg; | 4387 command = arg; |
4389 arg = skip_cmd_arg(command, TRUE); | 4388 arg = skip_cmd_arg(command, TRUE); |
4390 if (*arg != NUL) | 4389 if (*arg != NUL) |
4391 *arg++ = NUL; /* terminate command with NUL */ | 4390 *arg++ = NUL; // terminate command with NUL |
4392 } | 4391 } |
4393 | 4392 |
4394 arg = skipwhite(arg); /* skip over spaces */ | 4393 arg = skipwhite(arg); // skip over spaces |
4395 *argp = arg; | 4394 *argp = arg; |
4396 } | 4395 } |
4397 return command; | 4396 return command; |
4398 } | 4397 } |
4399 | 4398 |
4401 * Find end of "+command" argument. Skip over "\ " and "\\". | 4400 * Find end of "+command" argument. Skip over "\ " and "\\". |
4402 */ | 4401 */ |
4403 char_u * | 4402 char_u * |
4404 skip_cmd_arg( | 4403 skip_cmd_arg( |
4405 char_u *p, | 4404 char_u *p, |
4406 int rembs) /* TRUE to halve the number of backslashes */ | 4405 int rembs) // TRUE to halve the number of backslashes |
4407 { | 4406 { |
4408 while (*p && !vim_isspace(*p)) | 4407 while (*p && !vim_isspace(*p)) |
4409 { | 4408 { |
4410 if (*p == '\\' && p[1] != NUL) | 4409 if (*p == '\\' && p[1] != NUL) |
4411 { | 4410 { |
4443 char_u *arg = eap->arg + 2; | 4442 char_u *arg = eap->arg + 2; |
4444 int *pp = NULL; | 4443 int *pp = NULL; |
4445 int bad_char_idx; | 4444 int bad_char_idx; |
4446 char_u *p; | 4445 char_u *p; |
4447 | 4446 |
4448 /* ":edit ++[no]bin[ary] file" */ | 4447 // ":edit ++[no]bin[ary] file" |
4449 if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) | 4448 if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) |
4450 { | 4449 { |
4451 if (*arg == 'n') | 4450 if (*arg == 'n') |
4452 { | 4451 { |
4453 arg += 2; | 4452 arg += 2; |
4459 return FAIL; | 4458 return FAIL; |
4460 eap->arg = skipwhite(arg); | 4459 eap->arg = skipwhite(arg); |
4461 return OK; | 4460 return OK; |
4462 } | 4461 } |
4463 | 4462 |
4464 /* ":read ++edit file" */ | 4463 // ":read ++edit file" |
4465 if (STRNCMP(arg, "edit", 4) == 0) | 4464 if (STRNCMP(arg, "edit", 4) == 0) |
4466 { | 4465 { |
4467 eap->read_edit = TRUE; | 4466 eap->read_edit = TRUE; |
4468 eap->arg = skipwhite(arg + 4); | 4467 eap->arg = skipwhite(arg + 4); |
4469 return OK; | 4468 return OK; |
4508 return FAIL; | 4507 return FAIL; |
4509 eap->force_ff = eap->cmd[eap->force_ff]; | 4508 eap->force_ff = eap->cmd[eap->force_ff]; |
4510 } | 4509 } |
4511 else if (pp == &eap->force_enc) | 4510 else if (pp == &eap->force_enc) |
4512 { | 4511 { |
4513 /* Make 'fileencoding' lower case. */ | 4512 // Make 'fileencoding' lower case. |
4514 for (p = eap->cmd + eap->force_enc; *p != NUL; ++p) | 4513 for (p = eap->cmd + eap->force_enc; *p != NUL; ++p) |
4515 *p = TOLOWER_ASC(*p); | 4514 *p = TOLOWER_ASC(*p); |
4516 } | 4515 } |
4517 else | 4516 else |
4518 { | 4517 { |
4519 /* Check ++bad= argument. Must be a single-byte character, "keep" or | 4518 // Check ++bad= argument. Must be a single-byte character, "keep" or |
4520 * "drop". */ | 4519 // "drop". |
4521 if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) | 4520 if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) |
4522 return FAIL; | 4521 return FAIL; |
4523 } | 4522 } |
4524 | 4523 |
4525 return OK; | 4524 return OK; |
4552 char_u *arg = eap->arg; | 4551 char_u *arg = eap->arg; |
4553 int call_do_modelines = check_nomodeline(&arg); | 4552 int call_do_modelines = check_nomodeline(&arg); |
4554 int did_aucmd; | 4553 int did_aucmd; |
4555 | 4554 |
4556 (void)do_doautocmd(arg, TRUE, &did_aucmd); | 4555 (void)do_doautocmd(arg, TRUE, &did_aucmd); |
4557 /* Only when there is no <nomodeline>. */ | 4556 // Only when there is no <nomodeline>. |
4558 if (call_do_modelines && did_aucmd) | 4557 if (call_do_modelines && did_aucmd) |
4559 do_modelines(0); | 4558 do_modelines(0); |
4560 } | 4559 } |
4561 | 4560 |
4562 /* | 4561 /* |
4587 return; | 4586 return; |
4588 if (*eap->arg) | 4587 if (*eap->arg) |
4589 eap->errmsg = e_trailing; | 4588 eap->errmsg = e_trailing; |
4590 else | 4589 else |
4591 { | 4590 { |
4592 if (eap->addr_count == 0) /* default is current buffer */ | 4591 if (eap->addr_count == 0) // default is current buffer |
4593 goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); | 4592 goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); |
4594 else | 4593 else |
4595 goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); | 4594 goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); |
4596 if (eap->do_ecmd_cmd != NULL) | 4595 if (eap->do_ecmd_cmd != NULL) |
4597 do_cmdline_cmd(eap->do_ecmd_cmd); | 4596 do_cmdline_cmd(eap->do_ecmd_cmd); |
4710 * return FAIL and give error message if 'message' TRUE | 4709 * return FAIL and give error message if 'message' TRUE |
4711 * return OK otherwise | 4710 * return OK otherwise |
4712 */ | 4711 */ |
4713 static int | 4712 static int |
4714 check_more( | 4713 check_more( |
4715 int message, /* when FALSE check only, no messages */ | 4714 int message, // when FALSE check only, no messages |
4716 int forceit) | 4715 int forceit) |
4717 { | 4716 { |
4718 int n = ARGCOUNT - curwin->w_arg_idx - 1; | 4717 int n = ARGCOUNT - curwin->w_arg_idx - 1; |
4719 | 4718 |
4720 if (!forceit && only_one_window() | 4719 if (!forceit && only_one_window() |
4735 return FAIL; | 4734 return FAIL; |
4736 } | 4735 } |
4737 #endif | 4736 #endif |
4738 semsg(NGETTEXT("E173: %d more file to edit", | 4737 semsg(NGETTEXT("E173: %d more file to edit", |
4739 "E173: %d more files to edit", n), n); | 4738 "E173: %d more files to edit", n), n); |
4740 quitmore = 2; /* next try to quit is allowed */ | 4739 quitmore = 2; // next try to quit is allowed |
4741 } | 4740 } |
4742 return FAIL; | 4741 return FAIL; |
4743 } | 4742 } |
4744 return OK; | 4743 return OK; |
4745 } | 4744 } |
4857 { | 4856 { |
4858 cmdwin_result = Ctrl_C; | 4857 cmdwin_result = Ctrl_C; |
4859 return; | 4858 return; |
4860 } | 4859 } |
4861 #endif | 4860 #endif |
4862 /* Don't quit while editing the command line. */ | 4861 // Don't quit while editing the command line. |
4863 if (text_locked()) | 4862 if (text_locked()) |
4864 { | 4863 { |
4865 text_locked_msg(); | 4864 text_locked_msg(); |
4866 return; | 4865 return; |
4867 } | 4866 } |
4874 break; | 4873 break; |
4875 } | 4874 } |
4876 else | 4875 else |
4877 wp = curwin; | 4876 wp = curwin; |
4878 | 4877 |
4879 /* Refuse to quit when locked. */ | 4878 // Refuse to quit when locked. |
4880 if (curbuf_locked()) | 4879 if (curbuf_locked()) |
4881 return; | 4880 return; |
4882 | 4881 |
4883 /* Trigger QuitPre and maybe ExitPre */ | 4882 // Trigger QuitPre and maybe ExitPre |
4884 if (before_quit_autocmds(wp, FALSE, eap->forceit)) | 4883 if (before_quit_autocmds(wp, FALSE, eap->forceit)) |
4885 return; | 4884 return; |
4886 | 4885 |
4887 #ifdef FEAT_NETBEANS_INTG | 4886 #ifdef FEAT_NETBEANS_INTG |
4888 netbeansForcedQuit = eap->forceit; | 4887 netbeansForcedQuit = eap->forceit; |
4902 { | 4901 { |
4903 not_exiting(); | 4902 not_exiting(); |
4904 } | 4903 } |
4905 else | 4904 else |
4906 { | 4905 { |
4907 /* quit last window | 4906 // quit last window |
4908 * Note: only_one_window() returns true, even so a help window is | 4907 // Note: only_one_window() returns true, even so a help window is |
4909 * still open. In that case only quit, if no address has been | 4908 // still open. In that case only quit, if no address has been |
4910 * specified. Example: | 4909 // specified. Example: |
4911 * :h|wincmd w|1q - don't quit | 4910 // :h|wincmd w|1q - don't quit |
4912 * :h|wincmd w|q - quit | 4911 // :h|wincmd w|q - quit |
4913 */ | |
4914 if (only_one_window() && (ONE_WINDOW || eap->addr_count == 0)) | 4912 if (only_one_window() && (ONE_WINDOW || eap->addr_count == 0)) |
4915 getout(0); | 4913 getout(0); |
4916 not_exiting(); | 4914 not_exiting(); |
4917 #ifdef FEAT_GUI | 4915 #ifdef FEAT_GUI |
4918 need_mouse_correct = TRUE; | 4916 need_mouse_correct = TRUE; |
4919 #endif | 4917 #endif |
4920 /* close window; may free buffer */ | 4918 // close window; may free buffer |
4921 win_close(wp, !buf_hide(wp->w_buffer) || eap->forceit); | 4919 win_close(wp, !buf_hide(wp->w_buffer) || eap->forceit); |
4922 } | 4920 } |
4923 } | 4921 } |
4924 | 4922 |
4925 /* | 4923 /* |
4926 * ":cquit". | 4924 * ":cquit". |
4927 */ | 4925 */ |
4928 static void | 4926 static void |
4929 ex_cquit(exarg_T *eap UNUSED) | 4927 ex_cquit(exarg_T *eap UNUSED) |
4930 { | 4928 { |
4931 getout(1); /* this does not always pass on the exit code to the Manx | 4929 getout(1); // this does not always pass on the exit code to the Manx |
4932 compiler. why? */ | 4930 // compiler. why? |
4933 } | 4931 } |
4934 | 4932 |
4935 /* | 4933 /* |
4936 * ":qall": try to quit all windows | 4934 * ":qall": try to quit all windows |
4937 */ | 4935 */ |
4940 { | 4938 { |
4941 # ifdef FEAT_CMDWIN | 4939 # ifdef FEAT_CMDWIN |
4942 if (cmdwin_type != 0) | 4940 if (cmdwin_type != 0) |
4943 { | 4941 { |
4944 if (eap->forceit) | 4942 if (eap->forceit) |
4945 cmdwin_result = K_XF1; /* ex_window() takes care of this */ | 4943 cmdwin_result = K_XF1; // ex_window() takes care of this |
4946 else | 4944 else |
4947 cmdwin_result = K_XF2; | 4945 cmdwin_result = K_XF2; |
4948 return; | 4946 return; |
4949 } | 4947 } |
4950 # endif | 4948 # endif |
4951 | 4949 |
4952 /* Don't quit while editing the command line. */ | 4950 // Don't quit while editing the command line. |
4953 if (text_locked()) | 4951 if (text_locked()) |
4954 { | 4952 { |
4955 text_locked_msg(); | 4953 text_locked_msg(); |
4956 return; | 4954 return; |
4957 } | 4955 } |
5026 */ | 5024 */ |
5027 static void | 5025 static void |
5028 ex_win_close( | 5026 ex_win_close( |
5029 int forceit, | 5027 int forceit, |
5030 win_T *win, | 5028 win_T *win, |
5031 tabpage_T *tp) /* NULL or the tab page "win" is in */ | 5029 tabpage_T *tp) // NULL or the tab page "win" is in |
5032 { | 5030 { |
5033 int need_hide; | 5031 int need_hide; |
5034 buf_T *buf = win->w_buffer; | 5032 buf_T *buf = win->w_buffer; |
5035 | 5033 |
5036 need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1); | 5034 need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1); |
5057 | 5055 |
5058 #ifdef FEAT_GUI | 5056 #ifdef FEAT_GUI |
5059 need_mouse_correct = TRUE; | 5057 need_mouse_correct = TRUE; |
5060 #endif | 5058 #endif |
5061 | 5059 |
5062 /* free buffer when not hiding it or when it's a scratch buffer */ | 5060 // free buffer when not hiding it or when it's a scratch buffer |
5063 if (tp == NULL) | 5061 if (tp == NULL) |
5064 win_close(win, !need_hide && !buf_hide(buf)); | 5062 win_close(win, !need_hide && !buf_hide(buf)); |
5065 else | 5063 else |
5066 win_close_othertab(win, !need_hide && !buf_hide(buf), tp); | 5064 win_close_othertab(win, !need_hide && !buf_hide(buf), tp); |
5067 } | 5065 } |
5079 | 5077 |
5080 if (eap->arg && *eap->arg != NUL) | 5078 if (eap->arg && *eap->arg != NUL) |
5081 { | 5079 { |
5082 char_u *p = eap->arg; | 5080 char_u *p = eap->arg; |
5083 char_u *p_save; | 5081 char_u *p_save; |
5084 int relative = 0; /* argument +N/-N means: go to N places to the | 5082 int relative = 0; // argument +N/-N means: go to N places to the |
5085 * right/left relative to the current position. */ | 5083 // right/left relative to the current position. |
5086 | 5084 |
5087 if (*p == '-') | 5085 if (*p == '-') |
5088 { | 5086 { |
5089 relative = -1; | 5087 relative = -1; |
5090 p++; | 5088 p++; |
5103 if (STRCMP(p, "$") == 0) | 5101 if (STRCMP(p, "$") == 0) |
5104 tab_number = LAST_TAB_NR; | 5102 tab_number = LAST_TAB_NR; |
5105 else if (p == p_save || *p_save == '-' || *p != NUL | 5103 else if (p == p_save || *p_save == '-' || *p != NUL |
5106 || tab_number > LAST_TAB_NR) | 5104 || tab_number > LAST_TAB_NR) |
5107 { | 5105 { |
5108 /* No numbers as argument. */ | 5106 // No numbers as argument. |
5109 eap->errmsg = e_invarg; | 5107 eap->errmsg = e_invarg; |
5110 goto theend; | 5108 goto theend; |
5111 } | 5109 } |
5112 } | 5110 } |
5113 else | 5111 else |
5115 if (*p_save == NUL) | 5113 if (*p_save == NUL) |
5116 tab_number = 1; | 5114 tab_number = 1; |
5117 else if (p == p_save || *p_save == '-' || *p != NUL | 5115 else if (p == p_save || *p_save == '-' || *p != NUL |
5118 || tab_number == 0) | 5116 || tab_number == 0) |
5119 { | 5117 { |
5120 /* No numbers as argument. */ | 5118 // No numbers as argument. |
5121 eap->errmsg = e_invarg; | 5119 eap->errmsg = e_invarg; |
5122 goto theend; | 5120 goto theend; |
5123 } | 5121 } |
5124 tab_number = tab_number * relative + tabpage_index(curtab); | 5122 tab_number = tab_number * relative + tabpage_index(curtab); |
5125 if (!unaccept_arg0 && relative == -1) | 5123 if (!unaccept_arg0 && relative == -1) |
5227 { | 5225 { |
5228 tab_number = get_tabpage_arg(eap); | 5226 tab_number = get_tabpage_arg(eap); |
5229 if (eap->errmsg == NULL) | 5227 if (eap->errmsg == NULL) |
5230 { | 5228 { |
5231 goto_tabpage(tab_number); | 5229 goto_tabpage(tab_number); |
5232 /* Repeat this up to a 1000 times, because autocommands may | 5230 // Repeat this up to a 1000 times, because autocommands may |
5233 * mess up the lists. */ | 5231 // mess up the lists. |
5234 for (done = 0; done < 1000; ++done) | 5232 for (done = 0; done < 1000; ++done) |
5235 { | 5233 { |
5236 FOR_ALL_TABPAGES(tp) | 5234 FOR_ALL_TABPAGES(tp) |
5237 if (tp->tp_topframe != topframe) | 5235 if (tp->tp_topframe != topframe) |
5238 { | 5236 { |
5239 tabpage_close_other(tp, eap->forceit); | 5237 tabpage_close_other(tp, eap->forceit); |
5240 /* if we failed to close it quit */ | 5238 // if we failed to close it quit |
5241 if (valid_tabpage(tp)) | 5239 if (valid_tabpage(tp)) |
5242 done = 1000; | 5240 done = 1000; |
5243 /* start over, "tp" is now invalid */ | 5241 // start over, "tp" is now invalid |
5244 break; | 5242 break; |
5245 } | 5243 } |
5246 if (first_tabpage->tp_next == NULL) | 5244 if (first_tabpage->tp_next == NULL) |
5247 break; | 5245 break; |
5248 } | 5246 } |
5254 * Close the current tab page. | 5252 * Close the current tab page. |
5255 */ | 5253 */ |
5256 void | 5254 void |
5257 tabpage_close(int forceit) | 5255 tabpage_close(int forceit) |
5258 { | 5256 { |
5259 /* First close all the windows but the current one. If that worked then | 5257 // First close all the windows but the current one. If that worked then |
5260 * close the last window in this tab, that will close it. */ | 5258 // close the last window in this tab, that will close it. |
5261 if (!ONE_WINDOW) | 5259 if (!ONE_WINDOW) |
5262 close_others(TRUE, forceit); | 5260 close_others(TRUE, forceit); |
5263 if (ONE_WINDOW) | 5261 if (ONE_WINDOW) |
5264 ex_win_close(forceit, curwin, NULL); | 5262 ex_win_close(forceit, curwin, NULL); |
5265 # ifdef FEAT_GUI | 5263 # ifdef FEAT_GUI |
5278 { | 5276 { |
5279 int done = 0; | 5277 int done = 0; |
5280 win_T *wp; | 5278 win_T *wp; |
5281 int h = tabline_height(); | 5279 int h = tabline_height(); |
5282 | 5280 |
5283 /* Limit to 1000 windows, autocommands may add a window while we close | 5281 // Limit to 1000 windows, autocommands may add a window while we close |
5284 * one. OK, so I'm paranoid... */ | 5282 // one. OK, so I'm paranoid... |
5285 while (++done < 1000) | 5283 while (++done < 1000) |
5286 { | 5284 { |
5287 wp = tp->tp_firstwin; | 5285 wp = tp->tp_firstwin; |
5288 ex_win_close(forceit, wp, tp); | 5286 ex_win_close(forceit, wp, tp); |
5289 | 5287 |
5290 /* Autocommands may delete the tab page under our fingers and we may | 5288 // Autocommands may delete the tab page under our fingers and we may |
5291 * fail to close a window with a modified buffer. */ | 5289 // fail to close a window with a modified buffer. |
5292 if (!valid_tabpage(tp) || tp->tp_firstwin == wp) | 5290 if (!valid_tabpage(tp) || tp->tp_firstwin == wp) |
5293 break; | 5291 break; |
5294 } | 5292 } |
5295 | 5293 |
5296 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); | 5294 apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); |
5327 } | 5325 } |
5328 | 5326 |
5329 static void | 5327 static void |
5330 ex_hide(exarg_T *eap UNUSED) | 5328 ex_hide(exarg_T *eap UNUSED) |
5331 { | 5329 { |
5332 /* ":hide" or ":hide | cmd": hide current window */ | 5330 // ":hide" or ":hide | cmd": hide current window |
5333 if (!eap->skip) | 5331 if (!eap->skip) |
5334 { | 5332 { |
5335 #ifdef FEAT_GUI | 5333 #ifdef FEAT_GUI |
5336 need_mouse_correct = TRUE; | 5334 need_mouse_correct = TRUE; |
5337 #endif | 5335 #endif |
5338 if (eap->addr_count == 0) | 5336 if (eap->addr_count == 0) |
5339 win_close(curwin, FALSE); /* don't free buffer */ | 5337 win_close(curwin, FALSE); // don't free buffer |
5340 else | 5338 else |
5341 { | 5339 { |
5342 int winnr = 0; | 5340 int winnr = 0; |
5343 win_T *win; | 5341 win_T *win; |
5344 | 5342 |
5370 autowrite_all(); | 5368 autowrite_all(); |
5371 windgoto((int)Rows - 1, 0); | 5369 windgoto((int)Rows - 1, 0); |
5372 out_char('\n'); | 5370 out_char('\n'); |
5373 out_flush(); | 5371 out_flush(); |
5374 stoptermcap(); | 5372 stoptermcap(); |
5375 out_flush(); /* needed for SUN to restore xterm buffer */ | 5373 out_flush(); // needed for SUN to restore xterm buffer |
5376 #ifdef FEAT_TITLE | 5374 #ifdef FEAT_TITLE |
5377 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */ | 5375 mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles |
5378 #endif | 5376 #endif |
5379 ui_suspend(); /* call machine specific function */ | 5377 ui_suspend(); // call machine specific function |
5380 #ifdef FEAT_TITLE | 5378 #ifdef FEAT_TITLE |
5381 maketitle(); | 5379 maketitle(); |
5382 resettitle(); /* force updating the title */ | 5380 resettitle(); // force updating the title |
5383 #endif | 5381 #endif |
5384 starttermcap(); | 5382 starttermcap(); |
5385 scroll_start(); /* scroll screen before redrawing */ | 5383 scroll_start(); // scroll screen before redrawing |
5386 redraw_later_clear(); | 5384 redraw_later_clear(); |
5387 shell_resized(); /* may have resized window */ | 5385 shell_resized(); // may have resized window |
5388 } | 5386 } |
5389 } | 5387 } |
5390 | 5388 |
5391 /* | 5389 /* |
5392 * ":exit", ":xit" and ":wq": Write file and quite the current window. | 5390 * ":exit", ":xit" and ":wq": Write file and quite the current window. |
5399 { | 5397 { |
5400 cmdwin_result = Ctrl_C; | 5398 cmdwin_result = Ctrl_C; |
5401 return; | 5399 return; |
5402 } | 5400 } |
5403 #endif | 5401 #endif |
5404 /* Don't quit while editing the command line. */ | 5402 // Don't quit while editing the command line. |
5405 if (text_locked()) | 5403 if (text_locked()) |
5406 { | 5404 { |
5407 text_locked_msg(); | 5405 text_locked_msg(); |
5408 return; | 5406 return; |
5409 } | 5407 } |
5424 { | 5422 { |
5425 not_exiting(); | 5423 not_exiting(); |
5426 } | 5424 } |
5427 else | 5425 else |
5428 { | 5426 { |
5429 if (only_one_window()) /* quit last window, exit Vim */ | 5427 if (only_one_window()) // quit last window, exit Vim |
5430 getout(0); | 5428 getout(0); |
5431 not_exiting(); | 5429 not_exiting(); |
5432 # ifdef FEAT_GUI | 5430 # ifdef FEAT_GUI |
5433 need_mouse_correct = TRUE; | 5431 need_mouse_correct = TRUE; |
5434 # endif | 5432 # endif |
5435 /* Quit current window, may free the buffer. */ | 5433 // Quit current window, may free the buffer. |
5436 win_close(curwin, !buf_hide(curwin->w_buffer)); | 5434 win_close(curwin, !buf_hide(curwin->w_buffer)); |
5437 } | 5435 } |
5438 } | 5436 } |
5439 | 5437 |
5440 /* | 5438 /* |
5453 (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound | 5451 (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound |
5454 || (eap->flags & EXFLAG_NR)), | 5452 || (eap->flags & EXFLAG_NR)), |
5455 eap->cmdidx == CMD_list || (eap->flags & EXFLAG_LIST)); | 5453 eap->cmdidx == CMD_list || (eap->flags & EXFLAG_LIST)); |
5456 if (++eap->line1 > eap->line2) | 5454 if (++eap->line1 > eap->line2) |
5457 break; | 5455 break; |
5458 out_flush(); /* show one line at a time */ | 5456 out_flush(); // show one line at a time |
5459 } | 5457 } |
5460 setpcmark(); | 5458 setpcmark(); |
5461 /* put cursor at last line */ | 5459 // put cursor at last line |
5462 curwin->w_cursor.lnum = eap->line2; | 5460 curwin->w_cursor.lnum = eap->line2; |
5463 beginline(BL_SOL | BL_FIX); | 5461 beginline(BL_SOL | BL_FIX); |
5464 } | 5462 } |
5465 | 5463 |
5466 ex_no_reprint = TRUE; | 5464 ex_no_reprint = TRUE; |
5500 | 5498 |
5501 // Setting the argument list may cause screen updates and being called | 5499 // Setting the argument list may cause screen updates and being called |
5502 // recursively. Avoid that by setting drop_busy. | 5500 // recursively. Avoid that by setting drop_busy. |
5503 drop_busy = TRUE; | 5501 drop_busy = TRUE; |
5504 | 5502 |
5505 /* Check whether the current buffer is changed. If so, we will need | 5503 // Check whether the current buffer is changed. If so, we will need |
5506 * to split the current window or data could be lost. | 5504 // to split the current window or data could be lost. |
5507 * We don't need to check if the 'hidden' option is set, as in this | 5505 // We don't need to check if the 'hidden' option is set, as in this |
5508 * case the buffer won't be lost. | 5506 // case the buffer won't be lost. |
5509 */ | |
5510 if (!buf_hide(curbuf) && !drop_split) | 5507 if (!buf_hide(curbuf) && !drop_split) |
5511 { | 5508 { |
5512 ++emsg_off; | 5509 ++emsg_off; |
5513 drop_split = check_changed(curbuf, CCGD_AW); | 5510 drop_split = check_changed(curbuf, CCGD_AW); |
5514 --emsg_off; | 5511 --emsg_off; |
5517 { | 5514 { |
5518 if (win_split(0, 0) == FAIL) | 5515 if (win_split(0, 0) == FAIL) |
5519 return; | 5516 return; |
5520 RESET_BINDING(curwin); | 5517 RESET_BINDING(curwin); |
5521 | 5518 |
5522 /* When splitting the window, create a new alist. Otherwise the | 5519 // When splitting the window, create a new alist. Otherwise the |
5523 * existing one is overwritten. */ | 5520 // existing one is overwritten. |
5524 alist_unlink(curwin->w_alist); | 5521 alist_unlink(curwin->w_alist); |
5525 alist_new(); | 5522 alist_new(); |
5526 } | 5523 } |
5527 | 5524 |
5528 /* | 5525 /* |
5531 alist_set(ALIST(curwin), drop_filec, drop_filev, FALSE, NULL, 0); | 5528 alist_set(ALIST(curwin), drop_filec, drop_filev, FALSE, NULL, 0); |
5532 | 5529 |
5533 /* | 5530 /* |
5534 * Move to the first file. | 5531 * Move to the first file. |
5535 */ | 5532 */ |
5536 /* Fake up a minimal "next" command for do_argfile() */ | 5533 // Fake up a minimal "next" command for do_argfile() |
5537 vim_memset(&ea, 0, sizeof(ea)); | 5534 vim_memset(&ea, 0, sizeof(ea)); |
5538 ea.cmd = (char_u *)"next"; | 5535 ea.cmd = (char_u *)"next"; |
5539 do_argfile(&ea, 0); | 5536 do_argfile(&ea, 0); |
5540 | 5537 |
5541 /* do_ecmd() may set need_start_insertmode, but since we never left Insert | 5538 // do_ecmd() may set need_start_insertmode, but since we never left Insert |
5542 * mode that is not needed here. */ | 5539 // mode that is not needed here. |
5543 need_start_insertmode = FALSE; | 5540 need_start_insertmode = FALSE; |
5544 | 5541 |
5545 /* Restore msg_scroll, otherwise a following command may cause scrolling | 5542 // Restore msg_scroll, otherwise a following command may cause scrolling |
5546 * unexpectedly. The screen will be redrawn by the caller, thus | 5543 // unexpectedly. The screen will be redrawn by the caller, thus |
5547 * msg_scroll being set by displaying a message is irrelevant. */ | 5544 // msg_scroll being set by displaying a message is irrelevant. |
5548 msg_scroll = save_msg_scroll; | 5545 msg_scroll = save_msg_scroll; |
5549 | 5546 |
5550 if (drop_callback != NULL) | 5547 if (drop_callback != NULL) |
5551 drop_callback(drop_cookie); | 5548 drop_callback(drop_cookie); |
5552 | 5549 |
5635 * ":recover". | 5632 * ":recover". |
5636 */ | 5633 */ |
5637 static void | 5634 static void |
5638 ex_recover(exarg_T *eap) | 5635 ex_recover(exarg_T *eap) |
5639 { | 5636 { |
5640 /* Set recoverymode right away to avoid the ATTENTION prompt. */ | 5637 // Set recoverymode right away to avoid the ATTENTION prompt. |
5641 recoverymode = TRUE; | 5638 recoverymode = TRUE; |
5642 if (!check_changed(curbuf, (p_awa ? CCGD_AW : 0) | 5639 if (!check_changed(curbuf, (p_awa ? CCGD_AW : 0) |
5643 | CCGD_MULTWIN | 5640 | CCGD_MULTWIN |
5644 | (eap->forceit ? CCGD_FORCEIT : 0) | 5641 | (eap->forceit ? CCGD_FORCEIT : 0) |
5645 | CCGD_EXCMD) | 5642 | CCGD_EXCMD) |
5692 #ifdef FEAT_GUI | 5689 #ifdef FEAT_GUI |
5693 need_mouse_correct = TRUE; | 5690 need_mouse_correct = TRUE; |
5694 #endif | 5691 #endif |
5695 | 5692 |
5696 #ifdef FEAT_QUICKFIX | 5693 #ifdef FEAT_QUICKFIX |
5697 /* A ":split" in the quickfix window works like ":new". Don't want two | 5694 // A ":split" in the quickfix window works like ":new". Don't want two |
5698 * quickfix windows. But it's OK when doing ":tab split". */ | 5695 // quickfix windows. But it's OK when doing ":tab split". |
5699 if (bt_quickfix(curbuf) && cmdmod.tab == 0) | 5696 if (bt_quickfix(curbuf) && cmdmod.tab == 0) |
5700 { | 5697 { |
5701 if (eap->cmdidx == CMD_split) | 5698 if (eap->cmdidx == CMD_split) |
5702 eap->cmdidx = CMD_new; | 5699 eap->cmdidx = CMD_new; |
5703 if (eap->cmdidx == CMD_vsplit) | 5700 if (eap->cmdidx == CMD_vsplit) |
5727 # ifdef FEAT_GUI | 5724 # ifdef FEAT_GUI |
5728 !gui.in_use && | 5725 !gui.in_use && |
5729 # endif | 5726 # endif |
5730 au_has_group((char_u *)"FileExplorer")) | 5727 au_has_group((char_u *)"FileExplorer")) |
5731 { | 5728 { |
5732 /* No browsing supported but we do have the file explorer: | 5729 // No browsing supported but we do have the file explorer: |
5733 * Edit the directory. */ | 5730 // Edit the directory. |
5734 if (*eap->arg == NUL || !mch_isdir(eap->arg)) | 5731 if (*eap->arg == NUL || !mch_isdir(eap->arg)) |
5735 eap->arg = (char_u *)"."; | 5732 eap->arg = (char_u *)"."; |
5736 } | 5733 } |
5737 else | 5734 else |
5738 { | 5735 { |
5743 if (fname == NULL) | 5740 if (fname == NULL) |
5744 goto theend; | 5741 goto theend; |
5745 eap->arg = fname; | 5742 eap->arg = fname; |
5746 } | 5743 } |
5747 } | 5744 } |
5748 cmdmod.browse = FALSE; /* Don't browse again in do_ecmd(). */ | 5745 cmdmod.browse = FALSE; // Don't browse again in do_ecmd(). |
5749 #endif | 5746 #endif |
5750 | 5747 |
5751 /* | 5748 /* |
5752 * Either open new tab page or split the window. | 5749 * Either open new tab page or split the window. |
5753 */ | 5750 */ |
5757 : eap->addr_count == 0 ? 0 | 5754 : eap->addr_count == 0 ? 0 |
5758 : (int)eap->line2 + 1) != FAIL) | 5755 : (int)eap->line2 + 1) != FAIL) |
5759 { | 5756 { |
5760 do_exedit(eap, old_curwin); | 5757 do_exedit(eap, old_curwin); |
5761 | 5758 |
5762 /* set the alternate buffer for the window we came from */ | 5759 // set the alternate buffer for the window we came from |
5763 if (curwin != old_curwin | 5760 if (curwin != old_curwin |
5764 && win_valid(old_curwin) | 5761 && win_valid(old_curwin) |
5765 && old_curwin->w_buffer != curbuf | 5762 && old_curwin->w_buffer != curbuf |
5766 && !cmdmod.keepalt) | 5763 && !cmdmod.keepalt) |
5767 old_curwin->w_alt_fnum = curbuf->b_fnum; | 5764 old_curwin->w_alt_fnum = curbuf->b_fnum; |
5768 } | 5765 } |
5769 } | 5766 } |
5770 else if (win_split(eap->addr_count > 0 ? (int)eap->line2 : 0, | 5767 else if (win_split(eap->addr_count > 0 ? (int)eap->line2 : 0, |
5771 *eap->cmd == 'v' ? WSP_VERT : 0) != FAIL) | 5768 *eap->cmd == 'v' ? WSP_VERT : 0) != FAIL) |
5772 { | 5769 { |
5773 /* Reset 'scrollbind' when editing another file, but keep it when | 5770 // Reset 'scrollbind' when editing another file, but keep it when |
5774 * doing ":split" without arguments. */ | 5771 // doing ":split" without arguments. |
5775 if (*eap->arg != NUL | 5772 if (*eap->arg != NUL |
5776 # ifdef FEAT_BROWSE | 5773 # ifdef FEAT_BROWSE |
5777 || cmdmod.browse | 5774 || cmdmod.browse |
5778 # endif | 5775 # endif |
5779 ) | 5776 ) |
5836 | 5833 |
5837 tab_number = getdigits(&p); | 5834 tab_number = getdigits(&p); |
5838 if (p == p_save || *p_save == '-' || *p != NUL | 5835 if (p == p_save || *p_save == '-' || *p != NUL |
5839 || tab_number == 0) | 5836 || tab_number == 0) |
5840 { | 5837 { |
5841 /* No numbers as argument. */ | 5838 // No numbers as argument. |
5842 eap->errmsg = e_invarg; | 5839 eap->errmsg = e_invarg; |
5843 return; | 5840 return; |
5844 } | 5841 } |
5845 } | 5842 } |
5846 else | 5843 else |
5857 } | 5854 } |
5858 } | 5855 } |
5859 } | 5856 } |
5860 goto_tabpage(-tab_number); | 5857 goto_tabpage(-tab_number); |
5861 break; | 5858 break; |
5862 default: /* CMD_tabnext */ | 5859 default: // CMD_tabnext |
5863 tab_number = get_tabpage_arg(eap); | 5860 tab_number = get_tabpage_arg(eap); |
5864 if (eap->errmsg == NULL) | 5861 if (eap->errmsg == NULL) |
5865 goto_tabpage(tab_number); | 5862 goto_tabpage(tab_number); |
5866 break; | 5863 break; |
5867 } | 5864 } |
5895 for (tp = first_tabpage; tp != NULL && !got_int; tp = tp->tp_next) | 5892 for (tp = first_tabpage; tp != NULL && !got_int; tp = tp->tp_next) |
5896 { | 5893 { |
5897 msg_putchar('\n'); | 5894 msg_putchar('\n'); |
5898 vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); | 5895 vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); |
5899 msg_outtrans_attr(IObuff, HL_ATTR(HLF_T)); | 5896 msg_outtrans_attr(IObuff, HL_ATTR(HLF_T)); |
5900 out_flush(); /* output one line at a time */ | 5897 out_flush(); // output one line at a time |
5901 ui_breakcheck(); | 5898 ui_breakcheck(); |
5902 | 5899 |
5903 if (tp == curtab) | 5900 if (tp == curtab) |
5904 wp = firstwin; | 5901 wp = firstwin; |
5905 else | 5902 else |
5915 vim_strncpy(IObuff, buf_spname(wp->w_buffer), IOSIZE - 1); | 5912 vim_strncpy(IObuff, buf_spname(wp->w_buffer), IOSIZE - 1); |
5916 else | 5913 else |
5917 home_replace(wp->w_buffer, wp->w_buffer->b_fname, | 5914 home_replace(wp->w_buffer, wp->w_buffer->b_fname, |
5918 IObuff, IOSIZE, TRUE); | 5915 IObuff, IOSIZE, TRUE); |
5919 msg_outtrans(IObuff); | 5916 msg_outtrans(IObuff); |
5920 out_flush(); /* output one line at a time */ | 5917 out_flush(); // output one line at a time |
5921 ui_breakcheck(); | 5918 ui_breakcheck(); |
5922 } | 5919 } |
5923 } | 5920 } |
5924 } | 5921 } |
5925 | 5922 |
5959 n = atol((char *)eap->arg); | 5956 n = atol((char *)eap->arg); |
5960 if (cmdmod.split & WSP_VERT) | 5957 if (cmdmod.split & WSP_VERT) |
5961 { | 5958 { |
5962 if (*eap->arg == '-' || *eap->arg == '+') | 5959 if (*eap->arg == '-' || *eap->arg == '+') |
5963 n += curwin->w_width; | 5960 n += curwin->w_width; |
5964 else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */ | 5961 else if (n == 0 && eap->arg[0] == NUL) // default is very wide |
5965 n = 9999; | 5962 n = 9999; |
5966 win_setwidth_win((int)n, wp); | 5963 win_setwidth_win((int)n, wp); |
5967 } | 5964 } |
5968 else | 5965 else |
5969 { | 5966 { |
5970 if (*eap->arg == '-' || *eap->arg == '+') | 5967 if (*eap->arg == '-' || *eap->arg == '+') |
5971 n += curwin->w_height; | 5968 n += curwin->w_height; |
5972 else if (n == 0 && eap->arg[0] == NUL) /* default is very high */ | 5969 else if (n == 0 && eap->arg[0] == NUL) // default is very high |
5973 n = 9999; | 5970 n = 9999; |
5974 win_setheight_win((int)n, wp); | 5971 win_setheight_win((int)n, wp); |
5975 } | 5972 } |
5976 } | 5973 } |
5977 | 5974 |
5987 | 5984 |
5988 fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg), FNAME_MESS, | 5985 fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg), FNAME_MESS, |
5989 TRUE, curbuf->b_ffname); | 5986 TRUE, curbuf->b_ffname); |
5990 if (eap->addr_count > 0) | 5987 if (eap->addr_count > 0) |
5991 { | 5988 { |
5992 /* Repeat finding the file "count" times. This matters when it | 5989 // Repeat finding the file "count" times. This matters when it |
5993 * appears several times in the path. */ | 5990 // appears several times in the path. |
5994 count = eap->line2; | 5991 count = eap->line2; |
5995 while (fname != NULL && --count > 0) | 5992 while (fname != NULL && --count > 0) |
5996 { | 5993 { |
5997 vim_free(fname); | 5994 vim_free(fname); |
5998 fname = find_file_in_path(NULL, 0, FNAME_MESS, | 5995 fname = find_file_in_path(NULL, 0, FNAME_MESS, |
6022 | 6019 |
6023 curwin->w_cursor.lnum = eap->line2; | 6020 curwin->w_cursor.lnum = eap->line2; |
6024 beginline(BL_SOL | BL_FIX); | 6021 beginline(BL_SOL | BL_FIX); |
6025 if (*eap->arg == '/') | 6022 if (*eap->arg == '/') |
6026 { | 6023 { |
6027 /* ":open /pattern/": put cursor in column found with pattern */ | 6024 // ":open /pattern/": put cursor in column found with pattern |
6028 ++eap->arg; | 6025 ++eap->arg; |
6029 p = skip_regexp(eap->arg, '/', p_magic, NULL); | 6026 p = skip_regexp(eap->arg, '/', p_magic, NULL); |
6030 *p = NUL; | 6027 *p = NUL; |
6031 regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0); | 6028 regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0); |
6032 if (regmatch.regprog != NULL) | 6029 if (regmatch.regprog != NULL) |
6037 curwin->w_cursor.col = (colnr_T)(regmatch.startp[0] - p); | 6034 curwin->w_cursor.col = (colnr_T)(regmatch.startp[0] - p); |
6038 else | 6035 else |
6039 emsg(_(e_nomatch)); | 6036 emsg(_(e_nomatch)); |
6040 vim_regfree(regmatch.regprog); | 6037 vim_regfree(regmatch.regprog); |
6041 } | 6038 } |
6042 /* Move to the NUL, ignore any other arguments. */ | 6039 // Move to the NUL, ignore any other arguments. |
6043 eap->arg += STRLEN(eap->arg); | 6040 eap->arg += STRLEN(eap->arg); |
6044 } | 6041 } |
6045 check_cursor(); | 6042 check_cursor(); |
6046 | 6043 |
6047 eap->cmdidx = CMD_visual; | 6044 eap->cmdidx = CMD_visual; |
6061 * ":edit <file>" command and alikes. | 6058 * ":edit <file>" command and alikes. |
6062 */ | 6059 */ |
6063 void | 6060 void |
6064 do_exedit( | 6061 do_exedit( |
6065 exarg_T *eap, | 6062 exarg_T *eap, |
6066 win_T *old_curwin) /* curwin before doing a split or NULL */ | 6063 win_T *old_curwin) // curwin before doing a split or NULL |
6067 { | 6064 { |
6068 int n; | 6065 int n; |
6069 int need_hide; | 6066 int need_hide; |
6070 int exmode_was = exmode_active; | 6067 int exmode_was = exmode_active; |
6071 | 6068 |
6078 || eap->cmdidx == CMD_view)) | 6075 || eap->cmdidx == CMD_view)) |
6079 { | 6076 { |
6080 exmode_active = FALSE; | 6077 exmode_active = FALSE; |
6081 if (*eap->arg == NUL) | 6078 if (*eap->arg == NUL) |
6082 { | 6079 { |
6083 /* Special case: ":global/pat/visual\NLvi-commands" */ | 6080 // Special case: ":global/pat/visual\NLvi-commands" |
6084 if (global_busy) | 6081 if (global_busy) |
6085 { | 6082 { |
6086 int rd = RedrawingDisabled; | 6083 int rd = RedrawingDisabled; |
6087 int nwr = no_wait_return; | 6084 int nwr = no_wait_return; |
6088 int ms = msg_scroll; | 6085 int ms = msg_scroll; |
6123 if ((eap->cmdidx == CMD_new | 6120 if ((eap->cmdidx == CMD_new |
6124 || eap->cmdidx == CMD_tabnew | 6121 || eap->cmdidx == CMD_tabnew |
6125 || eap->cmdidx == CMD_tabedit | 6122 || eap->cmdidx == CMD_tabedit |
6126 || eap->cmdidx == CMD_vnew) && *eap->arg == NUL) | 6123 || eap->cmdidx == CMD_vnew) && *eap->arg == NUL) |
6127 { | 6124 { |
6128 /* ":new" or ":tabnew" without argument: edit an new empty buffer */ | 6125 // ":new" or ":tabnew" without argument: edit an new empty buffer |
6129 setpcmark(); | 6126 setpcmark(); |
6130 (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE, | 6127 (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE, |
6131 ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0), | 6128 ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0), |
6132 old_curwin == NULL ? curwin : NULL); | 6129 old_curwin == NULL ? curwin : NULL); |
6133 } | 6130 } |
6136 #ifdef FEAT_BROWSE | 6133 #ifdef FEAT_BROWSE |
6137 || cmdmod.browse | 6134 || cmdmod.browse |
6138 #endif | 6135 #endif |
6139 ) | 6136 ) |
6140 { | 6137 { |
6141 /* Can't edit another file when "curbuf_lock" is set. Only ":edit" | 6138 // Can't edit another file when "curbuf_lock" is set. Only ":edit" |
6142 * can bring us here, others are stopped earlier. */ | 6139 // can bring us here, others are stopped earlier. |
6143 if (*eap->arg != NUL && curbuf_locked()) | 6140 if (*eap->arg != NUL && curbuf_locked()) |
6144 return; | 6141 return; |
6145 | 6142 |
6146 n = readonlymode; | 6143 n = readonlymode; |
6147 if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) | 6144 if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) |
6148 readonlymode = TRUE; | 6145 readonlymode = TRUE; |
6149 else if (eap->cmdidx == CMD_enew) | 6146 else if (eap->cmdidx == CMD_enew) |
6150 readonlymode = FALSE; /* 'readonly' doesn't make sense in an | 6147 readonlymode = FALSE; // 'readonly' doesn't make sense in an |
6151 empty buffer */ | 6148 // empty buffer |
6152 setpcmark(); | 6149 setpcmark(); |
6153 if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), | 6150 if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), |
6154 NULL, eap, | 6151 NULL, eap, |
6155 /* ":edit" goes to first line if Vi compatible */ | 6152 // ":edit" goes to first line if Vi compatible |
6156 (*eap->arg == NUL && eap->do_ecmd_lnum == 0 | 6153 (*eap->arg == NUL && eap->do_ecmd_lnum == 0 |
6157 && vim_strchr(p_cpo, CPO_GOTO1) != NULL) | 6154 && vim_strchr(p_cpo, CPO_GOTO1) != NULL) |
6158 ? ECMD_ONE : eap->do_ecmd_lnum, | 6155 ? ECMD_ONE : eap->do_ecmd_lnum, |
6159 (buf_hide(curbuf) ? ECMD_HIDE : 0) | 6156 (buf_hide(curbuf) ? ECMD_HIDE : 0) |
6160 + (eap->forceit ? ECMD_FORCEIT : 0) | 6157 + (eap->forceit ? ECMD_FORCEIT : 0) |
6161 /* after a split we can use an existing buffer */ | 6158 // after a split we can use an existing buffer |
6162 + (old_curwin != NULL ? ECMD_OLDBUF : 0) | 6159 + (old_curwin != NULL ? ECMD_OLDBUF : 0) |
6163 + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 ) | 6160 + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 ) |
6164 , old_curwin == NULL ? curwin : NULL) == FAIL) | 6161 , old_curwin == NULL ? curwin : NULL) == FAIL) |
6165 { | 6162 { |
6166 /* Editing the file failed. If the window was split, close it. */ | 6163 // Editing the file failed. If the window was split, close it. |
6167 if (old_curwin != NULL) | 6164 if (old_curwin != NULL) |
6168 { | 6165 { |
6169 need_hide = (curbufIsChanged() && curbuf->b_nwindows <= 1); | 6166 need_hide = (curbufIsChanged() && curbuf->b_nwindows <= 1); |
6170 if (!need_hide || buf_hide(curbuf)) | 6167 if (!need_hide || buf_hide(curbuf)) |
6171 { | 6168 { |
6172 #if defined(FEAT_EVAL) | 6169 #if defined(FEAT_EVAL) |
6173 cleanup_T cs; | 6170 cleanup_T cs; |
6174 | 6171 |
6175 /* Reset the error/interrupt/exception state here so that | 6172 // Reset the error/interrupt/exception state here so that |
6176 * aborting() returns FALSE when closing a window. */ | 6173 // aborting() returns FALSE when closing a window. |
6177 enter_cleanup(&cs); | 6174 enter_cleanup(&cs); |
6178 #endif | 6175 #endif |
6179 #ifdef FEAT_GUI | 6176 #ifdef FEAT_GUI |
6180 need_mouse_correct = TRUE; | 6177 need_mouse_correct = TRUE; |
6181 #endif | 6178 #endif |
6182 win_close(curwin, !need_hide && !buf_hide(curbuf)); | 6179 win_close(curwin, !need_hide && !buf_hide(curbuf)); |
6183 | 6180 |
6184 #if defined(FEAT_EVAL) | 6181 #if defined(FEAT_EVAL) |
6185 /* Restore the error/interrupt/exception state if not | 6182 // Restore the error/interrupt/exception state if not |
6186 * discarded by a new aborting error, interrupt, or | 6183 // discarded by a new aborting error, interrupt, or |
6187 * uncaught exception. */ | 6184 // uncaught exception. |
6188 leave_cleanup(&cs); | 6185 leave_cleanup(&cs); |
6189 #endif | 6186 #endif |
6190 } | 6187 } |
6191 } | 6188 } |
6192 } | 6189 } |
6193 else if (readonlymode && curbuf->b_nwindows == 1) | 6190 else if (readonlymode && curbuf->b_nwindows == 1) |
6194 { | 6191 { |
6195 /* When editing an already visited buffer, 'readonly' won't be set | 6192 // When editing an already visited buffer, 'readonly' won't be set |
6196 * but the previous value is kept. With ":view" and ":sview" we | 6193 // but the previous value is kept. With ":view" and ":sview" we |
6197 * want the file to be readonly, except when another window is | 6194 // want the file to be readonly, except when another window is |
6198 * editing the same buffer. */ | 6195 // editing the same buffer. |
6199 curbuf->b_p_ro = TRUE; | 6196 curbuf->b_p_ro = TRUE; |
6200 } | 6197 } |
6201 readonlymode = n; | 6198 readonlymode = n; |
6202 } | 6199 } |
6203 else | 6200 else |
6358 { | 6355 { |
6359 int i; | 6356 int i; |
6360 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | 6357 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
6361 linenr_T lnum; | 6358 linenr_T lnum; |
6362 | 6359 |
6363 if (eap->usefilter) /* :r!cmd */ | 6360 if (eap->usefilter) // :r!cmd |
6364 do_bang(1, eap, FALSE, FALSE, TRUE); | 6361 do_bang(1, eap, FALSE, FALSE, TRUE); |
6365 else | 6362 else |
6366 { | 6363 { |
6367 if (u_save(eap->line2, (linenr_T)(eap->line2 + 1)) == FAIL) | 6364 if (u_save(eap->line2, (linenr_T)(eap->line2 + 1)) == FAIL) |
6368 return; | 6365 return; |
6385 } | 6382 } |
6386 else | 6383 else |
6387 #endif | 6384 #endif |
6388 if (*eap->arg == NUL) | 6385 if (*eap->arg == NUL) |
6389 { | 6386 { |
6390 if (check_fname() == FAIL) /* check for no file name */ | 6387 if (check_fname() == FAIL) // check for no file name |
6391 return; | 6388 return; |
6392 i = readfile(curbuf->b_ffname, curbuf->b_fname, | 6389 i = readfile(curbuf->b_ffname, curbuf->b_fname, |
6393 eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0); | 6390 eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0); |
6394 } | 6391 } |
6395 else | 6392 else |
6409 } | 6406 } |
6410 else | 6407 else |
6411 { | 6408 { |
6412 if (empty && exmode_active) | 6409 if (empty && exmode_active) |
6413 { | 6410 { |
6414 /* Delete the empty line that remains. Historically ex does | 6411 // Delete the empty line that remains. Historically ex does |
6415 * this but vi doesn't. */ | 6412 // this but vi doesn't. |
6416 if (eap->line2 == 0) | 6413 if (eap->line2 == 0) |
6417 lnum = curbuf->b_ml.ml_line_count; | 6414 lnum = curbuf->b_ml.ml_line_count; |
6418 else | 6415 else |
6419 lnum = 1; | 6416 lnum = 1; |
6420 if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) | 6417 if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) |
6454 // Clear tab local directory for both :cd and :tcd | 6451 // Clear tab local directory for both :cd and :tcd |
6455 VIM_CLEAR(curtab->tp_localdir); | 6452 VIM_CLEAR(curtab->tp_localdir); |
6456 VIM_CLEAR(curwin->w_localdir); | 6453 VIM_CLEAR(curwin->w_localdir); |
6457 if (scope != CDSCOPE_GLOBAL) | 6454 if (scope != CDSCOPE_GLOBAL) |
6458 { | 6455 { |
6459 /* If still in global directory, need to remember current | 6456 // If still in global directory, need to remember current |
6460 * directory as global directory. */ | 6457 // directory as global directory. |
6461 if (globaldir == NULL && prev_dir != NULL) | 6458 if (globaldir == NULL && prev_dir != NULL) |
6462 globaldir = vim_strsave(prev_dir); | 6459 globaldir = vim_strsave(prev_dir); |
6463 /* Remember this local directory for the window. */ | 6460 // Remember this local directory for the window. |
6464 if (mch_dirname(NameBuff, MAXPATHL) == OK) | 6461 if (mch_dirname(NameBuff, MAXPATHL) == OK) |
6465 { | 6462 { |
6466 if (scope == CDSCOPE_TABPAGE) | 6463 if (scope == CDSCOPE_TABPAGE) |
6467 curtab->tp_localdir = vim_strsave(NameBuff); | 6464 curtab->tp_localdir = vim_strsave(NameBuff); |
6468 else | 6465 else |
6469 curwin->w_localdir = vim_strsave(NameBuff); | 6466 curwin->w_localdir = vim_strsave(NameBuff); |
6470 } | 6467 } |
6471 } | 6468 } |
6472 else | 6469 else |
6473 { | 6470 { |
6474 /* We are now in the global directory, no need to remember its | 6471 // We are now in the global directory, no need to remember its |
6475 * name. */ | 6472 // name. |
6476 VIM_CLEAR(globaldir); | 6473 VIM_CLEAR(globaldir); |
6477 } | 6474 } |
6478 | 6475 |
6479 shorten_fnames(TRUE); | 6476 shorten_fnames(TRUE); |
6480 } | 6477 } |
6745 int xchar = NUL; | 6742 int xchar = NUL; |
6746 char_u *p; | 6743 char_u *p; |
6747 | 6744 |
6748 if (*eap->arg == 'g' || *eap->arg == Ctrl_G) | 6745 if (*eap->arg == 'g' || *eap->arg == Ctrl_G) |
6749 { | 6746 { |
6750 /* CTRL-W g and CTRL-W CTRL-G have an extra command character */ | 6747 // CTRL-W g and CTRL-W CTRL-G have an extra command character |
6751 if (eap->arg[1] == NUL) | 6748 if (eap->arg[1] == NUL) |
6752 { | 6749 { |
6753 emsg(_(e_invarg)); | 6750 emsg(_(e_invarg)); |
6754 return; | 6751 return; |
6755 } | 6752 } |
6763 p = skipwhite(p); | 6760 p = skipwhite(p); |
6764 if (*p != NUL && *p != '"' && eap->nextcmd == NULL) | 6761 if (*p != NUL && *p != '"' && eap->nextcmd == NULL) |
6765 emsg(_(e_invarg)); | 6762 emsg(_(e_invarg)); |
6766 else if (!eap->skip) | 6763 else if (!eap->skip) |
6767 { | 6764 { |
6768 /* Pass flags on for ":vertical wincmd ]". */ | 6765 // Pass flags on for ":vertical wincmd ]". |
6769 postponed_split_flags = cmdmod.split; | 6766 postponed_split_flags = cmdmod.split; |
6770 postponed_split_tab = cmdmod.tab; | 6767 postponed_split_tab = cmdmod.tab; |
6771 do_window(*eap->arg, eap->addr_count > 0 ? eap->line2 : 0L, xchar); | 6768 do_window(*eap->arg, eap->addr_count > 0 ? eap->line2 : 0L, xchar); |
6772 postponed_split_flags = 0; | 6769 postponed_split_flags = 0; |
6773 postponed_split_tab = 0; | 6770 postponed_split_tab = 0; |
6818 # ifdef FEAT_GUI | 6815 # ifdef FEAT_GUI |
6819 if (gui.in_use) | 6816 if (gui.in_use) |
6820 gui_mch_set_winpos(x, y); | 6817 gui_mch_set_winpos(x, y); |
6821 else if (gui.starting) | 6818 else if (gui.starting) |
6822 { | 6819 { |
6823 /* Remember the coordinates for when the window is opened. */ | 6820 // Remember the coordinates for when the window is opened. |
6824 gui_win_x = x; | 6821 gui_win_x = x; |
6825 gui_win_y = y; | 6822 gui_win_y = y; |
6826 } | 6823 } |
6827 # if defined(HAVE_TGETENT) || defined(VIMDLL) | 6824 # if defined(HAVE_TGETENT) || defined(VIMDLL) |
6828 else | 6825 else |
6852 oa.start.lnum = eap->line1; | 6849 oa.start.lnum = eap->line1; |
6853 oa.end.lnum = eap->line2; | 6850 oa.end.lnum = eap->line2; |
6854 oa.line_count = eap->line2 - eap->line1 + 1; | 6851 oa.line_count = eap->line2 - eap->line1 + 1; |
6855 oa.motion_type = MLINE; | 6852 oa.motion_type = MLINE; |
6856 virtual_op = FALSE; | 6853 virtual_op = FALSE; |
6857 if (eap->cmdidx != CMD_yank) /* position cursor for undo */ | 6854 if (eap->cmdidx != CMD_yank) // position cursor for undo |
6858 { | 6855 { |
6859 setpcmark(); | 6856 setpcmark(); |
6860 curwin->w_cursor.lnum = eap->line1; | 6857 curwin->w_cursor.lnum = eap->line1; |
6861 beginline(BL_SOL | BL_FIX); | 6858 beginline(BL_SOL | BL_FIX); |
6862 } | 6859 } |
6874 case CMD_yank: | 6871 case CMD_yank: |
6875 oa.op_type = OP_YANK; | 6872 oa.op_type = OP_YANK; |
6876 (void)op_yank(&oa, FALSE, TRUE); | 6873 (void)op_yank(&oa, FALSE, TRUE); |
6877 break; | 6874 break; |
6878 | 6875 |
6879 default: /* CMD_rshift or CMD_lshift */ | 6876 default: // CMD_rshift or CMD_lshift |
6880 if ( | 6877 if ( |
6881 #ifdef FEAT_RIGHTLEFT | 6878 #ifdef FEAT_RIGHTLEFT |
6882 (eap->cmdidx == CMD_rshift) ^ curwin->w_p_rl | 6879 (eap->cmdidx == CMD_rshift) ^ curwin->w_p_rl |
6883 #else | 6880 #else |
6884 eap->cmdidx == CMD_rshift | 6881 eap->cmdidx == CMD_rshift |
6898 * ":put". | 6895 * ":put". |
6899 */ | 6896 */ |
6900 static void | 6897 static void |
6901 ex_put(exarg_T *eap) | 6898 ex_put(exarg_T *eap) |
6902 { | 6899 { |
6903 /* ":0put" works like ":1put!". */ | 6900 // ":0put" works like ":1put!". |
6904 if (eap->line2 == 0) | 6901 if (eap->line2 == 0) |
6905 { | 6902 { |
6906 eap->line2 = 1; | 6903 eap->line2 = 1; |
6907 eap->forceit = TRUE; | 6904 eap->forceit = TRUE; |
6908 } | 6905 } |
6918 ex_copymove(exarg_T *eap) | 6915 ex_copymove(exarg_T *eap) |
6919 { | 6916 { |
6920 long n; | 6917 long n; |
6921 | 6918 |
6922 n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1); | 6919 n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1); |
6923 if (eap->arg == NULL) /* error detected */ | 6920 if (eap->arg == NULL) // error detected |
6924 { | 6921 { |
6925 eap->nextcmd = NULL; | 6922 eap->nextcmd = NULL; |
6926 return; | 6923 return; |
6927 } | 6924 } |
6928 get_flags(eap); | 6925 get_flags(eap); |
6982 ex_join(exarg_T *eap) | 6979 ex_join(exarg_T *eap) |
6983 { | 6980 { |
6984 curwin->w_cursor.lnum = eap->line1; | 6981 curwin->w_cursor.lnum = eap->line1; |
6985 if (eap->line1 == eap->line2) | 6982 if (eap->line1 == eap->line2) |
6986 { | 6983 { |
6987 if (eap->addr_count >= 2) /* :2,2join does nothing */ | 6984 if (eap->addr_count >= 2) // :2,2join does nothing |
6988 return; | 6985 return; |
6989 if (eap->line2 == curbuf->b_ml.ml_line_count) | 6986 if (eap->line2 == curbuf->b_ml.ml_line_count) |
6990 { | 6987 { |
6991 beep_flush(); | 6988 beep_flush(); |
6992 return; | 6989 return; |
7009 | 7006 |
7010 curwin->w_cursor.lnum = eap->line2; | 7007 curwin->w_cursor.lnum = eap->line2; |
7011 check_cursor_col(); | 7008 check_cursor_col(); |
7012 | 7009 |
7013 #ifdef USE_ON_FLY_SCROLL | 7010 #ifdef USE_ON_FLY_SCROLL |
7014 dont_scroll = TRUE; /* disallow scrolling here */ | 7011 dont_scroll = TRUE; // disallow scrolling here |
7015 #endif | 7012 #endif |
7016 | 7013 |
7017 /* get the register name. No name means to use the previous one */ | 7014 // get the register name. No name means to use the previous one |
7018 c = *eap->arg; | 7015 c = *eap->arg; |
7019 if (c == NUL || (c == '*' && *eap->cmd == '*')) | 7016 if (c == NUL || (c == '*' && *eap->cmd == '*')) |
7020 c = '@'; | 7017 c = '@'; |
7021 /* Put the register in the typeahead buffer with the "silent" flag. */ | 7018 // Put the register in the typeahead buffer with the "silent" flag. |
7022 if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, TRUE) | 7019 if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, TRUE) |
7023 == FAIL) | 7020 == FAIL) |
7024 { | 7021 { |
7025 beep_flush(); | 7022 beep_flush(); |
7026 } | 7023 } |
7055 * ":undo". | 7052 * ":undo". |
7056 */ | 7053 */ |
7057 static void | 7054 static void |
7058 ex_undo(exarg_T *eap) | 7055 ex_undo(exarg_T *eap) |
7059 { | 7056 { |
7060 if (eap->addr_count == 1) /* :undo 123 */ | 7057 if (eap->addr_count == 1) // :undo 123 |
7061 undo_time(eap->line2, FALSE, FALSE, TRUE); | 7058 undo_time(eap->line2, FALSE, FALSE, TRUE); |
7062 else | 7059 else |
7063 u_undo(1); | 7060 u_undo(1); |
7064 } | 7061 } |
7065 | 7062 |
7159 mode = "w"; | 7156 mode = "w"; |
7160 arg = skipwhite(arg); | 7157 arg = skipwhite(arg); |
7161 | 7158 |
7162 close_redir(); | 7159 close_redir(); |
7163 | 7160 |
7164 /* Expand environment variables and "~/". */ | 7161 // Expand environment variables and "~/". |
7165 fname = expand_env_save(arg); | 7162 fname = expand_env_save(arg); |
7166 if (fname == NULL) | 7163 if (fname == NULL) |
7167 return; | 7164 return; |
7168 #ifdef FEAT_BROWSE | 7165 #ifdef FEAT_BROWSE |
7169 if (cmdmod.browse) | 7166 if (cmdmod.browse) |
7173 browseFile = do_browse(BROWSE_SAVE, | 7170 browseFile = do_browse(BROWSE_SAVE, |
7174 (char_u *)_("Save Redirection"), | 7171 (char_u *)_("Save Redirection"), |
7175 fname, NULL, NULL, | 7172 fname, NULL, NULL, |
7176 (char_u *)_(BROWSE_FILTER_ALL_FILES), curbuf); | 7173 (char_u *)_(BROWSE_FILTER_ALL_FILES), curbuf); |
7177 if (browseFile == NULL) | 7174 if (browseFile == NULL) |
7178 return; /* operation cancelled */ | 7175 return; // operation cancelled |
7179 vim_free(fname); | 7176 vim_free(fname); |
7180 fname = browseFile; | 7177 fname = browseFile; |
7181 eap->forceit = TRUE; /* since dialog already asked */ | 7178 eap->forceit = TRUE; // since dialog already asked |
7182 } | 7179 } |
7183 #endif | 7180 #endif |
7184 | 7181 |
7185 redir_fd = open_exfile(fname, eap->forceit, mode); | 7182 redir_fd = open_exfile(fname, eap->forceit, mode); |
7186 vim_free(fname); | 7183 vim_free(fname); |
7187 } | 7184 } |
7188 #ifdef FEAT_EVAL | 7185 #ifdef FEAT_EVAL |
7189 else if (*arg == '@') | 7186 else if (*arg == '@') |
7190 { | 7187 { |
7191 /* redirect to a register a-z (resp. A-Z for appending) */ | 7188 // redirect to a register a-z (resp. A-Z for appending) |
7192 close_redir(); | 7189 close_redir(); |
7193 ++arg; | 7190 ++arg; |
7194 if (ASCII_ISALPHA(*arg) | 7191 if (ASCII_ISALPHA(*arg) |
7195 # ifdef FEAT_CLIPBOARD | 7192 # ifdef FEAT_CLIPBOARD |
7196 || *arg == '*' | 7193 || *arg == '*' |
7197 || *arg == '+' | 7194 || *arg == '+' |
7198 # endif | 7195 # endif |
7199 || *arg == '"') | 7196 || *arg == '"') |
7200 { | 7197 { |
7201 redir_reg = *arg++; | 7198 redir_reg = *arg++; |
7202 if (*arg == '>' && arg[1] == '>') /* append */ | 7199 if (*arg == '>' && arg[1] == '>') // append |
7203 arg += 2; | 7200 arg += 2; |
7204 else | 7201 else |
7205 { | 7202 { |
7206 /* Can use both "@a" and "@a>". */ | 7203 // Can use both "@a" and "@a>". |
7207 if (*arg == '>') | 7204 if (*arg == '>') |
7208 arg++; | 7205 arg++; |
7209 /* Make register empty when not using @A-@Z and the | 7206 // Make register empty when not using @A-@Z and the |
7210 * command is valid. */ | 7207 // command is valid. |
7211 if (*arg == NUL && !isupper(redir_reg)) | 7208 if (*arg == NUL && !isupper(redir_reg)) |
7212 write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); | 7209 write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); |
7213 } | 7210 } |
7214 } | 7211 } |
7215 if (*arg != NUL) | 7212 if (*arg != NUL) |
7220 } | 7217 } |
7221 else if (*arg == '=' && arg[1] == '>') | 7218 else if (*arg == '=' && arg[1] == '>') |
7222 { | 7219 { |
7223 int append; | 7220 int append; |
7224 | 7221 |
7225 /* redirect to a variable */ | 7222 // redirect to a variable |
7226 close_redir(); | 7223 close_redir(); |
7227 arg += 2; | 7224 arg += 2; |
7228 | 7225 |
7229 if (*arg == '>') | 7226 if (*arg == '>') |
7230 { | 7227 { |
7237 if (var_redir_start(skipwhite(arg), append) == OK) | 7234 if (var_redir_start(skipwhite(arg), append) == OK) |
7238 redir_vname = 1; | 7235 redir_vname = 1; |
7239 } | 7236 } |
7240 #endif | 7237 #endif |
7241 | 7238 |
7242 /* TODO: redirect to a buffer */ | 7239 // TODO: redirect to a buffer |
7243 | 7240 |
7244 else | 7241 else |
7245 semsg(_(e_invarg2), eap->arg); | 7242 semsg(_(e_invarg2), eap->arg); |
7246 } | 7243 } |
7247 | 7244 |
7248 /* Make sure redirection is not off. Can happen for cmdline completion | 7245 // Make sure redirection is not off. Can happen for cmdline completion |
7249 * that indirectly invokes a command to catch its output. */ | 7246 // that indirectly invokes a command to catch its output. |
7250 if (redir_fd != NULL | 7247 if (redir_fd != NULL |
7251 #ifdef FEAT_EVAL | 7248 #ifdef FEAT_EVAL |
7252 || redir_reg || redir_vname | 7249 || redir_reg || redir_vname |
7253 #endif | 7250 #endif |
7254 ) | 7251 ) |
7280 resize_console_buf(); | 7277 resize_console_buf(); |
7281 #endif | 7278 #endif |
7282 RedrawingDisabled = r; | 7279 RedrawingDisabled = r; |
7283 p_lz = p; | 7280 p_lz = p; |
7284 | 7281 |
7285 /* Reset msg_didout, so that a message that's there is overwritten. */ | 7282 // Reset msg_didout, so that a message that's there is overwritten. |
7286 msg_didout = FALSE; | 7283 msg_didout = FALSE; |
7287 msg_col = 0; | 7284 msg_col = 0; |
7288 | 7285 |
7289 /* No need to wait after an intentional redraw. */ | 7286 // No need to wait after an intentional redraw. |
7290 need_wait_return = FALSE; | 7287 need_wait_return = FALSE; |
7291 | 7288 |
7292 out_flush(); | 7289 out_flush(); |
7293 } | 7290 } |
7294 | 7291 |
7369 */ | 7366 */ |
7370 FILE * | 7367 FILE * |
7371 open_exfile( | 7368 open_exfile( |
7372 char_u *fname, | 7369 char_u *fname, |
7373 int forceit, | 7370 int forceit, |
7374 char *mode) /* "w" for create new file or "a" for append */ | 7371 char *mode) // "w" for create new file or "a" for append |
7375 { | 7372 { |
7376 FILE *fd; | 7373 FILE *fd; |
7377 | 7374 |
7378 #ifdef UNIX | 7375 #ifdef UNIX |
7379 /* with Unix it is possible to open a directory */ | 7376 // with Unix it is possible to open a directory |
7380 if (mch_isdir(fname)) | 7377 if (mch_isdir(fname)) |
7381 { | 7378 { |
7382 semsg(_(e_isadir2), fname); | 7379 semsg(_(e_isadir2), fname); |
7383 return NULL; | 7380 return NULL; |
7384 } | 7381 } |
7401 static void | 7398 static void |
7402 ex_mark(exarg_T *eap) | 7399 ex_mark(exarg_T *eap) |
7403 { | 7400 { |
7404 pos_T pos; | 7401 pos_T pos; |
7405 | 7402 |
7406 if (*eap->arg == NUL) /* No argument? */ | 7403 if (*eap->arg == NUL) // No argument? |
7407 emsg(_(e_argreq)); | 7404 emsg(_(e_argreq)); |
7408 else if (eap->arg[1] != NUL) /* more than one character? */ | 7405 else if (eap->arg[1] != NUL) // more than one character? |
7409 emsg(_(e_trailing)); | 7406 emsg(_(e_trailing)); |
7410 else | 7407 else |
7411 { | 7408 { |
7412 pos = curwin->w_cursor; /* save curwin->w_cursor */ | 7409 pos = curwin->w_cursor; // save curwin->w_cursor |
7413 curwin->w_cursor.lnum = eap->line2; | 7410 curwin->w_cursor.lnum = eap->line2; |
7414 beginline(BL_WHITE | BL_FIX); | 7411 beginline(BL_WHITE | BL_FIX); |
7415 if (setmark(*eap->arg) == FAIL) /* set mark */ | 7412 if (setmark(*eap->arg) == FAIL) // set mark |
7416 emsg(_("E191: Argument must be a letter or forward/backward quote")); | 7413 emsg(_("E191: Argument must be a letter or forward/backward quote")); |
7417 curwin->w_cursor = pos; /* restore curwin->w_cursor */ | 7414 curwin->w_cursor = pos; // restore curwin->w_cursor |
7418 } | 7415 } |
7419 } | 7416 } |
7420 | 7417 |
7421 /* | 7418 /* |
7422 * Update w_topline, w_leftcol and the cursor position. | 7419 * Update w_topline, w_leftcol and the cursor position. |
7423 */ | 7420 */ |
7424 void | 7421 void |
7425 update_topline_cursor(void) | 7422 update_topline_cursor(void) |
7426 { | 7423 { |
7427 check_cursor(); /* put cursor on valid line */ | 7424 check_cursor(); // put cursor on valid line |
7428 update_topline(); | 7425 update_topline(); |
7429 if (!curwin->w_p_wrap) | 7426 if (!curwin->w_p_wrap) |
7430 validate_cursor(); | 7427 validate_cursor(); |
7431 update_curswant(); | 7428 update_curswant(); |
7432 } | 7429 } |
7445 sst->save_insertmode = p_im; | 7442 sst->save_insertmode = p_im; |
7446 sst->save_finish_op = finish_op; | 7443 sst->save_finish_op = finish_op; |
7447 sst->save_opcount = opcount; | 7444 sst->save_opcount = opcount; |
7448 sst->save_reg_executing = reg_executing; | 7445 sst->save_reg_executing = reg_executing; |
7449 | 7446 |
7450 msg_scroll = FALSE; /* no msg scrolling in Normal mode */ | 7447 msg_scroll = FALSE; // no msg scrolling in Normal mode |
7451 restart_edit = 0; /* don't go to Insert mode */ | 7448 restart_edit = 0; // don't go to Insert mode |
7452 p_im = FALSE; /* don't use 'insertmode' */ | 7449 p_im = FALSE; // don't use 'insertmode' |
7453 | 7450 |
7454 /* | 7451 /* |
7455 * Save the current typeahead. This is required to allow using ":normal" | 7452 * Save the current typeahead. This is required to allow using ":normal" |
7456 * from an event handler and makes sure we don't hang when the argument | 7453 * from an event handler and makes sure we don't hang when the argument |
7457 * ends with half a command. | 7454 * ends with half a command. |
7461 } | 7458 } |
7462 | 7459 |
7463 void | 7460 void |
7464 restore_current_state(save_state_T *sst) | 7461 restore_current_state(save_state_T *sst) |
7465 { | 7462 { |
7466 /* Restore the previous typeahead. */ | 7463 // Restore the previous typeahead. |
7467 restore_typeahead(&sst->tabuf); | 7464 restore_typeahead(&sst->tabuf); |
7468 | 7465 |
7469 msg_scroll = sst->save_msg_scroll; | 7466 msg_scroll = sst->save_msg_scroll; |
7470 restart_edit = sst->save_restart_edit; | 7467 restart_edit = sst->save_restart_edit; |
7471 p_im = sst->save_insertmode; | 7468 p_im = sst->save_insertmode; |
7472 finish_op = sst->save_finish_op; | 7469 finish_op = sst->save_finish_op; |
7473 opcount = sst->save_opcount; | 7470 opcount = sst->save_opcount; |
7474 reg_executing = sst->save_reg_executing; | 7471 reg_executing = sst->save_reg_executing; |
7475 msg_didout |= sst->save_msg_didout; /* don't reset msg_didout now */ | 7472 msg_didout |= sst->save_msg_didout; // don't reset msg_didout now |
7476 | 7473 |
7477 /* Restore the state (needed when called from a function executed for | 7474 // Restore the state (needed when called from a function executed for |
7478 * 'indentexpr'). Update the mouse and cursor, they may have changed. */ | 7475 // 'indentexpr'). Update the mouse and cursor, they may have changed. |
7479 State = sst->save_State; | 7476 State = sst->save_State; |
7480 #ifdef CURSOR_SHAPE | 7477 #ifdef CURSOR_SHAPE |
7481 ui_cursor_shape(); /* may show different cursor shape */ | 7478 ui_cursor_shape(); // may show different cursor shape |
7482 #endif | 7479 #endif |
7483 } | 7480 } |
7484 | 7481 |
7485 /* | 7482 /* |
7486 * ":normal[!] {commands}": Execute normal mode commands. | 7483 * ":normal[!] {commands}": Execute normal mode commands. |
7511 */ | 7508 */ |
7512 if (has_mbyte) | 7509 if (has_mbyte) |
7513 { | 7510 { |
7514 int len = 0; | 7511 int len = 0; |
7515 | 7512 |
7516 /* Count the number of characters to be escaped. */ | 7513 // Count the number of characters to be escaped. |
7517 for (p = eap->arg; *p != NUL; ++p) | 7514 for (p = eap->arg; *p != NUL; ++p) |
7518 { | 7515 { |
7519 #ifdef FEAT_GUI | 7516 #ifdef FEAT_GUI |
7520 if (*p == CSI) /* leadbyte CSI */ | 7517 if (*p == CSI) // leadbyte CSI |
7521 len += 2; | 7518 len += 2; |
7522 #endif | 7519 #endif |
7523 for (l = (*mb_ptr2len)(p) - 1; l > 0; --l) | 7520 for (l = (*mb_ptr2len)(p) - 1; l > 0; --l) |
7524 if (*++p == K_SPECIAL /* trailbyte K_SPECIAL or CSI */ | 7521 if (*++p == K_SPECIAL // trailbyte K_SPECIAL or CSI |
7525 #ifdef FEAT_GUI | 7522 #ifdef FEAT_GUI |
7526 || *p == CSI | 7523 || *p == CSI |
7527 #endif | 7524 #endif |
7528 ) | 7525 ) |
7529 len += 2; | 7526 len += 2; |
7588 : eap->arg, eap->forceit ? REMAP_NONE : REMAP_YES, FALSE); | 7585 : eap->arg, eap->forceit ? REMAP_NONE : REMAP_YES, FALSE); |
7589 } | 7586 } |
7590 while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int); | 7587 while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int); |
7591 } | 7588 } |
7592 | 7589 |
7593 /* Might not return to the main loop when in an event handler. */ | 7590 // Might not return to the main loop when in an event handler. |
7594 update_topline_cursor(); | 7591 update_topline_cursor(); |
7595 | 7592 |
7596 restore_current_state(&save_state); | 7593 restore_current_state(&save_state); |
7597 --ex_normal_busy; | 7594 --ex_normal_busy; |
7598 setmouse(); | 7595 setmouse(); |
7599 #ifdef CURSOR_SHAPE | 7596 #ifdef CURSOR_SHAPE |
7600 ui_cursor_shape(); /* may show different cursor shape */ | 7597 ui_cursor_shape(); // may show different cursor shape |
7601 #endif | 7598 #endif |
7602 | 7599 |
7603 vim_free(arg); | 7600 vim_free(arg); |
7604 } | 7601 } |
7605 | 7602 |
7653 * "remap" can be REMAP_NONE or REMAP_YES. | 7650 * "remap" can be REMAP_NONE or REMAP_YES. |
7654 */ | 7651 */ |
7655 void | 7652 void |
7656 exec_normal_cmd(char_u *cmd, int remap, int silent) | 7653 exec_normal_cmd(char_u *cmd, int remap, int silent) |
7657 { | 7654 { |
7658 /* Stuff the argument into the typeahead buffer. */ | 7655 // Stuff the argument into the typeahead buffer. |
7659 ins_typebuf(cmd, remap, 0, TRUE, silent); | 7656 ins_typebuf(cmd, remap, 0, TRUE, silent); |
7660 exec_normal(FALSE, FALSE, FALSE); | 7657 exec_normal(FALSE, FALSE, FALSE); |
7661 } | 7658 } |
7662 | 7659 |
7663 /* | 7660 /* |
7683 #ifdef FEAT_TERMINAL | 7680 #ifdef FEAT_TERMINAL |
7684 if (may_use_terminal_loop && term_use_loop() | 7681 if (may_use_terminal_loop && term_use_loop() |
7685 && oa.op_type == OP_NOP && oa.regname == NUL | 7682 && oa.op_type == OP_NOP && oa.regname == NUL |
7686 && !VIsual_active) | 7683 && !VIsual_active) |
7687 { | 7684 { |
7688 /* If terminal_loop() returns OK we got a key that is handled | 7685 // If terminal_loop() returns OK we got a key that is handled |
7689 * in Normal model. With FAIL we first need to position the | 7686 // in Normal model. With FAIL we first need to position the |
7690 * cursor and the screen needs to be redrawn. */ | 7687 // cursor and the screen needs to be redrawn. |
7691 if (terminal_loop(TRUE) == OK) | 7688 if (terminal_loop(TRUE) == OK) |
7692 normal_cmd(&oa, TRUE); | 7689 normal_cmd(&oa, TRUE); |
7693 } | 7690 } |
7694 else | 7691 else |
7695 #endif | 7692 #endif |
7696 /* execute a Normal mode cmd */ | 7693 // execute a Normal mode cmd |
7697 normal_cmd(&oa, TRUE); | 7694 normal_cmd(&oa, TRUE); |
7698 } | 7695 } |
7699 } | 7696 } |
7700 | 7697 |
7701 #ifdef FEAT_FIND_ID | 7698 #ifdef FEAT_FIND_ID |
7728 char_u *p; | 7725 char_u *p; |
7729 int action; | 7726 int action; |
7730 | 7727 |
7731 switch (cmdnames[eap->cmdidx].cmd_name[2]) | 7728 switch (cmdnames[eap->cmdidx].cmd_name[2]) |
7732 { | 7729 { |
7733 case 'e': /* ":psearch", ":isearch" and ":dsearch" */ | 7730 case 'e': // ":psearch", ":isearch" and ":dsearch" |
7734 if (cmdnames[eap->cmdidx].cmd_name[0] == 'p') | 7731 if (cmdnames[eap->cmdidx].cmd_name[0] == 'p') |
7735 action = ACTION_GOTO; | 7732 action = ACTION_GOTO; |
7736 else | 7733 else |
7737 action = ACTION_SHOW; | 7734 action = ACTION_SHOW; |
7738 break; | 7735 break; |
7739 case 'i': /* ":ilist" and ":dlist" */ | 7736 case 'i': // ":ilist" and ":dlist" |
7740 action = ACTION_SHOW_ALL; | 7737 action = ACTION_SHOW_ALL; |
7741 break; | 7738 break; |
7742 case 'u': /* ":ijump" and ":djump" */ | 7739 case 'u': // ":ijump" and ":djump" |
7743 action = ACTION_GOTO; | 7740 action = ACTION_GOTO; |
7744 break; | 7741 break; |
7745 default: /* ":isplit" and ":dsplit" */ | 7742 default: // ":isplit" and ":dsplit" |
7746 action = ACTION_SPLIT; | 7743 action = ACTION_SPLIT; |
7747 break; | 7744 break; |
7748 } | 7745 } |
7749 | 7746 |
7750 n = 1; | 7747 n = 1; |
7751 if (vim_isdigit(*eap->arg)) /* get count */ | 7748 if (vim_isdigit(*eap->arg)) // get count |
7752 { | 7749 { |
7753 n = getdigits(&eap->arg); | 7750 n = getdigits(&eap->arg); |
7754 eap->arg = skipwhite(eap->arg); | 7751 eap->arg = skipwhite(eap->arg); |
7755 } | 7752 } |
7756 if (*eap->arg == '/') /* Match regexp, not just whole words */ | 7753 if (*eap->arg == '/') // Match regexp, not just whole words |
7757 { | 7754 { |
7758 whole = FALSE; | 7755 whole = FALSE; |
7759 ++eap->arg; | 7756 ++eap->arg; |
7760 p = skip_regexp(eap->arg, '/', p_magic, NULL); | 7757 p = skip_regexp(eap->arg, '/', p_magic, NULL); |
7761 if (*p) | 7758 if (*p) |
7762 { | 7759 { |
7763 *p++ = NUL; | 7760 *p++ = NUL; |
7764 p = skipwhite(p); | 7761 p = skipwhite(p); |
7765 | 7762 |
7766 /* Check for trailing illegal characters */ | 7763 // Check for trailing illegal characters |
7767 if (!ends_excmd(*p)) | 7764 if (!ends_excmd(*p)) |
7768 eap->errmsg = e_trailing; | 7765 eap->errmsg = e_trailing; |
7769 else | 7766 else |
7770 eap->nextcmd = check_nextcmd(p); | 7767 eap->nextcmd = check_nextcmd(p); |
7771 } | 7768 } |
7784 * ":ptag", ":ptselect", ":ptjump", ":ptnext", etc. | 7781 * ":ptag", ":ptselect", ":ptjump", ":ptnext", etc. |
7785 */ | 7782 */ |
7786 static void | 7783 static void |
7787 ex_ptag(exarg_T *eap) | 7784 ex_ptag(exarg_T *eap) |
7788 { | 7785 { |
7789 g_do_tagpreview = p_pvh; /* will be reset to 0 in ex_tag_cmd() */ | 7786 g_do_tagpreview = p_pvh; // will be reset to 0 in ex_tag_cmd() |
7790 ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); | 7787 ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); |
7791 } | 7788 } |
7792 | 7789 |
7793 /* | 7790 /* |
7794 * ":pedit" | 7791 * ":pedit" |
7851 { | 7848 { |
7852 int cmd; | 7849 int cmd; |
7853 | 7850 |
7854 switch (name[1]) | 7851 switch (name[1]) |
7855 { | 7852 { |
7856 case 'j': cmd = DT_JUMP; /* ":tjump" */ | 7853 case 'j': cmd = DT_JUMP; // ":tjump" |
7857 break; | 7854 break; |
7858 case 's': cmd = DT_SELECT; /* ":tselect" */ | 7855 case 's': cmd = DT_SELECT; // ":tselect" |
7859 break; | 7856 break; |
7860 case 'p': cmd = DT_PREV; /* ":tprevious" */ | 7857 case 'p': cmd = DT_PREV; // ":tprevious" |
7861 break; | 7858 break; |
7862 case 'N': cmd = DT_PREV; /* ":tNext" */ | 7859 case 'N': cmd = DT_PREV; // ":tNext" |
7863 break; | 7860 break; |
7864 case 'n': cmd = DT_NEXT; /* ":tnext" */ | 7861 case 'n': cmd = DT_NEXT; // ":tnext" |
7865 break; | 7862 break; |
7866 case 'o': cmd = DT_POP; /* ":pop" */ | 7863 case 'o': cmd = DT_POP; // ":pop" |
7867 break; | 7864 break; |
7868 case 'f': /* ":tfirst" */ | 7865 case 'f': // ":tfirst" |
7869 case 'r': cmd = DT_FIRST; /* ":trewind" */ | 7866 case 'r': cmd = DT_FIRST; // ":trewind" |
7870 break; | 7867 break; |
7871 case 'l': cmd = DT_LAST; /* ":tlast" */ | 7868 case 'l': cmd = DT_LAST; // ":tlast" |
7872 break; | 7869 break; |
7873 default: /* ":tag" */ | 7870 default: // ":tag" |
7874 #ifdef FEAT_CSCOPE | 7871 #ifdef FEAT_CSCOPE |
7875 if (p_cst && *eap->arg != NUL) | 7872 if (p_cst && *eap->arg != NUL) |
7876 { | 7873 { |
7877 ex_cstag(eap); | 7874 ex_cstag(eap); |
7878 return; | 7875 return; |
7909 static char *(spec_str[]) = { | 7906 static char *(spec_str[]) = { |
7910 "%", | 7907 "%", |
7911 #define SPEC_PERC 0 | 7908 #define SPEC_PERC 0 |
7912 "#", | 7909 "#", |
7913 #define SPEC_HASH (SPEC_PERC + 1) | 7910 #define SPEC_HASH (SPEC_PERC + 1) |
7914 "<cword>", /* cursor word */ | 7911 "<cword>", // cursor word |
7915 #define SPEC_CWORD (SPEC_HASH + 1) | 7912 #define SPEC_CWORD (SPEC_HASH + 1) |
7916 "<cWORD>", /* cursor WORD */ | 7913 "<cWORD>", // cursor WORD |
7917 #define SPEC_CCWORD (SPEC_CWORD + 1) | 7914 #define SPEC_CCWORD (SPEC_CWORD + 1) |
7918 "<cexpr>", /* expr under cursor */ | 7915 "<cexpr>", // expr under cursor |
7919 #define SPEC_CEXPR (SPEC_CCWORD + 1) | 7916 #define SPEC_CEXPR (SPEC_CCWORD + 1) |
7920 "<cfile>", /* cursor path name */ | 7917 "<cfile>", // cursor path name |
7921 #define SPEC_CFILE (SPEC_CEXPR + 1) | 7918 #define SPEC_CFILE (SPEC_CEXPR + 1) |
7922 "<sfile>", /* ":so" file name */ | 7919 "<sfile>", // ":so" file name |
7923 #define SPEC_SFILE (SPEC_CFILE + 1) | 7920 #define SPEC_SFILE (SPEC_CFILE + 1) |
7924 "<slnum>", /* ":so" file line number */ | 7921 "<slnum>", // ":so" file line number |
7925 #define SPEC_SLNUM (SPEC_SFILE + 1) | 7922 #define SPEC_SLNUM (SPEC_SFILE + 1) |
7926 "<afile>", /* autocommand file name */ | 7923 "<afile>", // autocommand file name |
7927 #define SPEC_AFILE (SPEC_SLNUM + 1) | 7924 #define SPEC_AFILE (SPEC_SLNUM + 1) |
7928 "<abuf>", /* autocommand buffer number */ | 7925 "<abuf>", // autocommand buffer number |
7929 #define SPEC_ABUF (SPEC_AFILE + 1) | 7926 #define SPEC_ABUF (SPEC_AFILE + 1) |
7930 "<amatch>", /* autocommand match name */ | 7927 "<amatch>", // autocommand match name |
7931 #define SPEC_AMATCH (SPEC_ABUF + 1) | 7928 #define SPEC_AMATCH (SPEC_ABUF + 1) |
7932 "<sflnum>", /* script file line number */ | 7929 "<sflnum>", // script file line number |
7933 #define SPEC_SFLNUM (SPEC_AMATCH + 1) | 7930 #define SPEC_SFLNUM (SPEC_AMATCH + 1) |
7934 #ifdef FEAT_CLIENTSERVER | 7931 #ifdef FEAT_CLIENTSERVER |
7935 "<client>" | 7932 "<client>" |
7936 # define SPEC_CLIENT (SPEC_SFLNUM + 1) | 7933 # define SPEC_CLIENT (SPEC_SFLNUM + 1) |
7937 #endif | 7934 #endif |
7970 * Returns NULL if no match was found. "usedlen" then still contains the | 7967 * Returns NULL if no match was found. "usedlen" then still contains the |
7971 * number of characters to skip. | 7968 * number of characters to skip. |
7972 */ | 7969 */ |
7973 char_u * | 7970 char_u * |
7974 eval_vars( | 7971 eval_vars( |
7975 char_u *src, /* pointer into commandline */ | 7972 char_u *src, // pointer into commandline |
7976 char_u *srcstart, /* beginning of valid memory for src */ | 7973 char_u *srcstart, // beginning of valid memory for src |
7977 int *usedlen, /* characters after src that are used */ | 7974 int *usedlen, // characters after src that are used |
7978 linenr_T *lnump, /* line number for :e command, or NULL */ | 7975 linenr_T *lnump, // line number for :e command, or NULL |
7979 char **errormsg, /* pointer to error message */ | 7976 char **errormsg, // pointer to error message |
7980 int *escaped) /* return value has escaped white space (can | 7977 int *escaped) // return value has escaped white space (can |
7981 * be NULL) */ | 7978 // be NULL) |
7982 { | 7979 { |
7983 int i; | 7980 int i; |
7984 char_u *s; | 7981 char_u *s; |
7985 char_u *result; | 7982 char_u *result; |
7986 char_u *resultbuf = NULL; | 7983 char_u *resultbuf = NULL; |
7987 int resultlen; | 7984 int resultlen; |
7988 buf_T *buf; | 7985 buf_T *buf; |
7989 int valid = VALID_HEAD + VALID_PATH; /* assume valid result */ | 7986 int valid = VALID_HEAD + VALID_PATH; // assume valid result |
7990 int spec_idx; | 7987 int spec_idx; |
7991 int tilde_file = FALSE; | 7988 int tilde_file = FALSE; |
7992 int skip_mod = FALSE; | 7989 int skip_mod = FALSE; |
7993 char_u strbuf[30]; | 7990 char_u strbuf[30]; |
7994 | 7991 |
7998 | 7995 |
7999 /* | 7996 /* |
8000 * Check if there is something to do. | 7997 * Check if there is something to do. |
8001 */ | 7998 */ |
8002 spec_idx = find_cmdline_var(src, usedlen); | 7999 spec_idx = find_cmdline_var(src, usedlen); |
8003 if (spec_idx < 0) /* no match */ | 8000 if (spec_idx < 0) // no match |
8004 { | 8001 { |
8005 *usedlen = 1; | 8002 *usedlen = 1; |
8006 return NULL; | 8003 return NULL; |
8007 } | 8004 } |
8008 | 8005 |
8011 * Note: In "\\%" the % is also not recognized! | 8008 * Note: In "\\%" the % is also not recognized! |
8012 */ | 8009 */ |
8013 if (src > srcstart && src[-1] == '\\') | 8010 if (src > srcstart && src[-1] == '\\') |
8014 { | 8011 { |
8015 *usedlen = 0; | 8012 *usedlen = 0; |
8016 STRMOVE(src - 1, src); /* remove backslash */ | 8013 STRMOVE(src - 1, src); // remove backslash |
8017 return NULL; | 8014 return NULL; |
8018 } | 8015 } |
8019 | 8016 |
8020 /* | 8017 /* |
8021 * word or WORD under cursor | 8018 * word or WORD under cursor |
8043 */ | 8040 */ |
8044 else | 8041 else |
8045 { | 8042 { |
8046 switch (spec_idx) | 8043 switch (spec_idx) |
8047 { | 8044 { |
8048 case SPEC_PERC: /* '%': current file */ | 8045 case SPEC_PERC: // '%': current file |
8049 if (curbuf->b_fname == NULL) | 8046 if (curbuf->b_fname == NULL) |
8050 { | 8047 { |
8051 result = (char_u *)""; | 8048 result = (char_u *)""; |
8052 valid = 0; /* Must have ":p:h" to be valid */ | 8049 valid = 0; // Must have ":p:h" to be valid |
8053 } | 8050 } |
8054 else | 8051 else |
8055 { | 8052 { |
8056 result = curbuf->b_fname; | 8053 result = curbuf->b_fname; |
8057 tilde_file = STRCMP(result, "~") == 0; | 8054 tilde_file = STRCMP(result, "~") == 0; |
8058 } | 8055 } |
8059 break; | 8056 break; |
8060 | 8057 |
8061 case SPEC_HASH: /* '#' or "#99": alternate file */ | 8058 case SPEC_HASH: // '#' or "#99": alternate file |
8062 if (src[1] == '#') /* "##": the argument list */ | 8059 if (src[1] == '#') // "##": the argument list |
8063 { | 8060 { |
8064 result = arg_all(); | 8061 result = arg_all(); |
8065 resultbuf = result; | 8062 resultbuf = result; |
8066 *usedlen = 2; | 8063 *usedlen = 2; |
8067 if (escaped != NULL) | 8064 if (escaped != NULL) |
8068 *escaped = TRUE; | 8065 *escaped = TRUE; |
8069 skip_mod = TRUE; | 8066 skip_mod = TRUE; |
8070 break; | 8067 break; |
8071 } | 8068 } |
8072 s = src + 1; | 8069 s = src + 1; |
8073 if (*s == '<') /* "#<99" uses v:oldfiles */ | 8070 if (*s == '<') // "#<99" uses v:oldfiles |
8074 ++s; | 8071 ++s; |
8075 i = (int)getdigits(&s); | 8072 i = (int)getdigits(&s); |
8076 if (s == src + 2 && src[1] == '-') | 8073 if (s == src + 2 && src[1] == '-') |
8077 /* just a minus sign, don't skip over it */ | 8074 // just a minus sign, don't skip over it |
8078 s--; | 8075 s--; |
8079 *usedlen = (int)(s - src); /* length of what we expand */ | 8076 *usedlen = (int)(s - src); // length of what we expand |
8080 | 8077 |
8081 if (src[1] == '<' && i != 0) | 8078 if (src[1] == '<' && i != 0) |
8082 { | 8079 { |
8083 if (*usedlen < 2) | 8080 if (*usedlen < 2) |
8084 { | 8081 { |
8085 /* Should we give an error message for #<text? */ | 8082 // Should we give an error message for #<text? |
8086 *usedlen = 1; | 8083 *usedlen = 1; |
8087 return NULL; | 8084 return NULL; |
8088 } | 8085 } |
8089 #ifdef FEAT_EVAL | 8086 #ifdef FEAT_EVAL |
8090 result = list_find_str(get_vim_var_list(VV_OLDFILES), | 8087 result = list_find_str(get_vim_var_list(VV_OLDFILES), |
8112 if (lnump != NULL) | 8109 if (lnump != NULL) |
8113 *lnump = ECMD_LAST; | 8110 *lnump = ECMD_LAST; |
8114 if (buf->b_fname == NULL) | 8111 if (buf->b_fname == NULL) |
8115 { | 8112 { |
8116 result = (char_u *)""; | 8113 result = (char_u *)""; |
8117 valid = 0; /* Must have ":p:h" to be valid */ | 8114 valid = 0; // Must have ":p:h" to be valid |
8118 } | 8115 } |
8119 else | 8116 else |
8120 { | 8117 { |
8121 result = buf->b_fname; | 8118 result = buf->b_fname; |
8122 tilde_file = STRCMP(result, "~") == 0; | 8119 tilde_file = STRCMP(result, "~") == 0; |
8123 } | 8120 } |
8124 } | 8121 } |
8125 break; | 8122 break; |
8126 | 8123 |
8127 #ifdef FEAT_SEARCHPATH | 8124 #ifdef FEAT_SEARCHPATH |
8128 case SPEC_CFILE: /* file name under cursor */ | 8125 case SPEC_CFILE: // file name under cursor |
8129 result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); | 8126 result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); |
8130 if (result == NULL) | 8127 if (result == NULL) |
8131 { | 8128 { |
8132 *errormsg = ""; | 8129 *errormsg = ""; |
8133 return NULL; | 8130 return NULL; |
8134 } | 8131 } |
8135 resultbuf = result; /* remember allocated string */ | 8132 resultbuf = result; // remember allocated string |
8136 break; | 8133 break; |
8137 #endif | 8134 #endif |
8138 | 8135 |
8139 case SPEC_AFILE: /* file name for autocommand */ | 8136 case SPEC_AFILE: // file name for autocommand |
8140 result = autocmd_fname; | 8137 result = autocmd_fname; |
8141 if (result != NULL && !autocmd_fname_full) | 8138 if (result != NULL && !autocmd_fname_full) |
8142 { | 8139 { |
8143 /* Still need to turn the fname into a full path. It is | 8140 // Still need to turn the fname into a full path. It is |
8144 * postponed to avoid a delay when <afile> is not used. */ | 8141 // postponed to avoid a delay when <afile> is not used. |
8145 autocmd_fname_full = TRUE; | 8142 autocmd_fname_full = TRUE; |
8146 result = FullName_save(autocmd_fname, FALSE); | 8143 result = FullName_save(autocmd_fname, FALSE); |
8147 vim_free(autocmd_fname); | 8144 vim_free(autocmd_fname); |
8148 autocmd_fname = result; | 8145 autocmd_fname = result; |
8149 } | 8146 } |
8153 return NULL; | 8150 return NULL; |
8154 } | 8151 } |
8155 result = shorten_fname1(result); | 8152 result = shorten_fname1(result); |
8156 break; | 8153 break; |
8157 | 8154 |
8158 case SPEC_ABUF: /* buffer number for autocommand */ | 8155 case SPEC_ABUF: // buffer number for autocommand |
8159 if (autocmd_bufnr <= 0) | 8156 if (autocmd_bufnr <= 0) |
8160 { | 8157 { |
8161 *errormsg = _("E496: no autocommand buffer number to substitute for \"<abuf>\""); | 8158 *errormsg = _("E496: no autocommand buffer number to substitute for \"<abuf>\""); |
8162 return NULL; | 8159 return NULL; |
8163 } | 8160 } |
8164 sprintf((char *)strbuf, "%d", autocmd_bufnr); | 8161 sprintf((char *)strbuf, "%d", autocmd_bufnr); |
8165 result = strbuf; | 8162 result = strbuf; |
8166 break; | 8163 break; |
8167 | 8164 |
8168 case SPEC_AMATCH: /* match name for autocommand */ | 8165 case SPEC_AMATCH: // match name for autocommand |
8169 result = autocmd_match; | 8166 result = autocmd_match; |
8170 if (result == NULL) | 8167 if (result == NULL) |
8171 { | 8168 { |
8172 *errormsg = _("E497: no autocommand match name to substitute for \"<amatch>\""); | 8169 *errormsg = _("E497: no autocommand match name to substitute for \"<amatch>\""); |
8173 return NULL; | 8170 return NULL; |
8174 } | 8171 } |
8175 break; | 8172 break; |
8176 | 8173 |
8177 case SPEC_SFILE: /* file name for ":so" command */ | 8174 case SPEC_SFILE: // file name for ":so" command |
8178 result = sourcing_name; | 8175 result = sourcing_name; |
8179 if (result == NULL) | 8176 if (result == NULL) |
8180 { | 8177 { |
8181 *errormsg = _("E498: no :source file name to substitute for \"<sfile>\""); | 8178 *errormsg = _("E498: no :source file name to substitute for \"<sfile>\""); |
8182 return NULL; | 8179 return NULL; |
8183 } | 8180 } |
8184 break; | 8181 break; |
8185 | 8182 |
8186 case SPEC_SLNUM: /* line in file for ":so" command */ | 8183 case SPEC_SLNUM: // line in file for ":so" command |
8187 if (sourcing_name == NULL || sourcing_lnum == 0) | 8184 if (sourcing_name == NULL || sourcing_lnum == 0) |
8188 { | 8185 { |
8189 *errormsg = _("E842: no line number to use for \"<slnum>\""); | 8186 *errormsg = _("E842: no line number to use for \"<slnum>\""); |
8190 return NULL; | 8187 return NULL; |
8191 } | 8188 } |
8192 sprintf((char *)strbuf, "%ld", (long)sourcing_lnum); | 8189 sprintf((char *)strbuf, "%ld", (long)sourcing_lnum); |
8193 result = strbuf; | 8190 result = strbuf; |
8194 break; | 8191 break; |
8195 | 8192 |
8196 #ifdef FEAT_EVAL | 8193 #ifdef FEAT_EVAL |
8197 case SPEC_SFLNUM: /* line in script file */ | 8194 case SPEC_SFLNUM: // line in script file |
8198 if (current_sctx.sc_lnum + sourcing_lnum == 0) | 8195 if (current_sctx.sc_lnum + sourcing_lnum == 0) |
8199 { | 8196 { |
8200 *errormsg = _("E961: no line number to use for \"<sflnum>\""); | 8197 *errormsg = _("E961: no line number to use for \"<sflnum>\""); |
8201 return NULL; | 8198 return NULL; |
8202 } | 8199 } |
8205 result = strbuf; | 8202 result = strbuf; |
8206 break; | 8203 break; |
8207 #endif | 8204 #endif |
8208 | 8205 |
8209 #ifdef FEAT_CLIENTSERVER | 8206 #ifdef FEAT_CLIENTSERVER |
8210 case SPEC_CLIENT: /* Source of last submitted input */ | 8207 case SPEC_CLIENT: // Source of last submitted input |
8211 sprintf((char *)strbuf, PRINTF_HEX_LONG_U, | 8208 sprintf((char *)strbuf, PRINTF_HEX_LONG_U, |
8212 (long_u)clientWindow); | 8209 (long_u)clientWindow); |
8213 result = strbuf; | 8210 result = strbuf; |
8214 break; | 8211 break; |
8215 #endif | 8212 #endif |
8216 | 8213 |
8217 default: | 8214 default: |
8218 result = (char_u *)""; /* avoid gcc warning */ | 8215 result = (char_u *)""; // avoid gcc warning |
8219 break; | 8216 break; |
8220 } | 8217 } |
8221 | 8218 |
8222 resultlen = (int)STRLEN(result); /* length of new string */ | 8219 resultlen = (int)STRLEN(result); // length of new string |
8223 if (src[*usedlen] == '<') /* remove the file name extension */ | 8220 if (src[*usedlen] == '<') // remove the file name extension |
8224 { | 8221 { |
8225 ++*usedlen; | 8222 ++*usedlen; |
8226 if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result)) | 8223 if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result)) |
8227 resultlen = (int)(s - result); | 8224 resultlen = (int)(s - result); |
8228 } | 8225 } |
8239 } | 8236 } |
8240 | 8237 |
8241 if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH) | 8238 if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH) |
8242 { | 8239 { |
8243 if (valid != VALID_HEAD + VALID_PATH) | 8240 if (valid != VALID_HEAD + VALID_PATH) |
8244 /* xgettext:no-c-format */ | 8241 // xgettext:no-c-format |
8245 *errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\""); | 8242 *errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\""); |
8246 else | 8243 else |
8247 *errormsg = _("E500: Evaluates to an empty string"); | 8244 *errormsg = _("E500: Evaluates to an empty string"); |
8248 result = NULL; | 8245 result = NULL; |
8249 } | 8246 } |
8277 { | 8274 { |
8278 if (STRNCMP(p, "<sfile>", 7) != 0) | 8275 if (STRNCMP(p, "<sfile>", 7) != 0) |
8279 ++p; | 8276 ++p; |
8280 else | 8277 else |
8281 { | 8278 { |
8282 /* replace "<sfile>" with the sourced file name, and do ":" stuff */ | 8279 // replace "<sfile>" with the sourced file name, and do ":" stuff |
8283 repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL); | 8280 repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL); |
8284 if (errormsg != NULL) | 8281 if (errormsg != NULL) |
8285 { | 8282 { |
8286 if (*errormsg) | 8283 if (*errormsg) |
8287 emsg(errormsg); | 8284 emsg(errormsg); |
8288 vim_free(result); | 8285 vim_free(result); |
8289 return NULL; | 8286 return NULL; |
8290 } | 8287 } |
8291 if (repl == NULL) /* no match (cannot happen) */ | 8288 if (repl == NULL) // no match (cannot happen) |
8292 { | 8289 { |
8293 p += srclen; | 8290 p += srclen; |
8294 continue; | 8291 continue; |
8295 } | 8292 } |
8296 len = (int)STRLEN(result) - srclen + (int)STRLEN(repl) + 1; | 8293 len = (int)STRLEN(result) - srclen + (int)STRLEN(repl) + 1; |
8306 len = (int)STRLEN(newres); | 8303 len = (int)STRLEN(newres); |
8307 STRCAT(newres, p + srclen); | 8304 STRCAT(newres, p + srclen); |
8308 vim_free(repl); | 8305 vim_free(repl); |
8309 vim_free(result); | 8306 vim_free(result); |
8310 result = newres; | 8307 result = newres; |
8311 p = newres + len; /* continue after the match */ | 8308 p = newres + len; // continue after the match |
8312 } | 8309 } |
8313 } | 8310 } |
8314 | 8311 |
8315 return result; | 8312 return result; |
8316 } | 8313 } |
8374 int plugin = FALSE; | 8371 int plugin = FALSE; |
8375 int indent = FALSE; | 8372 int indent = FALSE; |
8376 | 8373 |
8377 if (*eap->arg == NUL) | 8374 if (*eap->arg == NUL) |
8378 { | 8375 { |
8379 /* Print current status. */ | 8376 // Print current status. |
8380 smsg("filetype detection:%s plugin:%s indent:%s", | 8377 smsg("filetype detection:%s plugin:%s indent:%s", |
8381 filetype_detect ? "ON" : "OFF", | 8378 filetype_detect ? "ON" : "OFF", |
8382 filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF", | 8379 filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF", |
8383 filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF"); | 8380 filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF"); |
8384 return; | 8381 return; |
8385 } | 8382 } |
8386 | 8383 |
8387 /* Accept "plugin" and "indent" in any order. */ | 8384 // Accept "plugin" and "indent" in any order. |
8388 for (;;) | 8385 for (;;) |
8389 { | 8386 { |
8390 if (STRNCMP(arg, "plugin", 6) == 0) | 8387 if (STRNCMP(arg, "plugin", 6) == 0) |
8391 { | 8388 { |
8392 plugin = TRUE; | 8389 plugin = TRUE; |
8553 | 8550 |
8554 # ifdef FEAT_CLIPBOARD | 8551 # ifdef FEAT_CLIPBOARD |
8555 start_global_changes(); | 8552 start_global_changes(); |
8556 # endif | 8553 # endif |
8557 | 8554 |
8558 /* First set the marks for all lines closed/open. */ | 8555 // First set the marks for all lines closed/open. |
8559 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | 8556 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) |
8560 if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) | 8557 if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) |
8561 ml_setmarked(lnum); | 8558 ml_setmarked(lnum); |
8562 | 8559 |
8563 /* Execute the command on the marked lines. */ | 8560 // Execute the command on the marked lines. |
8564 global_exe(eap->arg); | 8561 global_exe(eap->arg); |
8565 ml_clearmarked(); /* clear rest of the marks */ | 8562 ml_clearmarked(); // clear rest of the marks |
8566 # ifdef FEAT_CLIPBOARD | 8563 # ifdef FEAT_CLIPBOARD |
8567 end_global_changes(); | 8564 end_global_changes(); |
8568 # endif | 8565 # endif |
8569 } | 8566 } |
8570 #endif | 8567 #endif |