vim-patch:partial:9.0.1237: code is indented more than necessary (#21971)

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes vim/vim#11858)

6ec6666047

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq
2023-01-24 08:43:51 +08:00
committed by GitHub
parent dbb6c7f1b8
commit fa12b9ca2b
11 changed files with 559 additions and 491 deletions

View File

@@ -126,13 +126,15 @@ static char *provider_err = NULL;
void conceal_check_cursor_line(void) void conceal_check_cursor_line(void)
{ {
bool should_conceal = conceal_cursor_line(curwin); bool should_conceal = conceal_cursor_line(curwin);
if (curwin->w_p_cole > 0 && (conceal_cursor_used != should_conceal)) { if (curwin->w_p_cole <= 0 || conceal_cursor_used == should_conceal) {
return;
}
redrawWinline(curwin, curwin->w_cursor.lnum); redrawWinline(curwin, curwin->w_cursor.lnum);
// Need to recompute cursor column, e.g., when starting Visual mode // Need to recompute cursor column, e.g., when starting Visual mode
// without concealing. // without concealing.
curs_columns(curwin, true); curs_columns(curwin, true);
} }
}
/// Resize default_grid to Rows and Columns. /// Resize default_grid to Rows and Columns.
/// ///
@@ -837,26 +839,30 @@ static bool vsep_connected(win_T *wp, WindowCorner corner)
/// Draw the vertical separator right of window "wp" /// Draw the vertical separator right of window "wp"
static void draw_vsep_win(win_T *wp) static void draw_vsep_win(win_T *wp)
{ {
if (wp->w_vsep_width) { if (!wp->w_vsep_width) {
return;
}
// draw the vertical separator right of this window // draw the vertical separator right of this window
int hl; int hl;
int c = fillchar_vsep(wp, &hl); int c = fillchar_vsep(wp, &hl);
grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp), grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl); W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
} }
}
/// Draw the horizontal separator below window "wp" /// Draw the horizontal separator below window "wp"
static void draw_hsep_win(win_T *wp) static void draw_hsep_win(win_T *wp)
{ {
if (wp->w_hsep_height) { if (!wp->w_hsep_height) {
return;
}
// draw the horizontal separator below this window // draw the horizontal separator below this window
int hl; int hl;
int c = fillchar_hsep(wp, &hl); int c = fillchar_hsep(wp, &hl);
grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1, grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
wp->w_wincol, W_ENDCOL(wp), c, c, hl); wp->w_wincol, W_ENDCOL(wp), c, c, hl);
} }
}
/// Get the separator connector for specified window corner of window "wp" /// Get the separator connector for specified window corner of window "wp"
static int get_corner_sep_connector(win_T *wp, WindowCorner corner) static int get_corner_sep_connector(win_T *wp, WindowCorner corner)

View File

@@ -112,7 +112,10 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
frame_T *frc; frame_T *frc;
int count = 0; int count = 0;
if (fr->fr_layout != FR_LEAF) { if (fr->fr_layout == FR_LEAF) {
return OK;
}
// Find first frame that's not skipped and then create a window for // Find first frame that's not skipped and then create a window for
// each following one (first frame is already there). // each following one (first frame is already there).
frc = ses_skipframe(fr->fr_child); frc = ses_skipframe(fr->fr_child);
@@ -145,7 +148,7 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
return FAIL; return FAIL;
} }
} }
}
return OK; return OK;
} }
@@ -906,13 +909,15 @@ static int makeopens(FILE *fd, char *dirnow)
void ex_loadview(exarg_T *eap) void ex_loadview(exarg_T *eap)
{ {
char *fname = get_view_file(*eap->arg); char *fname = get_view_file(*eap->arg);
if (fname != NULL) { if (fname == NULL) {
return;
}
if (do_source(fname, false, DOSO_NONE) == FAIL) { if (do_source(fname, false, DOSO_NONE) == FAIL) {
semsg(_(e_notopen), fname); semsg(_(e_notopen), fname);
} }
xfree(fname); xfree(fname);
} }
}
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession". /// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
/// ///

View File

@@ -142,17 +142,17 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr)
/// Also return its attribute in *attrp; /// Also return its attribute in *attrp;
void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
{ {
size_t off;
grid_adjust(&grid, &row, &col); grid_adjust(&grid, &row, &col);
// safety check // safety check
if (grid->chars != NULL && row < grid->rows && col < grid->cols) { if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) {
off = grid->line_offset[row] + (size_t)col; return;
}
size_t off = grid->line_offset[row] + (size_t)col;
*attrp = grid->attrs[off]; *attrp = grid->attrs[off];
schar_copy(bytes, grid->chars[off]); schar_copy(bytes, grid->chars[off]);
} }
}
/// put string '*text' on the window grid at position 'row' and 'col', with /// put string '*text' on the window grid at position 'row' and 'col', with
/// attributes 'attr', and update chars[] and attrs[]. /// attributes 'attr', and update chars[] and attrs[].

View File

@@ -821,13 +821,15 @@ static void source_all_matches(char *pat)
int num_files; int num_files;
char **files; char **files;
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) { if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK) {
return;
}
for (int i = 0; i < num_files; i++) { for (int i = 0; i < num_files; i++) {
(void)do_source(files[i], false, DOSO_NONE); (void)do_source(files[i], false, DOSO_NONE);
} }
FreeWild(num_files, files); FreeWild(num_files, files);
} }
}
/// Add the package directory to 'runtimepath' /// Add the package directory to 'runtimepath'
/// ///

View File

@@ -295,7 +295,6 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
return false; return false;
} }
{
buf_T *old_curbuf = curbuf; buf_T *old_curbuf = curbuf;
win_T *old_curwin = curwin; win_T *old_curwin = curwin;
char *s; char *s;
@@ -319,29 +318,32 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
buf[0] = NUL; buf[0] = NUL;
} }
xfree(s); xfree(s);
}
return buf[0] != NUL; return buf[0] != NUL;
} }
/// Prepare for 'hlsearch' highlighting. /// Prepare for 'hlsearch' highlighting.
void start_search_hl(void) void start_search_hl(void)
{ {
if (p_hls && !no_hlsearch) { if (!p_hls || no_hlsearch) {
return;
}
end_search_hl(); // just in case it wasn't called before end_search_hl(); // just in case it wasn't called before
last_pat_prog(&screen_search_hl.rm); last_pat_prog(&screen_search_hl.rm);
// Set the time limit to 'redrawtime'. // Set the time limit to 'redrawtime'.
screen_search_hl.tm = profile_setlimit(p_rdt); screen_search_hl.tm = profile_setlimit(p_rdt);
} }
}
/// Clean up for 'hlsearch' highlighting. /// Clean up for 'hlsearch' highlighting.
void end_search_hl(void) void end_search_hl(void)
{ {
if (screen_search_hl.rm.regprog != NULL) { if (screen_search_hl.rm.regprog == NULL) {
return;
}
vim_regfree(screen_search_hl.rm.regprog); vim_regfree(screen_search_hl.rm.regprog);
screen_search_hl.rm.regprog = NULL; screen_search_hl.rm.regprog = NULL;
} }
}
/// Check if there should be a delay. Used before clearing or redrawing the /// Check if there should be a delay. Used before clearing or redrawing the
/// screen or the command line. /// screen or the command line.
@@ -671,12 +673,14 @@ void clearmode(void)
static void recording_mode(int attr) static void recording_mode(int attr)
{ {
msg_puts_attr(_("recording"), attr); msg_puts_attr(_("recording"), attr);
if (!shortmess(SHM_RECORDING)) { if (shortmess(SHM_RECORDING)) {
return;
}
char s[4]; char s[4];
snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording); snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
msg_puts_attr(s, attr); msg_puts_attr(s, attr);
} }
}
void get_trans_bufname(buf_T *buf) void get_trans_bufname(buf_T *buf)
{ {

View File

@@ -206,7 +206,10 @@ char *get_search_pat(void)
void save_re_pat(int idx, char *pat, int magic) void save_re_pat(int idx, char *pat, int magic)
{ {
if (spats[idx].pat != pat) { if (spats[idx].pat == pat) {
return;
}
free_spat(&spats[idx]); free_spat(&spats[idx]);
spats[idx].pat = xstrdup(pat); spats[idx].pat = xstrdup(pat);
spats[idx].magic = magic; spats[idx].magic = magic;
@@ -220,7 +223,6 @@ void save_re_pat(int idx, char *pat, int magic)
} }
set_no_hlsearch(false); set_no_hlsearch(false);
} }
}
// Save the search patterns, so they can be restored later. // Save the search patterns, so they can be restored later.
// Used before/after executing autocommands and user functions. // Used before/after executing autocommands and user functions.
@@ -228,7 +230,10 @@ static int save_level = 0;
void save_search_patterns(void) void save_search_patterns(void)
{ {
if (save_level++ == 0) { if (save_level++ != 0) {
return;
}
saved_spats[0] = spats[0]; saved_spats[0] = spats[0];
if (spats[0].pat != NULL) { if (spats[0].pat != NULL) {
saved_spats[0].pat = xstrdup(spats[0].pat); saved_spats[0].pat = xstrdup(spats[0].pat);
@@ -245,11 +250,13 @@ void save_search_patterns(void)
saved_spats_last_idx = last_idx; saved_spats_last_idx = last_idx;
saved_spats_no_hlsearch = no_hlsearch; saved_spats_no_hlsearch = no_hlsearch;
} }
}
void restore_search_patterns(void) void restore_search_patterns(void)
{ {
if (--save_level == 0) { if (--save_level != 0) {
return;
}
free_spat(&spats[0]); free_spat(&spats[0]);
spats[0] = saved_spats[0]; spats[0] = saved_spats[0];
set_vv_searchforward(); set_vv_searchforward();
@@ -260,7 +267,6 @@ void restore_search_patterns(void)
last_idx = saved_spats_last_idx; last_idx = saved_spats_last_idx;
set_no_hlsearch(saved_spats_no_hlsearch); set_no_hlsearch(saved_spats_no_hlsearch);
} }
}
static inline void free_spat(struct spat *const spat) static inline void free_spat(struct spat *const spat)
{ {
@@ -2321,14 +2327,24 @@ void showmatch(int c)
if ((lpos = findmatch(NULL, NUL)) == NULL) { // no match, so beep if ((lpos = findmatch(NULL, NUL)) == NULL) { // no match, so beep
vim_beep(BO_MATCH); vim_beep(BO_MATCH);
} else if (lpos->lnum >= curwin->w_topline return;
&& lpos->lnum < curwin->w_botline) { }
if (lpos->lnum < curwin->w_topline || lpos->lnum >= curwin->w_botline) {
return;
}
if (!curwin->w_p_wrap) { if (!curwin->w_p_wrap) {
getvcol(curwin, lpos, NULL, &vcol, NULL); getvcol(curwin, lpos, NULL, &vcol, NULL);
} }
if (curwin->w_p_wrap
bool col_visible = curwin->w_p_wrap
|| (vcol >= curwin->w_leftcol || (vcol >= curwin->w_leftcol
&& vcol < curwin->w_leftcol + curwin->w_width_inner)) { && vcol < curwin->w_leftcol + curwin->w_width_inner);
if (!col_visible) {
return;
}
mpos = *lpos; // save the pos, update_screen() may change it mpos = *lpos; // save the pos, update_screen() may change it
save_cursor = curwin->w_cursor; save_cursor = curwin->w_cursor;
save_so = *so; save_so = *so;
@@ -2369,8 +2385,6 @@ void showmatch(int c)
State = save_state; State = save_state;
ui_cursor_shape(); // may show different cursor shape ui_cursor_shape(); // may show different cursor shape
} }
}
}
/// Find next search match under cursor, cursor at end. /// Find next search match under cursor, cursor at end.
/// Used while an operator is pending, and in Visual mode. /// Used while an operator is pending, and in Visual mode.
@@ -2588,7 +2602,10 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount, update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
timeout); timeout);
if (stat.cur > 0) { if (stat.cur <= 0) {
return;
}
char t[SEARCH_STAT_BUF_LEN]; char t[SEARCH_STAT_BUF_LEN];
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
@@ -2638,7 +2655,6 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
give_warning(msgbuf, false); give_warning(msgbuf, false);
msg_hist_off = false; msg_hist_off = false;
} }
}
// Add the search count information to "stat". // Add the search count information to "stat".
// "stat" must not be NULL. // "stat" must not be NULL.

View File

@@ -122,11 +122,12 @@ static signgroup_T *sign_group_ref(const char *groupname)
/// removed, then remove the group. /// removed, then remove the group.
static void sign_group_unref(char *groupname) static void sign_group_unref(char *groupname)
{ {
signgroup_T *group;
hashitem_T *hi = hash_find(&sg_table, groupname); hashitem_T *hi = hash_find(&sg_table, groupname);
if (!HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
group = HI2SG(hi); return;
}
signgroup_T *group = HI2SG(hi);
group->sg_refcount--; group->sg_refcount--;
if (group->sg_refcount == 0) { if (group->sg_refcount == 0) {
// All the signs in this group are removed // All the signs in this group are removed
@@ -134,7 +135,6 @@ static void sign_group_unref(char *groupname)
xfree(group); xfree(group);
} }
} }
}
/// @return true if 'sign' is in 'group'. /// @return true if 'sign' is in 'group'.
/// A sign can either be in the global group (sign->group == NULL) /// A sign can either be in the global group (sign->group == NULL)

View File

@@ -1488,7 +1488,10 @@ void spell_cat_line(char *buf, char *line, int maxlen)
p = (char_u *)skipwhite((char *)p + 1); p = (char_u *)skipwhite((char *)p + 1);
} }
if (*p != NUL) { if (*p == NUL) {
return;
}
// Only worth concatenating if there is something else than spaces to // Only worth concatenating if there is something else than spaces to
// concatenate. // concatenate.
int n = (int)(p - (char_u *)line) + 1; int n = (int)(p - (char_u *)line) + 1;
@@ -1497,7 +1500,6 @@ void spell_cat_line(char *buf, char *line, int maxlen)
xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n)); xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
} }
} }
}
// Load word list(s) for "lang" from Vim spell file(s). // Load word list(s) for "lang" from Vim spell file(s).
// "lang" must be the language without the region: e.g., "en". // "lang" must be the language without the region: e.g., "en".
@@ -1702,7 +1704,10 @@ static void spell_load_cb(char *fname, void *cookie)
{ {
spelload_T *slp = (spelload_T *)cookie; spelload_T *slp = (spelload_T *)cookie;
slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false); slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false);
if (slang != NULL) { if (slang == NULL) {
return;
}
// When a previously loaded file has NOBREAK also use it for the // When a previously loaded file has NOBREAK also use it for the
// ".add" files. // ".add" files.
if (slp->sl_nobreak && slang->sl_add) { if (slp->sl_nobreak && slang->sl_add) {
@@ -1713,7 +1718,6 @@ static void spell_load_cb(char *fname, void *cookie)
slp->sl_slang = slang; slp->sl_slang = slang;
} }
}
/// Add a word to the hashtable of common words. /// Add a word to the hashtable of common words.
/// If it's already there then the counter is increased. /// If it's already there then the counter is increased.
@@ -2258,14 +2262,16 @@ int captype(char *word, const char *end)
// Delete the internal wordlist and its .spl file. // Delete the internal wordlist and its .spl file.
void spell_delete_wordlist(void) void spell_delete_wordlist(void)
{ {
if (int_wordlist != NULL) { if (int_wordlist == NULL) {
return;
}
char fname[MAXPATHL] = { 0 }; char fname[MAXPATHL] = { 0 };
os_remove(int_wordlist); os_remove(int_wordlist);
int_wordlist_spl(fname); int_wordlist_spl(fname);
os_remove(fname); os_remove(fname);
XFREE_CLEAR(int_wordlist); XFREE_CLEAR(int_wordlist);
} }
}
// Free all languages. // Free all languages.
void spell_free_all(void) void spell_free_all(void)
@@ -2332,11 +2338,13 @@ buf_T *open_spellbuf(void)
// Close the buffer used for spell info. // Close the buffer used for spell info.
void close_spellbuf(buf_T *buf) void close_spellbuf(buf_T *buf)
{ {
if (buf != NULL) { if (buf == NULL) {
return;
}
ml_close(buf, true); ml_close(buf, true);
xfree(buf); xfree(buf);
} }
}
// Init the chartab used for spelling for ASCII. // Init the chartab used for spelling for ASCII.
void clear_spell_chartab(spelltab_T *sp) void clear_spell_chartab(spelltab_T *sp)
@@ -3624,15 +3632,16 @@ char *did_set_spell_option(bool is_spellfile)
} }
} }
if (errmsg == NULL) { if (errmsg != NULL) {
return errmsg;
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer == curbuf && wp->w_p_spell) { if (wp->w_buffer == curbuf && wp->w_p_spell) {
errmsg = did_set_spelllang(wp); errmsg = did_set_spelllang(wp);
break; break;
} }
} }
}
return errmsg; return errmsg;
} }

View File

@@ -1695,7 +1695,10 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
// Invalid length, multiply with sizeof(int) would overflow. // Invalid length, multiply with sizeof(int) would overflow.
return SP_FORMERROR; return SP_FORMERROR;
} }
if (len > 0) { if (len <= 0) {
return 0;
}
// Allocate the byte array. // Allocate the byte array.
bp = xmalloc((size_t)len); bp = xmalloc((size_t)len);
*bytsp = bp; *bytsp = bp;
@@ -1712,7 +1715,6 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
if (idx < 0) { if (idx < 0) {
return idx; return idx;
} }
}
return 0; return 0;
} }
@@ -2003,15 +2005,16 @@ static void spell_print_node(wordnode_T *node, int depth)
static void spell_print_tree(wordnode_T *root) static void spell_print_tree(wordnode_T *root)
{ {
if (root != NULL) { if (root == NULL) {
// Clear the "wn_u1.index" fields, used to remember what has been return;
// done. }
// Clear the "wn_u1.index" fields, used to remember what has been done.
spell_clear_flags(root); spell_clear_flags(root);
// Recursively print the tree. // Recursively print the tree.
spell_print_node(root, 0); spell_print_node(root, 0);
} }
}
#endif // SPELL_PRINTTREE #endif // SPELL_PRINTTREE
@@ -4197,7 +4200,10 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
// Skip the root itself, it's not actually used. The first sibling is the // Skip the root itself, it's not actually used. The first sibling is the
// start of the tree. // start of the tree.
if (root->wn_sibling != NULL) { if (root->wn_sibling == NULL) {
return;
}
hash_init(&ht); hash_init(&ht);
const long n = node_compress(spin, root->wn_sibling, &ht, &tot); const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
@@ -4222,7 +4228,6 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
#endif #endif
hash_clear(&ht); hash_clear(&ht);
} }
}
/// Compress a node, its siblings and its children, depth first. /// Compress a node, its siblings and its children, depth first.
/// Returns the number of compressed nodes. /// Returns the number of compressed nodes.
@@ -4887,11 +4892,13 @@ void ex_mkspell(exarg_T *eap)
} }
// Expand all the remaining arguments (e.g., $VIMRUNTIME). // Expand all the remaining arguments (e.g., $VIMRUNTIME).
if (get_arglist_exp(arg, &fcount, &fnames, false) == OK) { if (get_arglist_exp(arg, &fcount, &fnames, false) != OK) {
return;
}
mkspell(fcount, fnames, ascii, eap->forceit, false); mkspell(fcount, fnames, ascii, eap->forceit, false);
FreeWild(fcount, fnames); FreeWild(fcount, fnames);
} }
}
// Create the .sug file. // Create the .sug file.
// Uses the soundfold info in "spin". // Uses the soundfold info in "spin".
@@ -5681,7 +5688,10 @@ static void init_spellfile(void)
bool aspath = false; bool aspath = false;
char *lstart = curbuf->b_s.b_p_spl; char *lstart = curbuf->b_s.b_p_spl;
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) { if (*curwin->w_s->b_p_spl == NUL || GA_EMPTY(&curwin->w_s->b_langp)) {
return;
}
buf = xmalloc(MAXPATHL); buf = xmalloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there // Find the end of the language name. Exclude the region. If there
@@ -5739,7 +5749,6 @@ static void init_spellfile(void)
xfree(buf); xfree(buf);
} }
}
/// Set the spell character tables from strings in the .spl file. /// Set the spell character tables from strings in the .spl file.
/// ///

View File

@@ -276,7 +276,10 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
int newscore; int newscore;
hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word); hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
if (!HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
return score;
}
wc = HI2WC(hi); wc = HI2WC(hi);
if (wc->wc_count < SCORE_THRES2) { if (wc->wc_count < SCORE_THRES2) {
bonus = SCORE_COMMON1; bonus = SCORE_COMMON1;
@@ -295,8 +298,6 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
} }
return newscore; return newscore;
} }
return score;
}
/// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a /// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
/// capital. So that make_case_word() can turn WOrd into Word. /// capital. So that make_case_word() can turn WOrd into Word.
@@ -310,7 +311,10 @@ static int badword_captype(char_u *word, char_u *end)
bool first; bool first;
char_u *p; char_u *p;
if (flags & WF_KEEPCAP) { if (!(flags & WF_KEEPCAP)) {
return flags;
}
// Count the number of UPPER and lower case letters. // Count the number of UPPER and lower case letters.
l = u = 0; l = u = 0;
first = false; first = false;
@@ -339,7 +343,7 @@ static int badword_captype(char_u *word, char_u *end)
if (u >= 2 && l >= 2) { // maCARONI maCAroni if (u >= 2 && l >= 2) { // maCARONI maCAroni
flags |= WF_MIXCAP; flags |= WF_MIXCAP;
} }
}
return flags; return flags;
} }
@@ -3247,11 +3251,12 @@ static void add_banned(suginfo_T *su, char *word)
hash = hash_hash(word); hash = hash_hash(word);
const size_t word_len = strlen(word); const size_t word_len = strlen(word);
hi = hash_lookup(&su->su_banned, word, word_len, hash); hi = hash_lookup(&su->su_banned, word, word_len, hash);
if (HASHITEM_EMPTY(hi)) { if (!HASHITEM_EMPTY(hi)) { // already present
return;
}
s = xmemdupz(word, word_len); s = xmemdupz(word, word_len);
hash_add_item(&su->su_banned, hi, (char *)s, hash); hash_add_item(&su->su_banned, hi, (char *)s, hash);
} }
}
/// Recompute the score for all suggestions if sound-folding is possible. This /// Recompute the score for all suggestions if sound-folding is possible. This
/// is slow, thus only done for the final results. /// is slow, thus only done for the final results.
@@ -3317,7 +3322,10 @@ static int sug_compare(const void *s1, const void *s2)
static int cleanup_suggestions(garray_T *gap, int maxscore, int keep) static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (gap->ga_len > 0) { if (gap->ga_len <= 0) {
return maxscore;
}
// Sort the list. // Sort the list.
qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare); qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
@@ -3333,7 +3341,6 @@ static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
return stp[keep - 1].st_score; return stp[keep - 1].st_score;
} }
} }
}
return maxscore; return maxscore;
} }

View File

@@ -721,11 +721,13 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
static void save_chartab(char *chartab) static void save_chartab(char *chartab)
{ {
if (syn_block->b_syn_isk != empty_option) { if (syn_block->b_syn_isk == empty_option) {
return;
}
memmove(chartab, syn_buf->b_chartab, (size_t)32); memmove(chartab, syn_buf->b_chartab, (size_t)32);
memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32); memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
} }
}
static void restore_chartab(char *chartab) static void restore_chartab(char *chartab)
{ {
@@ -737,7 +739,10 @@ static void restore_chartab(char *chartab)
/// Return true if the line-continuation pattern matches in line "lnum". /// Return true if the line-continuation pattern matches in line "lnum".
static int syn_match_linecont(linenr_T lnum) static int syn_match_linecont(linenr_T lnum)
{ {
if (syn_block->b_syn_linecont_prog != NULL) { if (syn_block->b_syn_linecont_prog == NULL) {
return false;
}
regmmatch_T regmatch; regmmatch_T regmatch;
// chartab array for syn iskeyword // chartab array for syn iskeyword
char buf_chartab[32]; char buf_chartab[32];
@@ -752,8 +757,6 @@ static int syn_match_linecont(linenr_T lnum)
restore_chartab(buf_chartab); restore_chartab(buf_chartab);
return r; return r;
} }
return false;
}
// Prepare the current state for the start of a line. // Prepare the current state for the start of a line.
static void syn_start_line(void) static void syn_start_line(void)
@@ -873,7 +876,10 @@ static void syn_stack_free_block(synblock_T *block)
{ {
synstate_T *p; synstate_T *p;
if (block->b_sst_array != NULL) { if (block->b_sst_array == NULL) {
return;
}
for (p = block->b_sst_first; p != NULL; p = p->sst_next) { for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
clear_syn_state(p); clear_syn_state(p);
} }
@@ -881,7 +887,6 @@ static void syn_stack_free_block(synblock_T *block)
block->b_sst_first = NULL; block->b_sst_first = NULL;
block->b_sst_len = 0; block->b_sst_len = 0;
} }
}
// Free b_sst_array[] for buffer "buf". // Free b_sst_array[] for buffer "buf".
// Used when syntax items changed to force resyncing everywhere. // Used when syntax items changed to force resyncing everywhere.
void syn_stack_free_all(synblock_T *block) void syn_stack_free_all(synblock_T *block)
@@ -5369,10 +5374,17 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
include_link = 0; include_link = 0;
include_default = 0; include_default = 0;
if (*arg == NUL) {
return;
}
// (part of) subcommand already typed // (part of) subcommand already typed
if (*arg != NUL) {
const char *p = (const char *)skiptowhite(arg); const char *p = (const char *)skiptowhite(arg);
if (*p != NUL) { // Past first word. if (*p == NUL) {
return;
}
// past first world
xp->xp_pattern = skipwhite(p); xp->xp_pattern = skipwhite(p);
if (*skiptowhite(xp->xp_pattern) != NUL) { if (*skiptowhite(xp->xp_pattern) != NUL) {
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
@@ -5397,8 +5409,6 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
} }
} }
}
}
// Function given to ExpandGeneric() to obtain the list syntax names for // Function given to ExpandGeneric() to obtain the list syntax names for
// expansion. // expansion.