forked from aniani/vim
patch 9.0.1237: code is indented more than necessary
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11858)
This commit is contained in:
committed by
Bram Moolenaar
parent
9cbf791995
commit
6ec6666047
321
src/search.c
321
src/search.c
@@ -220,26 +220,26 @@ reverse_text(char_u *s)
|
||||
*/
|
||||
len = (unsigned)STRLEN(s);
|
||||
rev = alloc(len + 1);
|
||||
if (rev != NULL)
|
||||
if (rev == NULL)
|
||||
return NULL;
|
||||
|
||||
rev_i = len;
|
||||
for (s_i = 0; s_i < len; ++s_i)
|
||||
{
|
||||
rev_i = len;
|
||||
for (s_i = 0; s_i < len; ++s_i)
|
||||
if (has_mbyte)
|
||||
{
|
||||
if (has_mbyte)
|
||||
{
|
||||
int mb_len;
|
||||
|
||||
mb_len = (*mb_ptr2len)(s + s_i);
|
||||
rev_i -= mb_len;
|
||||
mch_memmove(rev + rev_i, s + s_i, mb_len);
|
||||
s_i += mb_len - 1;
|
||||
}
|
||||
else
|
||||
rev[--rev_i] = s[s_i];
|
||||
int mb_len;
|
||||
|
||||
mb_len = (*mb_ptr2len)(s + s_i);
|
||||
rev_i -= mb_len;
|
||||
mch_memmove(rev + rev_i, s + s_i, mb_len);
|
||||
s_i += mb_len - 1;
|
||||
}
|
||||
rev[len] = NUL;
|
||||
else
|
||||
rev[--rev_i] = s[s_i];
|
||||
|
||||
}
|
||||
rev[len] = NUL;
|
||||
return rev;
|
||||
}
|
||||
#endif
|
||||
@@ -247,20 +247,20 @@ reverse_text(char_u *s)
|
||||
void
|
||||
save_re_pat(int idx, char_u *pat, int magic)
|
||||
{
|
||||
if (spats[idx].pat != pat)
|
||||
{
|
||||
vim_free(spats[idx].pat);
|
||||
spats[idx].pat = vim_strsave(pat);
|
||||
spats[idx].magic = magic;
|
||||
spats[idx].no_scs = no_smartcase;
|
||||
last_idx = idx;
|
||||
if (spats[idx].pat == pat)
|
||||
return;
|
||||
|
||||
vim_free(spats[idx].pat);
|
||||
spats[idx].pat = vim_strsave(pat);
|
||||
spats[idx].magic = magic;
|
||||
spats[idx].no_scs = no_smartcase;
|
||||
last_idx = idx;
|
||||
#ifdef FEAT_SEARCH_EXTRA
|
||||
// If 'hlsearch' set and search pat changed: need redraw.
|
||||
if (p_hls)
|
||||
redraw_all_later(UPD_SOME_VALID);
|
||||
set_no_hlsearch(FALSE);
|
||||
// If 'hlsearch' set and search pat changed: need redraw.
|
||||
if (p_hls)
|
||||
redraw_all_later(UPD_SOME_VALID);
|
||||
set_no_hlsearch(FALSE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -272,44 +272,44 @@ static int save_level = 0;
|
||||
void
|
||||
save_search_patterns(void)
|
||||
{
|
||||
if (save_level++ == 0)
|
||||
{
|
||||
saved_spats[0] = spats[0];
|
||||
if (spats[0].pat != NULL)
|
||||
saved_spats[0].pat = vim_strsave(spats[0].pat);
|
||||
saved_spats[1] = spats[1];
|
||||
if (spats[1].pat != NULL)
|
||||
saved_spats[1].pat = vim_strsave(spats[1].pat);
|
||||
if (mr_pattern == NULL)
|
||||
saved_mr_pattern = NULL;
|
||||
else
|
||||
saved_mr_pattern = vim_strsave(mr_pattern);
|
||||
if (save_level++ != 0)
|
||||
return;
|
||||
|
||||
saved_spats[0] = spats[0];
|
||||
if (spats[0].pat != NULL)
|
||||
saved_spats[0].pat = vim_strsave(spats[0].pat);
|
||||
saved_spats[1] = spats[1];
|
||||
if (spats[1].pat != NULL)
|
||||
saved_spats[1].pat = vim_strsave(spats[1].pat);
|
||||
if (mr_pattern == NULL)
|
||||
saved_mr_pattern = NULL;
|
||||
else
|
||||
saved_mr_pattern = vim_strsave(mr_pattern);
|
||||
#ifdef FEAT_SEARCH_EXTRA
|
||||
saved_spats_last_idx = last_idx;
|
||||
saved_spats_no_hlsearch = no_hlsearch;
|
||||
saved_spats_last_idx = last_idx;
|
||||
saved_spats_no_hlsearch = no_hlsearch;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
restore_search_patterns(void)
|
||||
{
|
||||
if (--save_level == 0)
|
||||
{
|
||||
vim_free(spats[0].pat);
|
||||
spats[0] = saved_spats[0];
|
||||
if (--save_level != 0)
|
||||
return;
|
||||
|
||||
vim_free(spats[0].pat);
|
||||
spats[0] = saved_spats[0];
|
||||
#if defined(FEAT_EVAL)
|
||||
set_vv_searchforward();
|
||||
set_vv_searchforward();
|
||||
#endif
|
||||
vim_free(spats[1].pat);
|
||||
spats[1] = saved_spats[1];
|
||||
vim_free(mr_pattern);
|
||||
mr_pattern = saved_mr_pattern;
|
||||
vim_free(spats[1].pat);
|
||||
spats[1] = saved_spats[1];
|
||||
vim_free(mr_pattern);
|
||||
mr_pattern = saved_mr_pattern;
|
||||
#ifdef FEAT_SEARCH_EXTRA
|
||||
last_idx = saved_spats_last_idx;
|
||||
set_no_hlsearch(saved_spats_no_hlsearch);
|
||||
last_idx = saved_spats_last_idx;
|
||||
set_no_hlsearch(saved_spats_no_hlsearch);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(EXITFREE) || defined(PROTO)
|
||||
@@ -2791,61 +2791,68 @@ showmatch(
|
||||
return;
|
||||
|
||||
if ((lpos = findmatch(NULL, NUL)) == NULL) // no match, so beep
|
||||
vim_beep(BO_MATCH);
|
||||
else if (lpos->lnum >= curwin->w_topline && lpos->lnum < curwin->w_botline)
|
||||
{
|
||||
if (!curwin->w_p_wrap)
|
||||
getvcol(curwin, lpos, NULL, &vcol, NULL);
|
||||
if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol
|
||||
&& vcol < curwin->w_leftcol + curwin->w_width))
|
||||
{
|
||||
mpos = *lpos; // save the pos, update_screen() may change it
|
||||
save_cursor = curwin->w_cursor;
|
||||
save_so = *so;
|
||||
save_siso = *siso;
|
||||
// Handle "$" in 'cpo': If the ')' is typed on top of the "$",
|
||||
// stop displaying the "$".
|
||||
if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol)
|
||||
dollar_vcol = -1;
|
||||
++curwin->w_virtcol; // do display ')' just before "$"
|
||||
update_screen(UPD_VALID); // show the new char first
|
||||
|
||||
save_dollar_vcol = dollar_vcol;
|
||||
#ifdef CURSOR_SHAPE
|
||||
save_state = State;
|
||||
State = MODE_SHOWMATCH;
|
||||
ui_cursor_shape(); // may show different cursor shape
|
||||
#endif
|
||||
curwin->w_cursor = mpos; // move to matching char
|
||||
*so = 0; // don't use 'scrolloff' here
|
||||
*siso = 0; // don't use 'sidescrolloff' here
|
||||
showruler(FALSE);
|
||||
setcursor();
|
||||
cursor_on(); // make sure that the cursor is shown
|
||||
out_flush_cursor(TRUE, FALSE);
|
||||
|
||||
// Restore dollar_vcol(), because setcursor() may call curs_rows()
|
||||
// which resets it if the matching position is in a previous line
|
||||
// and has a higher column number.
|
||||
dollar_vcol = save_dollar_vcol;
|
||||
|
||||
/*
|
||||
* brief pause, unless 'm' is present in 'cpo' and a character is
|
||||
* available.
|
||||
*/
|
||||
if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL)
|
||||
ui_delay(p_mat * 100L + 8, TRUE);
|
||||
else if (!char_avail())
|
||||
ui_delay(p_mat * 100L + 9, FALSE);
|
||||
curwin->w_cursor = save_cursor; // restore cursor position
|
||||
*so = save_so;
|
||||
*siso = save_siso;
|
||||
#ifdef CURSOR_SHAPE
|
||||
State = save_state;
|
||||
ui_cursor_shape(); // may show different cursor shape
|
||||
#endif
|
||||
}
|
||||
vim_beep(BO_MATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lpos->lnum < curwin->w_topline || lpos->lnum >= curwin->w_botline)
|
||||
return;
|
||||
|
||||
if (!curwin->w_p_wrap)
|
||||
getvcol(curwin, lpos, NULL, &vcol, NULL);
|
||||
|
||||
int col_visible = (curwin->w_p_wrap
|
||||
|| (vcol >= curwin->w_leftcol
|
||||
&& vcol < curwin->w_leftcol + curwin->w_width));
|
||||
if (!col_visible)
|
||||
return;
|
||||
|
||||
mpos = *lpos; // save the pos, update_screen() may change it
|
||||
save_cursor = curwin->w_cursor;
|
||||
save_so = *so;
|
||||
save_siso = *siso;
|
||||
// Handle "$" in 'cpo': If the ')' is typed on top of the "$",
|
||||
// stop displaying the "$".
|
||||
if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol)
|
||||
dollar_vcol = -1;
|
||||
++curwin->w_virtcol; // do display ')' just before "$"
|
||||
update_screen(UPD_VALID); // show the new char first
|
||||
|
||||
save_dollar_vcol = dollar_vcol;
|
||||
#ifdef CURSOR_SHAPE
|
||||
save_state = State;
|
||||
State = MODE_SHOWMATCH;
|
||||
ui_cursor_shape(); // may show different cursor shape
|
||||
#endif
|
||||
curwin->w_cursor = mpos; // move to matching char
|
||||
*so = 0; // don't use 'scrolloff' here
|
||||
*siso = 0; // don't use 'sidescrolloff' here
|
||||
showruler(FALSE);
|
||||
setcursor();
|
||||
cursor_on(); // make sure that the cursor is shown
|
||||
out_flush_cursor(TRUE, FALSE);
|
||||
|
||||
// Restore dollar_vcol(), because setcursor() may call curs_rows()
|
||||
// which resets it if the matching position is in a previous line
|
||||
// and has a higher column number.
|
||||
dollar_vcol = save_dollar_vcol;
|
||||
|
||||
/*
|
||||
* brief pause, unless 'm' is present in 'cpo' and a character is
|
||||
* available.
|
||||
*/
|
||||
if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL)
|
||||
ui_delay(p_mat * 100L + 8, TRUE);
|
||||
else if (!char_avail())
|
||||
ui_delay(p_mat * 100L + 9, FALSE);
|
||||
curwin->w_cursor = save_cursor; // restore cursor position
|
||||
*so = save_so;
|
||||
*siso = save_siso;
|
||||
#ifdef CURSOR_SHAPE
|
||||
State = save_state;
|
||||
ui_cursor_shape(); // may show different cursor shape
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3101,60 +3108,60 @@ cmdline_search_stat(
|
||||
|
||||
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
|
||||
timeout);
|
||||
if (stat.cur > 0)
|
||||
{
|
||||
char t[SEARCH_STAT_BUF_LEN];
|
||||
size_t len;
|
||||
if (stat.cur <= 0)
|
||||
return;
|
||||
|
||||
char t[SEARCH_STAT_BUF_LEN];
|
||||
size_t len;
|
||||
|
||||
#ifdef FEAT_RIGHTLEFT
|
||||
if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
|
||||
{
|
||||
if (stat.incomplete == 1)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||
else if (stat.cnt > maxcount && stat.cur > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||
maxcount, maxcount);
|
||||
else if (stat.cnt > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/%d]",
|
||||
maxcount, stat.cur);
|
||||
else
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||
stat.cnt, stat.cur);
|
||||
}
|
||||
if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
|
||||
{
|
||||
if (stat.incomplete == 1)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||
else if (stat.cnt > maxcount && stat.cur > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||
maxcount, maxcount);
|
||||
else if (stat.cnt > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/%d]",
|
||||
maxcount, stat.cur);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (stat.incomplete == 1)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||
else if (stat.cnt > maxcount && stat.cur > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||
maxcount, maxcount);
|
||||
else if (stat.cnt > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/>%d]",
|
||||
stat.cur, maxcount);
|
||||
else
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||
stat.cur, stat.cnt);
|
||||
}
|
||||
|
||||
len = STRLEN(t);
|
||||
if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN)
|
||||
{
|
||||
mch_memmove(t + 2, t, len);
|
||||
t[0] = 'W';
|
||||
t[1] = ' ';
|
||||
len += 2;
|
||||
}
|
||||
|
||||
mch_memmove(msgbuf + STRLEN(msgbuf) - len, t, len);
|
||||
if (dirc == '?' && stat.cur == maxcount + 1)
|
||||
stat.cur = -1;
|
||||
|
||||
// keep the message even after redraw, but don't put in history
|
||||
msg_hist_off = TRUE;
|
||||
give_warning(msgbuf, FALSE);
|
||||
msg_hist_off = FALSE;
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||
stat.cnt, stat.cur);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (stat.incomplete == 1)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||
else if (stat.cnt > maxcount && stat.cur > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||
maxcount, maxcount);
|
||||
else if (stat.cnt > maxcount)
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/>%d]",
|
||||
stat.cur, maxcount);
|
||||
else
|
||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||
stat.cur, stat.cnt);
|
||||
}
|
||||
|
||||
len = STRLEN(t);
|
||||
if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN)
|
||||
{
|
||||
mch_memmove(t + 2, t, len);
|
||||
t[0] = 'W';
|
||||
t[1] = ' ';
|
||||
len += 2;
|
||||
}
|
||||
|
||||
mch_memmove(msgbuf + STRLEN(msgbuf) - len, t, len);
|
||||
if (dirc == '?' && stat.cur == maxcount + 1)
|
||||
stat.cur = -1;
|
||||
|
||||
// keep the message even after redraw, but don't put in history
|
||||
msg_hist_off = TRUE;
|
||||
give_warning(msgbuf, FALSE);
|
||||
msg_hist_off = FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user