diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-26 21:54:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-26 21:54:31 +0800 |
commit | 738427d4984f13ce5e7cda9cda2face9559ee7e7 (patch) | |
tree | 43c5b22693fbc81c86eda1be43a048f17a687869 | |
parent | 94ce25065bb709794904b8ee96c1144006520750 (diff) | |
download | rneovim-738427d4984f13ce5e7cda9cda2face9559ee7e7.tar.gz rneovim-738427d4984f13ce5e7cda9cda2face9559ee7e7.tar.bz2 rneovim-738427d4984f13ce5e7cda9cda2face9559ee7e7.zip |
vim-patch:9.0.1098: code uses too much indent (#21540)
Problem: Code uses too much indent.
Solution: Use an early return. (Yegappan Lakshmanan, closes vim/vim#11747)
https://github.com/vim/vim/commit/465de3a57b815f1188c707e7c083950c81652536
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r-- | src/nvim/cmdhist.c | 69 | ||||
-rw-r--r-- | src/nvim/debugger.c | 126 | ||||
-rw-r--r-- | src/nvim/diff.c | 46 | ||||
-rw-r--r-- | src/nvim/digraph.c | 82 |
4 files changed, 167 insertions, 156 deletions
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 1253f9cc2a..0556a56d5d 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -439,47 +439,48 @@ int clr_history(const int histype) /// @param histype may be one of the HIST_ values. static int del_history_entry(int histype, char_u *str) { + if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL + || hisidx[histype] < 0) { + return false; + } + + const int idx = hisidx[histype]; regmatch_T regmatch; - histentry_T *hisptr; - int idx; - int i; - int last; - bool found = false; + regmatch.regprog = vim_regcomp((char *)str, RE_MAGIC + RE_STRING); + if (regmatch.regprog == NULL) { + return false; + } - regmatch.regprog = NULL; regmatch.rm_ic = false; // always match case - if (hislen != 0 - && histype >= 0 - && histype < HIST_COUNT - && *str != NUL - && (idx = hisidx[histype]) >= 0 - && (regmatch.regprog = vim_regcomp((char *)str, RE_MAGIC + RE_STRING)) != NULL) { - i = last = idx; - do { - hisptr = &history[histype][i]; - if (hisptr->hisstr == NULL) { - break; - } - if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { - found = true; - hist_free_entry(hisptr); - } else { - if (i != last) { - history[histype][last] = *hisptr; - clear_hist_entry(hisptr); - } - if (--last < 0) { - last += hislen; - } + + bool found = false; + int i = idx, last = idx; + do { + histentry_T *hisptr = &history[histype][i]; + if (hisptr->hisstr == NULL) { + break; + } + if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { + found = true; + hist_free_entry(hisptr); + } else { + if (i != last) { + history[histype][last] = *hisptr; + clear_hist_entry(hisptr); } - if (--i < 0) { - i += hislen; + if (--last < 0) { + last += hislen; } - } while (i != idx); - if (history[histype][idx].hisstr == NULL) { - hisidx[histype] = -1; } + if (--i < 0) { + i += hislen; + } + } while (i != idx); + + if (history[histype][idx].hisstr == NULL) { + hisidx[histype] = -1; } + vim_regfree(regmatch.regprog); return found; } diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index fadb014604..3af8f8902d 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -594,33 +594,35 @@ void ex_breakadd(exarg_T *eap) gap = &prof_ga; } - if (dbg_parsearg(eap->arg, gap) == OK) { - struct debuggy *bp = &DEBUGGY(gap, gap->ga_len); - bp->dbg_forceit = eap->forceit; + if (dbg_parsearg(eap->arg, gap) != OK) { + return; + } - if (bp->dbg_type != DBG_EXPR) { - char *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false); - if (pat != NULL) { - bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - xfree(pat); + struct debuggy *bp = &DEBUGGY(gap, gap->ga_len); + bp->dbg_forceit = eap->forceit; + + if (bp->dbg_type != DBG_EXPR) { + char *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false); + if (pat != NULL) { + bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); + xfree(pat); + } + if (pat == NULL || bp->dbg_prog == NULL) { + xfree(bp->dbg_name); + } else { + if (bp->dbg_lnum == 0) { // default line number is 1 + bp->dbg_lnum = 1; } - if (pat == NULL || bp->dbg_prog == NULL) { - xfree(bp->dbg_name); - } else { - if (bp->dbg_lnum == 0) { // default line number is 1 - bp->dbg_lnum = 1; - } - if (eap->cmdidx != CMD_profile) { - DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; - debug_tick++; - } - gap->ga_len++; + if (eap->cmdidx != CMD_profile) { + DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; + debug_tick++; } - } else { - // DBG_EXPR - DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp; - debug_tick++; + gap->ga_len++; } + } else { + // DBG_EXPR + DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp; + debug_tick++; } } @@ -682,32 +684,33 @@ void ex_breakdel(exarg_T *eap) if (todel < 0) { semsg(_("E161: Breakpoint not found: %s"), eap->arg); - } else { - while (!GA_EMPTY(gap)) { - xfree(DEBUGGY(gap, todel).dbg_name); - if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR - && DEBUGGY(gap, todel).dbg_val != NULL) { - tv_free(DEBUGGY(gap, todel).dbg_val); - } - vim_regfree(DEBUGGY(gap, todel).dbg_prog); - gap->ga_len--; - if (todel < gap->ga_len) { - memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), - (size_t)(gap->ga_len - todel) * sizeof(struct debuggy)); - } - if (eap->cmdidx == CMD_breakdel) { - debug_tick++; - } - if (!del_all) { - break; - } - } + return; + } - // If all breakpoints were removed clear the array. - if (GA_EMPTY(gap)) { - ga_clear(gap); + while (!GA_EMPTY(gap)) { + xfree(DEBUGGY(gap, todel).dbg_name); + if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR + && DEBUGGY(gap, todel).dbg_val != NULL) { + tv_free(DEBUGGY(gap, todel).dbg_val); + } + vim_regfree(DEBUGGY(gap, todel).dbg_prog); + gap->ga_len--; + if (todel < gap->ga_len) { + memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), + (size_t)(gap->ga_len - todel) * sizeof(struct debuggy)); + } + if (eap->cmdidx == CMD_breakdel) { + debug_tick++; + } + if (!del_all) { + break; } } + + // If all breakpoints were removed clear the array. + if (GA_EMPTY(gap)) { + ga_clear(gap); + } } /// ":breaklist". @@ -715,21 +718,22 @@ void ex_breaklist(exarg_T *eap) { if (GA_EMPTY(&dbg_breakp)) { msg(_("No breakpoints defined")); - } else { - for (int i = 0; i < dbg_breakp.ga_len; i++) { - struct debuggy *bp = &BREAKP(i); - if (bp->dbg_type == DBG_FILE) { - home_replace(NULL, bp->dbg_name, (char *)NameBuff, MAXPATHL, true); - } - if (bp->dbg_type != DBG_EXPR) { - smsg(_("%3d %s %s line %" PRId64), - bp->dbg_nr, - bp->dbg_type == DBG_FUNC ? "func" : "file", - bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, - (int64_t)bp->dbg_lnum); - } else { - smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); - } + return; + } + + for (int i = 0; i < dbg_breakp.ga_len; i++) { + struct debuggy *bp = &BREAKP(i); + if (bp->dbg_type == DBG_FILE) { + home_replace(NULL, bp->dbg_name, (char *)NameBuff, MAXPATHL, true); + } + if (bp->dbg_type != DBG_EXPR) { + smsg(_("%3d %s %s line %" PRId64), + bp->dbg_nr, + bp->dbg_type == DBG_FUNC ? "func" : "file", + bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, + (int64_t)bp->dbg_lnum); + } else { + smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); } } } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index c913260a80..267ec16d72 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1147,6 +1147,7 @@ static int diff_file(diffio_T *dio) if (dio->dio_internal) { return diff_file_internal(dio); } + const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff) + strlen(p_srr) + 27); char *const cmd = xmalloc(len); @@ -1350,30 +1351,33 @@ void ex_diffsplit(exarg_T *eap) // don't use a new tab page, each tab page has its own diffs cmdmod.cmod_tab = 0; - if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { - // Pretend it was a ":split fname" command - eap->cmdidx = CMD_split; - curwin->w_p_diff = true; - do_exedit(eap, old_curwin); - - // split must have worked - if (curwin != old_curwin) { - // Set 'diff', 'scrollbind' on and 'wrap' off. - diff_win_options(curwin, true); - if (win_valid(old_curwin)) { - diff_win_options(old_curwin, true); + if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL) { + return; + } - if (bufref_valid(&old_curbuf)) { - // Move the cursor position to that of the old window. - curwin->w_cursor.lnum = diff_get_corresponding_line(old_curbuf.br_buf, - old_curwin->w_cursor.lnum); - } - } - // Now that lines are folded scroll to show the cursor at the same - // relative position. - scroll_to_fraction(curwin, curwin->w_height); + // Pretend it was a ":split fname" command + eap->cmdidx = CMD_split; + curwin->w_p_diff = true; + do_exedit(eap, old_curwin); + + if (curwin == old_curwin) { // split didn't work + return; + } + + // Set 'diff', 'scrollbind' on and 'wrap' off. + diff_win_options(curwin, true); + if (win_valid(old_curwin)) { + diff_win_options(old_curwin, true); + + if (bufref_valid(&old_curbuf)) { + // Move the cursor position to that of the old window. + curwin->w_cursor.lnum = diff_get_corresponding_line(old_curbuf.br_buf, + old_curwin->w_cursor.lnum); } } + // Now that lines are folded scroll to show the cursor at the same + // relative position. + scroll_to_fraction(curwin, curwin->w_height); } // Set options to show diffs for the current window. diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 2ca608ad93..dc85b39684 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1826,54 +1826,56 @@ static void printdigraph(const digr_T *dp, result_T *previous) char_u buf[30]; int list_width = 13; - if (dp->result != 0) { - if (previous != NULL) { - for (int i = 0; header_table[i].dg_header != NULL; i++) { - if (*previous < header_table[i].dg_start - && dp->result >= header_table[i].dg_start - && dp->result < header_table[i + 1].dg_start) { - digraph_header(_(header_table[i].dg_header)); - break; - } + if (dp->result == 0) { + return; + } + + if (previous != NULL) { + for (int i = 0; header_table[i].dg_header != NULL; i++) { + if (*previous < header_table[i].dg_start + && dp->result >= header_table[i].dg_start + && dp->result < header_table[i + 1].dg_start) { + digraph_header(_(header_table[i].dg_header)); + break; } - *previous = dp->result; - } - if (msg_col > Columns - list_width) { - msg_putchar('\n'); } + *previous = dp->result; + } + if (msg_col > Columns - list_width) { + msg_putchar('\n'); + } - // Make msg_col a multiple of list_width by using spaces. - if (msg_col % list_width != 0) { - int spaces = (msg_col / list_width + 1) * list_width - msg_col; - while (spaces--) { - msg_putchar(' '); - } + // Make msg_col a multiple of list_width by using spaces. + if (msg_col % list_width != 0) { + int spaces = (msg_col / list_width + 1) * list_width - msg_col; + while (spaces--) { + msg_putchar(' '); } + } - char_u *p = &buf[0]; - *p++ = dp->char1; - *p++ = dp->char2; - *p++ = ' '; - *p = NUL; - msg_outtrans((char *)buf); - p = buf; + char_u *p = &buf[0]; + *p++ = dp->char1; + *p++ = dp->char2; + *p++ = ' '; + *p = NUL; + msg_outtrans((char *)buf); + p = buf; - // add a space to draw a composing char on - if (utf_iscomposing(dp->result)) { - *p++ = ' '; - } - p += utf_char2bytes(dp->result, (char *)p); + // add a space to draw a composing char on + if (utf_iscomposing(dp->result)) { + *p++ = ' '; + } + p += utf_char2bytes(dp->result, (char *)p); - *p = NUL; - msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8)); - p = buf; - if (char2cells(dp->result) == 1) { - *p++ = ' '; - } - assert(p >= buf); - vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); - msg_outtrans((char *)buf); + *p = NUL; + msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8)); + p = buf; + if (char2cells(dp->result) == 1) { + *p++ = ' '; } + assert(p >= buf); + vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); + msg_outtrans((char *)buf); } /// Get the two digraph characters from a typval. |