1
0
forked from aniani/vim

patch 8.1.0296: command parsing for 'incsearch' is a bit ugly

Problem:    Command parsing for 'incsearch' is a bit ugly.
Solution:   Return when there is no pattern.  Put common checks together.
This commit is contained in:
Bram Moolenaar
2018-08-18 21:23:05 +02:00
parent 264cf5cfaf
commit 111bbd61e9
2 changed files with 109 additions and 122 deletions

View File

@@ -276,26 +276,30 @@ set_search_match(pos_T *t)
do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
int *skiplen, int *patlen) int *skiplen, int *patlen)
{ {
char_u *cmd;
cmdmod_T save_cmdmod = cmdmod;
char_u *p;
int delim_optional = FALSE;
int delim;
char_u *end;
char_u *dummy;
exarg_T ea;
pos_T save_cursor;
*skiplen = 0; *skiplen = 0;
*patlen = ccline.cmdlen; *patlen = ccline.cmdlen;
if (p_is && !cmd_silent) if (!p_is || cmd_silent)
{ return FALSE;
// by default search all lines // by default search all lines
search_first_line = 0; search_first_line = 0;
search_last_line = MAXLNUM; search_last_line = MAXLNUM;
if (firstc == '/' || firstc == '?') if (firstc == '/' || firstc == '?')
return TRUE; return TRUE;
if (firstc == ':') if (firstc != ':')
{ return FALSE;
char_u *cmd;
cmdmod_T save_cmdmod = cmdmod;
char_u *p;
int delim;
char_u *end;
char_u *dummy;
exarg_T ea;
vim_memset(&ea, 0, sizeof(ea)); vim_memset(&ea, 0, sizeof(ea));
ea.line1 = 1; ea.line1 = 1;
@@ -307,77 +311,65 @@ do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
cmdmod = save_cmdmod; cmdmod = save_cmdmod;
cmd = skip_range(ea.cmd, NULL); cmd = skip_range(ea.cmd, NULL);
if (*cmd == 's' || *cmd == 'g' || *cmd == 'v' || *cmd == 'l') if (vim_strchr((char_u *)"sgvl", *cmd) == NULL)
{ return FALSE;
// Skip over "substitute" to find the pattern separator. // Skip over "substitute" to find the pattern separator.
for (p = cmd; ASCII_ISALPHA(*p); ++p) for (p = cmd; ASCII_ISALPHA(*p); ++p)
; ;
if (*skipwhite(p) != NUL) if (*skipwhite(p) == NUL)
{ return FALSE;
if (STRNCMP(cmd, "substitute", p - cmd) == 0 if (STRNCMP(cmd, "substitute", p - cmd) == 0
|| STRNCMP(cmd, "smagic", p - cmd) == 0 || STRNCMP(cmd, "smagic", p - cmd) == 0
|| STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
|| STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0
|| STRNCMP(cmd, "global", p - cmd) == 0
|| STRNCMP(cmd, "vglobal", p - cmd) == 0) || STRNCMP(cmd, "vglobal", p - cmd) == 0)
{ {
if (*cmd == 's' && cmd[1] == 'm') if (*cmd == 's' && cmd[1] == 'm')
p_magic = TRUE; p_magic = TRUE;
else if (*cmd == 's' && cmd[1] == 'n') else if (*cmd == 's' && cmd[1] == 'n')
p_magic = FALSE; p_magic = FALSE;
// Check for "global!/".
if (*cmd == 'g' && *p == '!')
{
p++;
if (*skipwhite(p) == NUL)
return FALSE;
} }
else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0)
// For ":sort" skip over flags.
if (cmd[0] == 's' && cmd[1] == 'o')
{ {
// skip over flags
while (ASCII_ISALPHA(*(p = skipwhite(p)))) while (ASCII_ISALPHA(*(p = skipwhite(p))))
++p; ++p;
if (*p == NUL) if (*p == NUL)
return FALSE; return FALSE;
} }
p = skipwhite(p);
delim = *p++;
end = skip_regexp(p, delim, p_magic, NULL);
}
else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0
|| STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0
|| STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0
|| STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0) || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0
|| STRNCMP(cmd, "global", p - cmd) == 0)
{ {
// Check for "!/". // skip over "!"
if (*p == '!') if (*p == '!')
{ {
p++; p++;
if (*skipwhite(p) == NUL) if (*skipwhite(p) == NUL)
return FALSE; return FALSE;
} }
p = skipwhite(p); if (*cmd != 'g')
delim = (vim_isIDc(*p)) ? ' ' : *p++; delim_optional = TRUE;
end = skip_regexp(p, delim, p_magic, NULL);
} }
else else
{ return FALSE;
end = p;
delim = -1;
}
if (end > p || *end == delim) p = skipwhite(p);
{ delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
pos_T save_cursor = curwin->w_cursor; end = skip_regexp(p, delim, p_magic, NULL);
if (end == p && *end != delim)
return FALSE;
// found a non-empty pattern or // // found a non-empty pattern or //
*skiplen = (int)(p - ccline.cmdbuff); *skiplen = (int)(p - ccline.cmdbuff);
*patlen = (int)(end - p); *patlen = (int)(end - p);
// parse the address range // parse the address range
save_cursor = curwin->w_cursor;
curwin->w_cursor = is_state->search_start; curwin->w_cursor = is_state->search_start;
parse_cmd_address(&ea, &dummy); parse_cmd_address(&ea, &dummy);
if (ea.addr_count > 0) if (ea.addr_count > 0)
@@ -404,13 +396,6 @@ do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
curwin->w_cursor = save_cursor; curwin->w_cursor = save_cursor;
return TRUE; return TRUE;
} }
}
}
}
}
return FALSE;
}
static void static void
finish_incsearch_highlighting( finish_incsearch_highlighting(

View File

@@ -794,6 +794,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
296,
/**/ /**/
295, 295,
/**/ /**/