diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-01-09 19:04:23 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-01-09 19:04:23 +0000 |
commit | 1cfb14aa972ccf3235ac67f07b7db1175b7c5384 (patch) | |
tree | b746eda548993b9e0987d7c9c0c543ddddc5758f /src | |
parent | 765d82a657c5e42d5d7c88ae410e53f398c34c43 (diff) |
patch 9.0.1166: code is indented more than necessaryv9.0.1166
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11792)
Diffstat (limited to 'src')
-rw-r--r-- | src/autocmd.c | 24 | ||||
-rw-r--r-- | src/buffer.c | 114 | ||||
-rw-r--r-- | src/charset.c | 29 | ||||
-rw-r--r-- | src/cindent.c | 107 | ||||
-rw-r--r-- | src/clientserver.c | 28 | ||||
-rw-r--r-- | src/cmdexpand.c | 29 | ||||
-rw-r--r-- | src/debugger.c | 43 | ||||
-rw-r--r-- | src/dict.c | 130 | ||||
-rw-r--r-- | src/diff.c | 16 | ||||
-rw-r--r-- | src/digraph.c | 39 | ||||
-rw-r--r-- | src/edit.c | 12 | ||||
-rw-r--r-- | src/evalfunc.c | 108 | ||||
-rw-r--r-- | src/evalwindow.c | 60 | ||||
-rw-r--r-- | src/ex_cmds.c | 96 | ||||
-rw-r--r-- | src/ex_cmds2.c | 44 | ||||
-rw-r--r-- | src/ex_getln.c | 16 | ||||
-rw-r--r-- | src/filepath.c | 30 | ||||
-rw-r--r-- | src/findfile.c | 41 | ||||
-rw-r--r-- | src/fold.c | 2 | ||||
-rw-r--r-- | src/hardcopy.c | 180 | ||||
-rw-r--r-- | src/highlight.c | 638 | ||||
-rw-r--r-- | src/version.c | 2 |
22 files changed, 907 insertions, 881 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index 20c5afa744..c18d2a15ab 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -1063,18 +1063,18 @@ au_get_grouparg(char_u **argp) for (p = arg; *p && !VIM_ISWHITE(*p) && *p != '|'; ++p) ; - if (p > arg) - { - group_name = vim_strnsave(arg, p - arg); - if (group_name == NULL) // out of memory - return AUGROUP_ERROR; - group = au_find_group(group_name); - if (group == AUGROUP_ERROR) - group = AUGROUP_ALL; // no match, use all groups - else - *argp = skipwhite(p); // match, skip over group name - vim_free(group_name); - } + if (p <= arg) + return AUGROUP_ALL; + + group_name = vim_strnsave(arg, p - arg); + if (group_name == NULL) // out of memory + return AUGROUP_ERROR; + group = au_find_group(group_name); + if (group == AUGROUP_ERROR) + group = AUGROUP_ALL; // no match, use all groups + else + *argp = skipwhite(p); // match, skip over group name + vim_free(group_name); return group; } diff --git a/src/buffer.c b/src/buffer.c index 4016822616..a3de68df29 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -357,34 +357,34 @@ open_buffer( apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); #endif - if (retval == OK) + if (retval != OK) + return retval; + + // The autocommands may have changed the current buffer. Apply the + // modelines to the correct buffer, if it still exists and is loaded. + if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) { - // The autocommands may have changed the current buffer. Apply the - // modelines to the correct buffer, if it still exists and is loaded. - if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) - { - aco_save_T aco; + aco_save_T aco; - // Go to the buffer that was opened, make sure it is in a window. - // If not then skip it. - aucmd_prepbuf(&aco, old_curbuf.br_buf); - if (curbuf == old_curbuf.br_buf) - { - do_modelines(0); - curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); + // Go to the buffer that was opened, make sure it is in a window. + // If not then skip it. + aucmd_prepbuf(&aco, old_curbuf.br_buf); + if (curbuf == old_curbuf.br_buf) + { + do_modelines(0); + curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); - if ((flags & READ_NOWINENTER) == 0) + if ((flags & READ_NOWINENTER) == 0) #ifdef FEAT_EVAL - apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, - FALSE, curbuf, &retval); + apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, + FALSE, curbuf, &retval); #else - apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, - FALSE, curbuf); + apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, + FALSE, curbuf); #endif - // restore curwin/curbuf and a few other things - aucmd_restbuf(&aco); - } + // restore curwin/curbuf and a few other things + aucmd_restbuf(&aco); } } @@ -1761,7 +1761,6 @@ do_bufdel( } } - return errormsg; } @@ -3019,20 +3018,20 @@ fname_match( char_u *p; // extra check for valid arguments - if (name != NULL && rmp->regprog != NULL) + if (name == NULL || rmp->regprog == NULL) + return NULL; + + // Ignore case when 'fileignorecase' or the argument is set. + rmp->rm_ic = p_fic || ignore_case; + if (vim_regexec(rmp, name, (colnr_T)0)) + match = name; + else if (rmp->regprog != NULL) { - // Ignore case when 'fileignorecase' or the argument is set. - rmp->rm_ic = p_fic || ignore_case; - if (vim_regexec(rmp, name, (colnr_T)0)) + // Replace $(HOME) with '~' and try matching again. + p = home_replace_save(NULL, name); + if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) match = name; - else if (rmp->regprog != NULL) - { - // Replace $(HOME) with '~' and try matching again. - p = home_replace_save(NULL, name); - if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) - match = name; - vim_free(p); - } + vim_free(p); } return match; @@ -3160,16 +3159,15 @@ wininfo_other_tab_diff(wininfo_T *wip) { win_T *wp; - if (wip->wi_opt.wo_diff) - { - FOR_ALL_WINDOWS(wp) - // return FALSE when it's a window in the current tab page, thus - // the buffer was in diff mode here - if (wip->wi_win == wp) - return FALSE; - return TRUE; - } - return FALSE; + if (!wip->wi_opt.wo_diff) + return FALSE; + + FOR_ALL_WINDOWS(wp) + // return FALSE when it's a window in the current tab page, thus + // the buffer was in diff mode here + if (wip->wi_win == wp) + return FALSE; + return TRUE; } #endif @@ -3198,27 +3196,27 @@ find_wininfo( && (!need_options || wip->wi_optset)) break; + if (wip != NULL) + return wip; + // If no wininfo for curwin, use the first in the list (that doesn't have // 'diff' set and is in another tab page). // If "need_options" is TRUE skip entries that don't have options set, // unless the window is editing "buf", so we can copy from the window // itself. - if (wip == NULL) - { #ifdef FEAT_DIFF - if (skip_diff_buffer) - { - FOR_ALL_BUF_WININFO(buf, wip) - if (!wininfo_other_tab_diff(wip) - && (!need_options || wip->wi_optset - || (wip->wi_win != NULL - && wip->wi_win->w_buffer == buf))) - break; - } - else -#endif - wip = buf->b_wininfo; + if (skip_diff_buffer) + { + FOR_ALL_BUF_WININFO(buf, wip) + if (!wininfo_other_tab_diff(wip) + && (!need_options || wip->wi_optset + || (wip->wi_win != NULL + && wip->wi_win->w_buffer == buf))) + break; } + else +#endif + wip = buf->b_wininfo; return wip; } diff --git a/src/charset.c b/src/charset.c index 8d7b61a4a6..0bad471e45 100644 --- a/src/charset.c +++ b/src/charset.c @@ -345,24 +345,25 @@ transstr(char_u *s) } else res = alloc(vim_strsize(s) + 1); - if (res != NULL) + + if (res == NULL) + return NULL; + + *res = NUL; + p = s; + while (*p != NUL) { - *res = NUL; - p = s; - while (*p != NUL) + if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { - if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) - { - c = (*mb_ptr2char)(p); - if (vim_isprintc(c)) - STRNCAT(res, p, l); // append printable multi-byte char - else - transchar_hex(res + STRLEN(res), c); - p += l; - } + c = (*mb_ptr2char)(p); + if (vim_isprintc(c)) + STRNCAT(res, p, l); // append printable multi-byte char else - STRCAT(res, transchar_byte(*p++)); + transchar_hex(res + STRLEN(res), c); + p += l; } + else + STRCAT(res, transchar_byte(*p++)); } return res; } diff --git a/src/cindent.c b/src/cindent.c index 105e08cc8c..bc71cc092f 100644 --- a/src/cindent.c +++ b/src/cindent.c @@ -46,21 +46,21 @@ cin_is_cinword(char_u *line) cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1; cinw_buf = alloc(cinw_len); - if (cinw_buf != NULL) + if (cinw_buf == NULL) + return FALSE; + + line = skipwhite(line); + for (cinw = curbuf->b_p_cinw; *cinw; ) { - line = skipwhite(line); - for (cinw = curbuf->b_p_cinw; *cinw; ) + len = copy_option_part(&cinw, cinw_buf, cinw_len, ","); + if (STRNCMP(line, cinw_buf, len) == 0 + && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) { - len = copy_option_part(&cinw, cinw_buf, cinw_len, ","); - if (STRNCMP(line, cinw_buf, len) == 0 - && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) - { - retval = TRUE; - break; - } + retval = TRUE; + break; } - vim_free(cinw_buf); } + vim_free(cinw_buf); return retval; } @@ -644,43 +644,42 @@ cin_islabel(void) // XXX if (cin_isscopedecl(s)) return FALSE; - if (cin_islabel_skip(&s)) - { - // Only accept a label if the previous line is terminated or is a case - // label. - pos_T cursor_save; - pos_T *trypos; - char_u *line; + if (!cin_islabel_skip(&s)) + return FALSE; - cursor_save = curwin->w_cursor; - while (curwin->w_cursor.lnum > 1) - { - --curwin->w_cursor.lnum; + // Only accept a label if the previous line is terminated or is a case + // label. + pos_T cursor_save; + pos_T *trypos; + char_u *line; - // If we're in a comment or raw string now, skip to the start of - // it. - curwin->w_cursor.col = 0; - if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX - curwin->w_cursor = *trypos; + cursor_save = curwin->w_cursor; + while (curwin->w_cursor.lnum > 1) + { + --curwin->w_cursor.lnum; - line = ml_get_curline(); - if (cin_ispreproc(line)) // ignore #defines, #if, etc. - continue; - if (*(line = cin_skipcomment(line)) == NUL) - continue; + // If we're in a comment or raw string now, skip to the start of + // it. + curwin->w_cursor.col = 0; + if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX + curwin->w_cursor = *trypos; + + line = ml_get_curline(); + if (cin_ispreproc(line)) // ignore #defines, #if, etc. + continue; + if (*(line = cin_skipcomment(line)) == NUL) + continue; - curwin->w_cursor = cursor_save; - if (cin_isterminated(line, TRUE, FALSE) - || cin_isscopedecl(line) - || cin_iscase(line, TRUE) - || (cin_islabel_skip(&line) && cin_nocode(line))) - return TRUE; - return FALSE; - } curwin->w_cursor = cursor_save; - return TRUE; // label at start of file??? + if (cin_isterminated(line, TRUE, FALSE) + || cin_isscopedecl(line) + || cin_iscase(line, TRUE) + || (cin_islabel_skip(&line) && cin_nocode(line))) + return TRUE; + return FALSE; } - return FALSE; + curwin->w_cursor = cursor_save; + return TRUE; // label at start of file??? } /* @@ -1688,18 +1687,18 @@ find_match_paren_after_brace (int ind_maxparen) // XXX { pos_T *trypos = find_match_paren(ind_maxparen); - if (trypos != NULL) - { - pos_T *tryposBrace = find_start_brace(); - - // If both an unmatched '(' and '{' is found. Ignore the '(' - // position if the '{' is further down. - if (tryposBrace != NULL - && (trypos->lnum != tryposBrace->lnum - ? trypos->lnum < tryposBrace->lnum - : trypos->col < tryposBrace->col)) - trypos = NULL; - } + if (trypos == NULL) + return NULL; + + pos_T *tryposBrace = find_start_brace(); + + // If both an unmatched '(' and '{' is found. Ignore the '(' + // position if the '{' is further down. + if (tryposBrace != NULL + && (trypos->lnum != tryposBrace->lnum + ? trypos->lnum < tryposBrace->lnum + : trypos->col < tryposBrace->col)) + trypos = NULL; return trypos; } diff --git a/src/clientserver.c b/src/clientserver.c index 2a091a6e97..dfbb8a8b03 100644 --- a/src/clientserver.c +++ b/src/clientserver.c @@ -157,22 +157,22 @@ serverConvert( char_u *res = data; *tofree = NULL; - if (client_enc != NULL && p_enc != NULL) - { - vimconv_T vimconv; + if (client_enc == NULL || p_enc == NULL) + return res; - vimconv.vc_type = CONV_NONE; - if (convert_setup(&vimconv, client_enc, p_enc) != FAIL - && vimconv.vc_type != CONV_NONE) - { - res = string_convert(&vimconv, data, NULL); - if (res == NULL) - res = data; - else - *tofree = res; - } - convert_setup(&vimconv, NULL, NULL); + vimconv_T vimconv; + + vimconv.vc_type = CONV_NONE; + if (convert_setup(&vimconv, client_enc, p_enc) != FAIL + && vimconv.vc_type != CONV_NONE) + { + res = string_convert(&vimconv, data, NULL); + if (res == NULL) + res = data; + else + *tofree = res; } + convert_setup(&vimconv, NULL, NULL); return res; } #endif diff --git a/src/cmdexpand.c b/src/cmdexpand.c index cc34f296a8..5a47f6a24a 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -1850,21 +1850,22 @@ find_cmd_after_substitute_cmd(char_u *arg) find_cmd_after_isearch_cmd(expand_T *xp, char_u *arg) { arg = skipwhite(skipdigits(arg)); // skip count - if (*arg == '/') // Match regexp, not just whole words + if (*arg != '/') + return NULL; + + // Match regexp, not just whole words + for (++arg; *arg && *arg != '/'; arg++) + if (*arg == '\\' && arg[1] != NUL) + arg++; + if (*arg) { - for (++arg; *arg && *arg != '/'; arg++) - if (*arg == '\\' && arg[1] != NUL) - arg++; - if (*arg) - { - arg = skipwhite(arg + 1); + arg = skipwhite(arg + 1); - // Check for trailing illegal characters - if (*arg == NUL || vim_strchr((char_u *)"|\"\n", *arg) == NULL) - xp->xp_context = EXPAND_NOTHING; - else - return arg; - } + // Check for trailing illegal characters + if (*arg == NUL || vim_strchr((char_u *)"|\"\n", *arg) == NULL) + xp->xp_context = EXPAND_NOTHING; + else + return arg; } return NULL; @@ -2780,7 +2781,7 @@ get_breakadd_arg(expand_T *xp UNUSED, int idx) { char *opts[] = {"expr", "file", "func", "here"}; - if (idx >=0 && idx <= 3) + if (idx >= 0 && idx <= 3) { // breakadd {expr, file, func, here} if (breakpt_expand_what == EXP_BREAKPT_ADD) diff --git a/src/debugger.c b/src/debugger.c index 1352f49994..f627a9a4da 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -315,14 +315,14 @@ get_maxbacktrace_level(char_u *sname) char *p, *q; int maxbacktrace = 0; - if (sname != NULL) + if (sname == NULL) + return 0; + + p = (char *)sname; + while ((q = strstr(p, "..")) != NULL) { - p = (char *)sname; - while ((q = strstr(p, "..")) != NULL) - { - p = q + 2; - maxbacktrace++; - } + p = q + 2; + maxbacktrace++; } return maxbacktrace; } @@ -486,21 +486,20 @@ dbg_check_skipped(exarg_T *eap) { int prev_got_int; - if (debug_skipped) - { - // Save the value of got_int and reset it. We don't want a previous - // interruption cause flushing the input buffer. - prev_got_int = got_int; - got_int = FALSE; - debug_breakpoint_name = debug_skipped_name; - // eap->skip is TRUE - eap->skip = FALSE; - (void)dbg_check_breakpoint(eap); - eap->skip = TRUE; - got_int |= prev_got_int; - return TRUE; - } - return FALSE; + if (!debug_skipped) + return FALSE; + + // Save the value of got_int and reset it. We don't want a previous + // interruption cause flushing the input buffer. + prev_got_int = got_int; + got_int = FALSE; + debug_breakpoint_name = debug_skipped_name; + // eap->skip is TRUE + eap->skip = FALSE; + (void)dbg_check_breakpoint(eap); + eap->skip = TRUE; + got_int |= prev_got_int; + return TRUE; } /* diff --git a/src/dict.c b/src/dict.c index d45fcff0ab..6941845cda 100644 --- a/src/dict.c +++ b/src/dict.c @@ -30,21 +30,21 @@ dict_alloc(void) dict_T *d; d = ALLOC_CLEAR_ONE(dict_T); - if (d != NULL) - { - // Add the dict to the list of dicts for garbage collection. - if (first_dict != NULL) - first_dict->dv_used_prev = d; - d->dv_used_next = first_dict; - d->dv_used_prev = NULL; - first_dict = d; - - hash_init(&d->dv_hashtab); - d->dv_lock = 0; - d->dv_scope = 0; - d->dv_refcount = 0; - d->dv_copyID = 0; - } + if (d == NULL) + return NULL; + + // Add the dict to the list of dicts for garbage collection. + if (first_dict != NULL) + first_dict->dv_used_prev = d; + d->dv_used_next = first_dict; + d->dv_used_prev = NULL; + first_dict = d; + + hash_init(&d->dv_hashtab); + d->dv_lock = 0; + d->dv_scope = 0; + d->dv_refcount = 0; + d->dv_copyID = 0; return d; } @@ -228,13 +228,13 @@ dictitem_alloc(char_u *key) size_t len = STRLEN(key); di = alloc(offsetof(dictitem_T, di_key) + len + 1); - if (di != NULL) - { - mch_memmove(di->di_key, key, len + 1); - di->di_flags = DI_FLAGS_ALLOC; - di->di_tv.v_lock = 0; - di->di_tv.v_type = VAR_UNKNOWN; - } + if (di == NULL) + return NULL; + + mch_memmove(di->di_key, key, len + 1); + di->di_flags = DI_FLAGS_ALLOC; + di->di_tv.v_lock = 0; + di->di_tv.v_type = VAR_UNKNOWN; return di; } @@ -248,12 +248,12 @@ dictitem_copy(dictitem_T *org) size_t len = STRLEN(org->di_key); di = alloc(offsetof(dictitem_T, di_key) + len + 1); - if (di != NULL) - { - mch_memmove(di->di_key, org->di_key, len + 1); - di->di_flags = DI_FLAGS_ALLOC; - copy_tv(&org->di_tv, &di->di_tv); - } + if (di == NULL) + return NULL; + + mch_memmove(di->di_key, org->di_key, len + 1); + di->di_flags = DI_FLAGS_ALLOC; + copy_tv(&org->di_tv, &di->di_tv); return di; } @@ -303,53 +303,53 @@ dict_copy(dict_T *orig, int deep, int top, int copyID) return NULL; copy = dict_alloc(); - if (copy != NULL) + if (copy == NULL) + return NULL; + + if (copyID != 0) { - if (copyID != 0) - { - orig->dv_copyID = copyID; - orig->dv_copydict = copy; - } - if (orig->dv_type == NULL || top || deep) - copy->dv_type = NULL; - else - copy->dv_type = alloc_type(orig->dv_type); + orig->dv_copyID = copyID; + orig->dv_copydict = copy; + } + if (orig->dv_type == NULL || top || deep) + copy->dv_type = NULL; + else + copy->dv_type = alloc_type(orig->dv_type); - todo = (int)orig->dv_hashtab.ht_used; - for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) + todo = (int)orig->dv_hashtab.ht_used; + for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) + { + if (!HASHITEM_EMPTY(hi)) { - if (!HASHITEM_EMPTY(hi)) - { - --todo; + --todo; - di = dictitem_alloc(hi->hi_key); - if (di == NULL) - break; - if (deep) - { - if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, - deep, FALSE, copyID) == FAIL) - { - vim_free(di); - break; - } - } - else - copy_tv(&HI2DI(hi)->di_tv, &di->di_tv); - if (dict_add(copy, di) == FAIL) + di = dictitem_alloc(hi->hi_key); + if (di == NULL) + break; + if (deep) + { + if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, + deep, FALSE, copyID) == FAIL) { - dictitem_free(di); + vim_free(di); break; } } + else + copy_tv(&HI2DI(hi)->di_tv, &di->di_tv); + if (dict_add(copy, di) == FAIL) + { + dictitem_free(di); + break; + } } + } - ++copy->dv_refcount; - if (todo > 0) - { - dict_unref(copy); - copy = NULL; - } + ++copy->dv_refcount; + if (todo > 0) + { + dict_unref(copy); + copy = NULL; } return copy; diff --git a/src/diff.c b/src/diff.c index 41cfefe5e6..ec8c8f175d 100644 --- a/src/diff.c +++ b/src/diff.c @@ -559,14 +559,14 @@ diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) diff_T *dnew; dnew = ALLOC_ONE(diff_T); - if (dnew != NULL) - { - dnew->df_next = dp; - if (dprev == NULL) - tp->tp_first_diff = dnew; - else - dprev->df_next = dnew; - } + if (dnew == NULL) + return NULL; + + dnew->df_next = dp; + if (dprev == NULL) + tp->tp_first_diff = dnew; + else + dprev->df_next = dnew; return dnew; } diff --git a/src/digraph.c b/src/digraph.c index 88643e35f7..97a72e1d55 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -1533,29 +1533,30 @@ get_digraph( c = plain_vgetc(); --no_mapping; --allow_keys; - if (c != ESC) // ESC cancels CTRL-K + + if (c == ESC) // ESC cancels CTRL-K + return NUL; + + if (IS_SPECIAL(c)) // insert special key code + return c; + if (cmdline) { - if (IS_SPECIAL(c)) // insert special key code - return c; - if (cmdline) - { - if (char2cells(c) == 1 + if (char2cells(c) == 1 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) - && cmdline_star == 0 + && cmdline_star == 0 #endif - ) - putcmdline(c, TRUE); - } - else - add_to_showcmd(c); - ++no_mapping; - ++allow_keys; - cc = plain_vgetc(); - --no_mapping; - --allow_keys; - if (cc != ESC) // ESC cancels CTRL-K - return digraph_get(c, cc, TRUE); + ) + putcmdline(c, TRUE); } + else + add_to_showcmd(c); + ++no_mapping; + ++allow_keys; + cc = plain_vgetc(); + --no_mapping; + --allow_keys; + if (cc != ESC) // ESC cancels CTRL-K + return digraph_get(c, cc, TRUE); return NUL; } diff --git a/src/edit.c b/src/edit.c index 4a89fe13fb..983f1aca6d 100644 --- a/src/edit.c +++ b/src/edit.c @@ -2970,12 +2970,12 @@ get_last_insert_save(void) if (last_insert == NULL) return NULL; s = vim_strsave(last_insert + last_insert_skip); - if (s != NULL) - { - len = (int)STRLEN(s); - if (len > 0 && s[len - 1] == ESC) // remove trailing ESC - s[len - 1] = NUL; - } + if (s == NULL) + return NULL; + + len = (int)STRLEN(s); + if (len > 0 && s[len - 1] == ESC) // remove trailing ESC + s[len - 1] = NUL; return s; } diff --git a/src/evalfunc.c b/src/evalfunc.c index 274d0bdaa5..0184d61778 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -2950,22 +2950,22 @@ internal_func_check_arg_types( { argcheck_T *argchecks = global_functions[idx].f_argcheck; - if (argchecks != NULL) - { - argcontext_T context; + if (argchecks == NULL) + return OK; - context.arg_count = argcount; - context.arg_types = types; - context.arg_cctx = cctx; - for (int i = 0; i < argcount; ++i) - if (argchecks[i] != NULL) - { - context.arg_idx = i; - if (argchecks[i](types[i].type_curr, types[i].type_decl, - &context) == FAIL) - return FAIL; - } - } + argcontext_T context; + + context.arg_count = argcount; + context.arg_types = types; + context.arg_cctx = cctx; + for (int i = 0; i < argcount; ++i) + if (argchecks[i] != NULL) + { + context.arg_idx = i; + if (argchecks[i](types[i].type_curr, types[i].type_decl, + &context) == FAIL) + return FAIL; + } return OK; } @@ -3475,14 +3475,14 @@ get_optional_window(typval_T *argvars, int idx) { win_T *win = curwin; - if (argvars[idx].v_type != VAR_UNKNOWN) + if (argvars[idx].v_type == VAR_UNKNOWN) + return curwin; + + win = find_win_by_nr_or_id(&argvars[idx]); + if (win == NULL) { - win = find_win_by_nr_or_id(&argvars[idx]); - if (win == NULL) - { - emsg(_(e_invalid_window_number)); - return NULL; - } + emsg(_(e_invalid_window_number)); + return NULL; } return win; } @@ -8624,43 +8624,43 @@ get_search_arg(typval_T *varp, int *flagsp) char_u nbuf[NUMBUFLEN]; int mask; - if (varp->v_type != VAR_UNKNOWN) + if (varp->v_type == VAR_UNKNOWN) + return FORWARD; + + flags = tv_get_string_buf_chk(varp, nbuf); + if (flags == NULL) + return 0; // type error; errmsg already given + while (*flags != NUL) { - flags = tv_get_string_buf_chk(varp, nbuf); - if (flags == NULL) - return 0; // type error; errmsg already given - while (*flags != NUL) + switch (*flags) { - switch (*flags) - { - case 'b': dir = BACKWARD; break; - case 'w': p_ws = TRUE; break; - case 'W': p_ws = FALSE; break; - default: mask = 0; - if (flagsp != NULL) - switch (*flags) - { - case 'c': mask = SP_START; break; - case 'e': mask = SP_END; break; - case 'm': mask = SP_RETCOUNT; break; - case 'n': mask = SP_NOMOVE; break; - case 'p': mask = SP_SUBPAT; break; - case 'r': mask = SP_REPEAT; break; - case 's': mask = SP_SETPCMARK; break; - case 'z': mask = SP_COLUMN; break; - } - if (mask == 0) + case 'b': dir = BACKWARD; break; + case 'w': p_ws = TRUE; break; + case 'W': p_ws = FALSE; break; + default: mask = 0; + if (flagsp != NULL) + switch (*flags) { - semsg(_(e_invalid_argument_str), flags); - dir = 0; + case 'c': mask = SP_START; break; + case 'e': mask = SP_END; break; + case 'm': mask = SP_RETCOUNT; break; + case 'n': mask = SP_NOMOVE; break; + case 'p': mask = SP_SUBPAT; break; + case 'r': mask = SP_REPEAT; break; + case 's': mask = SP_SETPCMARK; break; + case 'z': mask = SP_COLUMN; break; } - else - *flagsp |= mask; - } - if (dir == 0) - break; - ++flags; + if (mask == 0) + { + semsg(_(e_invalid_argument_str), flags); + dir = 0; + } + else + *flagsp |= mask; } + if (dir == 0) + break; + ++flags; } return dir; } diff --git a/src/evalwindow.c b/src/evalwindow.c index 8b47b98fd1..fde90f2561 100644 --- a/src/evalwindow.c +++ b/src/evalwindow.c @@ -24,29 +24,29 @@ win_getid(typval_T *argvars) if (argvars[0].v_type == VAR_UNKNOWN) return curwin->w_id; winnr = tv_get_number(&argvars[0]); - if (winnr > 0) + if (winnr <= 0) + return 0; + + if (argvars[1].v_type == VAR_UNKNOWN) + wp = firstwin; + else { - if (argvars[1].v_type == VAR_UNKNOWN) + tabpage_T *tp; + int tabnr = tv_get_number(&argvars[1]); + + FOR_ALL_TABPAGES(tp) + if (--tabnr == 0) + break; + if (tp == NULL) + return -1; + if (tp == curtab) wp = firstwin; else - { - tabpage_T *tp; - int tabnr = tv_get_number(&argvars[1]); - - FOR_ALL_TABPAGES(tp) - if (--tabnr == 0) - break; - if (tp == NULL) - return -1; - if (tp == curtab) - wp = firstwin; - else - wp = tp->tp_firstwin; - } - for ( ; wp != NULL; wp = wp->w_next) - if (--winnr == 0) - return wp->w_id; + wp = tp->tp_firstwin; } + for ( ; wp != NULL; wp = wp->w_next) + if (--winnr == 0) + return wp->w_id; return 0; } @@ -380,18 +380,20 @@ get_winnr(tabpage_T *tp, typval_T *argvar) } } - if (nr > 0) - for (wp = (tp == |