aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-24 08:43:51 +0800
committerGitHub <noreply@github.com>2023-01-24 08:43:51 +0800
commitfa12b9ca2b1dd5515910875e04fe36564fbaadcc (patch)
treea9db5e808937b47883a341eabda44af00e0df878
parentdbb6c7f1b8bed789f5bebb73be332c063fc6a604 (diff)
downloadrneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.tar.gz
rneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.tar.bz2
rneovim-fa12b9ca2b1dd5515910875e04fe36564fbaadcc.zip
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) https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r--src/nvim/drawscreen.c40
-rw-r--r--src/nvim/ex_session.c71
-rw-r--r--src/nvim/grid.c12
-rw-r--r--src/nvim/runtime.c12
-rw-r--r--src/nvim/screen.c74
-rw-r--r--src/nvim/search.c278
-rw-r--r--src/nvim/sign.c20
-rw-r--r--src/nvim/spell.c75
-rw-r--r--src/nvim/spellfile.c193
-rw-r--r--src/nvim/spellsuggest.c127
-rw-r--r--src/nvim/syntax.c110
11 files changed, 540 insertions, 472 deletions
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 3f81fd1daa..04c342e068 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -126,12 +126,14 @@ static char *provider_err = NULL;
void conceal_check_cursor_line(void)
{
bool should_conceal = conceal_cursor_line(curwin);
- if (curwin->w_p_cole > 0 && (conceal_cursor_used != should_conceal)) {
- redrawWinline(curwin, curwin->w_cursor.lnum);
- // Need to recompute cursor column, e.g., when starting Visual mode
- // without concealing.
- curs_columns(curwin, true);
+ if (curwin->w_p_cole <= 0 || conceal_cursor_used == should_conceal) {
+ return;
}
+
+ redrawWinline(curwin, curwin->w_cursor.lnum);
+ // Need to recompute cursor column, e.g., when starting Visual mode
+ // without concealing.
+ curs_columns(curwin, true);
}
/// Resize default_grid to Rows and Columns.
@@ -837,25 +839,29 @@ static bool vsep_connected(win_T *wp, WindowCorner corner)
/// Draw the vertical separator right of window "wp"
static void draw_vsep_win(win_T *wp)
{
- if (wp->w_vsep_width) {
- // draw the vertical separator right of this window
- int hl;
- int c = fillchar_vsep(wp, &hl);
- grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
- W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
+ if (!wp->w_vsep_width) {
+ return;
}
+
+ // draw the vertical separator right of this window
+ int hl;
+ int c = fillchar_vsep(wp, &hl);
+ grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
+ W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
}
/// Draw the horizontal separator below window "wp"
static void draw_hsep_win(win_T *wp)
{
- if (wp->w_hsep_height) {
- // draw the horizontal separator below this window
- int hl;
- int c = fillchar_hsep(wp, &hl);
- grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
- wp->w_wincol, W_ENDCOL(wp), c, c, hl);
+ if (!wp->w_hsep_height) {
+ return;
}
+
+ // draw the horizontal separator below this window
+ int hl;
+ int c = fillchar_hsep(wp, &hl);
+ grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
+ wp->w_wincol, W_ENDCOL(wp), c, c, hl);
}
/// Get the separator connector for specified window corner of window "wp"
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index f15c2d258f..3de5e1db52 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -112,40 +112,43 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
frame_T *frc;
int count = 0;
- if (fr->fr_layout != FR_LEAF) {
- // Find first frame that's not skipped and then create a window for
- // each following one (first frame is already there).
- frc = ses_skipframe(fr->fr_child);
- if (frc != NULL) {
- while ((frc = ses_skipframe(frc->fr_next)) != NULL) {
- // Make window as big as possible so that we have lots of room
- // to split.
- if (fprintf(fd, "%s%s",
- "wincmd _ | wincmd |\n",
- (fr->fr_layout == FR_COL ? "split\n" : "vsplit\n")) < 0) {
- return FAIL;
- }
- count++;
+ if (fr->fr_layout == FR_LEAF) {
+ return OK;
+ }
+
+ // Find first frame that's not skipped and then create a window for
+ // each following one (first frame is already there).
+ frc = ses_skipframe(fr->fr_child);
+ if (frc != NULL) {
+ while ((frc = ses_skipframe(frc->fr_next)) != NULL) {
+ // Make window as big as possible so that we have lots of room
+ // to split.
+ if (fprintf(fd, "%s%s",
+ "wincmd _ | wincmd |\n",
+ (fr->fr_layout == FR_COL ? "split\n" : "vsplit\n")) < 0) {
+ return FAIL;
}
+ count++;
}
+ }
- // Go back to the first window.
- if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
- ? "%dwincmd k\n" : "%dwincmd h\n", count) < 0)) {
- return FAIL;
- }
+ // Go back to the first window.
+ if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
+ ? "%dwincmd k\n" : "%dwincmd h\n", count) < 0)) {
+ return FAIL;
+ }
- // Recursively create frames/windows in each window of this column or row.
- frc = ses_skipframe(fr->fr_child);
- while (frc != NULL) {
- ses_win_rec(fd, frc);
- frc = ses_skipframe(frc->fr_next);
- // Go to next window.
- if (frc != NULL && put_line(fd, "wincmd w") == FAIL) {
- return FAIL;
- }
+ // Recursively create frames/windows in each window of this column or row.
+ frc = ses_skipframe(fr->fr_child);
+ while (frc != NULL) {
+ ses_win_rec(fd, frc);
+ frc = ses_skipframe(frc->fr_next);
+ // Go to next window.
+ if (frc != NULL && put_line(fd, "wincmd w") == FAIL) {
+ return FAIL;
}
}
+
return OK;
}
@@ -906,12 +909,14 @@ static int makeopens(FILE *fd, char *dirnow)
void ex_loadview(exarg_T *eap)
{
char *fname = get_view_file(*eap->arg);
- if (fname != NULL) {
- if (do_source(fname, false, DOSO_NONE) == FAIL) {
- semsg(_(e_notopen), fname);
- }
- xfree(fname);
+ if (fname == NULL) {
+ return;
+ }
+
+ if (do_source(fname, false, DOSO_NONE) == FAIL) {
+ semsg(_(e_notopen), fname);
}
+ xfree(fname);
}
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
diff --git a/src/nvim/grid.c b/src/nvim/grid.c
index 4702e224c6..46f8a59710 100644
--- a/src/nvim/grid.c
+++ b/src/nvim/grid.c
@@ -142,16 +142,16 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr)
/// Also return its attribute in *attrp;
void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
{
- size_t off;
-
grid_adjust(&grid, &row, &col);
// safety check
- if (grid->chars != NULL && row < grid->rows && col < grid->cols) {
- off = grid->line_offset[row] + (size_t)col;
- *attrp = grid->attrs[off];
- schar_copy(bytes, grid->chars[off]);
+ if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) {
+ return;
}
+
+ size_t off = grid->line_offset[row] + (size_t)col;
+ *attrp = grid->attrs[off];
+ schar_copy(bytes, grid->chars[off]);
}
/// put string '*text' on the window grid at position 'row' and 'col', with
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 18eb2180d9..24500b80b9 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -821,12 +821,14 @@ static void source_all_matches(char *pat)
int num_files;
char **files;
- if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) {
- for (int i = 0; i < num_files; i++) {
- (void)do_source(files[i], false, DOSO_NONE);
- }
- FreeWild(num_files, files);
+ if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK) {
+ return;
+ }
+
+ for (int i = 0; i < num_files; i++) {
+ (void)do_source(files[i], false, DOSO_NONE);
}
+ FreeWild(num_files, files);
}
/// Add the package directory to 'runtimepath'
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 0b6b1d9e77..ebff52cd69 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -295,52 +295,54 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
return false;
}
- {
- buf_T *old_curbuf = curbuf;
- win_T *old_curwin = curwin;
- char *s;
-
- curbuf = wp->w_buffer;
- curwin = wp;
- STRCPY(buf, "b:keymap_name"); // must be writable
- emsg_skip++;
- s = p = eval_to_string(buf, NULL, false);
- emsg_skip--;
- curbuf = old_curbuf;
- curwin = old_curwin;
- if (p == NULL || *p == NUL) {
- if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) {
- p = wp->w_buffer->b_p_keymap;
- } else {
- p = "lang";
- }
- }
- if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) {
- buf[0] = NUL;
+ buf_T *old_curbuf = curbuf;
+ win_T *old_curwin = curwin;
+ char *s;
+
+ curbuf = wp->w_buffer;
+ curwin = wp;
+ STRCPY(buf, "b:keymap_name"); // must be writable
+ emsg_skip++;
+ s = p = eval_to_string(buf, NULL, false);
+ emsg_skip--;
+ curbuf = old_curbuf;
+ curwin = old_curwin;
+ if (p == NULL || *p == NUL) {
+ if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) {
+ p = wp->w_buffer->b_p_keymap;
+ } else {
+ p = "lang";
}
- xfree(s);
}
+ if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) {
+ buf[0] = NUL;
+ }
+ xfree(s);
return buf[0] != NUL;
}
/// Prepare for 'hlsearch' highlighting.
void start_search_hl(void)
{
- if (p_hls && !no_hlsearch) {
- end_search_hl(); // just in case it wasn't called before
- last_pat_prog(&screen_search_hl.rm);
- // Set the time limit to 'redrawtime'.
- screen_search_hl.tm = profile_setlimit(p_rdt);
+ if (!p_hls || no_hlsearch) {
+ return;
}
+
+ end_search_hl(); // just in case it wasn't called before
+ last_pat_prog(&screen_search_hl.rm);
+ // Set the time limit to 'redrawtime'.
+ screen_search_hl.tm = profile_setlimit(p_rdt);
}
/// Clean up for 'hlsearch' highlighting.
void end_search_hl(void)
{
- if (screen_search_hl.rm.regprog != NULL) {
- vim_regfree(screen_search_hl.rm.regprog);
- screen_search_hl.rm.regprog = NULL;
+ if (screen_search_hl.rm.regprog == NULL) {
+ return;
}
+
+ vim_regfree(screen_search_hl.rm.regprog);
+ screen_search_hl.rm.regprog = NULL;
}
/// Check if there should be a delay. Used before clearing or redrawing the
@@ -671,11 +673,13 @@ void clearmode(void)
static void recording_mode(int attr)
{
msg_puts_attr(_("recording"), attr);
- if (!shortmess(SHM_RECORDING)) {
- char s[4];
- snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
- msg_puts_attr(s, attr);
+ if (shortmess(SHM_RECORDING)) {
+ return;
}
+
+ char s[4];
+ snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
+ msg_puts_attr(s, attr);
}
void get_trans_bufname(buf_T *buf)
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 12fdfa8f4d..b24b6ad27c 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -206,20 +206,22 @@ char *get_search_pat(void)
void save_re_pat(int idx, char *pat, int magic)
{
- if (spats[idx].pat != pat) {
- free_spat(&spats[idx]);
- spats[idx].pat = xstrdup(pat);
- spats[idx].magic = magic;
- spats[idx].no_scs = no_smartcase;
- spats[idx].timestamp = os_time();
- spats[idx].additional_data = NULL;
- last_idx = idx;
- // If 'hlsearch' set and search pat changed: need redraw.
- if (p_hls) {
- redraw_all_later(UPD_SOME_VALID);
- }
- set_no_hlsearch(false);
+ if (spats[idx].pat == pat) {
+ return;
+ }
+
+ free_spat(&spats[idx]);
+ spats[idx].pat = xstrdup(pat);
+ spats[idx].magic = magic;
+ spats[idx].no_scs = no_smartcase;
+ spats[idx].timestamp = os_time();
+ spats[idx].additional_data = NULL;
+ last_idx = idx;
+ // If 'hlsearch' set and search pat changed: need redraw.
+ if (p_hls) {
+ redraw_all_later(UPD_SOME_VALID);
}
+ set_no_hlsearch(false);
}
// Save the search patterns, so they can be restored later.
@@ -228,38 +230,42 @@ 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 = xstrdup(spats[0].pat);
- }
- saved_spats[1] = spats[1];
- if (spats[1].pat != NULL) {
- saved_spats[1].pat = xstrdup(spats[1].pat);
- }
- if (mr_pattern == NULL) {
- saved_mr_pattern = NULL;
- } else {
- saved_mr_pattern = xstrdup(mr_pattern);
- }
- saved_spats_last_idx = last_idx;
- saved_spats_no_hlsearch = no_hlsearch;
+ if (save_level++ != 0) {
+ return;
+ }
+
+ saved_spats[0] = spats[0];
+ if (spats[0].pat != NULL) {
+ saved_spats[0].pat = xstrdup(spats[0].pat);
}
+ saved_spats[1] = spats[1];
+ if (spats[1].pat != NULL) {
+ saved_spats[1].pat = xstrdup(spats[1].pat);
+ }
+ if (mr_pattern == NULL) {
+ saved_mr_pattern = NULL;
+ } else {
+ saved_mr_pattern = xstrdup(mr_pattern);
+ }
+ saved_spats_last_idx = last_idx;
+ saved_spats_no_hlsearch = no_hlsearch;
}
void restore_search_patterns(void)
{
- if (--save_level == 0) {
- free_spat(&spats[0]);
- spats[0] = saved_spats[0];
- set_vv_searchforward();
- free_spat(&spats[1]);
- spats[1] = saved_spats[1];
- xfree(mr_pattern);
- mr_pattern = saved_mr_pattern;
- last_idx = saved_spats_last_idx;
- set_no_hlsearch(saved_spats_no_hlsearch);
+ if (--save_level != 0) {
+ return;
}
+
+ free_spat(&spats[0]);
+ spats[0] = saved_spats[0];
+ set_vv_searchforward();
+ free_spat(&spats[1]);
+ spats[1] = saved_spats[1];
+ xfree(mr_pattern);
+ mr_pattern = saved_mr_pattern;
+ last_idx = saved_spats_last_idx;
+ set_no_hlsearch(saved_spats_no_hlsearch);
}
static inline void free_spat(struct spat *const spat)
@@ -2321,55 +2327,63 @@ void showmatch(int c)
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_inner)) {
- 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(); // show the new char first
-
- save_dollar_vcol = dollar_vcol;
- save_state = State;
- State = MODE_SHOWMATCH;
- ui_cursor_shape(); // may show different cursor shape
- curwin->w_cursor = mpos; // move to matching char
- *so = 0; // don't use 'scrolloff' here
- *siso = 0; // don't use 'sidescrolloff' here
- show_cursor_info(false);
- setcursor();
- ui_flush();
- // 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) {
- os_delay((uint64_t)p_mat * 100L + 8, true);
- } else if (!char_avail()) {
- os_delay((uint64_t)p_mat * 100L + 9, false);
- }
- curwin->w_cursor = save_cursor; // restore cursor position
- *so = save_so;
- *siso = save_siso;
- State = save_state;
- ui_cursor_shape(); // may show different cursor shape
- }
+ return;
+ }
+
+ if (lpos->lnum < curwin->w_topline || lpos->lnum >= curwin->w_botline) {
+ return;
+ }
+
+ if (!curwin->w_p_wrap) {
+ getvcol(curwin, lpos, NULL, &vcol, NULL);
+ }
+
+ bool col_visible = curwin->w_p_wrap
+ || (vcol >= curwin->w_leftcol
+ && vcol < curwin->w_leftcol + curwin->w_width_inner);
+ 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(); // show the new char first
+
+ save_dollar_vcol = dollar_vcol;
+ save_state = State;
+ State = MODE_SHOWMATCH;
+ ui_cursor_shape(); // may show different cursor shape
+ curwin->w_cursor = mpos; // move to matching char
+ *so = 0; // don't use 'scrolloff' here
+ *siso = 0; // don't use 'sidescrolloff' here
+ show_cursor_info(false);
+ setcursor();
+ ui_flush();
+ // 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) {
+ os_delay((uint64_t)p_mat * 100L + 8, true);
+ } else if (!char_avail()) {
+ os_delay((uint64_t)p_mat * 100L + 9, false);
+ }
+ curwin->w_cursor = save_cursor; // restore cursor position
+ *so = save_so;
+ *siso = save_siso;
+ State = save_state;
+ ui_cursor_shape(); // may show different cursor shape
}
/// Find next search match under cursor, cursor at end.
@@ -2588,56 +2602,58 @@ 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,
timeout);
- if (stat.cur > 0) {
- char t[SEARCH_STAT_BUF_LEN];
-
- 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 (stat.cur <= 0) {
+ return;
+ }
+
+ char t[SEARCH_STAT_BUF_LEN];
+
+ 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 {
- 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);
- }
+ vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
+ stat.cnt, stat.cur);
}
-
- size_t len = strlen(t);
- if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) {
- memmove(t + 2, t, len);
- t[0] = 'W';
- t[1] = ' ';
- len += 2;
+ } else {
+ 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);
}
+ }
- memmove(msgbuf + strlen(msgbuf) - len, t, len);
- if (dirc == '?' && stat.cur == maxcount + 1) {
- stat.cur = -1;
- }
+ size_t len = strlen(t);
+ if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) {
+ memmove(t + 2, t, len);
+ t[0] = 'W';
+ t[1] = ' ';
+ len += 2;
+ }
- // keep the message even after redraw, but don't put in history
- msg_hist_off = true;
- msg_ext_set_kind("search_count");
- give_warning(msgbuf, false);
- msg_hist_off = false;
+ 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;
+ msg_ext_set_kind("search_count");
+ give_warning(msgbuf, false);
+ msg_hist_off = false;
}
// Add the search count information to "stat".
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index 753c814110..d0c093d93a 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -122,17 +122,17 @@ static signgroup_T *sign_group_ref(const char *groupname)
/// removed, then remove the group.
static void sign_group_unref(char *groupname)
{
- signgroup_T *group;
-
hashitem_T *hi = hash_find(&sg_table, groupname);
- if (!HASHITEM_EMPTY(hi)) {
- group = HI2SG(hi);
- group->sg_refcount--;
- if (group->sg_refcount == 0) {
- // All the signs in this group are removed
- hash_remove(&sg_table, hi);
- xfree(group);
- }
+ if (HASHITEM_EMPTY(hi)) {
+ return;
+ }
+
+ signgroup_T *group = HI2SG(hi);
+ group->sg_refcount--;
+ if (group->sg_refcount == 0) {
+ // All the signs in this group are removed
+ hash_remove(&sg_table, hi);
+ xfree(group);
}
}
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 215c546f83..8e18be5bd1 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -1488,14 +1488,16 @@ void spell_cat_line(char *buf, char *line, int maxlen)
p = (char_u *)skipwhite((char *)p + 1);
}
- if (*p != NUL) {
- // Only worth concatenating if there is something else than spaces to
- // concatenate.
- int n = (int)(p - (char_u *)line) + 1;
- if (n < maxlen - 1) {
- memset(buf, ' ', (size_t)n);
- xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
- }
+ if (*p == NUL) {
+ return;
+ }
+
+ // Only worth concatenating if there is something else than spaces to
+ // concatenate.
+ int n = (int)(p - (char_u *)line) + 1;
+ if (n < maxlen - 1) {
+ memset(buf, ' ', (size_t)n);
+ xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
}
}
@@ -1702,17 +1704,19 @@ static void spell_load_cb(char *fname, void *cookie)
{
spelload_T *slp = (spelload_T *)cookie;
slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false);
- if (slang != NULL) {
- // When a previously loaded file has NOBREAK also use it for the
- // ".add" files.
- if (slp->sl_nobreak && slang->sl_add) {
- slang->sl_nobreak = true;
- } else if (slang->sl_nobreak) {
- slp->sl_nobreak = true;
- }
+ if (slang == NULL) {
+ return;
+ }
- slp->sl_slang = slang;
+ // When a previously loaded file has NOBREAK also use it for the
+ // ".add" files.
+ if (slp->sl_nobreak && slang->sl_add) {
+ slang->sl_nobreak = true;
+ } else if (slang->sl_nobreak) {
+ slp->sl_nobreak = true;
}
+
+ slp->sl_slang = slang;
}
/// Add a word to the hashtable of common words.
@@ -2258,13 +2262,15 @@ int captype(char *word, const char *end)
// Delete the internal wordlist and its .spl file.
void spell_delete_wordlist(void)
{
- if (int_wordlist != NULL) {
- char fname[MAXPATHL] = { 0 };
- os_remove(int_wordlist);
- int_wordlist_spl(fname);
- os_remove(fname);
- XFREE_CLEAR(int_wordlist);
+ if (int_wordlist == NULL) {
+ return;
}
+
+ char fname[MAXPATHL] = { 0 };
+ os_remove(int_wordlist);
+ int_wordlist_spl(fname);
+ os_remove(fname);
+ XFREE_CLEAR(int_wordlist);
}
// Free all languages.
@@ -2332,10 +2338,12 @@ buf_T *open_spellbuf(void)
// Close the buffer used for spell info.
void close_spellbuf(buf_T *buf)
{
- if (buf != NULL) {
- ml_close(buf, true);
- xfree(buf);
+ if (buf == NULL) {
+ return;
}
+
+ ml_close(buf, true);
+ xfree(buf);
}
// Init the chartab used for spelling for ASCII.
@@ -3624,15 +3632,16 @@ char *did_set_spell_option(bool is_spellfile)
}
}
- if (errmsg == NULL) {
- FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- if (wp->w_buffer == curbuf && wp->w_p_spell) {
- errmsg = did_set_spelllang(wp);
- break;
- }
- }
+ if (errmsg != NULL) {
+ return errmsg;
}
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (wp->w_buffer == curbuf && wp->w_p_spell) {
+ errmsg = did_set_spelllang(wp);
+ break;
+ }
+ }
return errmsg;
}
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 1224e9cb9a..44414ca1a5 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -1695,23 +1695,25 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
// Invalid length, multiply with sizeof(int) would overflow.
return SP_FORMERROR;
}
- if (len > 0) {
- // Allocate the byte array.
- bp = xmalloc((size_t)len);
- *bytsp = bp;
- if (bytsp_len != NULL) {
- *bytsp_len = len;
- }
+ if (len <= 0) {
+ return 0;
+ }
- // Allocate the index array.
- ip = xcalloc((size_t)len, sizeof(*ip));
- *idxsp = ip;
+ // Allocate the byte array.
+ bp = xmalloc((size_t)len);
+ *bytsp = bp;
+ if (bytsp_len != NULL) {
+ *bytsp_len = len;
+ }
- // Recursively read the tree and store it in the array.
- idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt);
- if (idx < 0) {
- return idx;
- }
+ // Allocate the index array.
+ ip = xcalloc((size_t)len, sizeof(*ip));
+ *idxsp = ip;
+
+ // Recursively read the tree and store it in the array.
+ idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt);
+ if (idx < 0) {
+ return idx;
}
return 0;
}
@@ -2003,14 +2005,15 @@ static void spell_print_node(wordnode_T *node, int depth)
static void spell_print_tree(wordnode_T *root)
{
- if (root != NULL) {
- // Clear the "wn_u1.index" fields, used to remember what has been
- // done.
- spell_clear_flags(root);
-
- // Recursively print the tree.
- spell_print_node(root, 0);
+ if (root == NULL) {
+ return;
}
+
+ // Clear the "wn_u1.index" fields, used to remember what has been done.
+ spell_clear_flags(root);
+
+ // Recursively print the tree.
+ spell_print_node(root, 0);
}
#endif // SPELL_PRINTTREE
@@ -4197,31 +4200,33 @@ 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
// start of the tree.
- if (root->wn_sibling != NULL) {
- hash_init(&ht);
- const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
+ if (root->wn_sibling == NULL) {
+ return;
+ }
+
+ hash_init(&ht);
+ const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
#ifndef SPELL_PRINTTREE
- if (spin->si_verbose || p_verbose > 2)
+ if (spin->si_verbose || p_verbose > 2)
#endif
- {
- if (tot > 1000000) {
- perc = (tot - n) / (tot / 100);
- } else if (tot == 0) {
- perc = 0;
- } else {
- perc = (tot - n) * 100 / tot;
- }
- vim_snprintf(IObuff, IOSIZE,
- _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"),
- name, tot, tot - n, perc);
- spell_message(spin, IObuff);
+ {
+ if (tot > 1000000) {
+ perc = (tot - n) / (tot / 100);
+ } else if (tot == 0) {
+ perc = 0;
+ } else {
+ perc = (tot - n) * 100 / tot;
}
+ vim_snprintf(IObuff, IOSIZE,
+ _("Compressed %s of %ld nodes; %ld (%ld%%) remaining"),
+ name, tot, tot - n, perc);
+ spell_message(spin, IObuff);
+ }
#ifdef SPELL_PRINTTREE
- spell_print_tree(root->wn_sibling);
+ spell_print_tree(root->wn_sibling);
#endif
- hash_clear(&ht);
- }
+ hash_clear(&ht);
}
/// Compress a node, its siblings and its children, depth first.
@@ -4887,10 +4892,12 @@ void ex_mkspell(exarg_T *eap)
}
// Expand all the remaining arguments (e.g., $VIMRUNTIME).
- if (get_arglist_exp(arg, &fcount, &fnames, false) == OK) {
- mkspell(fcount, fnames, ascii, eap->forceit, false);
- FreeWild(fcount, fnames);
+ if (get_arglist_exp(arg, &fcount, &fnames, false) != OK) {
+ return;
}
+
+ mkspell(fcount, fnames, ascii, eap->forceit, false);
+ FreeWild(fcount, fnames);
}
// Create the .sug file.
@@ -5681,64 +5688,66 @@ static void init_spellfile(void)
bool aspath = false;
char *lstart = curbuf->b_s.b_p_spl;
- if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
- buf = xmalloc(MAXPATHL);
+ if (*curwin->w_s->b_p_spl == NUL || GA_EMPTY(&curwin->w_s->b_langp)) {
+ return;
+ }
- // Find the end of the language name. Exclude the region. If there
- // is a path separator remember the start of the tail.
- for (lend = curwin->w_s->b_p_spl; *lend != NUL
- && vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) {
- if (vim_ispathsep(*lend)) {
- aspath = true;
- lstart = lend + 1;
- }
+ buf = xmalloc(MAXPATHL);
+
+ // Find the end of the language name. Exclude the region. If there
+ // is a path separator remember the start of the tail.
+ for (lend = curwin->w_s->b_p_spl; *lend != NUL
+ && vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) {
+ if (vim_ispathsep(*lend)) {
+ aspath = true;
+ lstart = lend + 1;
}
+ }
- // Loop over all entries in 'runtimepath'. Use the first one where we
- // are allowed to write.
- rtp = p_rtp;
- while (*rtp != NUL) {
+ // Loop over all entries in 'runtimepath'. Use the first one where we
+ // are allowed to write.
+ rtp = p_rtp;
+ while (*rtp != NUL) {
+ if (aspath) {
+ // Use directory of an entry with path, e.g., for
+ // "/dir/lg.utf-8.spl" use "/dir".
+ xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl));
+ } else {
+ // Copy the path from 'runtimepath' to buf[].
+ copy_option_part(&rtp, buf, MAXPATHL, ",");
+ }
+ if (os_file_is_writable(buf) == 2) {
+ // Use the first language name from 'spelllang' and the
+ // encoding used in the first loaded .spl file.
if (aspath) {
- // Use directory of an entry with path, e.g., for
- // "/dir/lg.utf-8.spl" use "/dir".
- xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl));
+ xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1));
} else {
- // Copy the path from 'runtimepath' to buf[].
- copy_option_part(&rtp, buf, MAXPATHL, ",");
- }
- if (os_file_is_writable(buf) == 2) {
- // Use the first language name from 'spelllang' and the
- // encoding used in the first loaded .spl file.
- if (aspath) {
- xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1));
- } else {
- // Create the "spell" directory if it doesn't exist yet.
- l = (int)strlen(buf);
- vim_snprintf(buf + l, MAXPATHL - (size_t)l, "/spell");
- if (os_file_is_writable(buf) != 2) {
- os_mkdir(buf, 0755);
- }
-
- l = (int)strlen(buf);
- vim_snprintf(buf + l, MAXPATHL - (size_t)l,
- "/%.*s", (int)(lend - lstart), lstart);
+ // Create the "spell" directory if it doesn't exist yet.
+ l = (int)strlen(buf);
+ vim_snprintf(buf + l, MAXPATHL - (size_t)l, "/spell");
+ if (os_file_is_writable(buf) != 2) {
+ os_mkdir(buf, 0755);
}
+
l = (int)strlen(buf);
- fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
- ->lp_slang->sl_fname;
- vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add",
- ((fname != NULL
- && strstr(path_tail(fname), ".ascii.") != NULL)
- ? "ascii"
- : (const char *)spell_enc()));
- set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL);
- break;
+ vim_snprintf(buf + l, MAXPATHL - (size_t)l,
+ "/%.*s", (int)(lend - lstart), lstart);
}
- aspath = false;
+ l = (int)strlen(buf);
+ fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
+ ->lp_slang->sl_fname;
+ vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add",
+ ((fname != NULL
+ && strstr(path_tail(fname), ".ascii.") != NULL)
+ ? "ascii"
+ : (const char *)spell_enc()));
+ set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL);
+ break;
}
-
- xfree(buf);
+ aspath = false;
}
+
+ xfree(buf);
}
/// Set the spell character tables from strings in the .spl file.
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index 7823a411f3..22add418a0 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -276,26 +276,27 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
int newscore;
hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
- if (!HASHITEM_EMPTY(hi)) {
- wc = HI2WC(hi);
- if (wc->wc_count < SCORE_THRES2) {
- bonus = SCORE_COMMON1;
- } else if (wc->wc_count < SCORE_THRES3) {
- bonus = SCORE_COMMON2;
- } else {
- bonus = SCORE_COMMON3;
- }
- if (split) {
- newscore = score - bonus / 2;
- } else {
- newscore = score - bonus;
- }
- if (newscore < 0) {
- return 0;
- }
- return newscore;
+ if (HASHITEM_EMPTY(hi)) {
+ return score;
+ }
+
+ wc = HI2WC(hi);
+ if (wc->wc_count < SCORE_THRES2) {
+ bonus = SCORE_COMMON1;
+ } else if (wc->wc_count < SCORE_THRES3) {
+ bonus = SCORE_COMMON2;
+ } else {
+ bonus = SCORE_COMMON3;
+ }
+ if (split) {
+ newscore = score - bonus / 2;
+ } else {
+ newscore = score - bonus;
+ }
+ if (newscore < 0) {
+ return 0;
}
- return score;
+ return newscore;
}
/// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
@@ -310,36 +311,39 @@ static int badword_captype(char_u *word, char_u *end)
bool first;
char_u *p;
- if (flags & WF_KEEPCAP) {
- // Count the number of UPPER and lower case letters.
- l = u = 0;
- first = false;
- for (p = word; p < end; MB_PTR_ADV(p)) {
- c = utf_ptr2char((char *)p);
- if (SPELL_ISUPPER(c)) {
- u++;
- if (p == word) {
- first = true;
- }
- } else {
- l++;
+ if (!(flags & WF_KEEPCAP)) {
+ return flags;
+ }
+
+ // Count the number of UPPER and lower case letters.
+ l = u = 0;
+ first = false;
+ for (p = word; p < end; MB_PTR_ADV(p)) {
+ c = utf_ptr2char((char *)p);
+ if (SPELL_ISUPPER(c)) {
+ u++;
+ if (p == word) {
+ first = true;
}
+ } else {
+ l++;
}
+ }
- // If there are more UPPER than lower case letters suggest an
- // ALLCAP word. Otherwise, if the first letter is UPPER then
- // suggest ONECAP. Exception: "ALl" most likely should be "All",
- // require three upper case letters.
- if (u > l && u > 2) {
- flags |= WF_ALLCAP;
- } else if (first) {
- flags |= WF_ONECAP;
- }
+ // If there are more UPPER than lower case letters suggest an
+ // ALLCAP word. Otherwise, if the first letter is UPPER then
+ // suggest ONECAP. Exception: "ALl" most likely should be "All",
+ // require three upper case letters.
+ if (u > l && u > 2) {
+ flags |= WF_ALLCAP;
+ } else if (first) {
+ flags |= WF_ONECAP;
+ }
- if (u >= 2 && l >= 2) { // maCARONI maCAroni
- flags |= WF_MIXCAP;
- }
+ if (u >= 2 && l >= 2) { // maCARONI maCAroni
+ flags |= WF_MIXCAP;
}
+
return flags;
}
@@ -3247,10 +3251,11 @@ static void add_banned(suginfo_T *su, char *word)
hash = hash_hash(word);
const size_t word_len = strlen(word);
hi = hash_lookup(&su->su_banned, word, word_len, hash);
- if (HASHITEM_EMPTY(hi)) {
- s = xmemdupz(word, word_len);
- hash_add_item(&su->su_banned, hi, (char *)s, hash);
+ if (!HASHITEM_EMPTY(hi)) { // already present
+ return;
}
+ s = xmemdupz(word, word_len);
+ hash_add_item(&su->su_banned, hi, (char *)s, hash);
}
/// Recompute the score for all suggestions if sound-folding is possible. This
@@ -3317,21 +3322,23 @@ static int sug_compare(const void *s1, const void *s2)
static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
FUNC_ATTR_NONNULL_ALL
{
- if (gap->ga_len > 0) {
- // Sort the list.
- qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
+ if (gap->ga_len <= 0) {
+ return maxscore;
+ }
- // Truncate the list to the number of suggestions that will be displayed.
- if (gap->ga_len > keep) {
- suggest_T *const stp = &SUG(*gap, 0);
+ // Sort the list.
+ qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
- for (int i = keep; i < gap->ga_len; i++) {
- xfree(stp[i].st_word);
- }
- gap->ga_len = keep;
- if (keep >= 1) {
- return stp[keep - 1].st_score;
- }
+ // Truncate the list to the number of suggestions that will be displayed.
+ if (gap->ga_len > keep) {
+ suggest_T *const stp = &SUG(*gap, 0);
+
+ for (int i = keep; i < gap->ga_len; i++) {
+ xfree(stp[i].st_word);
+ }
+ gap->ga_len = keep;
+ if (keep >= 1) {
+ return stp[keep - 1].st_score;
}
}
return maxscore;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index edf44b816f..05c570e52f 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -721,10 +721,12 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
static void save_chartab(char *chartab)
{
- if (syn_block->b_syn_isk != empty_option) {
- memmove(chartab, syn_buf->b_chartab, (size_t)32);
- memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
+ if (syn_block->b_syn_isk == empty_option) {
+ return;
}
+
+ memmove(chartab, syn_buf->b_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)
@@ -737,22 +739,23 @@ static void restore_chartab(char *chartab)
/// Return true if the line-continuation pattern matches in line "lnum".
static int syn_match_linecont(linenr_T lnum)
{
- if (syn_block->b_syn_linecont_prog != NULL) {
- regmmatch_T regmatch;
- // chartab array for syn iskeyword
- char buf_chartab[32];
- save_chartab(buf_chartab);
+ if (syn_block->b_syn_linecont_prog == NULL) {
+ return false;
+ }
- regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
- regmatch.regprog = syn_block->b_syn_linecont_prog;
- int r = syn_regexec(&regmatch, lnum, (colnr_T)0,
- IF_SYN_TIME(&syn_block->b_syn_linecont_time));
- syn_block->b_syn_linecont_prog = regmatch.regprog;
+ regmmatch_T regmatch;
+ // chartab array for syn iskeyword
+ char buf_chartab[32];
+ save_chartab(buf_chartab);
- restore_chartab(buf_chartab);
- return r;
- }
- return false;
+ regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
+ regmatch.regprog = syn_block->b_syn_linecont_prog;
+ int r = syn_regexec(&regmatch, lnum, (colnr_T)0,
+ IF_SYN_TIME(&syn_block->b_syn_linecont_time));
+ syn_block->b_syn_linecont_prog = regmatch.regprog;
+
+ restore_chartab(buf_chartab);
+ return r;
}
// Prepare the current state for the start of a line.
@@ -873,14 +876,16 @@ static void syn_stack_free_block(synblock_T *block)
{
synstate_T *p;
- if (block->b_sst_array != NULL) {
- for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
- clear_syn_state(p);
- }
- XFREE_CLEAR(block->b_sst_array);
- block->b_sst_first = NULL;
- block->b_sst_len = 0;
+ if (block->b_sst_array == NULL) {
+ return;
+ }
+
+ for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
+ clear_syn_state(p);
}
+ XFREE_CLEAR(block->b_sst_array);
+ block->b_sst_first = NULL;
+ block->b_sst_len = 0;
}
// Free b_sst_array[] for buffer "buf".
// Used when syntax items changed to force resyncing everywhere.
@@ -5369,34 +5374,39 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
include_link = 0;
include_default = 0;
+ if (*arg == NUL) {
+ return;
+ }
+
// (part of) subcommand already typed
- if (*arg != NUL) {
- const char *p = (const char *)skiptowhite(arg);
- if (*p != NUL) { // Past first word.
- xp->xp_pattern = skipwhite(p);
- if (*skiptowhite(xp->xp_pattern) != NUL) {
- xp->xp_context = EXPAND_NOTHING;
- } else if (STRNICMP(arg, "case", p - arg) == 0) {
- expand_what = EXP_CASE;
- } else if (STRNICMP(arg, "spell", p - arg) == 0) {
- expand_what = EXP_SPELL;
- } else if (STRNICMP(arg, "sync", p - arg) == 0) {
- expand_what = EXP_SYNC;
- } else if (STRNICMP(arg, "list", p - arg) == 0) {
- p = skipwhite(p);
- if (*p == '@') {
- expand_what = EXP_CLUSTER;
- } else {
- xp->xp_context = EXPAND_HIGHLIGHT;
- }
- } else if (STRNICMP(arg, "keyword", p - arg) == 0
- || STRNICMP(arg, "region", p - arg) == 0
- || STRNICMP(arg, "match", p - arg) == 0) {
- xp->xp_context = EXPAND_HIGHLIGHT;
- } else {
- xp->xp_context = EXPAND_NOTHING;
- }
+ const char *p = (const char *)skiptowhite(arg);
+ if (*p == NUL) {
+ return;
+ }
+
+ // past first world
+ xp->xp_pattern = skipwhite(p);
+ if (*skiptowhite(xp->xp_pattern) != NUL) {
+ xp->xp_context = EXPAND_NOTHING;
+ } else if (STRNICMP(arg, "case", p - arg) == 0) {
+ expand_what = EXP_CASE;
+ } else if (STRNICMP(arg, "spell", p - arg) == 0) {
+ expand_what = EXP_SPELL;
+ } else if (STRNICMP(arg, "sync", p - arg) == 0) {
+ expand_what = EXP_SYNC;
+ } else if (STRNICMP(arg, "list", p - arg) == 0) {
+ p = skipwhite(p);
+ if (*p == '@') {
+ expand_what = EXP_CLUSTER;
+ } else {
+ xp->xp_context = EXPAND_HIGHLIGHT;
}
+ } else if (STRNICMP(arg, "keyword", p - arg) == 0
+ || STRNICMP(arg, "region", p - arg) == 0
+ || STRNICMP(arg, "match", p - arg) == 0) {
+ xp->xp_context = EXPAND_HIGHLIGHT;
+ } else {
+ xp->xp_context = EXPAND_NOTHING;
}
}