diff options
Diffstat (limited to 'src/cmdhist.c')
-rw-r--r-- | src/cmdhist.c | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/cmdhist.c b/src/cmdhist.c index ea955478ef..d398ca7a68 100644 --- a/src/cmdhist.c +++ b/src/cmdhist.c @@ -460,44 +460,46 @@ del_history_entry(int histype, char_u *str) int last; int found = FALSE; - regmatch.regprog = NULL; + if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL + || hisidx[histype] < 0) + return FALSE; + + idx = hisidx[histype]; + regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING); + if (regmatch.regprog == NULL) + return FALSE; + regmatch.rm_ic = FALSE; // always match case - if (hislen != 0 - && histype >= 0 - && histype < HIST_COUNT - && *str != NUL - && (idx = hisidx[histype]) >= 0 - && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) - != NULL) + + i = last = idx; + do { - i = last = idx; - do + hisptr = &history[histype][i]; + if (hisptr->hisstr == NULL) + break; + if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { - hisptr = &history[histype][i]; - if (hisptr->hisstr == NULL) - break; - if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) + found = TRUE; + vim_free(hisptr->hisstr); + clear_hist_entry(hisptr); + } + else + { + if (i != last) { - found = TRUE; - vim_free(hisptr->hisstr); + history[histype][last] = *hisptr; clear_hist_entry(hisptr); } - else - { - if (i != last) - { - history[histype][last] = *hisptr; - clear_hist_entry(hisptr); - } - if (--last < 0) - last += hislen; - } - if (--i < 0) - i += hislen; - } while (i != idx); - if (history[histype][idx].hisstr == NULL) - hisidx[histype] = -1; - } + if (--last < 0) + last += hislen; + } + if (--i < 0) + i += hislen; + } while (i != idx); + + if (history[histype][idx].hisstr == NULL) + hisidx[histype] = -1; + vim_regfree(regmatch.regprog); return found; } |