comparison src/search.c @ 18812:d34ec6fe207d v8.1.2394

patch 8.1.2394: using old C style comments Commit: https://github.com/vim/vim/commit/63d9e730f726341bf41ee4f4b829253cb9879110 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 5 21:10:38 2019 +0100 patch 8.1.2394: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Dec 2019 21:15:04 +0100
parents 49b78d6465e5
children 5c405689da3e
comparison
equal deleted inserted replaced
18811:65b77e62ec07 18812:d34ec6fe207d
53 * one for other searches. last_idx points to the one that was used the last 53 * one for other searches. last_idx points to the one that was used the last
54 * time. 54 * time.
55 */ 55 */
56 static spat_T spats[2] = 56 static spat_T spats[2] =
57 { 57 {
58 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}, /* last used search pat */ 58 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}, // last used search pat
59 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}} /* last used substitute pat */ 59 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}} // last used substitute pat
60 }; 60 };
61 61
62 static int last_idx = 0; /* index in spats[] for RE_LAST */ 62 static int last_idx = 0; // index in spats[] for RE_LAST
63 63
64 static char_u lastc[2] = {NUL, NUL}; /* last character searched for */ 64 static char_u lastc[2] = {NUL, NUL}; // last character searched for
65 static int lastcdir = FORWARD; /* last direction of character search */ 65 static int lastcdir = FORWARD; // last direction of character search
66 static int last_t_cmd = TRUE; /* last search t_cmd */ 66 static int last_t_cmd = TRUE; // last search t_cmd
67 static char_u lastc_bytes[MB_MAXBYTES + 1]; 67 static char_u lastc_bytes[MB_MAXBYTES + 1];
68 static int lastc_bytelen = 1; /* >1 for multi-byte char */ 68 static int lastc_bytelen = 1; // >1 for multi-byte char
69 69
70 /* copy of spats[], for keeping the search patterns while executing autocmds */ 70 // copy of spats[], for keeping the search patterns while executing autocmds
71 static spat_T saved_spats[2]; 71 static spat_T saved_spats[2];
72 # ifdef FEAT_SEARCH_EXTRA 72 # ifdef FEAT_SEARCH_EXTRA
73 static int saved_spats_last_idx = 0; 73 static int saved_spats_last_idx = 0;
74 static int saved_spats_no_hlsearch = 0; 74 static int saved_spats_no_hlsearch = 0;
75 # endif 75 # endif
76 76
77 static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ 77 static char_u *mr_pattern = NULL; // pattern used by search_regcomp()
78 #ifdef FEAT_RIGHTLEFT 78 #ifdef FEAT_RIGHTLEFT
79 static int mr_pattern_alloced = FALSE; /* mr_pattern was allocated */ 79 static int mr_pattern_alloced = FALSE; // mr_pattern was allocated
80 #endif 80 #endif
81 81
82 #ifdef FEAT_FIND_ID 82 #ifdef FEAT_FIND_ID
83 /* 83 /*
84 * Type used by find_pattern_in_path() to remember which included files have 84 * Type used by find_pattern_in_path() to remember which included files have
85 * been searched already. 85 * been searched already.
86 */ 86 */
87 typedef struct SearchedFile 87 typedef struct SearchedFile
88 { 88 {
89 FILE *fp; /* File pointer */ 89 FILE *fp; // File pointer
90 char_u *name; /* Full name of file */ 90 char_u *name; // Full name of file
91 linenr_T lnum; /* Line we were up to in file */ 91 linenr_T lnum; // Line we were up to in file
92 int matched; /* Found a match in this file */ 92 int matched; // Found a match in this file
93 } SearchedFile; 93 } SearchedFile;
94 #endif 94 #endif
95 95
96 /* 96 /*
97 * translate search pattern for vim_regcomp() 97 * translate search pattern for vim_regcomp()
111 search_regcomp( 111 search_regcomp(
112 char_u *pat, 112 char_u *pat,
113 int pat_save, 113 int pat_save,
114 int pat_use, 114 int pat_use,
115 int options, 115 int options,
116 regmmatch_T *regmatch) /* return: pattern and ignore-case flag */ 116 regmmatch_T *regmatch) // return: pattern and ignore-case flag
117 { 117 {
118 int magic; 118 int magic;
119 int i; 119 int i;
120 120
121 rc_did_emsg = FALSE; 121 rc_did_emsg = FALSE;
128 { 128 {
129 if (pat_use == RE_LAST) 129 if (pat_use == RE_LAST)
130 i = last_idx; 130 i = last_idx;
131 else 131 else
132 i = pat_use; 132 i = pat_use;
133 if (spats[i].pat == NULL) /* pattern was never defined */ 133 if (spats[i].pat == NULL) // pattern was never defined
134 { 134 {
135 if (pat_use == RE_SUBST) 135 if (pat_use == RE_SUBST)
136 emsg(_(e_nopresub)); 136 emsg(_(e_nopresub));
137 else 137 else
138 emsg(_(e_noprevre)); 138 emsg(_(e_noprevre));
141 } 141 }
142 pat = spats[i].pat; 142 pat = spats[i].pat;
143 magic = spats[i].magic; 143 magic = spats[i].magic;
144 no_smartcase = spats[i].no_scs; 144 no_smartcase = spats[i].no_scs;
145 } 145 }
146 else if (options & SEARCH_HIS) /* put new pattern in history */ 146 else if (options & SEARCH_HIS) // put new pattern in history
147 add_to_history(HIST_SEARCH, pat, TRUE, NUL); 147 add_to_history(HIST_SEARCH, pat, TRUE, NUL);
148 148
149 #ifdef FEAT_RIGHTLEFT 149 #ifdef FEAT_RIGHTLEFT
150 if (mr_pattern_alloced) 150 if (mr_pattern_alloced)
151 { 151 {
157 { 157 {
158 char_u *rev_pattern; 158 char_u *rev_pattern;
159 159
160 rev_pattern = reverse_text(pat); 160 rev_pattern = reverse_text(pat);
161 if (rev_pattern == NULL) 161 if (rev_pattern == NULL)
162 mr_pattern = pat; /* out of memory, keep normal pattern. */ 162 mr_pattern = pat; // out of memory, keep normal pattern.
163 else 163 else
164 { 164 {
165 mr_pattern = rev_pattern; 165 mr_pattern = rev_pattern;
166 mr_pattern_alloced = TRUE; 166 mr_pattern_alloced = TRUE;
167 } 167 }
174 * Save the currently used pattern in the appropriate place, 174 * Save the currently used pattern in the appropriate place,
175 * unless the pattern should not be remembered. 175 * unless the pattern should not be remembered.
176 */ 176 */
177 if (!(options & SEARCH_KEEP) && !cmdmod.keeppatterns) 177 if (!(options & SEARCH_KEEP) && !cmdmod.keeppatterns)
178 { 178 {
179 /* search or global command */ 179 // search or global command
180 if (pat_save == RE_SEARCH || pat_save == RE_BOTH) 180 if (pat_save == RE_SEARCH || pat_save == RE_BOTH)
181 save_re_pat(RE_SEARCH, pat, magic); 181 save_re_pat(RE_SEARCH, pat, magic);
182 /* substitute or global command */ 182 // substitute or global command
183 if (pat_save == RE_SUBST || pat_save == RE_BOTH) 183 if (pat_save == RE_SUBST || pat_save == RE_BOTH)
184 save_re_pat(RE_SUBST, pat, magic); 184 save_re_pat(RE_SUBST, pat, magic);
185 } 185 }
186 186
187 regmatch->rmm_ic = ignorecase(pat); 187 regmatch->rmm_ic = ignorecase(pat);
251 spats[idx].pat = vim_strsave(pat); 251 spats[idx].pat = vim_strsave(pat);
252 spats[idx].magic = magic; 252 spats[idx].magic = magic;
253 spats[idx].no_scs = no_smartcase; 253 spats[idx].no_scs = no_smartcase;
254 last_idx = idx; 254 last_idx = idx;
255 #ifdef FEAT_SEARCH_EXTRA 255 #ifdef FEAT_SEARCH_EXTRA
256 /* If 'hlsearch' set and search pat changed: need redraw. */ 256 // If 'hlsearch' set and search pat changed: need redraw.
257 if (p_hls) 257 if (p_hls)
258 redraw_all_later(SOME_VALID); 258 redraw_all_later(SOME_VALID);
259 set_no_hlsearch(FALSE); 259 set_no_hlsearch(FALSE);
260 #endif 260 #endif
261 } 261 }
424 return TRUE; 424 return TRUE;
425 p += l; 425 p += l;
426 } 426 }
427 else if (*p == '\\') 427 else if (*p == '\\')
428 { 428 {
429 if (p[1] == '_' && p[2] != NUL) /* skip "\_X" */ 429 if (p[1] == '_' && p[2] != NUL) // skip "\_X"
430 p += 3; 430 p += 3;
431 else if (p[1] == '%' && p[2] != NUL) /* skip "\%X" */ 431 else if (p[1] == '%' && p[2] != NUL) // skip "\%X"
432 p += 3; 432 p += 3;
433 else if (p[1] != NUL) /* skip "\X" */ 433 else if (p[1] != NUL) // skip "\X"
434 p += 2; 434 p += 2;
435 else 435 else
436 p += 1; 436 p += 1;
437 } 437 }
438 else if (MB_ISUPPER(*p)) 438 else if (MB_ISUPPER(*p))
515 int idx, 515 int idx,
516 int magic, 516 int magic,
517 int setlast) 517 int setlast)
518 { 518 {
519 vim_free(spats[idx].pat); 519 vim_free(spats[idx].pat);
520 /* An empty string means that nothing should be matched. */ 520 // An empty string means that nothing should be matched.
521 if (*s == NUL) 521 if (*s == NUL)
522 spats[idx].pat = NULL; 522 spats[idx].pat = NULL;
523 else 523 else
524 spats[idx].pat = vim_strsave(s); 524 spats[idx].pat = vim_strsave(s);
525 spats[idx].magic = magic; 525 spats[idx].magic = magic;
544 # ifdef FEAT_SEARCH_EXTRA 544 # ifdef FEAT_SEARCH_EXTRA
545 saved_spats_last_idx = last_idx; 545 saved_spats_last_idx = last_idx;
546 # endif 546 # endif
547 } 547 }
548 # ifdef FEAT_SEARCH_EXTRA 548 # ifdef FEAT_SEARCH_EXTRA
549 /* If 'hlsearch' set and search pat changed: need redraw. */ 549 // If 'hlsearch' set and search pat changed: need redraw.
550 if (p_hls && idx == last_idx && !no_hlsearch) 550 if (p_hls && idx == last_idx && !no_hlsearch)
551 redraw_all_later(SOME_VALID); 551 redraw_all_later(SOME_VALID);
552 # endif 552 # endif
553 } 553 }
554 #endif 554 #endif
565 if (spats[last_idx].pat == NULL) 565 if (spats[last_idx].pat == NULL)
566 { 566 {
567 regmatch->regprog = NULL; 567 regmatch->regprog = NULL;
568 return; 568 return;
569 } 569 }
570 ++emsg_off; /* So it doesn't beep if bad expr */ 570 ++emsg_off; // So it doesn't beep if bad expr
571 (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch); 571 (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch);
572 --emsg_off; 572 --emsg_off;
573 } 573 }
574 #endif 574 #endif
575 575
606 int options, 606 int options,
607 int pat_use, // which pattern to use when "pat" is empty 607 int pat_use, // which pattern to use when "pat" is empty
608 searchit_arg_T *extra_arg) // optional extra arguments, can be NULL 608 searchit_arg_T *extra_arg) // optional extra arguments, can be NULL
609 { 609 {
610 int found; 610 int found;
611 linenr_T lnum; /* no init to shut up Apollo cc */ 611 linenr_T lnum; // no init to shut up Apollo cc
612 colnr_T col; 612 colnr_T col;
613 regmmatch_T regmatch; 613 regmmatch_T regmatch;
614 char_u *ptr; 614 char_u *ptr;
615 colnr_T matchcol; 615 colnr_T matchcol;
616 lpos_T endpos; 616 lpos_T endpos;
653 653
654 /* 654 /*
655 * find the string 655 * find the string
656 */ 656 */
657 called_emsg = FALSE; 657 called_emsg = FALSE;
658 do /* loop for count */ 658 do // loop for count
659 { 659 {
660 /* When not accepting a match at the start position set "extra_col" to 660 // When not accepting a match at the start position set "extra_col" to
661 * a non-zero value. Don't do that when starting at MAXCOL, since 661 // a non-zero value. Don't do that when starting at MAXCOL, since
662 * MAXCOL + 1 is zero. */ 662 // MAXCOL + 1 is zero.
663 if (pos->col == MAXCOL) 663 if (pos->col == MAXCOL)
664 start_char_len = 0; 664 start_char_len = 0;
665 /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */ 665 // Watch out for the "col" being MAXCOL - 2, used in a closed fold.
666 else if (has_mbyte 666 else if (has_mbyte
667 && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count 667 && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
668 && pos->col < MAXCOL - 2) 668 && pos->col < MAXCOL - 2)
669 { 669 {
670 ptr = ml_get_buf(buf, pos->lnum, FALSE); 670 ptr = ml_get_buf(buf, pos->lnum, FALSE);
688 extra_col = start_char_len; 688 extra_col = start_char_len;
689 else 689 else
690 extra_col = 0; 690 extra_col = 0;
691 } 691 }
692 692
693 start_pos = *pos; /* remember start pos for detecting no match */ 693 start_pos = *pos; // remember start pos for detecting no match
694 found = 0; /* default: not found */ 694 found = 0; // default: not found
695 at_first_line = TRUE; /* default: start in first line */ 695 at_first_line = TRUE; // default: start in first line
696 if (pos->lnum == 0) /* correct lnum for when starting in line 0 */ 696 if (pos->lnum == 0) // correct lnum for when starting in line 0
697 { 697 {
698 pos->lnum = 1; 698 pos->lnum = 1;
699 pos->col = 0; 699 pos->col = 0;
700 at_first_line = FALSE; /* not in first line now */ 700 at_first_line = FALSE; // not in first line now
701 } 701 }
702 702
703 /* 703 /*
704 * Start searching in current line, unless searching backwards and 704 * Start searching in current line, unless searching backwards and
705 * we're in column 0. 705 * we're in column 0.
714 at_first_line = FALSE; 714 at_first_line = FALSE;
715 } 715 }
716 else 716 else
717 lnum = pos->lnum; 717 lnum = pos->lnum;
718 718
719 for (loop = 0; loop <= 1; ++loop) /* loop twice if 'wrapscan' set */ 719 for (loop = 0; loop <= 1; ++loop) // loop twice if 'wrapscan' set
720 { 720 {
721 for ( ; lnum > 0 && lnum <= buf->b_ml.ml_line_count; 721 for ( ; lnum > 0 && lnum <= buf->b_ml.ml_line_count;
722 lnum += dir, at_first_line = FALSE) 722 lnum += dir, at_first_line = FALSE)
723 { 723 {
724 /* Stop after checking "stop_lnum", if it's set. */ 724 // Stop after checking "stop_lnum", if it's set.
725 if (stop_lnum != 0 && (dir == FORWARD 725 if (stop_lnum != 0 && (dir == FORWARD
726 ? lnum > stop_lnum : lnum < stop_lnum)) 726 ? lnum > stop_lnum : lnum < stop_lnum))
727 break; 727 break;
728 #ifdef FEAT_RELTIME 728 #ifdef FEAT_RELTIME
729 /* Stop after passing the "tm" time limit. */ 729 // Stop after passing the "tm" time limit.
730 if (tm != NULL && profile_passed_limit(tm)) 730 if (tm != NULL && profile_passed_limit(tm))
731 break; 731 break;
732 #endif 732 #endif
733 733
734 /* 734 /*
742 tm, timed_out 742 tm, timed_out
743 #else 743 #else
744 NULL, NULL 744 NULL, NULL
745 #endif 745 #endif
746 ); 746 );
747 /* Abort searching on an error (e.g., out of stack). */ 747 // Abort searching on an error (e.g., out of stack).
748 if (called_emsg 748 if (called_emsg
749 #ifdef FEAT_RELTIME 749 #ifdef FEAT_RELTIME
750 || (timed_out != NULL && *timed_out) 750 || (timed_out != NULL && *timed_out)
751 #endif 751 #endif
752 ) 752 )
753 break; 753 break;
754 if (nmatched > 0) 754 if (nmatched > 0)
755 { 755 {
756 /* match may actually be in another line when using \zs */ 756 // match may actually be in another line when using \zs
757 matchpos = regmatch.startpos[0]; 757 matchpos = regmatch.startpos[0];
758 endpos = regmatch.endpos[0]; 758 endpos = regmatch.endpos[0];
759 #ifdef FEAT_EVAL 759 #ifdef FEAT_EVAL
760 submatch = first_submatch(&regmatch); 760 submatch = first_submatch(&regmatch);
761 #endif 761 #endif
762 /* "lnum" may be past end of buffer for "\n\zs". */ 762 // "lnum" may be past end of buffer for "\n\zs".
763 if (lnum + matchpos.lnum > buf->b_ml.ml_line_count) 763 if (lnum + matchpos.lnum > buf->b_ml.ml_line_count)
764 ptr = (char_u *)""; 764 ptr = (char_u *)"";
765 else 765 else
766 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); 766 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);
767 767
796 */ 796 */
797 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) 797 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL)
798 { 798 {
799 if (nmatched > 1) 799 if (nmatched > 1)
800 { 800 {
801 /* end is in next line, thus no match in 801 // end is in next line, thus no match in
802 * this line */ 802 // this line
803 match_ok = FALSE; 803 match_ok = FALSE;
804 break; 804 break;
805 } 805 }
806 matchcol = endpos.col; 806 matchcol = endpos.col;
807 /* for empty match: advance one char */ 807 // for empty match: advance one char
808 if (matchcol == matchpos.col 808 if (matchcol == matchpos.col
809 && ptr[matchcol] != NUL) 809 && ptr[matchcol] != NUL)
810 { 810 {
811 if (has_mbyte) 811 if (has_mbyte)
812 matchcol += 812 matchcol +=
847 endpos = regmatch.endpos[0]; 847 endpos = regmatch.endpos[0];
848 # ifdef FEAT_EVAL 848 # ifdef FEAT_EVAL
849 submatch = first_submatch(&regmatch); 849 submatch = first_submatch(&regmatch);
850 # endif 850 # endif
851 851
852 /* Need to get the line pointer again, a 852 // Need to get the line pointer again, a
853 * multi-line search may have made it invalid. */ 853 // multi-line search may have made it invalid.
854 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); 854 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);
855 } 855 }
856 if (!match_ok) 856 if (!match_ok)
857 continue; 857 continue;
858 } 858 }
866 * relative to the end of the match. 866 * relative to the end of the match.
867 */ 867 */
868 match_ok = FALSE; 868 match_ok = FALSE;
869 for (;;) 869 for (;;)
870 { 870 {
871 /* Remember a position that is before the start 871 // Remember a position that is before the start
872 * position, we use it if it's the last match in 872 // position, we use it if it's the last match in
873 * the line. Always accept a position after 873 // the line. Always accept a position after
874 * wrapping around. */ 874 // wrapping around.
875 if (loop 875 if (loop
876 || ((options & SEARCH_END) 876 || ((options & SEARCH_END)
877 ? (lnum + regmatch.endpos[0].lnum 877 ? (lnum + regmatch.endpos[0].lnum
878 < start_pos.lnum 878 < start_pos.lnum
879 || (lnum + regmatch.endpos[0].lnum 879 || (lnum + regmatch.endpos[0].lnum
909 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) 909 if (vim_strchr(p_cpo, CPO_SEARCH) != NULL)
910 { 910 {
911 if (nmatched > 1) 911 if (nmatched > 1)
912 break; 912 break;
913 matchcol = endpos.col; 913 matchcol = endpos.col;
914 /* for empty match: advance one char */ 914 // for empty match: advance one char
915 if (matchcol == matchpos.col 915 if (matchcol == matchpos.col
916 && ptr[matchcol] != NUL) 916 && ptr[matchcol] != NUL)
917 { 917 {
918 if (has_mbyte) 918 if (has_mbyte)
919 matchcol += 919 matchcol +=
922 ++matchcol; 922 ++matchcol;
923 } 923 }
924 } 924 }
925 else 925 else
926 { 926 {
927 /* Stop when the match is in a next line. */ 927 // Stop when the match is in a next line.
928 if (matchpos.lnum > 0) 928 if (matchpos.lnum > 0)
929 break; 929 break;
930 matchcol = matchpos.col; 930 matchcol = matchpos.col;
931 if (ptr[matchcol] != NUL) 931 if (ptr[matchcol] != NUL)
932 { 932 {
947 NULL, NULL 947 NULL, NULL
948 #endif 948 #endif
949 )) == 0) 949 )) == 0)
950 { 950 {
951 #ifdef FEAT_RELTIME 951 #ifdef FEAT_RELTIME
952 /* If the search timed out, we did find a match 952 // If the search timed out, we did find a match
953 * but it might be the wrong one, so that's not 953 // but it might be the wrong one, so that's not
954 * OK. */ 954 // OK.
955 if (timed_out != NULL && *timed_out) 955 if (timed_out != NULL && *timed_out)
956 match_ok = FALSE; 956 match_ok = FALSE;
957 #endif 957 #endif
958 break; 958 break;
959 } 959 }
960 960
961 /* Need to get the line pointer again, a 961 // Need to get the line pointer again, a
962 * multi-line search may have made it invalid. */ 962 // multi-line search may have made it invalid.
963 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE); 963 ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);
964 } 964 }
965 965
966 /* 966 /*
967 * If there is only a match after the cursor, skip 967 * If there is only a match after the cursor, skip
969 */ 969 */
970 if (!match_ok) 970 if (!match_ok)
971 continue; 971 continue;
972 } 972 }
973 973
974 /* With the SEARCH_END option move to the last character 974 // With the SEARCH_END option move to the last character
975 * of the match. Don't do it for an empty match, end 975 // of the match. Don't do it for an empty match, end
976 * should be same as start then. */ 976 // should be same as start then.
977 if ((options & SEARCH_END) && !(options & SEARCH_NOOF) 977 if ((options & SEARCH_END) && !(options & SEARCH_NOOF)
978 && !(matchpos.lnum == endpos.lnum 978 && !(matchpos.lnum == endpos.lnum
979 && matchpos.col == endpos.col)) 979 && matchpos.col == endpos.col))
980 { 980 {
981 /* For a match in the first column, set the position 981 // For a match in the first column, set the position
982 * on the NUL in the previous line. */ 982 // on the NUL in the previous line.
983 pos->lnum = lnum + endpos.lnum; 983 pos->lnum = lnum + endpos.lnum;
984 pos->col = endpos.col; 984 pos->col = endpos.col;
985 if (endpos.col == 0) 985 if (endpos.col == 0)
986 { 986 {
987 if (pos->lnum > 1) /* just in case */ 987 if (pos->lnum > 1) // just in case
988 { 988 {
989 --pos->lnum; 989 --pos->lnum;
990 pos->col = (colnr_T)STRLEN(ml_get_buf(buf, 990 pos->col = (colnr_T)STRLEN(ml_get_buf(buf,
991 pos->lnum, FALSE)); 991 pos->lnum, FALSE));
992 } 992 }
1021 if (end_pos != NULL) 1021 if (end_pos != NULL)
1022 end_pos->coladd = 0; 1022 end_pos->coladd = 0;
1023 found = 1; 1023 found = 1;
1024 first_match = FALSE; 1024 first_match = FALSE;
1025 1025
1026 /* Set variables used for 'incsearch' highlighting. */ 1026 // Set variables used for 'incsearch' highlighting.
1027 search_match_lines = endpos.lnum - matchpos.lnum; 1027 search_match_lines = endpos.lnum - matchpos.lnum;
1028 search_match_endcol = endpos.col; 1028 search_match_endcol = endpos.col;
1029 break; 1029 break;
1030 } 1030 }
1031 line_breakcheck(); /* stop if ctrl-C typed */ 1031 line_breakcheck(); // stop if ctrl-C typed
1032 if (got_int) 1032 if (got_int)
1033 break; 1033 break;
1034 1034
1035 #ifdef FEAT_SEARCH_EXTRA 1035 #ifdef FEAT_SEARCH_EXTRA
1036 /* Cancel searching if a character was typed. Used for 1036 // Cancel searching if a character was typed. Used for
1037 * 'incsearch'. Don't check too often, that would slowdown 1037 // 'incsearch'. Don't check too often, that would slowdown
1038 * searching too much. */ 1038 // searching too much.
1039 if ((options & SEARCH_PEEK) 1039 if ((options & SEARCH_PEEK)
1040 && ((lnum - pos->lnum) & 0x3f) == 0 1040 && ((lnum - pos->lnum) & 0x3f) == 0
1041 && char_avail()) 1041 && char_avail())
1042 { 1042 {
1043 break_loop = TRUE; 1043 break_loop = TRUE;
1044 break; 1044 break;
1045 } 1045 }
1046 #endif 1046 #endif
1047 1047
1048 if (loop && lnum == start_pos.lnum) 1048 if (loop && lnum == start_pos.lnum)
1049 break; /* if second loop, stop where started */ 1049 break; // if second loop, stop where started
1050 } 1050 }
1051 at_first_line = FALSE; 1051 at_first_line = FALSE;
1052 1052
1053 /* 1053 /*
1054 * Stop the search if wrapscan isn't set, "stop_lnum" is 1054 * Stop the search if wrapscan isn't set, "stop_lnum" is
1070 * If 'shortmess' does not contain 's', we give a message. 1070 * If 'shortmess' does not contain 's', we give a message.
1071 * This message is also remembered in keep_msg for when the screen 1071 * This message is also remembered in keep_msg for when the screen
1072 * is redrawn. The keep_msg is cleared whenever another message is 1072 * is redrawn. The keep_msg is cleared whenever another message is
1073 * written. 1073 * written.
1074 */ 1074 */
1075 if (dir == BACKWARD) /* start second loop at the other end */ 1075 if (dir == BACKWARD) // start second loop at the other end
1076 lnum = buf->b_ml.ml_line_count; 1076 lnum = buf->b_ml.ml_line_count;
1077 else 1077 else
1078 lnum = 1; 1078 lnum = 1;
1079 if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG)) 1079 if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG))
1080 give_warning((char_u *)_(dir == BACKWARD 1080 give_warning((char_u *)_(dir == BACKWARD
1090 || break_loop 1090 || break_loop
1091 #endif 1091 #endif
1092 ) 1092 )
1093 break; 1093 break;
1094 } 1094 }
1095 while (--count > 0 && found); /* stop after count matches or no match */ 1095 while (--count > 0 && found); // stop after count matches or no match
1096 1096
1097 vim_regfree(regmatch.regprog); 1097 vim_regfree(regmatch.regprog);
1098 1098
1099 called_emsg |= save_called_emsg; 1099 called_emsg |= save_called_emsg;
1100 1100
1101 if (!found) /* did not find it */ 1101 if (!found) // did not find it
1102 { 1102 {
1103 if (got_int) 1103 if (got_int)
1104 emsg(_(e_interr)); 1104 emsg(_(e_interr));
1105 else if ((options & SEARCH_MSG) == SEARCH_MSG) 1105 else if ((options & SEARCH_MSG) == SEARCH_MSG)
1106 { 1106 {
1114 mr_pattern); 1114 mr_pattern);
1115 } 1115 }
1116 return FAIL; 1116 return FAIL;
1117 } 1117 }
1118 1118
1119 /* A pattern like "\n\zs" may go past the last line. */ 1119 // A pattern like "\n\zs" may go past the last line.
1120 if (pos->lnum > buf->b_ml.ml_line_count) 1120 if (pos->lnum > buf->b_ml.ml_line_count)
1121 { 1121 {
1122 pos->lnum = buf->b_ml.ml_line_count; 1122 pos->lnum = buf->b_ml.ml_line_count;
1123 pos->col = (int)STRLEN(ml_get_buf(buf, pos->lnum, FALSE)); 1123 pos->col = (int)STRLEN(ml_get_buf(buf, pos->lnum, FALSE));
1124 if (pos->col > 0) 1124 if (pos->col > 0)
1185 * 1185 *
1186 * Return 0 for failure, 1 for found, 2 for found and line offset added. 1186 * Return 0 for failure, 1 for found, 2 for found and line offset added.
1187 */ 1187 */
1188 int 1188 int
1189 do_search( 1189 do_search(
1190 oparg_T *oap, /* can be NULL */ 1190 oparg_T *oap, // can be NULL
1191 int dirc, /* '/' or '?' */ 1191 int dirc, // '/' or '?'
1192 char_u *pat, 1192 char_u *pat,
1193 long count, 1193 long count,
1194 int options, 1194 int options,
1195 searchit_arg_T *sia) // optional arguments or NULL 1195 searchit_arg_T *sia) // optional arguments or NULL
1196 { 1196 {
1197 pos_T pos; /* position of the last match */ 1197 pos_T pos; // position of the last match
1198 char_u *searchstr; 1198 char_u *searchstr;
1199 soffset_T old_off; 1199 soffset_T old_off;
1200 int retval; /* Return value */ 1200 int retval; // Return value
1201 char_u *p; 1201 char_u *p;
1202 long c; 1202 long c;
1203 char_u *dircp; 1203 char_u *dircp;
1204 char_u *strcopy = NULL; 1204 char_u *strcopy = NULL;
1205 char_u *ps; 1205 char_u *ps;
1221 * Save the values for when (options & SEARCH_KEEP) is used. 1221 * Save the values for when (options & SEARCH_KEEP) is used.
1222 * (there is no "if ()" around this because gcc wants them initialized) 1222 * (there is no "if ()" around this because gcc wants them initialized)
1223 */ 1223 */
1224 old_off = spats[0].off; 1224 old_off = spats[0].off;
1225 1225
1226 pos = curwin->w_cursor; /* start searching at the cursor position */ 1226 pos = curwin->w_cursor; // start searching at the cursor position
1227 1227
1228 /* 1228 /*
1229 * Find out the direction of the search. 1229 * Find out the direction of the search.
1230 */ 1230 */
1231 if (dirc == 0) 1231 if (dirc == 0)
1238 #endif 1238 #endif
1239 } 1239 }
1240 if (options & SEARCH_REV) 1240 if (options & SEARCH_REV)
1241 { 1241 {
1242 #ifdef MSWIN 1242 #ifdef MSWIN
1243 /* There is a bug in the Visual C++ 2.2 compiler which means that 1243 // There is a bug in the Visual C++ 2.2 compiler which means that
1244 * dirc always ends up being '/' */ 1244 // dirc always ends up being '/'
1245 dirc = (dirc == '/') ? '?' : '/'; 1245 dirc = (dirc == '/') ? '?' : '/';
1246 #else 1246 #else
1247 if (dirc == '/') 1247 if (dirc == '/')
1248 dirc = '?'; 1248 dirc = '?';
1249 else 1249 else
1250 dirc = '/'; 1250 dirc = '/';
1251 #endif 1251 #endif
1252 } 1252 }
1253 1253
1254 #ifdef FEAT_FOLDING 1254 #ifdef FEAT_FOLDING
1255 /* If the cursor is in a closed fold, don't find another match in the same 1255 // If the cursor is in a closed fold, don't find another match in the same
1256 * fold. */ 1256 // fold.
1257 if (dirc == '/') 1257 if (dirc == '/')
1258 { 1258 {
1259 if (hasFolding(pos.lnum, NULL, &pos.lnum)) 1259 if (hasFolding(pos.lnum, NULL, &pos.lnum))
1260 pos.col = MAXCOL - 2; /* avoid overflow when adding 1 */ 1260 pos.col = MAXCOL - 2; // avoid overflow when adding 1
1261 } 1261 }
1262 else 1262 else
1263 { 1263 {
1264 if (hasFolding(pos.lnum, &pos.lnum, NULL)) 1264 if (hasFolding(pos.lnum, &pos.lnum, NULL))
1265 pos.col = 0; 1265 pos.col = 0;
1284 { 1284 {
1285 int show_top_bot_msg = FALSE; 1285 int show_top_bot_msg = FALSE;
1286 1286
1287 searchstr = pat; 1287 searchstr = pat;
1288 dircp = NULL; 1288 dircp = NULL;
1289 /* use previous pattern */ 1289 // use previous pattern
1290 if (pat == NULL || *pat == NUL || *pat == dirc) 1290 if (pat == NULL || *pat == NUL || *pat == dirc)
1291 { 1291 {
1292 if (spats[RE_SEARCH].pat == NULL) /* no previous pattern */ 1292 if (spats[RE_SEARCH].pat == NULL) // no previous pattern
1293 { 1293 {
1294 searchstr = spats[RE_SUBST].pat; 1294 searchstr = spats[RE_SUBST].pat;
1295 if (searchstr == NULL) 1295 if (searchstr == NULL)
1296 { 1296 {
1297 emsg(_(e_noprevre)); 1297 emsg(_(e_noprevre));
1299 goto end_do_search; 1299 goto end_do_search;
1300 } 1300 }
1301 } 1301 }
1302 else 1302 else
1303 { 1303 {
1304 /* make search_regcomp() use spats[RE_SEARCH].pat */ 1304 // make search_regcomp() use spats[RE_SEARCH].pat
1305 searchstr = (char_u *)""; 1305 searchstr = (char_u *)"";
1306 } 1306 }
1307 } 1307 }
1308 1308
1309 if (pat != NULL && *pat != NUL) /* look for (new) offset */ 1309 if (pat != NULL && *pat != NUL) // look for (new) offset
1310 { 1310 {
1311 /* 1311 /*
1312 * Find end of regular expression. 1312 * Find end of regular expression.
1313 * If there is a matching '/' or '?', toss it. 1313 * If there is a matching '/' or '?', toss it.
1314 */ 1314 */
1315 ps = strcopy; 1315 ps = strcopy;
1316 p = skip_regexp(pat, dirc, (int)p_magic, &strcopy); 1316 p = skip_regexp(pat, dirc, (int)p_magic, &strcopy);
1317 if (strcopy != ps) 1317 if (strcopy != ps)
1318 { 1318 {
1319 /* made a copy of "pat" to change "\?" to "?" */ 1319 // made a copy of "pat" to change "\?" to "?"
1320 searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy)); 1320 searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy));
1321 pat = strcopy; 1321 pat = strcopy;
1322 searchstr = strcopy; 1322 searchstr = strcopy;
1323 } 1323 }
1324 if (*p == dirc) 1324 if (*p == dirc)
1325 { 1325 {
1326 dircp = p; /* remember where we put the NUL */ 1326 dircp = p; // remember where we put the NUL
1327 *p++ = NUL; 1327 *p++ = NUL;
1328 } 1328 }
1329 spats[0].off.line = FALSE; 1329 spats[0].off.line = FALSE;
1330 spats[0].off.end = FALSE; 1330 spats[0].off.end = FALSE;
1331 spats[0].off.off = 0; 1331 spats[0].off.off = 0;
1338 if (*p == '+' || *p == '-' || VIM_ISDIGIT(*p)) 1338 if (*p == '+' || *p == '-' || VIM_ISDIGIT(*p))
1339 spats[0].off.line = TRUE; 1339 spats[0].off.line = TRUE;
1340 else if ((options & SEARCH_OPT) && 1340 else if ((options & SEARCH_OPT) &&
1341 (*p == 'e' || *p == 's' || *p == 'b')) 1341 (*p == 'e' || *p == 's' || *p == 'b'))
1342 { 1342 {
1343 if (*p == 'e') /* end */ 1343 if (*p == 'e') // end
1344 spats[0].off.end = SEARCH_END; 1344 spats[0].off.end = SEARCH_END;
1345 ++p; 1345 ++p;
1346 } 1346 }
1347 if (VIM_ISDIGIT(*p) || *p == '+' || *p == '-') /* got an offset */ 1347 if (VIM_ISDIGIT(*p) || *p == '+' || *p == '-') // got an offset
1348 { 1348 {
1349 /* 'nr' or '+nr' or '-nr' */ 1349 // 'nr' or '+nr' or '-nr'
1350 if (VIM_ISDIGIT(*p) || VIM_ISDIGIT(*(p + 1))) 1350 if (VIM_ISDIGIT(*p) || VIM_ISDIGIT(*(p + 1)))
1351 spats[0].off.off = atol((char *)p); 1351 spats[0].off.off = atol((char *)p);
1352 else if (*p == '-') /* single '-' */ 1352 else if (*p == '-') // single '-'
1353 spats[0].off.off = -1; 1353 spats[0].off.off = -1;
1354 else /* single '+' */ 1354 else // single '+'
1355 spats[0].off.off = 1; 1355 spats[0].off.off = 1;
1356 ++p; 1356 ++p;
1357 while (VIM_ISDIGIT(*p)) /* skip number */ 1357 while (VIM_ISDIGIT(*p)) // skip number
1358 ++p; 1358 ++p;
1359 } 1359 }
1360 1360
1361 /* compute length of search command for get_address() */ 1361 // compute length of search command for get_address()
1362 searchcmdlen += (int)(p - pat); 1362 searchcmdlen += (int)(p - pat);
1363 1363
1364 pat = p; /* put pat after search command */ 1364 pat = p; // put pat after search command
1365 } 1365 }
1366 1366
1367 if ((options & SEARCH_ECHO) && messaging() && 1367 if ((options & SEARCH_ECHO) && messaging() &&
1368 !msg_silent && 1368 !msg_silent &&
1369 (!cmd_silent || !shortmess(SHM_SEARCHCOUNT))) 1369 (!cmd_silent || !shortmess(SHM_SEARCHCOUNT)))
1497 if (spats[0].off.off > 0) 1497 if (spats[0].off.off > 0)
1498 { 1498 {
1499 for (c = spats[0].off.off; c; --c) 1499 for (c = spats[0].off.off; c; --c)
1500 if (decl(&pos) == -1) 1500 if (decl(&pos) == -1)
1501 break; 1501 break;
1502 if (c) /* at start of buffer */ 1502 if (c) // at start of buffer
1503 { 1503 {
1504 pos.lnum = 0; /* allow lnum == 0 here */ 1504 pos.lnum = 0; // allow lnum == 0 here
1505 pos.col = MAXCOL; 1505 pos.col = MAXCOL;
1506 } 1506 }
1507 } 1507 }
1508 else 1508 else
1509 { 1509 {
1510 for (c = spats[0].off.off; c; ++c) 1510 for (c = spats[0].off.off; c; ++c)
1511 if (incl(&pos) == -1) 1511 if (incl(&pos) == -1)
1512 break; 1512 break;
1513 if (c) /* at end of buffer */ 1513 if (c) // at end of buffer
1514 { 1514 {
1515 pos.lnum = curbuf->b_ml.ml_line_count + 1; 1515 pos.lnum = curbuf->b_ml.ml_line_count + 1;
1516 pos.col = 0; 1516 pos.col = 0;
1517 } 1517 }
1518 } 1518 }
1538 { 1538 {
1539 retval = 0; 1539 retval = 0;
1540 goto end_do_search; 1540 goto end_do_search;
1541 } 1541 }
1542 if (spats[0].off.end && oap != NULL) 1542 if (spats[0].off.end && oap != NULL)
1543 oap->inclusive = TRUE; /* 'e' includes last character */ 1543 oap->inclusive = TRUE; // 'e' includes last character
1544 1544
1545 retval = 1; /* pattern found */ 1545 retval = 1; // pattern found
1546 1546
1547 /* 1547 /*
1548 * Add character and/or line offset 1548 * Add character and/or line offset
1549 */ 1549 */
1550 if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';')) 1550 if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';'))
1551 { 1551 {
1552 pos_T org_pos = pos; 1552 pos_T org_pos = pos;
1553 1553
1554 if (spats[0].off.line) /* Add the offset to the line number. */ 1554 if (spats[0].off.line) // Add the offset to the line number.
1555 { 1555 {
1556 c = pos.lnum + spats[0].off.off; 1556 c = pos.lnum + spats[0].off.off;
1557 if (c < 1) 1557 if (c < 1)
1558 pos.lnum = 1; 1558 pos.lnum = 1;
1559 else if (c > curbuf->b_ml.ml_line_count) 1559 else if (c > curbuf->b_ml.ml_line_count)
1560 pos.lnum = curbuf->b_ml.ml_line_count; 1560 pos.lnum = curbuf->b_ml.ml_line_count;
1561 else 1561 else
1562 pos.lnum = c; 1562 pos.lnum = c;
1563 pos.col = 0; 1563 pos.col = 0;
1564 1564
1565 retval = 2; /* pattern found, line offset added */ 1565 retval = 2; // pattern found, line offset added
1566 } 1566 }
1567 else if (pos.col < MAXCOL - 2) /* just in case */ 1567 else if (pos.col < MAXCOL - 2) // just in case
1568 { 1568 {
1569 /* to the right, check for end of file */ 1569 // to the right, check for end of file
1570 c = spats[0].off.off; 1570 c = spats[0].off.off;
1571 if (c > 0) 1571 if (c > 0)
1572 { 1572 {
1573 while (c-- > 0) 1573 while (c-- > 0)
1574 if (incl(&pos) == -1) 1574 if (incl(&pos) == -1)
1575 break; 1575 break;
1576 } 1576 }
1577 /* to the left, check for start of file */ 1577 // to the left, check for start of file
1578 else 1578 else
1579 { 1579 {
1580 while (c++ < 0) 1580 while (c++ < 0)
1581 if (decl(&pos) == -1) 1581 if (decl(&pos) == -1)
1582 break; 1582 break;
1690 start = pos->lnum; 1690 start = pos->lnum;
1691 ptr = ml_get_buf(buf, pos->lnum, FALSE); 1691 ptr = ml_get_buf(buf, pos->lnum, FALSE);
1692 p = skipwhite(ptr); 1692 p = skipwhite(ptr);
1693 pos->col = (colnr_T) (p - ptr); 1693 pos->col = (colnr_T) (p - ptr);
1694 1694
1695 /* when adding lines the matching line may be empty but it is not 1695 // when adding lines the matching line may be empty but it is not
1696 * ignored because we are interested in the next line -- Acevedo */ 1696 // ignored because we are interested in the next line -- Acevedo
1697 if ((compl_cont_status & CONT_ADDING) 1697 if ((compl_cont_status & CONT_ADDING)
1698 && !(compl_cont_status & CONT_SOL)) 1698 && !(compl_cont_status & CONT_SOL))
1699 { 1699 {
1700 if ((p_ic ? MB_STRICMP(p, pat) : STRCMP(p, pat)) == 0) 1700 if ((p_ic ? MB_STRICMP(p, pat) : STRCMP(p, pat)) == 0)
1701 return OK; 1701 return OK;
1702 } 1702 }
1703 else if (*p != NUL) /* ignore empty lines */ 1703 else if (*p != NUL) // ignore empty lines
1704 { /* expanding lines or words */ 1704 { // expanding lines or words
1705 if ((p_ic ? MB_STRNICMP(p, pat, compl_length) 1705 if ((p_ic ? MB_STRNICMP(p, pat, compl_length)
1706 : STRNCMP(p, pat, compl_length)) == 0) 1706 : STRNCMP(p, pat, compl_length)) == 0)
1707 return OK; 1707 return OK;
1708 } 1708 }
1709 } 1709 }
1721 * Return FAIL or OK. 1721 * Return FAIL or OK.
1722 */ 1722 */
1723 int 1723 int
1724 searchc(cmdarg_T *cap, int t_cmd) 1724 searchc(cmdarg_T *cap, int t_cmd)
1725 { 1725 {
1726 int c = cap->nchar; /* char to search for */ 1726 int c = cap->nchar; // char to search for
1727 int dir = cap->arg; /* TRUE for searching forward */ 1727 int dir = cap->arg; // TRUE for searching forward
1728 long count = cap->count1; /* repeat count */ 1728 long count = cap->count1; // repeat count
1729 int col; 1729 int col;
1730 char_u *p; 1730 char_u *p;
1731 int len; 1731 int len;
1732 int stop = TRUE; 1732 int stop = TRUE;
1733 1733
1734 if (c != NUL) /* normal search: remember args for repeat */ 1734 if (c != NUL) // normal search: remember args for repeat
1735 { 1735 {
1736 if (!KeyStuffed) /* don't remember when redoing */ 1736 if (!KeyStuffed) // don't remember when redoing
1737 { 1737 {
1738 *lastc = c; 1738 *lastc = c;
1739 set_csearch_direction(dir); 1739 set_csearch_direction(dir);
1740 set_csearch_until(t_cmd); 1740 set_csearch_until(t_cmd);
1741 lastc_bytelen = (*mb_char2bytes)(c, lastc_bytes); 1741 lastc_bytelen = (*mb_char2bytes)(c, lastc_bytes);
1747 lastc_bytelen += (*mb_char2bytes)(cap->ncharC2, 1747 lastc_bytelen += (*mb_char2bytes)(cap->ncharC2,
1748 lastc_bytes + lastc_bytelen); 1748 lastc_bytes + lastc_bytelen);
1749 } 1749 }
1750 } 1750 }
1751 } 1751 }
1752 else /* repeat previous search */ 1752 else // repeat previous search
1753 { 1753 {
1754 if (*lastc == NUL && lastc_bytelen == 1) 1754 if (*lastc == NUL && lastc_bytelen == 1)
1755 return FAIL; 1755 return FAIL;
1756 if (dir) /* repeat in opposite direction */ 1756 if (dir) // repeat in opposite direction
1757 dir = -lastcdir; 1757 dir = -lastcdir;
1758 else 1758 else
1759 dir = lastcdir; 1759 dir = lastcdir;
1760 t_cmd = last_t_cmd; 1760 t_cmd = last_t_cmd;
1761 c = *lastc; 1761 c = *lastc;
1762 /* For multi-byte re-use last lastc_bytes[] and lastc_bytelen. */ 1762 // For multi-byte re-use last lastc_bytes[] and lastc_bytelen.
1763 1763
1764 /* Force a move of at least one char, so ";" and "," will move the 1764 // Force a move of at least one char, so ";" and "," will move the
1765 * cursor, even if the cursor is right in front of char we are looking 1765 // cursor, even if the cursor is right in front of char we are looking
1766 * at. */ 1766 // at.
1767 if (vim_strchr(p_cpo, CPO_SCOLON) == NULL && count == 1 && t_cmd) 1767 if (vim_strchr(p_cpo, CPO_SCOLON) == NULL && count == 1 && t_cmd)
1768 stop = FALSE; 1768 stop = FALSE;
1769 } 1769 }
1770 1770
1771 if (dir == BACKWARD) 1771 if (dir == BACKWARD)
1819 } 1819 }
1820 } 1820 }
1821 1821
1822 if (t_cmd) 1822 if (t_cmd)
1823 { 1823 {
1824 /* backup to before the character (possibly double-byte) */ 1824 // backup to before the character (possibly double-byte)
1825 col -= dir; 1825 col -= dir;
1826 if (has_mbyte) 1826 if (has_mbyte)
1827 { 1827 {
1828 if (dir < 0) 1828 if (dir < 0)
1829 /* Landed on the search char which is lastc_bytelen long */ 1829 // Landed on the search char which is lastc_bytelen long
1830 col += lastc_bytelen - 1; 1830 col += lastc_bytelen - 1;
1831 else 1831 else
1832 /* To previous char, which may be multi-byte. */ 1832 // To previous char, which may be multi-byte.
1833 col -= (*mb_head_off)(p, p + col); 1833 col -= (*mb_head_off)(p, p + col);
1834 } 1834 }
1835 } 1835 }
1836 curwin->w_cursor.col = col; 1836 curwin->w_cursor.col = col;
1837 1837
2039 oparg_T *oap, 2039 oparg_T *oap,
2040 int initc, 2040 int initc,
2041 int flags, 2041 int flags,
2042 int maxtravel) 2042 int maxtravel)
2043 { 2043 {
2044 static pos_T pos; /* current search position */ 2044 static pos_T pos; // current search position
2045 int findc = 0; /* matching brace */ 2045 int findc = 0; // matching brace
2046 int c; 2046 int c;
2047 int count = 0; /* cumulative number of braces */ 2047 int count = 0; // cumulative number of braces
2048 int backwards = FALSE; /* init for gcc */ 2048 int backwards = FALSE; // init for gcc
2049 int raw_string = FALSE; /* search for raw string */ 2049 int raw_string = FALSE; // search for raw string
2050 int inquote = FALSE; /* TRUE when inside quotes */ 2050 int inquote = FALSE; // TRUE when inside quotes
2051 char_u *linep; /* pointer to current line */ 2051 char_u *linep; // pointer to current line
2052 char_u *ptr; 2052 char_u *ptr;
2053 int do_quotes; /* check for quotes in current line */ 2053 int do_quotes; // check for quotes in current line
2054 int at_start; /* do_quotes value at start position */ 2054 int at_start; // do_quotes value at start position
2055 int hash_dir = 0; /* Direction searched for # things */ 2055 int hash_dir = 0; // Direction searched for # things
2056 int comment_dir = 0; /* Direction searched for comments */ 2056 int comment_dir = 0; // Direction searched for comments
2057 pos_T match_pos; /* Where last slash-star was found */ 2057 pos_T match_pos; // Where last slash-star was found
2058 int start_in_quotes; /* start position is in quotes */ 2058 int start_in_quotes; // start position is in quotes
2059 int traveled = 0; /* how far we've searched so far */ 2059 int traveled = 0; // how far we've searched so far
2060 int ignore_cend = FALSE; /* ignore comment end */ 2060 int ignore_cend = FALSE; // ignore comment end
2061 int cpo_match; /* vi compatible matching */ 2061 int cpo_match; // vi compatible matching
2062 int cpo_bsl; /* don't recognize backslashes */ 2062 int cpo_bsl; // don't recognize backslashes
2063 int match_escaped = 0; /* search for escaped match */ 2063 int match_escaped = 0; // search for escaped match
2064 int dir; /* Direction to search */ 2064 int dir; // Direction to search
2065 int comment_col = MAXCOL; /* start of / / comment */ 2065 int comment_col = MAXCOL; // start of / / comment
2066 #ifdef FEAT_LISP 2066 #ifdef FEAT_LISP
2067 int lispcomm = FALSE; /* inside of Lisp-style comment */ 2067 int lispcomm = FALSE; // inside of Lisp-style comment
2068 int lisp = curbuf->b_p_lisp; /* engage Lisp-specific hacks ;) */ 2068 int lisp = curbuf->b_p_lisp; // engage Lisp-specific hacks ;)
2069 #endif 2069 #endif
2070 2070
2071 pos = curwin->w_cursor; 2071 pos = curwin->w_cursor;
2072 pos.coladd = 0; 2072 pos.coladd = 0;
2073 linep = ml_get(pos.lnum); 2073 linep = ml_get(pos.lnum);
2074 2074
2075 cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); 2075 cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL);
2076 cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL); 2076 cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL);
2077 2077
2078 /* Direction to search when initc is '/', '*' or '#' */ 2078 // Direction to search when initc is '/', '*' or '#'
2079 if (flags & FM_BACKWARD) 2079 if (flags & FM_BACKWARD)
2080 dir = BACKWARD; 2080 dir = BACKWARD;
2081 else if (flags & FM_FORWARD) 2081 else if (flags & FM_FORWARD)
2082 dir = FORWARD; 2082 dir = FORWARD;
2083 else 2083 else
2121 * or near the cursor. 2121 * or near the cursor.
2122 * Only check for special things when 'cpo' doesn't have '%'. 2122 * Only check for special things when 'cpo' doesn't have '%'.
2123 */ 2123 */
2124 if (!cpo_match) 2124 if (!cpo_match)
2125 { 2125 {
2126 /* Are we before or at #if, #else etc.? */ 2126 // Are we before or at #if, #else etc.?
2127 ptr = skipwhite(linep); 2127 ptr = skipwhite(linep);
2128 if (*ptr == '#' && pos.col <= (colnr_T)(ptr - linep)) 2128 if (*ptr == '#' && pos.col <= (colnr_T)(ptr - linep))
2129 { 2129 {
2130 ptr = skipwhite(ptr + 1); 2130 ptr = skipwhite(ptr + 1);
2131 if ( STRNCMP(ptr, "if", 2) == 0 2131 if ( STRNCMP(ptr, "if", 2) == 0
2132 || STRNCMP(ptr, "endif", 5) == 0 2132 || STRNCMP(ptr, "endif", 5) == 0
2133 || STRNCMP(ptr, "el", 2) == 0) 2133 || STRNCMP(ptr, "el", 2) == 0)
2134 hash_dir = 1; 2134 hash_dir = 1;
2135 } 2135 }
2136 2136
2137 /* Are we on a comment? */ 2137 // Are we on a comment?
2138 else if (linep[pos.col] == '/') 2138 else if (linep[pos.col] == '/')
2139 { 2139 {
2140 if (linep[pos.col + 1] == '*') 2140 if (linep[pos.col + 1] == '*')
2141 { 2141 {
2142 comment_dir = FORWARD; 2142 comment_dir = FORWARD;
2189 break; 2189 break;
2190 pos.col += mb_ptr2len(linep + pos.col); 2190 pos.col += mb_ptr2len(linep + pos.col);
2191 } 2191 }
2192 if (!findc) 2192 if (!findc)
2193 { 2193 {
2194 /* no brace in the line, maybe use " #if" then */ 2194 // no brace in the line, maybe use " #if" then
2195 if (!cpo_match && *skipwhite(linep) == '#') 2195 if (!cpo_match && *skipwhite(linep) == '#')
2196 hash_dir = 1; 2196 hash_dir = 1;
2197 else 2197 else
2198 return NULL; 2198 return NULL;
2199 } 2199 }
2200 else if (!cpo_bsl) 2200 else if (!cpo_bsl)
2201 { 2201 {
2202 int col, bslcnt = 0; 2202 int col, bslcnt = 0;
2203 2203
2204 /* Set "match_escaped" if there are an odd number of 2204 // Set "match_escaped" if there are an odd number of
2205 * backslashes. */ 2205 // backslashes.
2206 for (col = pos.col; check_prevcol(linep, col, '\\', &col);) 2206 for (col = pos.col; check_prevcol(linep, col, '\\', &col);)
2207 bslcnt++; 2207 bslcnt++;
2208 match_escaped = (bslcnt & 1); 2208 match_escaped = (bslcnt & 1);
2209 } 2209 }
2210 } 2210 }
2213 { 2213 {
2214 /* 2214 /*
2215 * Look for matching #if, #else, #elif, or #endif 2215 * Look for matching #if, #else, #elif, or #endif
2216 */ 2216 */
2217 if (oap != NULL) 2217 if (oap != NULL)
2218 oap->motion_type = MLINE; /* Linewise for this case only */ 2218 oap->motion_type = MLINE; // Linewise for this case only
2219 if (initc != '#') 2219 if (initc != '#')
2220 { 2220 {
2221 ptr = skipwhite(skipwhite(linep) + 1); 2221 ptr = skipwhite(skipwhite(linep) + 1);
2222 if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0) 2222 if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0)
2223 hash_dir = 1; 2223 hash_dir = 1;
2236 } 2236 }
2237 else if (pos.lnum == 1) 2237 else if (pos.lnum == 1)
2238 break; 2238 break;
2239 pos.lnum += hash_dir; 2239 pos.lnum += hash_dir;
2240 linep = ml_get(pos.lnum); 2240 linep = ml_get(pos.lnum);
2241 line_breakcheck(); /* check for CTRL-C typed */ 2241 line_breakcheck(); // check for CTRL-C typed
2242 ptr = skipwhite(linep); 2242 ptr = skipwhite(linep);
2243 if (*ptr != '#') 2243 if (*ptr != '#')
2244 continue; 2244 continue;
2245 pos.col = (colnr_T) (ptr - linep); 2245 pos.col = (colnr_T) (ptr - linep);
2246 ptr = skipwhite(ptr + 1); 2246 ptr = skipwhite(ptr + 1);
2280 return NULL; 2280 return NULL;
2281 } 2281 }
2282 } 2282 }
2283 2283
2284 #ifdef FEAT_RIGHTLEFT 2284 #ifdef FEAT_RIGHTLEFT
2285 /* This is just guessing: when 'rightleft' is set, search for a matching 2285 // This is just guessing: when 'rightleft' is set, search for a matching
2286 * paren/brace in the other direction. */ 2286 // paren/brace in the other direction.
2287 if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL) 2287 if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL)
2288 backwards = !backwards; 2288 backwards = !backwards;
2289 #endif 2289 #endif
2290 2290
2291 do_quotes = -1; 2291 do_quotes = -1;
2292 start_in_quotes = MAYBE; 2292 start_in_quotes = MAYBE;
2293 CLEAR_POS(&match_pos); 2293 CLEAR_POS(&match_pos);
2294 2294
2295 /* backward search: Check if this line contains a single-line comment */ 2295 // backward search: Check if this line contains a single-line comment
2296 if ((backwards && comment_dir) 2296 if ((backwards && comment_dir)
2297 #ifdef FEAT_LISP 2297 #ifdef FEAT_LISP
2298 || lisp 2298 || lisp
2299 #endif 2299 #endif
2300 ) 2300 )
2301 comment_col = check_linecomment(linep); 2301 comment_col = check_linecomment(linep);
2302 #ifdef FEAT_LISP 2302 #ifdef FEAT_LISP
2303 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) 2303 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col)
2304 lispcomm = TRUE; /* find match inside this comment */ 2304 lispcomm = TRUE; // find match inside this comment
2305 #endif 2305 #endif
2306 while (!got_int) 2306 while (!got_int)
2307 { 2307 {
2308 /* 2308 /*
2309 * Go to the next position, forward or backward. We could use 2309 * Go to the next position, forward or backward. We could use
2310 * inc() and dec() here, but that is much slower 2310 * inc() and dec() here, but that is much slower
2311 */ 2311 */
2312 if (backwards) 2312 if (backwards)
2313 { 2313 {
2314 #ifdef FEAT_LISP 2314 #ifdef FEAT_LISP
2315 /* char to match is inside of comment, don't search outside */ 2315 // char to match is inside of comment, don't search outside
2316 if (lispcomm && pos.col < (colnr_T)comment_col) 2316 if (lispcomm && pos.col < (colnr_T)comment_col)
2317 break; 2317 break;
2318 #endif 2318 #endif
2319 if (pos.col == 0) /* at start of line, go to prev. one */ 2319 if (pos.col == 0) // at start of line, go to prev. one
2320 { 2320 {
2321 if (pos.lnum == 1) /* start of file */ 2321 if (pos.lnum == 1) // start of file
2322 break; 2322 break;
2323 --pos.lnum; 2323 --pos.lnum;
2324 2324
2325 if (maxtravel > 0 && ++traveled > maxtravel) 2325 if (maxtravel > 0 && ++traveled > maxtravel)
2326 break; 2326 break;
2327 2327
2328 linep = ml_get(pos.lnum); 2328 linep = ml_get(pos.lnum);
2329 pos.col = (colnr_T)STRLEN(linep); /* pos.col on trailing NUL */ 2329 pos.col = (colnr_T)STRLEN(linep); // pos.col on trailing NUL
2330 do_quotes = -1; 2330 do_quotes = -1;
2331 line_breakcheck(); 2331 line_breakcheck();
2332 2332
2333 /* Check if this line contains a single-line comment */ 2333 // Check if this line contains a single-line comment
2334 if (comment_dir 2334 if (comment_dir
2335 #ifdef FEAT_LISP 2335 #ifdef FEAT_LISP
2336 || lisp 2336 || lisp
2337 #endif 2337 #endif
2338 ) 2338 )
2339 comment_col = check_linecomment(linep); 2339 comment_col = check_linecomment(linep);
2340 #ifdef FEAT_LISP 2340 #ifdef FEAT_LISP
2341 /* skip comment */ 2341 // skip comment
2342 if (lisp && comment_col != MAXCOL) 2342 if (lisp && comment_col != MAXCOL)
2343 pos.col = comment_col; 2343 pos.col = comment_col;
2344 #endif 2344 #endif
2345 } 2345 }
2346 else 2346 else
2348 --pos.col; 2348 --pos.col;
2349 if (has_mbyte) 2349 if (has_mbyte)
2350 pos.col -= (*mb_head_off)(linep, linep + pos.col); 2350 pos.col -= (*mb_head_off)(linep, linep + pos.col);
2351 } 2351 }
2352 } 2352 }
2353 else /* forward search */ 2353 else // forward search
2354 { 2354 {
2355 if (linep[pos.col] == NUL 2355 if (linep[pos.col] == NUL
2356 /* at end of line, go to next one */ 2356 // at end of line, go to next one
2357 #ifdef FEAT_LISP 2357 #ifdef FEAT_LISP
2358 /* don't search for match in comment */ 2358 // don't search for match in comment
2359 || (lisp && comment_col != MAXCOL 2359 || (lisp && comment_col != MAXCOL
2360 && pos.col == (colnr_T)comment_col) 2360 && pos.col == (colnr_T)comment_col)
2361 #endif 2361 #endif
2362 ) 2362 )
2363 { 2363 {
2364 if (pos.lnum == curbuf->b_ml.ml_line_count /* end of file */ 2364 if (pos.lnum == curbuf->b_ml.ml_line_count // end of file
2365 #ifdef FEAT_LISP 2365 #ifdef FEAT_LISP
2366 /* line is exhausted and comment with it, 2366 // line is exhausted and comment with it,
2367 * don't search for match in code */ 2367 // don't search for match in code
2368 || lispcomm 2368 || lispcomm
2369 #endif 2369 #endif
2370 ) 2370 )
2371 break; 2371 break;
2372 ++pos.lnum; 2372 ++pos.lnum;
2377 linep = ml_get(pos.lnum); 2377 linep = ml_get(pos.lnum);
2378 pos.col = 0; 2378 pos.col = 0;
2379 do_quotes = -1; 2379 do_quotes = -1;
2380 line_breakcheck(); 2380 line_breakcheck();
2381 #ifdef FEAT_LISP 2381 #ifdef FEAT_LISP
2382 if (lisp) /* find comment pos in new line */ 2382 if (lisp) // find comment pos in new line
2383 comment_col = check_linecomment(linep); 2383 comment_col = check_linecomment(linep);
2384 #endif 2384 #endif
2385 } 2385 }
2386 else 2386 else
2387 { 2387 {
2396 * If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0. 2396 * If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0.
2397 */ 2397 */
2398 if (pos.col == 0 && (flags & FM_BLOCKSTOP) && 2398 if (pos.col == 0 && (flags & FM_BLOCKSTOP) &&
2399 (linep[0] == '{' || linep[0] == '}')) 2399 (linep[0] == '{' || linep[0] == '}'))
2400 { 2400 {
2401 if (linep[0] == findc && count == 0) /* match! */ 2401 if (linep[0] == findc && count == 0) // match!
2402 return &pos; 2402 return &pos;
2403 break; /* out of scope */ 2403 break; // out of scope
2404 } 2404 }
2405 2405
2406 if (comment_dir) 2406 if (comment_dir)
2407 { 2407 {
2408 /* Note: comments do not nest, and we ignore quotes in them */ 2408 // Note: comments do not nest, and we ignore quotes in them
2409 /* TODO: ignore comment brackets inside strings */ 2409 // TODO: ignore comment brackets inside strings
2410 if (comment_dir == FORWARD) 2410 if (comment_dir == FORWARD)
2411 { 2411 {
2412 if (linep[pos.col] == '*' && linep[pos.col + 1] == '/') 2412 if (linep[pos.col] == '*' && linep[pos.col + 1] == '/')
2413 { 2413 {
2414 pos.col++; 2414 pos.col++;
2415 return &pos; 2415 return &pos;
2416 } 2416 }
2417 } 2417 }
2418 else /* Searching backwards */ 2418 else // Searching backwards
2419 { 2419 {
2420 /* 2420 /*
2421 * A comment may contain / * or / /, it may also start or end 2421 * A comment may contain / * or / /, it may also start or end
2422 * with / * /. Ignore a / * after / / and after *. 2422 * with / * /. Ignore a / * after / / and after *.
2423 */ 2423 */
2427 { 2427 {
2428 if (linep[pos.col - 1] == 'R' 2428 if (linep[pos.col - 1] == 'R'
2429 && linep[pos.col] == '"' 2429 && linep[pos.col] == '"'
2430 && vim_strchr(linep + pos.col + 1, '(') != NULL) 2430 && vim_strchr(linep + pos.col + 1, '(') != NULL)
2431 { 2431 {
2432 /* Possible start of raw string. Now that we have the 2432 // Possible start of raw string. Now that we have the
2433 * delimiter we can check if it ends before where we 2433 // delimiter we can check if it ends before where we
2434 * started searching, or before the previously found 2434 // started searching, or before the previously found
2435 * raw string start. */ 2435 // raw string start.
2436 if (!find_rawstring_end(linep, &pos, 2436 if (!find_rawstring_end(linep, &pos,
2437 count > 0 ? &match_pos : &curwin->w_cursor)) 2437 count > 0 ? &match_pos : &curwin->w_cursor))
2438 { 2438 {
2439 count++; 2439 count++;
2440 match_pos = pos; 2440 match_pos = pos;
2441 match_pos.col--; 2441 match_pos.col--;
2442 } 2442 }
2443 linep = ml_get(pos.lnum); /* may have been released */ 2443 linep = ml_get(pos.lnum); // may have been released
2444 } 2444 }
2445 } 2445 }
2446 else if ( linep[pos.col - 1] == '/' 2446 else if ( linep[pos.col - 1] == '/'
2447 && linep[pos.col] == '*' 2447 && linep[pos.col] == '*'
2448 && (pos.col == 1 || linep[pos.col - 2] != '*') 2448 && (pos.col == 1 || linep[pos.col - 2] != '*')
2491 && (ptr == linep || ptr[-1] != '\'' || ptr[1] != '\'')) 2491 && (ptr == linep || ptr[-1] != '\'' || ptr[1] != '\''))
2492 ++do_quotes; 2492 ++do_quotes;
2493 if (*ptr == '\\' && ptr[1] != NUL) 2493 if (*ptr == '\\' && ptr[1] != NUL)
2494 ++ptr; 2494 ++ptr;
2495 } 2495 }
2496 do_quotes &= 1; /* result is 1 with even number of quotes */ 2496 do_quotes &= 1; // result is 1 with even number of quotes
2497 2497
2498 /* 2498 /*
2499 * If we find an uneven count, check current line and previous 2499 * If we find an uneven count, check current line and previous
2500 * one for a '\' at the end. 2500 * one for a '\' at the end.
2501 */ 2501 */
2505 if (ptr[-1] == '\\') 2505 if (ptr[-1] == '\\')
2506 { 2506 {
2507 do_quotes = 1; 2507 do_quotes = 1;
2508 if (start_in_quotes == MAYBE) 2508 if (start_in_quotes == MAYBE)
2509 { 2509 {
2510 /* Do we need to use at_start here? */ 2510 // Do we need to use at_start here?
2511 inquote = TRUE; 2511 inquote = TRUE;
2512 start_in_quotes = TRUE; 2512 start_in_quotes = TRUE;
2513 } 2513 }
2514 else if (backwards) 2514 else if (backwards)
2515 inquote = TRUE; 2515 inquote = TRUE;
2528 } 2528 }
2529 else if (!backwards) 2529 else if (!backwards)
2530 inquote = TRUE; 2530 inquote = TRUE;
2531 } 2531 }
2532 2532
2533 /* ml_get() only keeps one line, need to get linep again */ 2533 // ml_get() only keeps one line, need to get linep again
2534 linep = ml_get(pos.lnum); 2534 linep = ml_get(pos.lnum);
2535 } 2535 }
2536 } 2536 }
2537 } 2537 }
2538 if (start_in_quotes == MAYBE) 2538 if (start_in_quotes == MAYBE)
2551 */ 2551 */
2552 c = PTR2CHAR(linep + pos.col); 2552 c = PTR2CHAR(linep + pos.col);
2553 switch (c) 2553 switch (c)
2554 { 2554 {
2555 case NUL: 2555 case NUL:
2556 /* at end of line without trailing backslash, reset inquote */ 2556 // at end of line without trailing backslash, reset inquote
2557 if (pos.col == 0 || linep[pos.col - 1] != '\\') 2557 if (pos.col == 0 || linep[pos.col - 1] != '\\')
2558 { 2558 {
2559 inquote = FALSE; 2559 inquote = FALSE;
2560 start_in_quotes = FALSE; 2560 start_in_quotes = FALSE;
2561 } 2561 }
2562 break; 2562 break;
2563 2563
2564 case '"': 2564 case '"':
2565 /* a quote that is preceded with an odd number of backslashes is 2565 // a quote that is preceded with an odd number of backslashes is
2566 * ignored */ 2566 // ignored
2567 if (do_quotes) 2567 if (do_quotes)
2568 { 2568 {
2569 int col; 2569 int col;
2570 2570
2571 for (col = pos.col - 1; col >= 0; --col) 2571 for (col = pos.col - 1; col >= 0; --col)
2604 pos.col -= 3; 2604 pos.col -= 3;
2605 break; 2605 break;
2606 } 2606 }
2607 } 2607 }
2608 } 2608 }
2609 else if (linep[pos.col + 1]) /* forward search */ 2609 else if (linep[pos.col + 1]) // forward search
2610 { 2610 {
2611 if (linep[pos.col + 1] == '\\' && 2611 if (linep[pos.col + 1] == '\\' &&
2612 linep[pos.col + 2] && linep[pos.col + 3] == '\'') 2612 linep[pos.col + 2] && linep[pos.col + 3] == '\'')
2613 { 2613 {
2614 pos.col += 3; 2614 pos.col += 3;
2619 pos.col += 2; 2619 pos.col += 2;
2620 break; 2620 break;
2621 } 2621 }
2622 } 2622 }
2623 } 2623 }
2624 /* FALLTHROUGH */ 2624 // FALLTHROUGH
2625 2625
2626 default: 2626 default:
2627 #ifdef FEAT_LISP 2627 #ifdef FEAT_LISP
2628 /* 2628 /*
2629 * For Lisp skip over backslashed (), {} and []. 2629 * For Lisp skip over backslashed (), {} and [].
2635 && check_prevcol(linep, pos.col, '\\', NULL) 2635 && check_prevcol(linep, pos.col, '\\', NULL)
2636 && check_prevcol(linep, pos.col - 1, '#', NULL)) 2636 && check_prevcol(linep, pos.col - 1, '#', NULL))
2637 break; 2637 break;
2638 #endif 2638 #endif
2639 2639
2640 /* Check for match outside of quotes, and inside of 2640 // Check for match outside of quotes, and inside of
2641 * quotes when the start is also inside of quotes. */ 2641 // quotes when the start is also inside of quotes.
2642 if ((!inquote || start_in_quotes == TRUE) 2642 if ((!inquote || start_in_quotes == TRUE)
2643 && (c == initc || c == findc)) 2643 && (c == initc || c == findc))
2644 { 2644 {
2645 int col, bslcnt = 0; 2645 int col, bslcnt = 0;
2646 2646
2647 if (!cpo_bsl) 2647 if (!cpo_bsl)
2648 { 2648 {
2649 for (col = pos.col; check_prevcol(linep, col, '\\', &col);) 2649 for (col = pos.col; check_prevcol(linep, col, '\\', &col);)
2650 bslcnt++; 2650 bslcnt++;
2651 } 2651 }
2652 /* Only accept a match when 'M' is in 'cpo' or when escaping 2652 // Only accept a match when 'M' is in 'cpo' or when escaping
2653 * is what we expect. */ 2653 // is what we expect.
2654 if (cpo_bsl || (bslcnt & 1) == match_escaped) 2654 if (cpo_bsl || (bslcnt & 1) == match_escaped)
2655 { 2655 {
2656 if (c == initc) 2656 if (c == initc)
2657 count++; 2657 count++;
2658 else 2658 else
2669 if (comment_dir == BACKWARD && count > 0) 2669 if (comment_dir == BACKWARD && count > 0)
2670 { 2670 {
2671 pos = match_pos; 2671 pos = match_pos;
2672 return &pos; 2672 return &pos;
2673 } 2673 }
2674 return (pos_T *)NULL; /* never found it */ 2674 return (pos_T *)NULL; // never found it
2675 } 2675 }
2676 2676
2677 /* 2677 /*
2678 * Check if line[] contains a / / comment. 2678 * Check if line[] contains a / / comment.
2679 * Return MAXCOL if not, otherwise return the column. 2679 * Return MAXCOL if not, otherwise return the column.
2684 { 2684 {
2685 char_u *p; 2685 char_u *p;
2686 2686
2687 p = line; 2687 p = line;
2688 #ifdef FEAT_LISP 2688 #ifdef FEAT_LISP
2689 /* skip Lispish one-line comments */ 2689 // skip Lispish one-line comments
2690 if (curbuf->b_p_lisp) 2690 if (curbuf->b_p_lisp)
2691 { 2691 {
2692 if (vim_strchr(p, ';') != NULL) /* there may be comments */ 2692 if (vim_strchr(p, ';') != NULL) // there may be comments
2693 { 2693 {
2694 int in_str = FALSE; /* inside of string */ 2694 int in_str = FALSE; // inside of string
2695 2695
2696 p = line; /* scan from start */ 2696 p = line; // scan from start
2697 while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL) 2697 while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL)
2698 { 2698 {
2699 if (*p == '"') 2699 if (*p == '"')
2700 { 2700 {
2701 if (in_str) 2701 if (in_str)
2702 { 2702 {
2703 if (*(p - 1) != '\\') /* skip escaped quote */ 2703 if (*(p - 1) != '\\') // skip escaped quote
2704 in_str = FALSE; 2704 in_str = FALSE;
2705 } 2705 }
2706 else if (p == line || ((p - line) >= 2 2706 else if (p == line || ((p - line) >= 2
2707 /* skip #\" form */ 2707 // skip #\" form
2708 && *(p - 1) != '\\' && *(p - 2) != '#')) 2708 && *(p - 1) != '\\' && *(p - 2) != '#'))
2709 in_str = TRUE; 2709 in_str = TRUE;
2710 } 2710 }
2711 else if (!in_str && ((p - line) < 2 2711 else if (!in_str && ((p - line) < 2
2712 || (*(p - 1) != '\\' && *(p - 2) != '#'))) 2712 || (*(p - 1) != '\\' && *(p - 2) != '#')))
2713 break; /* found! */ 2713 break; // found!
2714 ++p; 2714 ++p;
2715 } 2715 }
2716 } 2716 }
2717 else 2717 else
2718 p = NULL; 2718 p = NULL;
2719 } 2719 }
2720 else 2720 else
2721 #endif 2721 #endif
2722 while ((p = vim_strchr(p, '/')) != NULL) 2722 while ((p = vim_strchr(p, '/')) != NULL)
2723 { 2723 {
2724 /* accept a double /, unless it's preceded with * and followed by *, 2724 // accept a double /, unless it's preceded with * and followed by *,
2725 * because * / / * is an end and start of a C comment */ 2725 // because * / / * is an end and start of a C comment
2726 if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*')) 2726 if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*'))
2727 break; 2727 break;
2728 ++p; 2728 ++p;
2729 } 2729 }
2730 2730
2739 * Show the match only if it is visible on the screen. 2739 * Show the match only if it is visible on the screen.
2740 * If there isn't a match, then beep. 2740 * If there isn't a match, then beep.
2741 */ 2741 */
2742 void 2742 void
2743 showmatch( 2743 showmatch(
2744 int c) /* char to show match for */ 2744 int c) // char to show match for
2745 { 2745 {
2746 pos_T *lpos, save_cursor; 2746 pos_T *lpos, save_cursor;
2747 pos_T mpos; 2747 pos_T mpos;
2748 colnr_T vcol; 2748 colnr_T vcol;
2749 long save_so; 2749 long save_so;
2757 long *siso = curwin->w_p_siso >= 0 ? &curwin->w_p_siso : &p_siso; 2757 long *siso = curwin->w_p_siso >= 0 ? &curwin->w_p_siso : &p_siso;
2758 2758
2759 /* 2759 /*
2760 * Only show match for chars in the 'matchpairs' option. 2760 * Only show match for chars in the 'matchpairs' option.
2761 */ 2761 */
2762 /* 'matchpairs' is "x:y,x:y" */ 2762 // 'matchpairs' is "x:y,x:y"
2763 for (p = curbuf->b_p_mps; *p != NUL; ++p) 2763 for (p = curbuf->b_p_mps; *p != NUL; ++p)
2764 { 2764 {
2765 #ifdef FEAT_RIGHTLEFT 2765 #ifdef FEAT_RIGHTLEFT
2766 if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri)) 2766 if (PTR2CHAR(p) == c && (curwin->w_p_rl ^ p_ri))
2767 break; 2767 break;
2776 p += mb_ptr2len(p); 2776 p += mb_ptr2len(p);
2777 if (*p == NUL) 2777 if (*p == NUL)
2778 return; 2778 return;
2779 } 2779 }
2780 2780
2781 if ((lpos = findmatch(NULL, NUL)) == NULL) /* no match, so beep */ 2781 if ((lpos = findmatch(NULL, NUL)) == NULL) // no match, so beep
2782 vim_beep(BO_MATCH); 2782 vim_beep(BO_MATCH);
2783 else if (lpos->lnum >= curwin->w_topline && lpos->lnum < curwin->w_botline) 2783 else if (lpos->lnum >= curwin->w_topline && lpos->lnum < curwin->w_botline)
2784 { 2784 {
2785 if (!curwin->w_p_wrap) 2785 if (!curwin->w_p_wrap)
2786 getvcol(curwin, lpos, NULL, &vcol, NULL); 2786 getvcol(curwin, lpos, NULL, &vcol, NULL);
2787 if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol 2787 if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol
2788 && vcol < curwin->w_leftcol + curwin->w_width)) 2788 && vcol < curwin->w_leftcol + curwin->w_width))
2789 { 2789 {
2790 mpos = *lpos; /* save the pos, update_screen() may change it */ 2790 mpos = *lpos; // save the pos, update_screen() may change it
2791 save_cursor = curwin->w_cursor; 2791 save_cursor = curwin->w_cursor;
2792 save_so = *so; 2792 save_so = *so;
2793 save_siso = *siso; 2793 save_siso = *siso;
2794 /* Handle "$" in 'cpo': If the ')' is typed on top of the "$", 2794 // Handle "$" in 'cpo': If the ')' is typed on top of the "$",
2795 * stop displaying the "$". */ 2795 // stop displaying the "$".
2796 if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol) 2796 if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol)
2797 dollar_vcol = -1; 2797 dollar_vcol = -1;
2798 ++curwin->w_virtcol; /* do display ')' just before "$" */ 2798 ++curwin->w_virtcol; // do display ')' just before "$"
2799 update_screen(VALID); /* show the new char first */ 2799 update_screen(VALID); // show the new char first
2800 2800
2801 save_dollar_vcol = dollar_vcol; 2801 save_dollar_vcol = dollar_vcol;
2802 #ifdef CURSOR_SHAPE 2802 #ifdef CURSOR_SHAPE
2803 save_state = State; 2803 save_state = State;
2804 State = SHOWMATCH; 2804 State = SHOWMATCH;
2805 ui_cursor_shape(); /* may show different cursor shape */ 2805 ui_cursor_shape(); // may show different cursor shape
2806 #endif 2806 #endif
2807 curwin->w_cursor = mpos; /* move to matching char */ 2807 curwin->w_cursor = mpos; // move to matching char
2808 *so = 0; /* don't use 'scrolloff' here */ 2808 *so = 0; // don't use 'scrolloff' here
2809 *siso = 0; /* don't use 'sidescrolloff' here */ 2809 *siso = 0; // don't use 'sidescrolloff' here
2810 showruler(FALSE); 2810 showruler(FALSE);
2811 setcursor(); 2811 setcursor();
2812 cursor_on(); /* make sure that the cursor is shown */ 2812 cursor_on(); // make sure that the cursor is shown
2813 out_flush_cursor(TRUE, FALSE); 2813 out_flush_cursor(TRUE, FALSE);
2814 2814
2815 /* Restore dollar_vcol(), because setcursor() may call curs_rows() 2815 // Restore dollar_vcol(), because setcursor() may call curs_rows()
2816 * which resets it if the matching position is in a previous line 2816 // which resets it if the matching position is in a previous line
2817 * and has a higher column number. */ 2817 // and has a higher column number.
2818 dollar_vcol = save_dollar_vcol; 2818 dollar_vcol = save_dollar_vcol;
2819 2819
2820 /* 2820 /*
2821 * brief pause, unless 'm' is present in 'cpo' and a character is 2821 * brief pause, unless 'm' is present in 'cpo' and a character is
2822 * available. 2822 * available.
2823 */ 2823 */
2824 if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) 2824 if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL)
2825 ui_delay(p_mat * 100L + 8, TRUE); 2825 ui_delay(p_mat * 100L + 8, TRUE);
2826 else if (!char_avail()) 2826 else if (!char_avail())
2827 ui_delay(p_mat * 100L + 9, FALSE); 2827 ui_delay(p_mat * 100L + 9, FALSE);
2828 curwin->w_cursor = save_cursor; /* restore cursor position */ 2828 curwin->w_cursor = save_cursor; // restore cursor position
2829 *so = save_so; 2829 *so = save_so;
2830 *siso = save_siso; 2830 *siso = save_siso;
2831 #ifdef CURSOR_SHAPE 2831 #ifdef CURSOR_SHAPE
2832 State = save_state; 2832 State = save_state;
2833 ui_cursor_shape(); /* may show different cursor shape */ 2833 ui_cursor_shape(); // may show different cursor shape
2834 #endif 2834 #endif
2835 } 2835 }
2836 } 2836 }
2837 } 2837 }
2838 2838
2848 { 2848 {
2849 pos_T pos, tpos; 2849 pos_T pos, tpos;
2850 int c; 2850 int c;
2851 int (*func)(pos_T *); 2851 int (*func)(pos_T *);
2852 int startlnum; 2852 int startlnum;
2853 int noskip = FALSE; /* do not skip blanks */ 2853 int noskip = FALSE; // do not skip blanks
2854 int cpo_J; 2854 int cpo_J;
2855 int found_dot; 2855 int found_dot;
2856 2856
2857 pos = curwin->w_cursor; 2857 pos = curwin->w_cursor;
2858 if (dir == FORWARD) 2858 if (dir == FORWARD)
2908 break; 2908 break;
2909 2909
2910 decl(&pos); 2910 decl(&pos);
2911 } 2911 }
2912 2912
2913 /* remember the line where the search started */ 2913 // remember the line where the search started
2914 startlnum = pos.lnum; 2914 startlnum = pos.lnum;
2915 cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL; 2915 cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL;
2916 2916
2917 for (;;) /* find end of sentence */ 2917 for (;;) // find end of sentence
2918 { 2918 {
2919 c = gchar_pos(&pos); 2919 c = gchar_pos(&pos);
2920 if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE))) 2920 if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE)))
2921 { 2921 {
2922 if (dir == BACKWARD && pos.lnum != startlnum) 2922 if (dir == BACKWARD && pos.lnum != startlnum)
2934 if (c == -1 || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL 2934 if (c == -1 || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL
2935 || (cpo_J && (c == ' ' && inc(&tpos) >= 0 2935 || (cpo_J && (c == ' ' && inc(&tpos) >= 0
2936 && gchar_pos(&tpos) == ' '))) 2936 && gchar_pos(&tpos) == ' ')))
2937 { 2937 {
2938 pos = tpos; 2938 pos = tpos;
2939 if (gchar_pos(&pos) == NUL) /* skip NUL at EOL */ 2939 if (gchar_pos(&pos) == NUL) // skip NUL at EOL
2940 inc(&pos); 2940 inc(&pos);
2941 break; 2941 break;
2942 } 2942 }
2943 } 2943 }
2944 if ((*func)(&pos) == -1) 2944 if ((*func)(&pos) == -1)
2948 noskip = TRUE; 2948 noskip = TRUE;
2949 break; 2949 break;
2950 } 2950 }
2951 } 2951 }
2952 found: 2952 found:
2953 /* skip white space */ 2953 // skip white space
2954 while (!noskip && ((c = gchar_pos(&pos)) == ' ' || c == '\t')) 2954 while (!noskip && ((c = gchar_pos(&pos)) == ' ' || c == '\t'))
2955 if (incl(&pos) == -1) 2955 if (incl(&pos) == -1)
2956 break; 2956 break;
2957 } 2957 }
2958 2958
2969 * If 'both' is TRUE also stop at '}'. 2969 * If 'both' is TRUE also stop at '}'.
2970 * Return TRUE if the next paragraph or section was found. 2970 * Return TRUE if the next paragraph or section was found.
2971 */ 2971 */
2972 int 2972 int
2973 findpar( 2973 findpar(
2974 int *pincl, /* Return: TRUE if last char is to be included */ 2974 int *pincl, // Return: TRUE if last char is to be included
2975 int dir, 2975 int dir,
2976 long count, 2976 long count,
2977 int what, 2977 int what,
2978 int both) 2978 int both)
2979 { 2979 {
2980 linenr_T curr; 2980 linenr_T curr;
2981 int did_skip; /* TRUE after separating lines have been skipped */ 2981 int did_skip; // TRUE after separating lines have been skipped
2982 int first; /* TRUE on first line */ 2982 int first; // TRUE on first line
2983 int posix = (vim_strchr(p_cpo, CPO_PARA) != NULL); 2983 int posix = (vim_strchr(p_cpo, CPO_PARA) != NULL);
2984 #ifdef FEAT_FOLDING 2984 #ifdef FEAT_FOLDING
2985 linenr_T fold_first; /* first line of a closed fold */ 2985 linenr_T fold_first; // first line of a closed fold
2986 linenr_T fold_last; /* last line of a closed fold */ 2986 linenr_T fold_last; // last line of a closed fold
2987 int fold_skipped; /* TRUE if a closed fold was skipped this 2987 int fold_skipped; // TRUE if a closed fold was skipped this
2988 iteration */ 2988 // iteration
2989 #endif 2989 #endif
2990 2990
2991 curr = curwin->w_cursor.lnum; 2991 curr = curwin->w_cursor.lnum;
2992 2992
2993 while (count--) 2993 while (count--)
2997 { 2997 {
2998 if (*ml_get(curr) != NUL) 2998 if (*ml_get(curr) != NUL)
2999 did_skip = TRUE; 2999 did_skip = TRUE;
3000 3000
3001 #ifdef FEAT_FOLDING 3001 #ifdef FEAT_FOLDING
3002 /* skip folded lines */ 3002 // skip folded lines
3003 fold_skipped = FALSE; 3003 fold_skipped = FALSE;
3004 if (first && hasFolding(curr, &fold_first, &fold_last)) 3004 if (first && hasFolding(curr, &fold_first, &fold_last))
3005 { 3005 {
3006 curr = ((dir > 0) ? fold_last : fold_first) + dir; 3006 curr = ((dir > 0) ? fold_last : fold_first) + dir;
3007 fold_skipped = TRUE; 3007 fold_skipped = TRUE;
3008 } 3008 }
3009 #endif 3009 #endif
3010 3010
3011 /* POSIX has its own ideas of what a paragraph boundary is and it 3011 // POSIX has its own ideas of what a paragraph boundary is and it
3012 * doesn't match historical Vi: It also stops at a "{" in the 3012 // doesn't match historical Vi: It also stops at a "{" in the
3013 * first column and at an empty line. */ 3013 // first column and at an empty line.
3014 if (!first && did_skip && (startPS(curr, what, both) 3014 if (!first && did_skip && (startPS(curr, what, both)
3015 || (posix && what == NUL && *ml_get(curr) == '{'))) 3015 || (posix && what == NUL && *ml_get(curr) == '{')))
3016 break; 3016 break;
3017 3017
3018 #ifdef FEAT_FOLDING 3018 #ifdef FEAT_FOLDING
3027 break; 3027 break;
3028 } 3028 }
3029 } 3029 }
3030 } 3030 }
3031 setpcmark(); 3031 setpcmark();
3032 if (both && *ml_get(curr) == '}') /* include line with '}' */ 3032 if (both && *ml_get(curr) == '}') // include line with '}'
3033 ++curr; 3033 ++curr;
3034 curwin->w_cursor.lnum = curr; 3034 curwin->w_cursor.lnum = curr;
3035 if (curr == curbuf->b_ml.ml_line_count && what != '}') 3035 if (curr == curbuf->b_ml.ml_line_count && what != '}')
3036 { 3036 {
3037 char_u *line = ml_get(curr); 3037 char_u *line = ml_get(curr);
3038 3038
3039 /* Put the cursor on the last character in the last line and make the 3039 // Put the cursor on the last character in the last line and make the
3040 * motion inclusive. */ 3040 // motion inclusive.
3041 if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) 3041 if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0)
3042 { 3042 {
3043 --curwin->w_cursor.col; 3043 --curwin->w_cursor.col;
3044 curwin->w_cursor.col -= 3044 curwin->w_cursor.col -=
3045 (*mb_head_off)(line, line + curwin->w_cursor.col); 3045 (*mb_head_off)(line, line + curwin->w_cursor.col);
3059 { 3059 {
3060 char_u *macro; 3060 char_u *macro;
3061 3061
3062 for (macro = opt; macro[0]; ++macro) 3062 for (macro = opt; macro[0]; ++macro)
3063 { 3063 {
3064 /* Accept two characters in the option being equal to two characters 3064 // Accept two characters in the option being equal to two characters
3065 * in the line. A space in the option matches with a space in the 3065 // in the line. A space in the option matches with a space in the
3066 * line or the line having ended. */ 3066 // line or the line having ended.
3067 if ( (macro[0] == s[0] 3067 if ( (macro[0] == s[0]
3068 || (macro[0] == ' ' 3068 || (macro[0] == ' '
3069 && (s[0] == NUL || s[0] == ' '))) 3069 && (s[0] == NUL || s[0] == ' ')))
3070 && (macro[1] == s[1] 3070 && (macro[1] == s[1]
3071 || ((macro[1] == NUL || macro[1] == ' ') 3071 || ((macro[1] == NUL || macro[1] == ' ')
3111 * 0 - white space 3111 * 0 - white space
3112 * 1 - punctuation 3112 * 1 - punctuation
3113 * 2 or higher - keyword characters (letters, digits and underscore) 3113 * 2 or higher - keyword characters (letters, digits and underscore)
3114 */ 3114 */
3115 3115
3116 static int cls_bigword; /* TRUE for "W", "B" or "E" */ 3116 static int cls_bigword; // TRUE for "W", "B" or "E"
3117 3117
3118 /* 3118 /*
3119 * cls() - returns the class of character at curwin->w_cursor 3119 * cls() - returns the class of character at curwin->w_cursor
3120 * 3120 *
3121 * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars 3121 * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars
3130 c = gchar_cursor(); 3130 c = gchar_cursor();
3131 if (c == ' ' || c == '\t' || c == NUL) 3131 if (c == ' ' || c == '\t' || c == NUL)
3132 return 0; 3132 return 0;
3133 if (enc_dbcs != 0 && c > 0xFF) 3133 if (enc_dbcs != 0 && c > 0xFF)
3134 { 3134 {
3135 /* If cls_bigword, report multi-byte chars as class 1. */ 3135 // If cls_bigword, report multi-byte chars as class 1.
3136 if (enc_dbcs == DBCS_KOR && cls_bigword) 3136 if (enc_dbcs == DBCS_KOR && cls_bigword)
3137 return 1; 3137 return 1;
3138 3138
3139 /* process code leading/trailing bytes */ 3139 // process code leading/trailing bytes
3140 return dbcs_class(((unsigned)c >> 8), (c & 0xFF)); 3140 return dbcs_class(((unsigned)c >> 8), (c & 0xFF));
3141 } 3141 }
3142 if (enc_utf8) 3142 if (enc_utf8)
3143 { 3143 {
3144 c = utf_class(c); 3144 c = utf_class(c);
3145 if (c != 0 && cls_bigword) 3145 if (c != 0 && cls_bigword)
3146 return 1; 3146 return 1;
3147 return c; 3147 return c;
3148 } 3148 }
3149 3149
3150 /* If cls_bigword is TRUE, report all non-blanks as class 1. */ 3150 // If cls_bigword is TRUE, report all non-blanks as class 1.
3151 if (cls_bigword) 3151 if (cls_bigword)
3152 return 1; 3152 return 1;
3153 3153
3154 if (vim_iswordc(c)) 3154 if (vim_iswordc(c))
3155 return 2; 3155 return 2;
3164 * If eol is TRUE, last word stops at end of line (for operators). 3164 * If eol is TRUE, last word stops at end of line (for operators).
3165 */ 3165 */
3166 int 3166 int
3167 fwd_word( 3167 fwd_word(
3168 long count, 3168 long count,
3169 int bigword, /* "W", "E" or "B" */ 3169 int bigword, // "W", "E" or "B"
3170 int eol) 3170 int eol)
3171 { 3171 {
3172 int sclass; /* starting class */ 3172 int sclass; // starting class
3173 int i; 3173 int i;
3174 int last_line; 3174 int last_line;
3175 3175
3176 curwin->w_cursor.coladd = 0; 3176 curwin->w_cursor.coladd = 0;
3177 cls_bigword = bigword; 3177 cls_bigword = bigword;
3178 while (--count >= 0) 3178 while (--count >= 0)
3179 { 3179 {
3180 #ifdef FEAT_FOLDING 3180 #ifdef FEAT_FOLDING
3181 /* When inside a range of folded lines, move to the last char of the 3181 // When inside a range of folded lines, move to the last char of the
3182 * last line. */ 3182 // last line.
3183 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) 3183 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
3184 coladvance((colnr_T)MAXCOL); 3184 coladvance((colnr_T)MAXCOL);
3185 #endif 3185 #endif
3186 sclass = cls(); 3186 sclass = cls();
3187 3187
3189 * We always move at least one character, unless on the last 3189 * We always move at least one character, unless on the last
3190 * character in the buffer. 3190 * character in the buffer.
3191 */ 3191 */
3192 last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); 3192 last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count);
3193 i = inc_cursor(); 3193 i = inc_cursor();
3194 if (i == -1 || (i >= 1 && last_line)) /* started at last char in file */ 3194 if (i == -1 || (i >= 1 && last_line)) // started at last char in file
3195 return FAIL; 3195 return FAIL;
3196 if (i >= 1 && eol && count == 0) /* started at last char in line */ 3196 if (i >= 1 && eol && count == 0) // started at last char in line
3197 return OK; 3197 return OK;
3198 3198
3199 /* 3199 /*
3200 * Go one char past end of current word (if any) 3200 * Go one char past end of current word (if any)
3201 */ 3201 */
3234 * Returns FAIL if top of the file was reached. 3234 * Returns FAIL if top of the file was reached.
3235 */ 3235 */
3236 int 3236 int
3237 bck_word(long count, int bigword, int stop) 3237 bck_word(long count, int bigword, int stop)
3238 { 3238 {
3239 int sclass; /* starting class */ 3239 int sclass; // starting class
3240 3240
3241 curwin->w_cursor.coladd = 0; 3241 curwin->w_cursor.coladd = 0;
3242 cls_bigword = bigword; 3242 cls_bigword = bigword;
3243 while (--count >= 0) 3243 while (--count >= 0)
3244 { 3244 {
3245 #ifdef FEAT_FOLDING 3245 #ifdef FEAT_FOLDING
3246 /* When inside a range of folded lines, move to the first char of the 3246 // When inside a range of folded lines, move to the first char of the
3247 * first line. */ 3247 // first line.
3248 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL)) 3248 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL))
3249 curwin->w_cursor.col = 0; 3249 curwin->w_cursor.col = 0;
3250 #endif 3250 #endif
3251 sclass = cls(); 3251 sclass = cls();
3252 if (dec_cursor() == -1) /* started at start of file */ 3252 if (dec_cursor() == -1) // started at start of file
3253 return FAIL; 3253 return FAIL;
3254 3254
3255 if (!stop || sclass == cls() || sclass == 0) 3255 if (!stop || sclass == cls() || sclass == 0)
3256 { 3256 {
3257 /* 3257 /*
3261 while (cls() == 0) 3261 while (cls() == 0)
3262 { 3262 {
3263 if (curwin->w_cursor.col == 0 3263 if (curwin->w_cursor.col == 0
3264 && LINEEMPTY(curwin->w_cursor.lnum)) 3264 && LINEEMPTY(curwin->w_cursor.lnum))
3265 goto finished; 3265 goto finished;
3266 if (dec_cursor() == -1) /* hit start of file, stop here */ 3266 if (dec_cursor() == -1) // hit start of file, stop here
3267 return OK; 3267 return OK;
3268 } 3268 }
3269 3269
3270 /* 3270 /*
3271 * Move backward to start of this word. 3271 * Move backward to start of this word.
3272 */ 3272 */
3273 if (skip_chars(cls(), BACKWARD)) 3273 if (skip_chars(cls(), BACKWARD))
3274 return OK; 3274 return OK;
3275 } 3275 }
3276 3276
3277 inc_cursor(); /* overshot - forward one */ 3277 inc_cursor(); // overshot - forward one
3278 finished: 3278 finished:
3279 stop = FALSE; 3279 stop = FALSE;
3280 } 3280 }
3281 return OK; 3281 return OK;
3282 } 3282 }
3301 long count, 3301 long count,
3302 int bigword, 3302 int bigword,
3303 int stop, 3303 int stop,
3304 int empty) 3304 int empty)
3305 { 3305 {
3306 int sclass; /* starting class */ 3306 int sclass; // starting class
3307 3307
3308 curwin->w_cursor.coladd = 0; 3308 curwin->w_cursor.coladd = 0;
3309 cls_bigword = bigword; 3309 cls_bigword = bigword;
3310 while (--count >= 0) 3310 while (--count >= 0)
3311 { 3311 {
3312 #ifdef FEAT_FOLDING 3312 #ifdef FEAT_FOLDING
3313 /* When inside a range of folded lines, move to the last char of the 3313 // When inside a range of folded lines, move to the last char of the
3314 * last line. */ 3314 // last line.
3315 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) 3315 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
3316 coladvance((colnr_T)MAXCOL); 3316 coladvance((colnr_T)MAXCOL);
3317 #endif 3317 #endif
3318 sclass = cls(); 3318 sclass = cls();
3319 if (inc_cursor() == -1) 3319 if (inc_cursor() == -1)
3340 while (cls() == 0) 3340 while (cls() == 0)
3341 { 3341 {
3342 if (empty && curwin->w_cursor.col == 0 3342 if (empty && curwin->w_cursor.col == 0
3343 && LINEEMPTY(curwin->w_cursor.lnum)) 3343 && LINEEMPTY(curwin->w_cursor.lnum))
3344 goto finished; 3344 goto finished;
3345 if (inc_cursor() == -1) /* hit end of file, stop here */ 3345 if (inc_cursor() == -1) // hit end of file, stop here
3346 return FAIL; 3346 return FAIL;
3347 } 3347 }
3348 3348
3349 /* 3349 /*
3350 * Move forward to the end of this word. 3350 * Move forward to the end of this word.
3351 */ 3351 */
3352 if (skip_chars(cls(), FORWARD)) 3352 if (skip_chars(cls(), FORWARD))
3353 return FAIL; 3353 return FAIL;
3354 } 3354 }
3355 dec_cursor(); /* overshot - one char backward */ 3355 dec_cursor(); // overshot - one char backward
3356 finished: 3356 finished:
3357 stop = FALSE; /* we move only one word less */ 3357 stop = FALSE; // we move only one word less
3358 } 3358 }
3359 return OK; 3359 return OK;
3360 } 3360 }
3361 3361
3362 /* 3362 /*
3365 * Returns FAIL if start of the file was reached. 3365 * Returns FAIL if start of the file was reached.
3366 */ 3366 */
3367 int 3367 int
3368 bckend_word( 3368 bckend_word(
3369 long count, 3369 long count,
3370 int bigword, /* TRUE for "B" */ 3370 int bigword, // TRUE for "B"
3371 int eol) /* TRUE: stop at end of line. */ 3371 int eol) // TRUE: stop at end of line.
3372 { 3372 {
3373 int sclass; /* starting class */ 3373 int sclass; // starting class
3374 int i; 3374 int i;
3375 3375
3376 curwin->w_cursor.coladd = 0; 3376 curwin->w_cursor.coladd = 0;
3377 cls_bigword = bigword; 3377 cls_bigword = bigword;
3378 while (--count >= 0) 3378 while (--count >= 0)
3425 * Go back to the start of the word or the start of white space 3425 * Go back to the start of the word or the start of white space
3426 */ 3426 */
3427 static void 3427 static void
3428 back_in_line(void) 3428 back_in_line(void)
3429 { 3429 {
3430 int sclass; /* starting class */ 3430 int sclass; // starting class
3431 3431
3432 sclass = cls(); 3432 sclass = cls();
3433 for (;;) 3433 for (;;)
3434 { 3434 {
3435 if (curwin->w_cursor.col == 0) /* stop at start of line */ 3435 if (curwin->w_cursor.col == 0) // stop at start of line
3436 break; 3436 break;
3437 dec_cursor(); 3437 dec_cursor();
3438 if (cls() != sclass) /* stop at start of word */ 3438 if (cls() != sclass) // stop at start of word
3439 { 3439 {
3440 inc_cursor(); 3440 inc_cursor();
3441 break; 3441 break;
3442 } 3442 }
3443 } 3443 }
3463 * Skip count/2 sentences and count/2 separating white spaces. 3463 * Skip count/2 sentences and count/2 separating white spaces.
3464 */ 3464 */
3465 static void 3465 static void
3466 findsent_forward( 3466 findsent_forward(
3467 long count, 3467 long count,
3468 int at_start_sent) /* cursor is at start of sentence */ 3468 int at_start_sent) // cursor is at start of sentence
3469 { 3469 {
3470 while (count--) 3470 while (count--)
3471 { 3471 {
3472 findsent(FORWARD, 1L); 3472 findsent(FORWARD, 1L);
3473 if (at_start_sent) 3473 if (at_start_sent)
3484 */ 3484 */
3485 int 3485 int
3486 current_word( 3486 current_word(
3487 oparg_T *oap, 3487 oparg_T *oap,
3488 long count, 3488 long count,
3489 int include, /* TRUE: include word and white space */ 3489 int include, // TRUE: include word and white space
3490 int bigword) /* FALSE == word, TRUE == WORD */ 3490 int bigword) // FALSE == word, TRUE == WORD
3491 { 3491 {
3492 pos_T start_pos; 3492 pos_T start_pos;
3493 pos_T pos; 3493 pos_T pos;
3494 int inclusive = TRUE; 3494 int inclusive = TRUE;
3495 int include_white = FALSE; 3495 int include_white = FALSE;
3496 3496
3497 cls_bigword = bigword; 3497 cls_bigword = bigword;
3498 CLEAR_POS(&start_pos); 3498 CLEAR_POS(&start_pos);
3499 3499
3500 /* Correct cursor when 'selection' is exclusive */ 3500 // Correct cursor when 'selection' is exclusive
3501 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) 3501 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
3502 dec_cursor(); 3502 dec_cursor();
3503 3503
3504 /* 3504 /*
3505 * When Visual mode is not active, or when the VIsual area is only one 3505 * When Visual mode is not active, or when the VIsual area is only one
3542 include_white = TRUE; 3542 include_white = TRUE;
3543 } 3543 }
3544 3544
3545 if (VIsual_active) 3545 if (VIsual_active)
3546 { 3546 {
3547 /* should do something when inclusive == FALSE ! */ 3547 // should do something when inclusive == FALSE !
3548 VIsual = start_pos; 3548 VIsual = start_pos;
3549 redraw_curbuf_later(INVERTED); /* update the inversion */ 3549 redraw_curbuf_later(INVERTED); // update the inversion
3550 } 3550 }
3551 else 3551 else
3552 { 3552 {
3553 oap->start = start_pos; 3553 oap->start = start_pos;
3554 oap->motion_type = MCHAR; 3554 oap->motion_type = MCHAR;
3618 * better on the last word in a sentence (and "2daw" on last-but-one 3618 * better on the last word in a sentence (and "2daw" on last-but-one
3619 * word). Also when "2daw" deletes "word." at the end of the line 3619 * word). Also when "2daw" deletes "word." at the end of the line
3620 * (cursor is at start of next line). 3620 * (cursor is at start of next line).
3621 * But don't delete white space at start of line (indent). 3621 * But don't delete white space at start of line (indent).
3622 */ 3622 */
3623 pos = curwin->w_cursor; /* save cursor position */ 3623 pos = curwin->w_cursor; // save cursor position
3624 curwin->w_cursor = start_pos; 3624 curwin->w_cursor = start_pos;
3625 if (oneleft() == OK) 3625 if (oneleft() == OK)
3626 { 3626 {
3627 back_in_line(); 3627 back_in_line();
3628 if (cls() == 0 && curwin->w_cursor.col > 0) 3628 if (cls() == 0 && curwin->w_cursor.col > 0)
3631 VIsual = curwin->w_cursor; 3631 VIsual = curwin->w_cursor;
3632 else 3632 else
3633 oap->start = curwin->w_cursor; 3633 oap->start = curwin->w_cursor;
3634 } 3634 }
3635 } 3635 }
3636 curwin->w_cursor = pos; /* put cursor back at end */ 3636 curwin->w_cursor = pos; // put cursor back at end
3637 } 3637 }
3638 3638
3639 if (VIsual_active) 3639 if (VIsual_active)
3640 { 3640 {
3641 if (*p_sel == 'e' && inclusive && LTOREQ_POS(VIsual, curwin->w_cursor)) 3641 if (*p_sel == 'e' && inclusive && LTOREQ_POS(VIsual, curwin->w_cursor))
3642 inc_cursor(); 3642 inc_cursor();
3643 if (VIsual_mode == 'V') 3643 if (VIsual_mode == 'V')
3644 { 3644 {
3645 VIsual_mode = 'v'; 3645 VIsual_mode = 'v';
3646 redraw_cmdline = TRUE; /* show mode later */ 3646 redraw_cmdline = TRUE; // show mode later
3647 } 3647 }
3648 } 3648 }
3649 else 3649 else
3650 oap->inclusive = inclusive; 3650 oap->inclusive = inclusive;
3651 3651
3666 int at_start_sent; 3666 int at_start_sent;
3667 long ncount; 3667 long ncount;
3668 3668
3669 start_pos = curwin->w_cursor; 3669 start_pos = curwin->w_cursor;
3670 pos = start_pos; 3670 pos = start_pos;
3671 findsent(FORWARD, 1L); /* Find start of next sentence. */ 3671 findsent(FORWARD, 1L); // Find start of next sentence.
3672 3672
3673 /* 3673 /*
3674 * When the Visual area is bigger than one character: Extend it. 3674 * When the Visual area is bigger than one character: Extend it.
3675 */ 3675 */
3676 if (VIsual_active && !EQUAL_POS(start_pos, VIsual)) 3676 if (VIsual_active && !EQUAL_POS(start_pos, VIsual))
3699 } 3699 }
3700 if (!at_start_sent) 3700 if (!at_start_sent)
3701 { 3701 {
3702 findsent(BACKWARD, 1L); 3702 findsent(BACKWARD, 1L);
3703 if (EQUAL_POS(curwin->w_cursor, start_pos)) 3703 if (EQUAL_POS(curwin->w_cursor, start_pos))
3704 at_start_sent = TRUE; /* exactly at start of sentence */ 3704 at_start_sent = TRUE; // exactly at start of sentence
3705 else 3705 else
3706 /* inside a sentence, go to its end (start of next) */ 3706 // inside a sentence, go to its end (start of next)
3707 findsent(FORWARD, 1L); 3707 findsent(FORWARD, 1L);
3708 } 3708 }
3709 if (include) /* "as" gets twice as much as "is" */ 3709 if (include) // "as" gets twice as much as "is"
3710 count *= 2; 3710 count *= 2;
3711 while (count--) 3711 while (count--)
3712 { 3712 {
3713 if (at_start_sent) 3713 if (at_start_sent)
3714 find_first_blank(&curwin->w_cursor); 3714 find_first_blank(&curwin->w_cursor);
3727 * - just before or in the white space before a sentence 3727 * - just before or in the white space before a sentence
3728 * - in a sentence 3728 * - in a sentence
3729 */ 3729 */
3730 incl(&pos); 3730 incl(&pos);
3731 at_start_sent = TRUE; 3731 at_start_sent = TRUE;
3732 /* not just before a sentence */ 3732 // not just before a sentence
3733 if (!EQUAL_POS(pos, curwin->w_cursor)) 3733 if (!EQUAL_POS(pos, curwin->w_cursor))
3734 { 3734 {
3735 at_start_sent = FALSE; 3735 at_start_sent = FALSE;
3736 while (LT_POS(pos, curwin->w_cursor)) 3736 while (LT_POS(pos, curwin->w_cursor))
3737 { 3737 {
3741 at_start_sent = TRUE; 3741 at_start_sent = TRUE;
3742 break; 3742 break;
3743 } 3743 }
3744 incl(&pos); 3744 incl(&pos);
3745 } 3745 }
3746 if (at_start_sent) /* in the sentence */ 3746 if (at_start_sent) // in the sentence
3747 findsent(BACKWARD, 1L); 3747 findsent(BACKWARD, 1L);
3748 else /* in/before white before a sentence */ 3748 else // in/before white before a sentence
3749 curwin->w_cursor = start_pos; 3749 curwin->w_cursor = start_pos;
3750 } 3750 }
3751 3751
3752 if (include) /* "as" gets twice as much as "is" */ 3752 if (include) // "as" gets twice as much as "is"
3753 count *= 2; 3753 count *= 2;
3754 findsent_forward(count, at_start_sent); 3754 findsent_forward(count, at_start_sent);
3755 if (*p_sel == 'e') 3755 if (*p_sel == 'e')
3756 ++curwin->w_cursor.col; 3756 ++curwin->w_cursor.col;
3757 } 3757 }
3760 3760
3761 /* 3761 /*
3762 * If the cursor started on a blank, check if it is just before the start 3762 * If the cursor started on a blank, check if it is just before the start
3763 * of the next sentence. 3763 * of the next sentence.
3764 */ 3764 */
3765 while (c = gchar_pos(&pos), VIM_ISWHITE(c)) /* VIM_ISWHITE() is a macro */ 3765 while (c = gchar_pos(&pos), VIM_ISWHITE(c)) // VIM_ISWHITE() is a macro
3766 incl(&pos); 3766 incl(&pos);
3767 if (EQUAL_POS(pos, curwin->w_cursor)) 3767 if (EQUAL_POS(pos, curwin->w_cursor))
3768 { 3768 {
3769 start_blank = TRUE; 3769 start_blank = TRUE;
3770 find_first_blank(&start_pos); /* go back to first blank */ 3770 find_first_blank(&start_pos); // go back to first blank
3771 } 3771 }
3772 else 3772 else
3773 { 3773 {
3774 start_blank = FALSE; 3774 start_blank = FALSE;
3775 findsent(BACKWARD, 1L); 3775 findsent(BACKWARD, 1L);
3796 * If there are no trailing blanks, try to include leading blanks. 3796 * If there are no trailing blanks, try to include leading blanks.
3797 */ 3797 */
3798 if (start_blank) 3798 if (start_blank)
3799 { 3799 {
3800 find_first_blank(&curwin->w_cursor); 3800 find_first_blank(&curwin->w_cursor);
3801 c = gchar_pos(&curwin->w_cursor); /* VIM_ISWHITE() is a macro */ 3801 c = gchar_pos(&curwin->w_cursor); // VIM_ISWHITE() is a macro
3802 if (VIM_ISWHITE(c)) 3802 if (VIM_ISWHITE(c))
3803 decl(&curwin->w_cursor); 3803 decl(&curwin->w_cursor);
3804 } 3804 }
3805 else if (c = gchar_cursor(), !VIM_ISWHITE(c)) 3805 else if (c = gchar_cursor(), !VIM_ISWHITE(c))
3806 find_first_blank(&start_pos); 3806 find_first_blank(&start_pos);
3807 } 3807 }
3808 3808
3809 if (VIsual_active) 3809 if (VIsual_active)
3810 { 3810 {
3811 /* Avoid getting stuck with "is" on a single space before a sentence. */ 3811 // Avoid getting stuck with "is" on a single space before a sentence.
3812 if (EQUAL_POS(start_pos, curwin->w_cursor)) 3812 if (EQUAL_POS(start_pos, curwin->w_cursor))
3813 goto extend; 3813 goto extend;
3814 if (*p_sel == 'e') 3814 if (*p_sel == 'e')
3815 ++curwin->w_cursor.col; 3815 ++curwin->w_cursor.col;
3816 VIsual = start_pos; 3816 VIsual = start_pos;
3817 VIsual_mode = 'v'; 3817 VIsual_mode = 'v';
3818 redraw_cmdline = TRUE; /* show mode later */ 3818 redraw_cmdline = TRUE; // show mode later
3819 redraw_curbuf_later(INVERTED); /* update the inversion */ 3819 redraw_curbuf_later(INVERTED); // update the inversion
3820 } 3820 }
3821 else 3821 else
3822 { 3822 {
3823 /* include a newline after the sentence, if there is one */ 3823 // include a newline after the sentence, if there is one
3824 if (incl(&curwin->w_cursor) == -1) 3824 if (incl(&curwin->w_cursor) == -1)
3825 oap->inclusive = TRUE; 3825 oap->inclusive = TRUE;
3826 else 3826 else
3827 oap->inclusive = FALSE; 3827 oap->inclusive = FALSE;
3828 oap->start = start_pos; 3828 oap->start = start_pos;
3837 */ 3837 */
3838 int 3838 int
3839 current_block( 3839 current_block(
3840 oparg_T *oap, 3840 oparg_T *oap,
3841 long count, 3841 long count,
3842 int include, /* TRUE == include white space */ 3842 int include, // TRUE == include white space
3843 int what, /* '(', '{', etc. */ 3843 int what, // '(', '{', etc.
3844 int other) /* ')', '}', etc. */ 3844 int other) // ')', '}', etc.
3845 { 3845 {
3846 pos_T old_pos; 3846 pos_T old_pos;
3847 pos_T *pos = NULL; 3847 pos_T *pos = NULL;
3848 pos_T start_pos; 3848 pos_T start_pos;
3849 pos_T *end_pos; 3849 pos_T *end_pos;
3850 pos_T old_start, old_end; 3850 pos_T old_start, old_end;
3851 char_u *save_cpo; 3851 char_u *save_cpo;
3852 int sol = FALSE; /* '{' at start of line */ 3852 int sol = FALSE; // '{' at start of line
3853 3853
3854 old_pos = curwin->w_cursor; 3854 old_pos = curwin->w_cursor;
3855 old_end = curwin->w_cursor; /* remember where we started */ 3855 old_end = curwin->w_cursor; // remember where we started
3856 old_start = old_end; 3856 old_start = old_end;
3857 3857
3858 /* 3858 /*
3859 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive. 3859 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
3860 */ 3860 */
3861 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor)) 3861 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
3862 { 3862 {
3863 setpcmark(); 3863 setpcmark();
3864 if (what == '{') /* ignore indent */ 3864 if (what == '{') // ignore indent
3865 while (inindent(1)) 3865 while (inindent(1))
3866 if (inc_cursor() != 0) 3866 if (inc_cursor() != 0)
3867 break; 3867 break;
3868 if (gchar_cursor() == what) 3868 if (gchar_cursor() == what)
3869 /* cursor on '(' or '{', move cursor just after it */ 3869 // cursor on '(' or '{', move cursor just after it
3870 ++curwin->w_cursor.col; 3870 ++curwin->w_cursor.col;
3871 } 3871 }
3872 else if (LT_POS(VIsual, curwin->w_cursor)) 3872 else if (LT_POS(VIsual, curwin->w_cursor))
3873 { 3873 {
3874 old_start = VIsual; 3874 old_start = VIsual;
3875 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ 3875 curwin->w_cursor = VIsual; // cursor at low end of Visual
3876 } 3876 }
3877 else 3877 else
3878 old_end = VIsual; 3878 old_end = VIsual;
3879 3879
3880 /* 3880 /*
3888 while (count-- > 0) 3888 while (count-- > 0)
3889 { 3889 {
3890 if ((pos = findmatch(NULL, what)) == NULL) 3890 if ((pos = findmatch(NULL, what)) == NULL)
3891 break; 3891 break;
3892 curwin->w_cursor = *pos; 3892 curwin->w_cursor = *pos;
3893 start_pos = *pos; /* the findmatch for end_pos will overwrite *pos */ 3893 start_pos = *pos; // the findmatch for end_pos will overwrite *pos
3894 } 3894 }
3895 p_cpo = save_cpo; 3895 p_cpo = save_cpo;
3896 3896
3897 /* 3897 /*
3898 * Search for matching ')', '}', etc. 3898 * Search for matching ')', '}', etc.
3953 if (VIsual_active) 3953 if (VIsual_active)
3954 { 3954 {
3955 if (*p_sel == 'e') 3955 if (*p_sel == 'e')
3956 inc(&curwin->w_cursor); 3956 inc(&curwin->w_cursor);
3957 if (sol && gchar_cursor() != NUL) 3957 if (sol && gchar_cursor() != NUL)
3958 inc(&curwin->w_cursor); /* include the line break */ 3958 inc(&curwin->w_cursor); // include the line break
3959 VIsual = start_pos; 3959 VIsual = start_pos;
3960 VIsual_mode = 'v'; 3960 VIsual_mode = 'v';
3961 redraw_curbuf_later(INVERTED); /* update the inversion */ 3961 redraw_curbuf_later(INVERTED); // update the inversion
3962 showmode(); 3962 showmode();
3963 } 3963 }
3964 else 3964 else
3965 { 3965 {
3966 oap->start = start_pos; 3966 oap->start = start_pos;
3967 oap->motion_type = MCHAR; 3967 oap->motion_type = MCHAR;
3968 oap->inclusive = FALSE; 3968 oap->inclusive = FALSE;
3969 if (sol) 3969 if (sol)
3970 incl(&curwin->w_cursor); 3970 incl(&curwin->w_cursor);
3971 else if (LTOREQ_POS(start_pos, curwin->w_cursor)) 3971 else if (LTOREQ_POS(start_pos, curwin->w_cursor))
3972 /* Include the character under the cursor. */ 3972 // Include the character under the cursor.
3973 oap->inclusive = TRUE; 3973 oap->inclusive = TRUE;
3974 else 3974 else
3975 /* End is before the start (no text in between <>, [], etc.): don't 3975 // End is before the start (no text in between <>, [], etc.): don't
3976 * operate on any text. */ 3976 // operate on any text.
3977 curwin->w_cursor = start_pos; 3977 curwin->w_cursor = start_pos;
3978 } 3978 }
3979 3979
3980 return OK; 3980 return OK;
3981 } 3981 }
3996 3996
3997 if (enc_dbcs) 3997 if (enc_dbcs)
3998 { 3998 {
3999 char_u *lp = NULL; 3999 char_u *lp = NULL;
4000 4000
4001 /* We search forward until the cursor, because searching backwards is 4001 // We search forward until the cursor, because searching backwards is
4002 * very slow for DBCS encodings. */ 4002 // very slow for DBCS encodings.
4003 for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p)) 4003 for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p))
4004 if (*p == '>' || *p == '<') 4004 if (*p == '>' || *p == '<')
4005 { 4005 {
4006 lc = *p; 4006 lc = *p;
4007 lp = p; 4007 lp = p;
4008 } 4008 }
4009 if (*p != '<') /* check for '<' under cursor */ 4009 if (*p != '<') // check for '<' under cursor
4010 { 4010 {
4011 if (lc != '<') 4011 if (lc != '<')
4012 return FALSE; 4012 return FALSE;
4013 p = lp; 4013 p = lp;
4014 } 4014 }
4015 } 4015 }
4016 else 4016 else
4017 { 4017 {
4018 for (p = line + curwin->w_cursor.col; p > line; ) 4018 for (p = line + curwin->w_cursor.col; p > line; )
4019 { 4019 {
4020 if (*p == '<') /* find '<' under/before cursor */ 4020 if (*p == '<') // find '<' under/before cursor
4021 break; 4021 break;
4022 MB_PTR_BACK(line, p); 4022 MB_PTR_BACK(line, p);
4023 if (*p == '>') /* find '>' before cursor */ 4023 if (*p == '>') // find '>' before cursor
4024 break; 4024 break;
4025 } 4025 }
4026 if (*p != '<') 4026 if (*p != '<')
4027 return FALSE; 4027 return FALSE;
4028 } 4028 }
4030 pos.lnum = curwin->w_cursor.lnum; 4030 pos.lnum = curwin->w_cursor.lnum;
4031 pos.col = (colnr_T)(p - line); 4031 pos.col = (colnr_T)(p - line);
4032 4032
4033 MB_PTR_ADV(p); 4033 MB_PTR_ADV(p);
4034 if (end_tag) 4034 if (end_tag)
4035 /* check that there is a '/' after the '<' */ 4035 // check that there is a '/' after the '<'
4036 return *p == '/'; 4036 return *p == '/';
4037 4037
4038 /* check that there is no '/' after the '<' */ 4038 // check that there is no '/' after the '<'
4039 if (*p == '/') 4039 if (*p == '/')
4040 return FALSE; 4040 return FALSE;
4041 4041
4042 /* check that the matching '>' is not preceded by '/' */ 4042 // check that the matching '>' is not preceded by '/'
4043 for (;;) 4043 for (;;)
4044 { 4044 {
4045 if (inc(&pos) < 0) 4045 if (inc(&pos) < 0)
4046 return FALSE; 4046 return FALSE;
4047 c = *ml_get_pos(&pos); 4047 c = *ml_get_pos(&pos);
4057 */ 4057 */
4058 int 4058 int
4059 current_tagblock( 4059 current_tagblock(
4060 oparg_T *oap, 4060 oparg_T *oap,
4061 long count_arg, 4061 long count_arg,
4062 int include) /* TRUE == include white space */ 4062 int include) // TRUE == include white space
4063 { 4063 {
4064 long count = count_arg; 4064 long count = count_arg;
4065 long n; 4065 long n;
4066 pos_T old_pos; 4066 pos_T old_pos;
4067 pos_T start_pos; 4067 pos_T start_pos;
4078 int is_inclusive = TRUE; 4078 int is_inclusive = TRUE;
4079 4079
4080 p_ws = FALSE; 4080 p_ws = FALSE;
4081 4081
4082 old_pos = curwin->w_cursor; 4082 old_pos = curwin->w_cursor;
4083 old_end = curwin->w_cursor; /* remember where we started */ 4083 old_end = curwin->w_cursor; // remember where we started
4084 old_start = old_end; 4084 old_start = old_end;
4085 if (!VIsual_active || *p_sel == 'e') 4085 if (!VIsual_active || *p_sel == 'e')
4086 decl(&old_end); /* old_end is inclusive */ 4086 decl(&old_end); // old_end is inclusive
4087 4087
4088 /* 4088 /*
4089 * If we start on "<aaa>" select that block. 4089 * If we start on "<aaa>" select that block.
4090 */ 4090 */
4091 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor)) 4091 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
4092 { 4092 {
4093 setpcmark(); 4093 setpcmark();
4094 4094
4095 /* ignore indent */ 4095 // ignore indent
4096 while (inindent(1)) 4096 while (inindent(1))
4097 if (inc_cursor() != 0) 4097 if (inc_cursor() != 0)
4098 break; 4098 break;
4099 4099
4100 if (in_html_tag(FALSE)) 4100 if (in_html_tag(FALSE))
4101 { 4101 {
4102 /* cursor on start tag, move to its '>' */ 4102 // cursor on start tag, move to its '>'
4103 while (*ml_get_cursor() != '>') 4103 while (*ml_get_cursor() != '>')
4104 if (inc_cursor() < 0) 4104 if (inc_cursor() < 0)
4105 break; 4105 break;
4106 } 4106 }
4107 else if (in_html_tag(TRUE)) 4107 else if (in_html_tag(TRUE))
4108 { 4108 {
4109 /* cursor on end tag, move to just before it */ 4109 // cursor on end tag, move to just before it
4110 while (*ml_get_cursor() != '<') 4110 while (*ml_get_cursor() != '<')
4111 if (dec_cursor() < 0) 4111 if (dec_cursor() < 0)
4112 break; 4112 break;
4113 dec_cursor(); 4113 dec_cursor();
4114 old_end = curwin->w_cursor; 4114 old_end = curwin->w_cursor;
4115 } 4115 }
4116 } 4116 }
4117 else if (LT_POS(VIsual, curwin->w_cursor)) 4117 else if (LT_POS(VIsual, curwin->w_cursor))
4118 { 4118 {
4119 old_start = VIsual; 4119 old_start = VIsual;
4120 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ 4120 curwin->w_cursor = VIsual; // cursor at low end of Visual
4121 } 4121 }
4122 else 4122 else
4123 old_end = VIsual; 4123 old_end = VIsual;
4124 4124
4125 again: 4125 again:
4171 vim_free(spat); 4171 vim_free(spat);
4172 vim_free(epat); 4172 vim_free(epat);
4173 4173
4174 if (r < 1 || LT_POS(curwin->w_cursor, old_end)) 4174 if (r < 1 || LT_POS(curwin->w_cursor, old_end))
4175 { 4175 {
4176 /* Can't find other end or it's before the previous end. Could be a 4176 // Can't find other end or it's before the previous end. Could be a
4177 * HTML tag that doesn't have a matching end. Search backwards for 4177 // HTML tag that doesn't have a matching end. Search backwards for
4178 * another starting tag. */ 4178 // another starting tag.
4179 count = 1; 4179 count = 1;
4180 curwin->w_cursor = start_pos; 4180 curwin->w_cursor = start_pos;
4181 goto again; 4181 goto again;
4182 } 4182 }
4183 4183
4184 if (do_include) 4184 if (do_include)
4185 { 4185 {
4186 /* Include up to the '>'. */ 4186 // Include up to the '>'.
4187 while (*ml_get_cursor() != '>') 4187 while (*ml_get_cursor() != '>')
4188 if (inc_cursor() < 0) 4188 if (inc_cursor() < 0)
4189 break; 4189 break;
4190 } 4190 }
4191 else 4191 else
4192 { 4192 {
4193 char_u *c = ml_get_cursor(); 4193 char_u *c = ml_get_cursor();
4194 4194
4195 /* Exclude the '<' of the end tag. 4195 // Exclude the '<' of the end tag.
4196 * If the closing tag is on new line, do not decrement cursor, but 4196 // If the closing tag is on new line, do not decrement cursor, but
4197 * make operation exclusive, so that the linefeed will be selected */ 4197 // make operation exclusive, so that the linefeed will be selected
4198 if (*c == '<' && !VIsual_active && curwin->w_cursor.col == 0) 4198 if (*c == '<' && !VIsual_active && curwin->w_cursor.col == 0)
4199 /* do not decrement cursor */ 4199 // do not decrement cursor
4200 is_inclusive = FALSE; 4200 is_inclusive = FALSE;
4201 else if (*c == '<') 4201 else if (*c == '<')
4202 dec_cursor(); 4202 dec_cursor();
4203 } 4203 }
4204 end_pos = curwin->w_cursor; 4204 end_pos = curwin->w_cursor;
4205 4205
4206 if (!do_include) 4206 if (!do_include)
4207 { 4207 {
4208 /* Exclude the start tag. */ 4208 // Exclude the start tag.
4209 curwin->w_cursor = start_pos; 4209 curwin->w_cursor = start_pos;
4210 while (inc_cursor() >= 0) 4210 while (inc_cursor() >= 0)
4211 if (*ml_get_cursor() == '>') 4211 if (*ml_get_cursor() == '>')
4212 { 4212 {
4213 inc_cursor(); 4213 inc_cursor();
4228 } 4228 }
4229 } 4229 }
4230 4230
4231 if (VIsual_active) 4231 if (VIsual_active)
4232 { 4232 {
4233 /* If the end is before the start there is no text between tags, select 4233 // If the end is before the start there is no text between tags, select
4234 * the char under the cursor. */ 4234 // the char under the cursor.
4235 if (LT_POS(end_pos, start_pos)) 4235 if (LT_POS(end_pos, start_pos))
4236 curwin->w_cursor = start_pos; 4236 curwin->w_cursor = start_pos;
4237 else if (*p_sel == 'e') 4237 else if (*p_sel == 'e')
4238 inc_cursor(); 4238 inc_cursor();
4239 VIsual = start_pos; 4239 VIsual = start_pos;
4240 VIsual_mode = 'v'; 4240 VIsual_mode = 'v';
4241 redraw_curbuf_later(INVERTED); /* update the inversion */ 4241 redraw_curbuf_later(INVERTED); // update the inversion
4242 showmode(); 4242 showmode();
4243 } 4243 }
4244 else 4244 else
4245 { 4245 {
4246 oap->start = start_pos; 4246 oap->start = start_pos;
4247 oap->motion_type = MCHAR; 4247 oap->motion_type = MCHAR;
4248 if (LT_POS(end_pos, start_pos)) 4248 if (LT_POS(end_pos, start_pos))
4249 { 4249 {
4250 /* End is before the start: there is no text between tags; operate 4250 // End is before the start: there is no text between tags; operate
4251 * on an empty area. */ 4251 // on an empty area.
4252 curwin->w_cursor = start_pos; 4252 curwin->w_cursor = start_pos;
4253 oap->inclusive = FALSE; 4253 oap->inclusive = FALSE;
4254 } 4254 }
4255 else 4255 else
4256 oap->inclusive = is_inclusive; 4256 oap->inclusive = is_inclusive;
4264 4264
4265 int 4265 int
4266 current_par( 4266 current_par(
4267 oparg_T *oap, 4267 oparg_T *oap,
4268 long count, 4268 long count,
4269 int include, /* TRUE == include white space */ 4269 int include, // TRUE == include white space
4270 int type) /* 'p' for paragraph, 'S' for section */ 4270 int type) // 'p' for paragraph, 'S' for section
4271 { 4271 {
4272 linenr_T start_lnum; 4272 linenr_T start_lnum;
4273 linenr_T end_lnum; 4273 linenr_T end_lnum;
4274 int white_in_front; 4274 int white_in_front;
4275 int dir; 4275 int dir;
4278 int retval = OK; 4278 int retval = OK;
4279 int do_white = FALSE; 4279 int do_white = FALSE;
4280 int t; 4280 int t;
4281 int i; 4281 int i;
4282 4282
4283 if (type == 'S') /* not implemented yet */ 4283 if (type == 'S') // not implemented yet
4284 return FAIL; 4284 return FAIL;
4285 4285
4286 start_lnum = curwin->w_cursor.lnum; 4286 start_lnum = curwin->w_cursor.lnum;
4287 4287
4288 /* 4288 /*
4343 * First move back to the start_lnum of the paragraph or white lines 4343 * First move back to the start_lnum of the paragraph or white lines
4344 */ 4344 */
4345 white_in_front = linewhite(start_lnum); 4345 white_in_front = linewhite(start_lnum);
4346 while (start_lnum > 1) 4346 while (start_lnum > 1)
4347 { 4347 {
4348 if (white_in_front) /* stop at first white line */ 4348 if (white_in_front) // stop at first white line
4349 { 4349 {
4350 if (!linewhite(start_lnum - 1)) 4350 if (!linewhite(start_lnum - 1))
4351 break; 4351 break;
4352 } 4352 }
4353 else /* stop at first non-white line of start of paragraph */ 4353 else // stop at first non-white line of start of paragraph
4354 { 4354 {
4355 if (linewhite(start_lnum - 1) || startPS(start_lnum, 0, 0)) 4355 if (linewhite(start_lnum - 1) || startPS(start_lnum, 0, 0))
4356 break; 4356 break;
4357 } 4357 }
4358 --start_lnum; 4358 --start_lnum;
4409 while (start_lnum > 1 && linewhite(start_lnum - 1)) 4409 while (start_lnum > 1 && linewhite(start_lnum - 1))
4410 --start_lnum; 4410 --start_lnum;
4411 4411
4412 if (VIsual_active) 4412 if (VIsual_active)
4413 { 4413 {
4414 /* Problem: when doing "Vipipip" nothing happens in a single white 4414 // Problem: when doing "Vipipip" nothing happens in a single white
4415 * line, we get stuck there. Trap this here. */ 4415 // line, we get stuck there. Trap this here.
4416 if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum) 4416 if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum)
4417 goto extend; 4417 goto extend;
4418 if (VIsual.lnum != start_lnum) 4418 if (VIsual.lnum != start_lnum)
4419 { 4419 {
4420 VIsual.lnum = start_lnum; 4420 VIsual.lnum = start_lnum;
4421 VIsual.col = 0; 4421 VIsual.col = 0;
4422 } 4422 }
4423 VIsual_mode = 'V'; 4423 VIsual_mode = 'V';
4424 redraw_curbuf_later(INVERTED); /* update the inversion */ 4424 redraw_curbuf_later(INVERTED); // update the inversion
4425 showmode(); 4425 showmode();
4426 } 4426 }
4427 else 4427 else
4428 { 4428 {
4429 oap->start.lnum = start_lnum; 4429 oap->start.lnum = start_lnum;
4445 static int 4445 static int
4446 find_next_quote( 4446 find_next_quote(
4447 char_u *line, 4447 char_u *line,
4448 int col, 4448 int col,
4449 int quotechar, 4449 int quotechar,
4450 char_u *escape) /* escape characters, can be NULL */ 4450 char_u *escape) // escape characters, can be NULL
4451 { 4451 {
4452 int c; 4452 int c;
4453 4453
4454 for (;;) 4454 for (;;)
4455 { 4455 {
4477 static int 4477 static int
4478 find_prev_quote( 4478 find_prev_quote(
4479 char_u *line, 4479 char_u *line,
4480 int col_start, 4480 int col_start,
4481 int quotechar, 4481 int quotechar,
4482 char_u *escape) /* escape characters, can be NULL */ 4482 char_u *escape) // escape characters, can be NULL
4483 { 4483 {
4484 int n; 4484 int n;
4485 4485
4486 while (col_start > 0) 4486 while (col_start > 0)
4487 { 4487 {
4491 if (escape != NULL) 4491 if (escape != NULL)
4492 while (col_start - n > 0 && vim_strchr(escape, 4492 while (col_start - n > 0 && vim_strchr(escape,
4493 line[col_start - n - 1]) != NULL) 4493 line[col_start - n - 1]) != NULL)
4494 ++n; 4494 ++n;
4495 if (n & 1) 4495 if (n & 1)
4496 col_start -= n; /* uneven number of escape chars, skip it */ 4496 col_start -= n; // uneven number of escape chars, skip it
4497 else if (line[col_start] == quotechar) 4497 else if (line[col_start] == quotechar)
4498 break; 4498 break;
4499 } 4499 }
4500 return col_start; 4500 return col_start;
4501 } 4501 }
4526 // When 'selection' is "exclusive" move the cursor to where it would be 4526 // When 'selection' is "exclusive" move the cursor to where it would be
4527 // with 'selection' "inclusive", so that the logic is the same for both. 4527 // with 'selection' "inclusive", so that the logic is the same for both.
4528 // The cursor then is moved forward after adjusting the area. 4528 // The cursor then is moved forward after adjusting the area.
4529 if (VIsual_active) 4529 if (VIsual_active)
4530 { 4530 {
4531 /* this only works within one line */ 4531 // this only works within one line
4532 if (VIsual.lnum != curwin->w_cursor.lnum) 4532 if (VIsual.lnum != curwin->w_cursor.lnum)
4533 return FALSE; 4533 return FALSE;
4534 4534
4535 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); 4535 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor);
4536 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); 4536 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor);
4560 } 4560 }
4561 } 4561 }
4562 4562
4563 if (!vis_empty) 4563 if (!vis_empty)
4564 { 4564 {
4565 /* Check if the existing selection exactly spans the text inside 4565 // Check if the existing selection exactly spans the text inside
4566 * quotes. */ 4566 // quotes.
4567 if (vis_bef_curs) 4567 if (vis_bef_curs)
4568 { 4568 {
4569 inside_quotes = VIsual.col > 0 4569 inside_quotes = VIsual.col > 0
4570 && line[VIsual.col - 1] == quotechar 4570 && line[VIsual.col - 1] == quotechar
4571 && line[curwin->w_cursor.col] != NUL 4571 && line[curwin->w_cursor.col] != NUL
4581 && line[VIsual.col + 1] == quotechar; 4581 && line[VIsual.col + 1] == quotechar;
4582 i = curwin->w_cursor.col; 4582 i = curwin->w_cursor.col;
4583 col_end = VIsual.col; 4583 col_end = VIsual.col;
4584 } 4584 }
4585 4585
4586 /* Find out if we have a quote in the selection. */ 4586 // Find out if we have a quote in the selection.
4587 while (i <= col_end) 4587 while (i <= col_end)
4588 if (line[i++] == quotechar) 4588 if (line[i++] == quotechar)
4589 { 4589 {
4590 selected_quote = TRUE; 4590 selected_quote = TRUE;
4591 break; 4591 break;
4592 } 4592 }
4593 } 4593 }
4594 4594
4595 if (!vis_empty && line[col_start] == quotechar) 4595 if (!vis_empty && line[col_start] == quotechar)
4596 { 4596 {
4597 /* Already selecting something and on a quote character. Find the 4597 // Already selecting something and on a quote character. Find the
4598 * next quoted string. */ 4598 // next quoted string.
4599 if (vis_bef_curs) 4599 if (vis_bef_curs)
4600 { 4600 {
4601 /* Assume we are on a closing quote: move to after the next 4601 // Assume we are on a closing quote: move to after the next
4602 * opening quote. */ 4602 // opening quote.
4603 col_start = find_next_quote(line, col_start + 1, quotechar, NULL); 4603 col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
4604 if (col_start < 0) 4604 if (col_start < 0)
4605 goto abort_search; 4605 goto abort_search;
4606 col_end = find_next_quote(line, col_start + 1, quotechar, 4606 col_end = find_next_quote(line, col_start + 1, quotechar,
4607 curbuf->b_p_qe); 4607 curbuf->b_p_qe);
4608 if (col_end < 0) 4608 if (col_end < 0)
4609 { 4609 {
4610 /* We were on a starting quote perhaps? */ 4610 // We were on a starting quote perhaps?
4611 col_end = col_start; 4611 col_end = col_start;
4612 col_start = curwin->w_cursor.col; 4612 col_start = curwin->w_cursor.col;
4613 } 4613 }
4614 } 4614 }
4615 else 4615 else
4619 goto abort_search; 4619 goto abort_search;
4620 col_start = find_prev_quote(line, col_end, quotechar, 4620 col_start = find_prev_quote(line, col_end, quotechar,
4621 curbuf->b_p_qe); 4621 curbuf->b_p_qe);
4622 if (line[col_start] != quotechar) 4622 if (line[col_start] != quotechar)
4623 { 4623 {
4624 /* We were on an ending quote perhaps? */ 4624 // We were on an ending quote perhaps?
4625 col_start = col_end; 4625 col_start = col_end;
4626 col_end = curwin->w_cursor.col; 4626 col_end = curwin->w_cursor.col;
4627 } 4627 }
4628 } 4628 }
4629 } 4629 }
4639 first_col = find_next_quote(line, col_start, quotechar, NULL); 4639 first_col = find_next_quote(line, col_start, quotechar, NULL);
4640 else 4640 else
4641 first_col = find_prev_quote(line, col_start, quotechar, NULL); 4641 first_col = find_prev_quote(line, col_start, quotechar, NULL);
4642 } 4642 }
4643 4643
4644 /* The cursor is on a quote, we don't know if it's the opening or 4644 // The cursor is on a quote, we don't know if it's the opening or
4645 * closing quote. Search from the start of the line to find out. 4645 // closing quote. Search from the start of the line to find out.
4646 * Also do this when there is a Visual area, a' may leave the cursor 4646 // Also do this when there is a Visual area, a' may leave the cursor
4647 * in between two strings. */ 4647 // in between two strings.
4648 col_start = 0; 4648 col_start = 0;
4649 for (;;) 4649 for (;;)
4650 { 4650 {
4651 /* Find open quote character. */ 4651 // Find open quote character.
4652 col_start = find_next_quote(line, col_start, quotechar, NULL); 4652 col_start = find_next_quote(line, col_start, quotechar, NULL);
4653 if (col_start < 0 || col_start > first_col) 4653 if (col_start < 0 || col_start > first_col)
4654 goto abort_search; 4654 goto abort_search;
4655 /* Find close quote character. */ 4655 // Find close quote character.
4656 col_end = find_next_quote(line, col_start + 1, quotechar, 4656 col_end = find_next_quote(line, col_start + 1, quotechar,
4657 curbuf->b_p_qe); 4657 curbuf->b_p_qe);
4658 if (col_end < 0) 4658 if (col_end < 0)
4659 goto abort_search; 4659 goto abort_search;
4660 /* If is cursor between start and end quote character, it is 4660 // If is cursor between start and end quote character, it is
4661 * target text object. */ 4661 // target text object.
4662 if (col_start <= first_col && first_col <= col_end) 4662 if (col_start <= first_col && first_col <= col_end)
4663 break; 4663 break;
4664 col_start = col_end + 1; 4664 col_start = col_end + 1;
4665 } 4665 }
4666 } 4666 }
4667 else 4667 else
4668 { 4668 {
4669 /* Search backward for a starting quote. */ 4669 // Search backward for a starting quote.
4670 col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe); 4670 col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe);
4671 if (line[col_start] != quotechar) 4671 if (line[col_start] != quotechar)
4672 { 4672 {
4673 /* No quote before the cursor, look after the cursor. */ 4673 // No quote before the cursor, look after the cursor.
4674 col_start = find_next_quote(line, col_start, quotechar, NULL); 4674 col_start = find_next_quote(line, col_start, quotechar, NULL);
4675 if (col_start < 0) 4675 if (col_start < 0)
4676 goto abort_search; 4676 goto abort_search;
4677 } 4677 }
4678 4678
4679 /* Find close quote character. */ 4679 // Find close quote character.
4680 col_end = find_next_quote(line, col_start + 1, quotechar, 4680 col_end = find_next_quote(line, col_start + 1, quotechar,
4681 curbuf->b_p_qe); 4681 curbuf->b_p_qe);
4682 if (col_end < 0) 4682 if (col_end < 0)
4683 goto abort_search; 4683 goto abort_search;
4684 } 4684 }
4685 4685
4686 /* When "include" is TRUE, include spaces after closing quote or before 4686 // When "include" is TRUE, include spaces after closing quote or before
4687 * the starting quote. */ 4687 // the starting quote.
4688 if (include) 4688 if (include)
4689 { 4689 {
4690 if (VIM_ISWHITE(line[col_end + 1])) 4690 if (VIM_ISWHITE(line[col_end + 1]))
4691 while (VIM_ISWHITE(line[col_end + 1])) 4691 while (VIM_ISWHITE(line[col_end + 1]))
4692 ++col_end; 4692 ++col_end;
4693 else 4693 else
4694 while (col_start > 0 && VIM_ISWHITE(line[col_start - 1])) 4694 while (col_start > 0 && VIM_ISWHITE(line[col_start - 1]))
4695 --col_start; 4695 --col_start;
4696 } 4696 }
4697 4697
4698 /* Set start position. After vi" another i" must include the ". 4698 // Set start position. After vi" another i" must include the ".
4699 * For v2i" include the quotes. */ 4699 // For v2i" include the quotes.
4700 if (!include && count < 2 && (vis_empty || !inside_quotes)) 4700 if (!include && count < 2 && (vis_empty || !inside_quotes))
4701 ++col_start; 4701 ++col_start;
4702 curwin->w_cursor.col = col_start; 4702 curwin->w_cursor.col = col_start;
4703 if (VIsual_active) 4703 if (VIsual_active)
4704 { 4704 {
4705 /* Set the start of the Visual area when the Visual area was empty, we 4705 // Set the start of the Visual area when the Visual area was empty, we
4706 * were just inside quotes or the Visual area didn't start at a quote 4706 // were just inside quotes or the Visual area didn't start at a quote
4707 * and didn't include a quote. 4707 // and didn't include a quote.
4708 */
4709 if (vis_empty 4708 if (vis_empty
4710 || (vis_bef_curs 4709 || (vis_bef_curs
4711 && !selected_quote 4710 && !selected_quote
4712 && (inside_quotes 4711 && (inside_quotes
4713 || (line[VIsual.col] != quotechar 4712 || (line[VIsual.col] != quotechar
4722 { 4721 {
4723 oap->start = curwin->w_cursor; 4722 oap->start = curwin->w_cursor;
4724 oap->motion_type = MCHAR; 4723 oap->motion_type = MCHAR;
4725 } 4724 }
4726 4725
4727 /* Set end position. */ 4726 // Set end position.
4728 curwin->w_cursor.col = col_end; 4727 curwin->w_cursor.col = col_end;
4729 if ((include || count > 1 /* After vi" another i" must include the ". */ 4728 if ((include || count > 1 // After vi" another i" must include the ".
4730 || (!vis_empty && inside_quotes) 4729 || (!vis_empty && inside_quotes)
4731 ) && inc_cursor() == 2) 4730 ) && inc_cursor() == 2)
4732 inclusive = TRUE; 4731 inclusive = TRUE;
4733 if (VIsual_active) 4732 if (VIsual_active)
4734 { 4733 {
4738 if (*p_sel != 'e') 4737 if (*p_sel != 'e')
4739 dec_cursor(); 4738 dec_cursor();
4740 } 4739 }
4741 else 4740 else
4742 { 4741 {
4743 /* Cursor is at start of Visual area. Set the end of the Visual 4742 // Cursor is at start of Visual area. Set the end of the Visual
4744 * area when it was just inside quotes or it didn't end at a 4743 // area when it was just inside quotes or it didn't end at a
4745 * quote. */ 4744 // quote.
4746 if (inside_quotes 4745 if (inside_quotes
4747 || (!selected_quote 4746 || (!selected_quote
4748 && line[VIsual.col] != quotechar 4747 && line[VIsual.col] != quotechar
4749 && (line[VIsual.col] == NUL 4748 && (line[VIsual.col] == NUL
4750 || line[VIsual.col + 1] != quotechar))) 4749 || line[VIsual.col + 1] != quotechar)))
4755 curwin->w_cursor.col = col_start; 4754 curwin->w_cursor.col = col_start;
4756 } 4755 }
4757 if (VIsual_mode == 'V') 4756 if (VIsual_mode == 'V')
4758 { 4757 {
4759 VIsual_mode = 'v'; 4758 VIsual_mode = 'v';
4760 redraw_cmdline = TRUE; /* show mode later */ 4759 redraw_cmdline = TRUE; // show mode later
4761 } 4760 }
4762 } 4761 }
4763 else 4762 else
4764 { 4763 {
4765 /* Set inclusive and other oap's flags. */ 4764 // Set inclusive and other oap's flags.
4766 oap->inclusive = inclusive; 4765 oap->inclusive = inclusive;
4767 } 4766 }
4768 4767
4769 return OK; 4768 return OK;
4770 4769
4782 } 4781 }
4783 } 4782 }
4784 return FALSE; 4783 return FALSE;
4785 } 4784 }
4786 4785
4787 #endif /* FEAT_TEXTOBJ */ 4786 #endif // FEAT_TEXTOBJ
4788 4787
4789 /* 4788 /*
4790 * Check if the pattern is zero-width. 4789 * Check if the pattern is zero-width.
4791 * If move is TRUE, check from the beginning of the buffer, else from position 4790 * If move is TRUE, check from the beginning of the buffer, else from position
4792 * "cur". 4791 * "cur".
4873 char_u old_p_ws = p_ws; 4872 char_u old_p_ws = p_ws;
4874 int flags = 0; 4873 int flags = 0;
4875 pos_T save_VIsual = VIsual; 4874 pos_T save_VIsual = VIsual;
4876 int zero_width; 4875 int zero_width;
4877 4876
4878 /* Correct cursor when 'selection' is exclusive */ 4877 // Correct cursor when 'selection' is exclusive
4879 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) 4878 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
4880 dec_cursor(); 4879 dec_cursor();
4881 4880
4882 orig_pos = pos = curwin->w_cursor; 4881 orig_pos = pos = curwin->w_cursor;
4883 if (VIsual_active) 4882 if (VIsual_active)
4886 incl(&pos); 4885 incl(&pos);
4887 else 4886 else
4888 decl(&pos); 4887 decl(&pos);
4889 } 4888 }
4890 4889
4891 /* Is the pattern is zero-width?, this time, don't care about the direction 4890 // Is the pattern is zero-width?, this time, don't care about the direction
4892 */
4893 zero_width = is_zero_width(spats[last_idx].pat, TRUE, &curwin->w_cursor, 4891 zero_width = is_zero_width(spats[last_idx].pat, TRUE, &curwin->w_cursor,
4894 FORWARD); 4892 FORWARD);
4895 if (zero_width == -1) 4893 if (zero_width == -1)
4896 return FAIL; /* pattern not found */ 4894 return FAIL; // pattern not found
4897 4895
4898 /* 4896 /*
4899 * The trick is to first search backwards and then search forward again, 4897 * The trick is to first search backwards and then search forward again,
4900 * so that a match at the current cursor position will be correctly 4898 * so that a match at the current cursor position will be correctly
4901 * captured. 4899 * captured.
4921 spats[last_idx].pat, (long) (i ? count : 1), 4919 spats[last_idx].pat, (long) (i ? count : 1),
4922 SEARCH_KEEP | flags, RE_SEARCH, NULL); 4920 SEARCH_KEEP | flags, RE_SEARCH, NULL);
4923 4921
4924 p_ws = old_p_ws; 4922 p_ws = old_p_ws;
4925 4923
4926 /* First search may fail, but then start searching from the 4924 // First search may fail, but then start searching from the
4927 * beginning of the file (cursor might be on the search match) 4925 // beginning of the file (cursor might be on the search match)
4928 * except when Visual mode is active, so that extending the visual 4926 // except when Visual mode is active, so that extending the visual
4929 * selection works. */ 4927 // selection works.
4930 if (i == 1 && !result) /* not found, abort */ 4928 if (i == 1 && !result) // not found, abort
4931 { 4929 {
4932 curwin->w_cursor = orig_pos; 4930 curwin->w_cursor = orig_pos;
4933 if (VIsual_active) 4931 if (VIsual_active)
4934 VIsual = save_VIsual; 4932 VIsual = save_VIsual;
4935 return FAIL; 4933 return FAIL;
4936 } 4934 }
4937 else if (i == 0 && !result) 4935 else if (i == 0 && !result)
4938 { 4936 {
4939 if (forward) 4937 if (forward)
4940 { 4938 {
4941 /* try again from start of buffer */ 4939 // try again from start of buffer
4942 CLEAR_POS(&pos); 4940 CLEAR_POS(&pos);
4943 } 4941 }
4944 else 4942 else
4945 { 4943 {
4946 /* try again from end of buffer */ 4944 // try again from end of buffer
4947 /* searching backwards, so set pos to last line and col */ 4945 // searching backwards, so set pos to last line and col
4948 pos.lnum = curwin->w_buffer->b_ml.ml_line_count; 4946 pos.lnum = curwin->w_buffer->b_ml.ml_line_count;
4949 pos.col = (colnr_T)STRLEN( 4947 pos.col = (colnr_T)STRLEN(
4950 ml_get(curwin->w_buffer->b_ml.ml_line_count)); 4948 ml_get(curwin->w_buffer->b_ml.ml_line_count));
4951 } 4949 }
4952 } 4950 }
4966 VIsual_active = TRUE; 4964 VIsual_active = TRUE;
4967 VIsual_mode = 'v'; 4965 VIsual_mode = 'v';
4968 4966
4969 if (*p_sel == 'e') 4967 if (*p_sel == 'e')
4970 { 4968 {
4971 /* Correction for exclusive selection depends on the direction. */ 4969 // Correction for exclusive selection depends on the direction.
4972 if (forward && LTOREQ_POS(VIsual, curwin->w_cursor)) 4970 if (forward && LTOREQ_POS(VIsual, curwin->w_cursor))
4973 inc_cursor(); 4971 inc_cursor();
4974 else if (!forward && LTOREQ_POS(curwin->w_cursor, VIsual)) 4972 else if (!forward && LTOREQ_POS(curwin->w_cursor, VIsual))
4975 inc(&VIsual); 4973 inc(&VIsual);
4976 } 4974 }
4981 #endif 4979 #endif
4982 4980
4983 may_start_select('c'); 4981 may_start_select('c');
4984 setmouse(); 4982 setmouse();
4985 #ifdef FEAT_CLIPBOARD 4983 #ifdef FEAT_CLIPBOARD
4986 /* Make sure the clipboard gets updated. Needed because start and 4984 // Make sure the clipboard gets updated. Needed because start and
4987 * end are still the same, and the selection needs to be owned */ 4985 // end are still the same, and the selection needs to be owned
4988 clip_star.vmode = NUL; 4986 clip_star.vmode = NUL;
4989 #endif 4987 #endif
4990 redraw_curbuf_later(INVERTED); 4988 redraw_curbuf_later(INVERTED);
4991 showmode(); 4989 showmode();
4992 4990
5145 * Find identifiers or defines in included files. 5143 * Find identifiers or defines in included files.
5146 * If p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase. 5144 * If p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase.
5147 */ 5145 */
5148 void 5146 void
5149 find_pattern_in_path( 5147 find_pattern_in_path(
5150 char_u *ptr, /* pointer to search pattern */ 5148 char_u *ptr, // pointer to search pattern
5151 int dir UNUSED, /* direction of expansion */ 5149 int dir UNUSED, // direction of expansion
5152 int len, /* length of search pattern */ 5150 int len, // length of search pattern
5153 int whole, /* match whole words only */ 5151 int whole, // match whole words only
5154 int skip_comments, /* don't match inside comments */ 5152 int skip_comments, // don't match inside comments
5155 int type, /* Type of search; are we looking for a type? 5153 int type, // Type of search; are we looking for a type?
5156 a macro? */ 5154 // a macro?
5157 long count, 5155 long count,
5158 int action, /* What to do when we find it */ 5156 int action, // What to do when we find it
5159 linenr_T start_lnum, /* first line to start searching */ 5157 linenr_T start_lnum, // first line to start searching
5160 linenr_T end_lnum) /* last line for searching */ 5158 linenr_T end_lnum) // last line for searching
5161 { 5159 {
5162 SearchedFile *files; /* Stack of included files */ 5160 SearchedFile *files; // Stack of included files
5163 SearchedFile *bigger; /* When we need more space */ 5161 SearchedFile *bigger; // When we need more space
5164 int max_path_depth = 50; 5162 int max_path_depth = 50;
5165 long match_count = 1; 5163 long match_count = 1;
5166 5164
5167 char_u *pat; 5165 char_u *pat;
5168 char_u *new_fname; 5166 char_u *new_fname;
5169 char_u *curr_fname = curbuf->b_fname; 5167 char_u *curr_fname = curbuf->b_fname;
5170 char_u *prev_fname = NULL; 5168 char_u *prev_fname = NULL;
5171 linenr_T lnum; 5169 linenr_T lnum;
5172 int depth; 5170 int depth;
5173 int depth_displayed; /* For type==CHECK_PATH */ 5171 int depth_displayed; // For type==CHECK_PATH
5174 int old_files; 5172 int old_files;
5175 int already_searched; 5173 int already_searched;
5176 char_u *file_line; 5174 char_u *file_line;
5177 char_u *line; 5175 char_u *line;
5178 char_u *p; 5176 char_u *p;
5199 file_line = alloc(LSIZE); 5197 file_line = alloc(LSIZE);
5200 if (file_line == NULL) 5198 if (file_line == NULL)
5201 return; 5199 return;
5202 5200
5203 if (type != CHECK_PATH && type != FIND_DEFINE 5201 if (type != CHECK_PATH && type != FIND_DEFINE
5204 /* when CONT_SOL is set compare "ptr" with the beginning of the line 5202 // when CONT_SOL is set compare "ptr" with the beginning of the line
5205 * is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo */ 5203 // is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo
5206 && !(compl_cont_status & CONT_SOL)) 5204 && !(compl_cont_status & CONT_SOL))
5207 { 5205 {
5208 pat = alloc(len + 5); 5206 pat = alloc(len + 5);
5209 if (pat == NULL) 5207 if (pat == NULL)
5210 goto fpip_end; 5208 goto fpip_end;
5211 sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr); 5209 sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
5212 /* ignore case according to p_ic, p_scs and pat */ 5210 // ignore case according to p_ic, p_scs and pat
5213 regmatch.rm_ic = ignorecase(pat); 5211 regmatch.rm_ic = ignorecase(pat);
5214 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); 5212 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
5215 vim_free(pat); 5213 vim_free(pat);
5216 if (regmatch.regprog == NULL) 5214 if (regmatch.regprog == NULL)
5217 goto fpip_end; 5215 goto fpip_end;
5220 if (*inc_opt != NUL) 5218 if (*inc_opt != NUL)
5221 { 5219 {
5222 incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0); 5220 incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0);
5223 if (incl_regmatch.regprog == NULL) 5221 if (incl_regmatch.regprog == NULL)
5224 goto fpip_end; 5222 goto fpip_end;
5225 incl_regmatch.rm_ic = FALSE; /* don't ignore case in incl. pat. */ 5223 incl_regmatch.rm_ic = FALSE; // don't ignore case in incl. pat.
5226 } 5224 }
5227 if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL)) 5225 if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL))
5228 { 5226 {
5229 def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL 5227 def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL
5230 ? p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0); 5228 ? p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0);
5231 if (def_regmatch.regprog == NULL) 5229 if (def_regmatch.regprog == NULL)
5232 goto fpip_end; 5230 goto fpip_end;
5233 def_regmatch.rm_ic = FALSE; /* don't ignore case in define pat. */ 5231 def_regmatch.rm_ic = FALSE; // don't ignore case in define pat.
5234 } 5232 }
5235 files = lalloc_clear(max_path_depth * sizeof(SearchedFile), TRUE); 5233 files = lalloc_clear(max_path_depth * sizeof(SearchedFile), TRUE);
5236 if (files == NULL) 5234 if (files == NULL)
5237 goto fpip_end; 5235 goto fpip_end;
5238 old_files = max_path_depth; 5236 old_files = max_path_depth;
5239 depth = depth_displayed = -1; 5237 depth = depth_displayed = -1;
5240 5238
5241 lnum = start_lnum; 5239 lnum = start_lnum;
5242 if (end_lnum > curbuf->b_ml.ml_line_count) 5240 if (end_lnum > curbuf->b_ml.ml_line_count)
5243 end_lnum = curbuf->b_ml.ml_line_count; 5241 end_lnum = curbuf->b_ml.ml_line_count;
5244 if (lnum > end_lnum) /* do at least one line */ 5242 if (lnum > end_lnum) // do at least one line
5245 lnum = end_lnum; 5243 lnum = end_lnum;
5246 line = ml_get(lnum); 5244 line = ml_get(lnum);
5247 5245
5248 for (;;) 5246 for (;;)
5249 { 5247 {
5252 { 5250 {
5253 char_u *p_fname = (curr_fname == curbuf->b_fname) 5251 char_u *p_fname = (curr_fname == curbuf->b_fname)
5254 ? curbuf->b_ffname : curr_fname; 5252 ? curbuf->b_ffname : curr_fname;
5255 5253
5256 if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL) 5254 if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL)
5257 /* Use text from '\zs' to '\ze' (or end) of 'include'. */ 5255 // Use text from '\zs' to '\ze' (or end) of 'include'.
5258 new_fname = find_file_name_in_path(incl_regmatch.startp[0], 5256 new_fname = find_file_name_in_path(incl_regmatch.startp[0],
5259 (int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]), 5257 (int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]),
5260 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname); 5258 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname);
5261 else 5259 else
5262 /* Use text after match with 'include'. */ 5260 // Use text after match with 'include'.
5263 new_fname = file_name_in_line(incl_regmatch.endp[0], 0, 5261 new_fname = file_name_in_line(incl_regmatch.endp[0], 0,
5264 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); 5262 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL);
5265 already_searched = FALSE; 5263 already_searched = FALSE;
5266 if (new_fname != NULL) 5264 if (new_fname != NULL)
5267 { 5265 {
5268 /* Check whether we have already searched in this file */ 5266 // Check whether we have already searched in this file
5269 for (i = 0;; i++) 5267 for (i = 0;; i++)
5270 { 5268 {
5271 if (i == depth + 1) 5269 if (i == depth + 1)
5272 i = old_files; 5270 i = old_files;
5273 if (i == max_path_depth) 5271 if (i == max_path_depth)
5276 & FPC_SAME) 5274 & FPC_SAME)
5277 { 5275 {
5278 if (type != CHECK_PATH && 5276 if (type != CHECK_PATH &&
5279 action == ACTION_SHOW_ALL && files[i].matched) 5277 action == ACTION_SHOW_ALL && files[i].matched)
5280 { 5278 {
5281 msg_putchar('\n'); /* cursor below last one */ 5279 msg_putchar('\n'); // cursor below last one
5282 if (!got_int) /* don't display if 'q' 5280 if (!got_int) // don't display if 'q'
5283 typed at "--more--" 5281 // typed at "--more--"
5284 message */ 5282 // message
5285 { 5283 {
5286 msg_home_replace_hl(new_fname); 5284 msg_home_replace_hl(new_fname);
5287 msg_puts(_(" (includes previously listed match)")); 5285 msg_puts(_(" (includes previously listed match)"));
5288 prev_fname = NULL; 5286 prev_fname = NULL;
5289 } 5287 }
5297 5295
5298 if (type == CHECK_PATH && (action == ACTION_SHOW_ALL 5296 if (type == CHECK_PATH && (action == ACTION_SHOW_ALL
5299 || (new_fname == NULL && !already_searched))) 5297 || (new_fname == NULL && !already_searched)))
5300 { 5298 {
5301 if (did_show) 5299 if (did_show)
5302 msg_putchar('\n'); /* cursor below last one */ 5300 msg_putchar('\n'); // cursor below last one
5303 else 5301 else
5304 { 5302 {
5305 gotocmdline(TRUE); /* cursor at status line */ 5303 gotocmdline(TRUE); // cursor at status line
5306 msg_puts_title(_("--- Included files ")); 5304 msg_puts_title(_("--- Included files "));
5307 if (action != ACTION_SHOW_ALL) 5305 if (action != ACTION_SHOW_ALL)
5308 msg_puts_title(_("not found ")); 5306 msg_puts_title(_("not found "));
5309 msg_puts_title(_("in path ---\n")); 5307 msg_puts_title(_("in path ---\n"));
5310 } 5308 }
5315 for (i = 0; i < depth_displayed; i++) 5313 for (i = 0; i < depth_displayed; i++)
5316 msg_puts(" "); 5314 msg_puts(" ");
5317 msg_home_replace(files[depth_displayed].name); 5315 msg_home_replace(files[depth_displayed].name);
5318 msg_puts(" -->\n"); 5316 msg_puts(" -->\n");
5319 } 5317 }
5320 if (!got_int) /* don't display if 'q' typed 5318 if (!got_int) // don't display if 'q' typed
5321 for "--more--" message */ 5319 // for "--more--" message
5322 { 5320 {
5323 for (i = 0; i <= depth_displayed; i++) 5321 for (i = 0; i <= depth_displayed; i++)
5324 msg_puts(" "); 5322 msg_puts(" ");
5325 if (new_fname != NULL) 5323 if (new_fname != NULL)
5326 { 5324 {
5327 /* using "new_fname" is more reliable, e.g., when 5325 // using "new_fname" is more reliable, e.g., when
5328 * 'includeexpr' is set. */ 5326 // 'includeexpr' is set.
5329 msg_outtrans_attr(new_fname, HL_ATTR(HLF_D)); 5327 msg_outtrans_attr(new_fname, HL_ATTR(HLF_D));
5330 } 5328 }
5331 else 5329 else
5332 { 5330 {
5333 /* 5331 /*
5335 * Include the surrounding "" or <> if present. 5333 * Include the surrounding "" or <> if present.
5336 */ 5334 */
5337 if (inc_opt != NULL 5335 if (inc_opt != NULL
5338 && strstr((char *)inc_opt, "\\zs") != NULL) 5336 && strstr((char *)inc_opt, "\\zs") != NULL)
5339 { 5337 {
5340 /* pattern contains \zs, use the match */ 5338 // pattern contains \zs, use the match
5341 p = incl_regmatch.startp[0]; 5339 p = incl_regmatch.startp[0];
5342 i = (int)(incl_regmatch.endp[0] 5340 i = (int)(incl_regmatch.endp[0]
5343 - incl_regmatch.startp[0]); 5341 - incl_regmatch.startp[0]);
5344 } 5342 }
5345 else 5343 else
5346 { 5344 {
5347 /* find the file name after the end of the match */ 5345 // find the file name after the end of the match
5348 for (p = incl_regmatch.endp[0]; 5346 for (p = incl_regmatch.endp[0];
5349 *p && !vim_isfilec(*p); p++) 5347 *p && !vim_isfilec(*p); p++)
5350 ; 5348 ;
5351 for (i = 0; vim_isfilec(p[i]); i++) 5349 for (i = 0; vim_isfilec(p[i]); i++)
5352 ; 5350 ;
5353 } 5351 }
5354 5352
5355 if (i == 0) 5353 if (i == 0)
5356 { 5354 {
5357 /* Nothing found, use the rest of the line. */ 5355 // Nothing found, use the rest of the line.
5358 p = incl_regmatch.endp[0]; 5356 p = incl_regmatch.endp[0];
5359 i = (int)STRLEN(p); 5357 i = (int)STRLEN(p);
5360 } 5358 }
5361 /* Avoid checking before the start of the line, can 5359 // Avoid checking before the start of the line, can
5362 * happen if \zs appears in the regexp. */ 5360 // happen if \zs appears in the regexp.
5363 else if (p > line) 5361 else if (p > line)
5364 { 5362 {
5365 if (p[-1] == '"' || p[-1] == '<') 5363 if (p[-1] == '"' || p[-1] == '<')
5366 { 5364 {
5367 --p; 5365 --p;
5382 msg_puts(_(" (Already listed)")); 5380 msg_puts(_(" (Already listed)"));
5383 else 5381 else
5384 msg_puts(_(" NOT FOUND")); 5382 msg_puts(_(" NOT FOUND"));
5385 } 5383 }
5386 } 5384 }
5387 out_flush(); /* output each line directly */ 5385 out_flush(); // output each line directly
5388 } 5386 }
5389 5387
5390 if (new_fname != NULL) 5388 if (new_fname != NULL)
5391 { 5389 {
5392 /* Push the new file onto the file stack */ 5390 // Push the new file onto the file stack
5393 if (depth + 1 == old_files) 5391 if (depth + 1 == old_files)
5394 { 5392 {
5395 bigger = ALLOC_MULT(SearchedFile, max_path_depth * 2); 5393 bigger = ALLOC_MULT(SearchedFile, max_path_depth * 2);
5396 if (bigger != NULL) 5394 if (bigger != NULL)
5397 { 5395 {
5429 files[depth].name = curr_fname = new_fname; 5427 files[depth].name = curr_fname = new_fname;
5430 files[depth].lnum = 0; 5428 files[depth].lnum = 0;
5431 files[depth].matched = FALSE; 5429 files[depth].matched = FALSE;
5432 if (action == ACTION_EXPAND) 5430 if (action == ACTION_EXPAND)
5433 { 5431 {
5434 msg_hist_off = TRUE; /* reset in msg_trunc_attr() */ 5432 msg_hist_off = TRUE; // reset in msg_trunc_attr()
5435 vim_snprintf((char*)IObuff, IOSIZE, 5433 vim_snprintf((char*)IObuff, IOSIZE,
5436 _("Scanning included file: %s"), 5434 _("Scanning included file: %s"),
5437 (char *)new_fname); 5435 (char *)new_fname);
5438 msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R)); 5436 msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R));
5439 } 5437 }
5476 */ 5474 */
5477 if (def_regmatch.regprog == NULL || define_matched) 5475 if (def_regmatch.regprog == NULL || define_matched)
5478 { 5476 {
5479 if (define_matched || (compl_cont_status & CONT_SOL)) 5477 if (define_matched || (compl_cont_status & CONT_SOL))
5480 { 5478 {
5481 /* compare the first "len" chars from "ptr" */ 5479 // compare the first "len" chars from "ptr"
5482 startp = skipwhite(p); 5480 startp = skipwhite(p);
5483 if (p_ic) 5481 if (p_ic)
5484 matched = !MB_STRNICMP(startp, ptr, len); 5482 matched = !MB_STRNICMP(startp, ptr, len);
5485 else 5483 else
5486 matched = !STRNCMP(startp, ptr, len); 5484 matched = !STRNCMP(startp, ptr, len);
5519 if (matched 5517 if (matched
5520 && p[0] == '/' 5518 && p[0] == '/'
5521 && (p[1] == '*' || p[1] == '/')) 5519 && (p[1] == '*' || p[1] == '/'))
5522 { 5520 {
5523 matched = FALSE; 5521 matched = FALSE;
5524 /* After "//" all text is comment */ 5522 // After "//" all text is comment
5525 if (p[1] == '/') 5523 if (p[1] == '/')
5526 break; 5524 break;
5527 ++p; 5525 ++p;
5528 } 5526 }
5529 else if (!matched && p[0] == '*' && p[1] == '/') 5527 else if (!matched && p[0] == '*' && p[1] == '/')
5530 { 5528 {
5531 /* Can find match after "* /". */ 5529 // Can find match after "* /".
5532 matched = TRUE; 5530 matched = TRUE;
5533 ++p; 5531 ++p;
5534 } 5532 }
5535 } 5533 }
5536 } 5534 }
5559 p = find_word_end(p); 5557 p = find_word_end(p);
5560 i = (int)(p - aux); 5558 i = (int)(p - aux);
5561 5559
5562 if ((compl_cont_status & CONT_ADDING) && i == compl_length) 5560 if ((compl_cont_status & CONT_ADDING) && i == compl_length)
5563 { 5561 {
5564 /* IOSIZE > compl_length, so the STRNCPY works */ 5562 // IOSIZE > compl_length, so the STRNCPY works
5565 STRNCPY(IObuff, aux, i); 5563 STRNCPY(IObuff, aux, i);
5566 5564
5567 /* Get the next line: when "depth" < 0 from the current 5565 // Get the next line: when "depth" < 0 from the current
5568 * buffer, otherwise from the included file. Jump to 5566 // buffer, otherwise from the included file. Jump to
5569 * exit_matched when past the last line. */ 5567 // exit_matched when past the last line.
5570 if (depth < 0) 5568 if (depth < 0)
5571 { 5569 {
5572 if (lnum >= end_lnum) 5570 if (lnum >= end_lnum)
5573 goto exit_matched; 5571 goto exit_matched;
5574 line = ml_get(++lnum); 5572 line = ml_get(++lnum);
5575 } 5573 }
5576 else if (vim_fgets(line = file_line, 5574 else if (vim_fgets(line = file_line,
5577 LSIZE, files[depth].fp)) 5575 LSIZE, files[depth].fp))
5578 goto exit_matched; 5576 goto exit_matched;
5579 5577
5580 /* we read a line, set "already" to check this "line" later 5578 // we read a line, set "already" to check this "line" later
5581 * if depth >= 0 we'll increase files[depth].lnum far 5579 // if depth >= 0 we'll increase files[depth].lnum far
5582 * bellow -- Acevedo */ 5580 // bellow -- Acevedo
5583 already = aux = p = skipwhite(line); 5581 already = aux = p = skipwhite(line);
5584 p = find_word_start(p); 5582 p = find_word_start(p);
5585 p = find_word_end(p); 5583 p = find_word_end(p);
5586 if (p > aux) 5584 if (p > aux)
5587 { 5585 {
5588 if (*aux != ')' && IObuff[i-1] != TAB) 5586 if (*aux != ')' && IObuff[i-1] != TAB)
5589 { 5587 {
5590 if (IObuff[i-1] != ' ') 5588 if (IObuff[i-1] != ' ')
5591 IObuff[i++] = ' '; 5589 IObuff[i++] = ' ';
5592 /* IObuf =~ "\(\k\|\i\).* ", thus i >= 2*/ 5590 // IObuf =~ "\(\k\|\i\).* ", thus i >= 2
5593 if (p_js 5591 if (p_js
5594 && (IObuff[i-2] == '.' 5592 && (IObuff[i-2] == '.'
5595 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL 5593 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL
5596 && (IObuff[i-2] == '?' 5594 && (IObuff[i-2] == '?'
5597 || IObuff[i-2] == '!')))) 5595 || IObuff[i-2] == '!'))))
5598 IObuff[i++] = ' '; 5596 IObuff[i++] = ' ';
5599 } 5597 }
5600 /* copy as much as possible of the new word */ 5598 // copy as much as possible of the new word
5601 if (p - aux >= IOSIZE - i) 5599 if (p - aux >= IOSIZE - i)
5602 p = aux + IOSIZE - i - 1; 5600 p = aux + IOSIZE - i - 1;
5603 STRNCPY(IObuff + i, aux, p - aux); 5601 STRNCPY(IObuff + i, aux, p - aux);
5604 i += (int)(p - aux); 5602 i += (int)(p - aux);
5605 cont_s_ipos = TRUE; 5603 cont_s_ipos = TRUE;
5613 5611
5614 add_r = ins_compl_add_infercase(aux, i, p_ic, 5612 add_r = ins_compl_add_infercase(aux, i, p_ic,
5615 curr_fname == curbuf->b_fname ? NULL : curr_fname, 5613 curr_fname == curbuf->b_fname ? NULL : curr_fname,
5616 dir, cont_s_ipos); 5614 dir, cont_s_ipos);
5617 if (add_r == OK) 5615 if (add_r == OK)
5618 /* if dir was BACKWARD then honor it just once */ 5616 // if dir was BACKWARD then honor it just once
5619 dir = FORWARD; 5617 dir = FORWARD;
5620 else if (add_r == FAIL) 5618 else if (add_r == FAIL)
5621 break; 5619 break;
5622 } 5620 }
5623 else if (action == ACTION_SHOW_ALL) 5621 else if (action == ACTION_SHOW_ALL)
5624 { 5622 {
5625 found = TRUE; 5623 found = TRUE;
5626 if (!did_show) 5624 if (!did_show)
5627 gotocmdline(TRUE); /* cursor at status line */ 5625 gotocmdline(TRUE); // cursor at status line
5628 if (curr_fname != prev_fname) 5626 if (curr_fname != prev_fname)
5629 { 5627 {
5630 if (did_show) 5628 if (did_show)
5631 msg_putchar('\n'); /* cursor below last one */ 5629 msg_putchar('\n'); // cursor below last one
5632 if (!got_int) /* don't display if 'q' typed 5630 if (!got_int) // don't display if 'q' typed
5633 at "--more--" message */ 5631 // at "--more--" message
5634 msg_home_replace_hl(curr_fname); 5632 msg_home_replace_hl(curr_fname);
5635 prev_fname = curr_fname; 5633 prev_fname = curr_fname;
5636 } 5634 }
5637 did_show = TRUE; 5635 did_show = TRUE;
5638 if (!got_int) 5636 if (!got_int)
5639 show_pat_in_path(line, type, TRUE, action, 5637 show_pat_in_path(line, type, TRUE, action,
5640 (depth == -1) ? NULL : files[depth].fp, 5638 (depth == -1) ? NULL : files[depth].fp,
5641 (depth == -1) ? &lnum : &files[depth].lnum, 5639 (depth == -1) ? &lnum : &files[depth].lnum,
5642 match_count++); 5640 match_count++);
5643 5641
5644 /* Set matched flag for this file and all the ones that 5642 // Set matched flag for this file and all the ones that
5645 * include it */ 5643 // include it
5646 for (i = 0; i <= depth; ++i) 5644 for (i = 0; i <= depth; ++i)
5647 files[i].matched = TRUE; 5645 files[i].matched = TRUE;
5648 } 5646 }
5649 else if (--count <= 0) 5647 else if (--count <= 0)
5650 { 5648 {
5666 { 5664 {
5667 #ifdef FEAT_GUI 5665 #ifdef FEAT_GUI
5668 need_mouse_correct = TRUE; 5666 need_mouse_correct = TRUE;
5669 #endif 5667 #endif
5670 #if defined(FEAT_QUICKFIX) 5668 #if defined(FEAT_QUICKFIX)
5671 /* ":psearch" uses the preview window */ 5669 // ":psearch" uses the preview window
5672 if (g_do_tagpreview != 0) 5670 if (g_do_tagpreview != 0)
5673 { 5671 {
5674 curwin_save = curwin; 5672 curwin_save = curwin;
5675 prepare_tagpreview(TRUE, TRUE, FALSE); 5673 prepare_tagpreview(TRUE, TRUE, FALSE);
5676 } 5674 }
5681 break; 5679 break;
5682 RESET_BINDING(curwin); 5680 RESET_BINDING(curwin);
5683 } 5681 }
5684 if (depth == -1) 5682 if (depth == -1)
5685 { 5683 {
5686 /* match in current file */ 5684 // match in current file
5687 #if defined(FEAT_QUICKFIX) 5685 #if defined(FEAT_QUICKFIX)
5688 if (g_do_tagpreview != 0) 5686 if (g_do_tagpreview != 0)
5689 { 5687 {
5690 if (!GETFILE_SUCCESS(getfile( 5688 if (!GETFILE_SUCCESS(getfile(
5691 curwin_save->w_buffer->b_fnum, NULL, 5689 curwin_save->w_buffer->b_fnum, NULL,
5692 NULL, TRUE, lnum, FALSE))) 5690 NULL, TRUE, lnum, FALSE)))
5693 break; /* failed to jump to file */ 5691 break; // failed to jump to file
5694 } 5692 }
5695 else 5693 else
5696 #endif 5694 #endif
5697 setpcmark(); 5695 setpcmark();
5698 curwin->w_cursor.lnum = lnum; 5696 curwin->w_cursor.lnum = lnum;
5701 else 5699 else
5702 { 5700 {
5703 if (!GETFILE_SUCCESS(getfile( 5701 if (!GETFILE_SUCCESS(getfile(
5704 0, files[depth].name, NULL, TRUE, 5702 0, files[depth].name, NULL, TRUE,
5705 files[depth].lnum, FALSE))) 5703 files[depth].lnum, FALSE)))
5706 break; /* failed to jump to file */ 5704 break; // failed to jump to file
5707 /* autocommands may have changed the lnum, we don't 5705 // autocommands may have changed the lnum, we don't
5708 * want that here */ 5706 // want that here
5709 curwin->w_cursor.lnum = files[depth].lnum; 5707 curwin->w_cursor.lnum = files[depth].lnum;
5710 } 5708 }
5711 } 5709 }
5712 if (action != ACTION_SHOW) 5710 if (action != ACTION_SHOW)
5713 { 5711 {
5717 5715
5718 #if defined(FEAT_QUICKFIX) 5716 #if defined(FEAT_QUICKFIX)
5719 if (g_do_tagpreview != 0 5717 if (g_do_tagpreview != 0
5720 && curwin != curwin_save && win_valid(curwin_save)) 5718 && curwin != curwin_save && win_valid(curwin_save))
5721 { 5719 {
5722 /* Return cursor to where we were */ 5720 // Return cursor to where we were
5723 validate_cursor(); 5721 validate_cursor();
5724 redraw_later(VALID); 5722 redraw_later(VALID);
5725 win_enter(curwin_save, TRUE); 5723 win_enter(curwin_save, TRUE);
5726 } 5724 }
5727 # ifdef FEAT_PROP_POPUP 5725 # ifdef FEAT_PROP_POPUP
5732 #endif 5730 #endif
5733 break; 5731 break;
5734 } 5732 }
5735 exit_matched: 5733 exit_matched:
5736 matched = FALSE; 5734 matched = FALSE;
5737 /* look for other matches in the rest of the line if we 5735 // look for other matches in the rest of the line if we
5738 * are not at the end of it already */ 5736 // are not at the end of it already
5739 if (def_regmatch.regprog == NULL 5737 if (def_regmatch.regprog == NULL
5740 && action == ACTION_EXPAND 5738 && action == ACTION_EXPAND
5741 && !(compl_cont_status & CONT_SOL) 5739 && !(compl_cont_status & CONT_SOL)
5742 && *startp != NUL 5740 && *startp != NUL
5743 && *(p = startp + mb_ptr2len(startp)) != NUL) 5741 && *(p = startp + mb_ptr2len(startp)) != NUL)
5765 curr_fname = (depth == -1) ? curbuf->b_fname 5763 curr_fname = (depth == -1) ? curbuf->b_fname
5766 : files[depth].name; 5764 : files[depth].name;
5767 if (depth < depth_displayed) 5765 if (depth < depth_displayed)
5768 depth_displayed = depth; 5766 depth_displayed = depth;
5769 } 5767 }
5770 if (depth >= 0) /* we could read the line */ 5768 if (depth >= 0) // we could read the line
5771 { 5769 {
5772 files[depth].lnum++; 5770 files[depth].lnum++;
5773 /* Remove any CR and LF from the line. */ 5771 // Remove any CR and LF from the line.
5774 i = (int)STRLEN(line); 5772 i = (int)STRLEN(line);
5775 if (i > 0 && line[i - 1] == '\n') 5773 if (i > 0 && line[i - 1] == '\n')
5776 line[--i] = NUL; 5774 line[--i] = NUL;
5777 if (i > 0 && line[i - 1] == '\r') 5775 if (i > 0 && line[i - 1] == '\r')
5778 line[--i] = NUL; 5776 line[--i] = NUL;
5783 break; 5781 break;
5784 line = ml_get(lnum); 5782 line = ml_get(lnum);
5785 } 5783 }
5786 already = NULL; 5784 already = NULL;
5787 } 5785 }
5788 /* End of big for (;;) loop. */ 5786 // End of big for (;;) loop.
5789 5787
5790 /* Close any files that are still open. */ 5788 // Close any files that are still open.
5791 for (i = 0; i <= depth; i++) 5789 for (i = 0; i <= depth; i++)
5792 { 5790 {
5793 fclose(files[i].fp); 5791 fclose(files[i].fp);
5794 vim_free(files[i].name); 5792 vim_free(files[i].name);
5795 } 5793 }
5837 long count) 5835 long count)
5838 { 5836 {
5839 char_u *p; 5837 char_u *p;
5840 5838
5841 if (did_show) 5839 if (did_show)
5842 msg_putchar('\n'); /* cursor below last one */ 5840 msg_putchar('\n'); // cursor below last one
5843 else if (!msg_silent) 5841 else if (!msg_silent)
5844 gotocmdline(TRUE); /* cursor at status line */ 5842 gotocmdline(TRUE); // cursor at status line
5845 if (got_int) /* 'q' typed at "--more--" message */ 5843 if (got_int) // 'q' typed at "--more--" message
5846 return; 5844 return;
5847 for (;;) 5845 for (;;)
5848 { 5846 {
5849 p = line + STRLEN(line) - 1; 5847 p = line + STRLEN(line) - 1;
5850 if (fp != NULL) 5848 if (fp != NULL)
5851 { 5849 {
5852 /* We used fgets(), so get rid of newline at end */ 5850 // We used fgets(), so get rid of newline at end
5853 if (p >= line && *p == '\n') 5851 if (p >= line && *p == '\n')
5854 --p; 5852 --p;
5855 if (p >= line && *p == '\r') 5853 if (p >= line && *p == '\r')
5856 --p; 5854 --p;
5857 *(p + 1) = NUL; 5855 *(p + 1) = NUL;
5858 } 5856 }
5859 if (action == ACTION_SHOW_ALL) 5857 if (action == ACTION_SHOW_ALL)
5860 { 5858 {
5861 sprintf((char *)IObuff, "%3ld: ", count); /* show match nr */ 5859 sprintf((char *)IObuff, "%3ld: ", count); // show match nr
5862 msg_puts((char *)IObuff); 5860 msg_puts((char *)IObuff);
5863 sprintf((char *)IObuff, "%4ld", *lnum); /* show line nr */ 5861 sprintf((char *)IObuff, "%4ld", *lnum); // show line nr
5864 /* Highlight line numbers */ 5862 // Highlight line numbers
5865 msg_puts_attr((char *)IObuff, HL_ATTR(HLF_N)); 5863 msg_puts_attr((char *)IObuff, HL_ATTR(HLF_N));
5866 msg_puts(" "); 5864 msg_puts(" ");
5867 } 5865 }
5868 msg_prt_line(line, FALSE); 5866 msg_prt_line(line, FALSE);
5869 out_flush(); /* show one line at a time */ 5867 out_flush(); // show one line at a time
5870 5868
5871 /* Definition continues until line that doesn't end with '\' */ 5869 // Definition continues until line that doesn't end with '\'
5872 if (got_int || type != FIND_DEFINE || p < line || *p != '\\') 5870 if (got_int || type != FIND_DEFINE || p < line || *p != '\\')
5873 break; 5871 break;
5874 5872
5875 if (fp != NULL) 5873 if (fp != NULL)
5876 { 5874 {
5877 if (vim_fgets(line, LSIZE, fp)) /* end of file */ 5875 if (vim_fgets(line, LSIZE, fp)) // end of file
5878 break; 5876 break;
5879 ++*lnum; 5877 ++*lnum;
5880 } 5878 }
5881 else 5879 else
5882 { 5880 {