comparison src/search.c @ 11121:778c10516955 v8.0.0448

patch 8.0.0448: some macros are in lower case commit https://github.com/vim/vim/commit/b5aedf3e228d35821591da9ae8501b61cf2e264c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 12 18:23:53 2017 +0100 patch 8.0.0448: some macros are in lower case Problem: Some macros are in lower case, which can be confusing. Solution: Make a few lower case macros upper case.
author Christian Brabandt <cb@256bit.org>
date Sun, 12 Mar 2017 18:30:06 +0100
parents e2258e86d8e1
children 506f5d8b7d8b
comparison
equal deleted inserted replaced
11120:29ee7ffe8df7 11121:778c10516955
2098 backwards = !backwards; 2098 backwards = !backwards;
2099 #endif 2099 #endif
2100 2100
2101 do_quotes = -1; 2101 do_quotes = -1;
2102 start_in_quotes = MAYBE; 2102 start_in_quotes = MAYBE;
2103 clearpos(&match_pos); 2103 CLEAR_POS(&match_pos);
2104 2104
2105 /* backward search: Check if this line contains a single-line comment */ 2105 /* backward search: Check if this line contains a single-line comment */
2106 if ((backwards && comment_dir) 2106 if ((backwards && comment_dir)
2107 #ifdef FEAT_LISP 2107 #ifdef FEAT_LISP
2108 || lisp 2108 || lisp
2718 found_dot = TRUE; 2718 found_dot = TRUE;
2719 } 2719 }
2720 if (decl(&pos) == -1) 2720 if (decl(&pos) == -1)
2721 break; 2721 break;
2722 /* when going forward: Stop in front of empty line */ 2722 /* when going forward: Stop in front of empty line */
2723 if (lineempty(pos.lnum) && dir == FORWARD) 2723 if (LINEEMPTY(pos.lnum) && dir == FORWARD)
2724 { 2724 {
2725 incl(&pos); 2725 incl(&pos);
2726 goto found; 2726 goto found;
2727 } 2727 }
2728 } 2728 }
3080 * Stop on an empty line. 3080 * Stop on an empty line.
3081 */ 3081 */
3082 while (cls() == 0) 3082 while (cls() == 0)
3083 { 3083 {
3084 if (curwin->w_cursor.col == 0 3084 if (curwin->w_cursor.col == 0
3085 && lineempty(curwin->w_cursor.lnum)) 3085 && LINEEMPTY(curwin->w_cursor.lnum))
3086 goto finished; 3086 goto finished;
3087 if (dec_cursor() == -1) /* hit start of file, stop here */ 3087 if (dec_cursor() == -1) /* hit start of file, stop here */
3088 return OK; 3088 return OK;
3089 } 3089 }
3090 3090
3161 * First skip white space, if 'empty' is TRUE, stop at empty line. 3161 * First skip white space, if 'empty' is TRUE, stop at empty line.
3162 */ 3162 */
3163 while (cls() == 0) 3163 while (cls() == 0)
3164 { 3164 {
3165 if (empty && curwin->w_cursor.col == 0 3165 if (empty && curwin->w_cursor.col == 0
3166 && lineempty(curwin->w_cursor.lnum)) 3166 && LINEEMPTY(curwin->w_cursor.lnum))
3167 goto finished; 3167 goto finished;
3168 if (inc_cursor() == -1) /* hit end of file, stop here */ 3168 if (inc_cursor() == -1) /* hit end of file, stop here */
3169 return FAIL; 3169 return FAIL;
3170 } 3170 }
3171 3171
3221 /* 3221 /*
3222 * Move backward to end of the previous word 3222 * Move backward to end of the previous word
3223 */ 3223 */
3224 while (cls() == 0) 3224 while (cls() == 0)
3225 { 3225 {
3226 if (curwin->w_cursor.col == 0 && lineempty(curwin->w_cursor.lnum)) 3226 if (curwin->w_cursor.col == 0 && LINEEMPTY(curwin->w_cursor.lnum))
3227 break; 3227 break;
3228 if ((i = dec_cursor()) == -1 || (eol && i == 1)) 3228 if ((i = dec_cursor()) == -1 || (eol && i == 1))
3229 return OK; 3229 return OK;
3230 } 3230 }
3231 } 3231 }
3318 pos_T pos; 3318 pos_T pos;
3319 int inclusive = TRUE; 3319 int inclusive = TRUE;
3320 int include_white = FALSE; 3320 int include_white = FALSE;
3321 3321
3322 cls_bigword = bigword; 3322 cls_bigword = bigword;
3323 clearpos(&start_pos); 3323 CLEAR_POS(&start_pos);
3324 3324
3325 /* Correct cursor when 'selection' is exclusive */ 3325 /* Correct cursor when 'selection' is exclusive */
3326 if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor)) 3326 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
3327 dec_cursor(); 3327 dec_cursor();
3328 3328
3329 /* 3329 /*
3330 * When Visual mode is not active, or when the VIsual area is only one 3330 * When Visual mode is not active, or when the VIsual area is only one
3331 * character, select the word and/or white space under the cursor. 3331 * character, select the word and/or white space under the cursor.
3332 */ 3332 */
3333 if (!VIsual_active || equalpos(curwin->w_cursor, VIsual)) 3333 if (!VIsual_active || EQUAL_POS(curwin->w_cursor, VIsual))
3334 { 3334 {
3335 /* 3335 /*
3336 * Go to start of current word or white space. 3336 * Go to start of current word or white space.
3337 */ 3337 */
3338 back_in_line(); 3338 back_in_line();
3385 * When count is still > 0, extend with more objects. 3385 * When count is still > 0, extend with more objects.
3386 */ 3386 */
3387 while (count > 0) 3387 while (count > 0)
3388 { 3388 {
3389 inclusive = TRUE; 3389 inclusive = TRUE;
3390 if (VIsual_active && lt(curwin->w_cursor, VIsual)) 3390 if (VIsual_active && LT_POS(curwin->w_cursor, VIsual))
3391 { 3391 {
3392 /* 3392 /*
3393 * In Visual mode, with cursor at start: move cursor back. 3393 * In Visual mode, with cursor at start: move cursor back.
3394 */ 3394 */
3395 if (decl(&curwin->w_cursor) == -1) 3395 if (decl(&curwin->w_cursor) == -1)
3461 curwin->w_cursor = pos; /* put cursor back at end */ 3461 curwin->w_cursor = pos; /* put cursor back at end */
3462 } 3462 }
3463 3463
3464 if (VIsual_active) 3464 if (VIsual_active)
3465 { 3465 {
3466 if (*p_sel == 'e' && inclusive && ltoreq(VIsual, curwin->w_cursor)) 3466 if (*p_sel == 'e' && inclusive && LTOREQ_POS(VIsual, curwin->w_cursor))
3467 inc_cursor(); 3467 inc_cursor();
3468 if (VIsual_mode == 'V') 3468 if (VIsual_mode == 'V')
3469 { 3469 {
3470 VIsual_mode = 'v'; 3470 VIsual_mode = 'v';
3471 redraw_cmdline = TRUE; /* show mode later */ 3471 redraw_cmdline = TRUE; /* show mode later */
3496 findsent(FORWARD, 1L); /* Find start of next sentence. */ 3496 findsent(FORWARD, 1L); /* Find start of next sentence. */
3497 3497
3498 /* 3498 /*
3499 * When the Visual area is bigger than one character: Extend it. 3499 * When the Visual area is bigger than one character: Extend it.
3500 */ 3500 */
3501 if (VIsual_active && !equalpos(start_pos, VIsual)) 3501 if (VIsual_active && !EQUAL_POS(start_pos, VIsual))
3502 { 3502 {
3503 extend: 3503 extend:
3504 if (lt(start_pos, VIsual)) 3504 if (LT_POS(start_pos, VIsual))
3505 { 3505 {
3506 /* 3506 /*
3507 * Cursor at start of Visual area. 3507 * Cursor at start of Visual area.
3508 * Find out where we are: 3508 * Find out where we are:
3509 * - in the white space before a sentence 3509 * - in the white space before a sentence
3510 * - in a sentence or just after it 3510 * - in a sentence or just after it
3511 * - at the start of a sentence 3511 * - at the start of a sentence
3512 */ 3512 */
3513 at_start_sent = TRUE; 3513 at_start_sent = TRUE;
3514 decl(&pos); 3514 decl(&pos);
3515 while (lt(pos, curwin->w_cursor)) 3515 while (LT_POS(pos, curwin->w_cursor))
3516 { 3516 {
3517 c = gchar_pos(&pos); 3517 c = gchar_pos(&pos);
3518 if (!vim_iswhite(c)) 3518 if (!vim_iswhite(c))
3519 { 3519 {
3520 at_start_sent = FALSE; 3520 at_start_sent = FALSE;
3523 incl(&pos); 3523 incl(&pos);
3524 } 3524 }
3525 if (!at_start_sent) 3525 if (!at_start_sent)
3526 { 3526 {
3527 findsent(BACKWARD, 1L); 3527 findsent(BACKWARD, 1L);
3528 if (equalpos(curwin->w_cursor, start_pos)) 3528 if (EQUAL_POS(curwin->w_cursor, start_pos))
3529 at_start_sent = TRUE; /* exactly at start of sentence */ 3529 at_start_sent = TRUE; /* exactly at start of sentence */
3530 else 3530 else
3531 /* inside a sentence, go to its end (start of next) */ 3531 /* inside a sentence, go to its end (start of next) */
3532 findsent(FORWARD, 1L); 3532 findsent(FORWARD, 1L);
3533 } 3533 }
3552 * - just before or in the white space before a sentence 3552 * - just before or in the white space before a sentence
3553 * - in a sentence 3553 * - in a sentence
3554 */ 3554 */
3555 incl(&pos); 3555 incl(&pos);
3556 at_start_sent = TRUE; 3556 at_start_sent = TRUE;
3557 if (!equalpos(pos, curwin->w_cursor)) /* not just before a sentence */ 3557 /* not just before a sentence */
3558 if (!EQUAL_POS(pos, curwin->w_cursor))
3558 { 3559 {
3559 at_start_sent = FALSE; 3560 at_start_sent = FALSE;
3560 while (lt(pos, curwin->w_cursor)) 3561 while (LT_POS(pos, curwin->w_cursor))
3561 { 3562 {
3562 c = gchar_pos(&pos); 3563 c = gchar_pos(&pos);
3563 if (!vim_iswhite(c)) 3564 if (!vim_iswhite(c))
3564 { 3565 {
3565 at_start_sent = TRUE; 3566 at_start_sent = TRUE;
3586 * If the cursor started on a blank, check if it is just before the start 3587 * If the cursor started on a blank, check if it is just before the start
3587 * of the next sentence. 3588 * of the next sentence.
3588 */ 3589 */
3589 while (c = gchar_pos(&pos), vim_iswhite(c)) /* vim_iswhite() is a macro */ 3590 while (c = gchar_pos(&pos), vim_iswhite(c)) /* vim_iswhite() is a macro */
3590 incl(&pos); 3591 incl(&pos);
3591 if (equalpos(pos, curwin->w_cursor)) 3592 if (EQUAL_POS(pos, curwin->w_cursor))
3592 { 3593 {
3593 start_blank = TRUE; 3594 start_blank = TRUE;
3594 find_first_blank(&start_pos); /* go back to first blank */ 3595 find_first_blank(&start_pos); /* go back to first blank */
3595 } 3596 }
3596 else 3597 else
3631 } 3632 }
3632 3633
3633 if (VIsual_active) 3634 if (VIsual_active)
3634 { 3635 {
3635 /* Avoid getting stuck with "is" on a single space before a sentence. */ 3636 /* Avoid getting stuck with "is" on a single space before a sentence. */
3636 if (equalpos(start_pos, curwin->w_cursor)) 3637 if (EQUAL_POS(start_pos, curwin->w_cursor))
3637 goto extend; 3638 goto extend;
3638 if (*p_sel == 'e') 3639 if (*p_sel == 'e')
3639 ++curwin->w_cursor.col; 3640 ++curwin->w_cursor.col;
3640 VIsual = start_pos; 3641 VIsual = start_pos;
3641 VIsual_mode = 'v'; 3642 VIsual_mode = 'v';
3680 old_start = old_end; 3681 old_start = old_end;
3681 3682
3682 /* 3683 /*
3683 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive. 3684 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
3684 */ 3685 */
3685 if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) 3686 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
3686 { 3687 {
3687 setpcmark(); 3688 setpcmark();
3688 if (what == '{') /* ignore indent */ 3689 if (what == '{') /* ignore indent */
3689 while (inindent(1)) 3690 while (inindent(1))
3690 if (inc_cursor() != 0) 3691 if (inc_cursor() != 0)
3691 break; 3692 break;
3692 if (gchar_cursor() == what) 3693 if (gchar_cursor() == what)
3693 /* cursor on '(' or '{', move cursor just after it */ 3694 /* cursor on '(' or '{', move cursor just after it */
3694 ++curwin->w_cursor.col; 3695 ++curwin->w_cursor.col;
3695 } 3696 }
3696 else if (lt(VIsual, curwin->w_cursor)) 3697 else if (LT_POS(VIsual, curwin->w_cursor))
3697 { 3698 {
3698 old_start = VIsual; 3699 old_start = VIsual;
3699 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ 3700 curwin->w_cursor = VIsual; /* cursor at low end of Visual */
3700 } 3701 }
3701 else 3702 else
3749 3750
3750 /* 3751 /*
3751 * In Visual mode, when the resulting area is not bigger than what we 3752 * In Visual mode, when the resulting area is not bigger than what we
3752 * started with, extend it to the next block, and then exclude again. 3753 * started with, extend it to the next block, and then exclude again.
3753 */ 3754 */
3754 if (!lt(start_pos, old_start) && !lt(old_end, curwin->w_cursor) 3755 if (!LT_POS(start_pos, old_start) && !LT_POS(old_end, curwin->w_cursor)
3755 && VIsual_active) 3756 && VIsual_active)
3756 { 3757 {
3757 curwin->w_cursor = old_start; 3758 curwin->w_cursor = old_start;
3758 decl(&curwin->w_cursor); 3759 decl(&curwin->w_cursor);
3759 if ((pos = findmatch(NULL, what)) == NULL) 3760 if ((pos = findmatch(NULL, what)) == NULL)
3790 oap->start = start_pos; 3791 oap->start = start_pos;
3791 oap->motion_type = MCHAR; 3792 oap->motion_type = MCHAR;
3792 oap->inclusive = FALSE; 3793 oap->inclusive = FALSE;
3793 if (sol) 3794 if (sol)
3794 incl(&curwin->w_cursor); 3795 incl(&curwin->w_cursor);
3795 else if (ltoreq(start_pos, curwin->w_cursor)) 3796 else if (LTOREQ_POS(start_pos, curwin->w_cursor))
3796 /* Include the character under the cursor. */ 3797 /* Include the character under the cursor. */
3797 oap->inclusive = TRUE; 3798 oap->inclusive = TRUE;
3798 else 3799 else
3799 /* End is before the start (no text in between <>, [], etc.): don't 3800 /* End is before the start (no text in between <>, [], etc.): don't
3800 * operate on any text. */ 3801 * operate on any text. */
3914 decl(&old_end); /* old_end is inclusive */ 3915 decl(&old_end); /* old_end is inclusive */
3915 3916
3916 /* 3917 /*
3917 * If we start on "<aaa>" select that block. 3918 * If we start on "<aaa>" select that block.
3918 */ 3919 */
3919 if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) 3920 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
3920 { 3921 {
3921 setpcmark(); 3922 setpcmark();
3922 3923
3923 /* ignore indent */ 3924 /* ignore indent */
3924 while (inindent(1)) 3925 while (inindent(1))
3940 break; 3941 break;
3941 dec_cursor(); 3942 dec_cursor();
3942 old_end = curwin->w_cursor; 3943 old_end = curwin->w_cursor;
3943 } 3944 }
3944 } 3945 }
3945 else if (lt(VIsual, curwin->w_cursor)) 3946 else if (LT_POS(VIsual, curwin->w_cursor))
3946 { 3947 {
3947 old_start = VIsual; 3948 old_start = VIsual;
3948 curwin->w_cursor = VIsual; /* cursor at low end of Visual */ 3949 curwin->w_cursor = VIsual; /* cursor at low end of Visual */
3949 } 3950 }
3950 else 3951 else
3997 0, NULL, (linenr_T)0, 0L); 3998 0, NULL, (linenr_T)0, 0L);
3998 3999
3999 vim_free(spat); 4000 vim_free(spat);
4000 vim_free(epat); 4001 vim_free(epat);
4001 4002
4002 if (r < 1 || lt(curwin->w_cursor, old_end)) 4003 if (r < 1 || LT_POS(curwin->w_cursor, old_end))
4003 { 4004 {
4004 /* Can't find other end or it's before the previous end. Could be a 4005 /* Can't find other end or it's before the previous end. Could be a
4005 * HTML tag that doesn't have a matching end. Search backwards for 4006 * HTML tag that doesn't have a matching end. Search backwards for
4006 * another starting tag. */ 4007 * another starting tag. */
4007 count = 1; 4008 count = 1;
4044 } 4045 }
4045 curwin->w_cursor = end_pos; 4046 curwin->w_cursor = end_pos;
4046 4047
4047 /* If we now have the same text as before reset "do_include" and try 4048 /* If we now have the same text as before reset "do_include" and try
4048 * again. */ 4049 * again. */
4049 if (equalpos(start_pos, old_start) && equalpos(end_pos, old_end)) 4050 if (EQUAL_POS(start_pos, old_start) && EQUAL_POS(end_pos, old_end))
4050 { 4051 {
4051 do_include = TRUE; 4052 do_include = TRUE;
4052 curwin->w_cursor = old_start; 4053 curwin->w_cursor = old_start;
4053 count = count_arg; 4054 count = count_arg;
4054 goto again; 4055 goto again;
4057 4058
4058 if (VIsual_active) 4059 if (VIsual_active)
4059 { 4060 {
4060 /* If the end is before the start there is no text between tags, select 4061 /* If the end is before the start there is no text between tags, select
4061 * the char under the cursor. */ 4062 * the char under the cursor. */
4062 if (lt(end_pos, start_pos)) 4063 if (LT_POS(end_pos, start_pos))
4063 curwin->w_cursor = start_pos; 4064 curwin->w_cursor = start_pos;
4064 else if (*p_sel == 'e') 4065 else if (*p_sel == 'e')
4065 inc_cursor(); 4066 inc_cursor();
4066 VIsual = start_pos; 4067 VIsual = start_pos;
4067 VIsual_mode = 'v'; 4068 VIsual_mode = 'v';
4070 } 4071 }
4071 else 4072 else
4072 { 4073 {
4073 oap->start = start_pos; 4074 oap->start = start_pos;
4074 oap->motion_type = MCHAR; 4075 oap->motion_type = MCHAR;
4075 if (lt(end_pos, start_pos)) 4076 if (LT_POS(end_pos, start_pos))
4076 { 4077 {
4077 /* End is before the start: there is no text between tags; operate 4078 /* End is before the start: there is no text between tags; operate
4078 * on an empty area. */ 4079 * on an empty area. */
4079 curwin->w_cursor = start_pos; 4080 curwin->w_cursor = start_pos;
4080 oap->inclusive = FALSE; 4081 oap->inclusive = FALSE;
4360 { 4361 {
4361 /* this only works within one line */ 4362 /* this only works within one line */
4362 if (VIsual.lnum != curwin->w_cursor.lnum) 4363 if (VIsual.lnum != curwin->w_cursor.lnum)
4363 return FALSE; 4364 return FALSE;
4364 4365
4365 vis_bef_curs = lt(VIsual, curwin->w_cursor); 4366 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor);
4366 if (*p_sel == 'e' && vis_bef_curs) 4367 if (*p_sel == 'e' && vis_bef_curs)
4367 dec_cursor(); 4368 dec_cursor();
4368 vis_empty = equalpos(VIsual, curwin->w_cursor); 4369 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor);
4369 } 4370 }
4370 4371
4371 if (!vis_empty) 4372 if (!vis_empty)
4372 { 4373 {
4373 /* Check if the existing selection exactly spans the text inside 4374 /* Check if the existing selection exactly spans the text inside
4603 4604
4604 /* wrapping should not occur */ 4605 /* wrapping should not occur */
4605 p_ws = FALSE; 4606 p_ws = FALSE;
4606 4607
4607 /* Correct cursor when 'selection' is exclusive */ 4608 /* Correct cursor when 'selection' is exclusive */
4608 if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor)) 4609 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
4609 dec_cursor(); 4610 dec_cursor();
4610 4611
4611 if (VIsual_active) 4612 if (VIsual_active)
4612 { 4613 {
4613 orig_pos = curwin->w_cursor; 4614 orig_pos = curwin->w_cursor;
4666 p_ws = old_p_ws; 4667 p_ws = old_p_ws;
4667 return FAIL; 4668 return FAIL;
4668 } 4669 }
4669 else if (!i && !result) 4670 else if (!i && !result)
4670 { 4671 {
4671 if (forward) /* try again from start of buffer */ 4672 if (forward)
4672 { 4673 {
4673 clearpos(&pos); 4674 /* try again from start of buffer */
4674 } 4675 CLEAR_POS(&pos);
4675 else /* try again from end of buffer */ 4676 }
4676 { 4677 else
4678 {
4679 /* try again from end of buffer */
4677 /* searching backwards, so set pos to last line and col */ 4680 /* searching backwards, so set pos to last line and col */
4678 pos.lnum = curwin->w_buffer->b_ml.ml_line_count; 4681 pos.lnum = curwin->w_buffer->b_ml.ml_line_count;
4679 pos.col = (colnr_T)STRLEN( 4682 pos.col = (colnr_T)STRLEN(
4680 ml_get(curwin->w_buffer->b_ml.ml_line_count)); 4683 ml_get(curwin->w_buffer->b_ml.ml_line_count));
4681 } 4684 }
4707 { 4710 {
4708 redraw_curbuf_later(INVERTED); /* update the inversion */ 4711 redraw_curbuf_later(INVERTED); /* update the inversion */
4709 if (*p_sel == 'e') 4712 if (*p_sel == 'e')
4710 { 4713 {
4711 /* Correction for exclusive selection depends on the direction. */ 4714 /* Correction for exclusive selection depends on the direction. */
4712 if (forward && ltoreq(VIsual, curwin->w_cursor)) 4715 if (forward && LTOREQ_POS(VIsual, curwin->w_cursor))
4713 inc_cursor(); 4716 inc_cursor();
4714 else if (!forward && ltoreq(curwin->w_cursor, VIsual)) 4717 else if (!forward && LTOREQ_POS(curwin->w_cursor, VIsual))
4715 inc(&VIsual); 4718 inc(&VIsual);
4716 } 4719 }
4717 4720
4718 } 4721 }
4719 4722
4762 4765
4763 /* init startcol correctly */ 4766 /* init startcol correctly */
4764 regmatch.startpos[0].col = -1; 4767 regmatch.startpos[0].col = -1;
4765 /* move to match */ 4768 /* move to match */
4766 if (move) 4769 if (move)
4767 clearpos(&pos) 4770 {
4771 CLEAR_POS(&pos);
4772 }
4768 else 4773 else
4769 { 4774 {
4770 pos = curwin->w_cursor; 4775 pos = curwin->w_cursor;
4771 /* accept a match at the cursor position */ 4776 /* accept a match at the cursor position */
4772 flag = SEARCH_START; 4777 flag = SEARCH_START;