mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00
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)
465de3a57b
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
regmatch_T regmatch;
|
||||
histentry_T *hisptr;
|
||||
int idx;
|
||||
int i;
|
||||
int last;
|
||||
bool found = 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;
|
||||
}
|
||||
}
|
||||
if (--i < 0) {
|
||||
i += hislen;
|
||||
}
|
||||
} while (i != idx);
|
||||
if (history[histype][idx].hisstr == NULL) {
|
||||
hisidx[histype] = -1;
|
||||
}
|
||||
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL
|
||||
|| hisidx[histype] < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int idx = hisidx[histype];
|
||||
regmatch_T regmatch;
|
||||
regmatch.regprog = vim_regcomp((char *)str, RE_MAGIC + RE_STRING);
|
||||
if (regmatch.regprog == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
regmatch.rm_ic = false; // always match case
|
||||
|
||||
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 (--last < 0) {
|
||||
last += hislen;
|
||||
}
|
||||
}
|
||||
if (--i < 0) {
|
||||
i += hislen;
|
||||
}
|
||||
} while (i != idx);
|
||||
|
||||
if (history[histype][idx].hisstr == NULL) {
|
||||
hisidx[histype] = -1;
|
||||
}
|
||||
|
||||
vim_regfree(regmatch.regprog);
|
||||
return found;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
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++;
|
||||
}
|
||||
} else {
|
||||
// DBG_EXPR
|
||||
DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
|
||||
debug_tick++;
|
||||
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 (eap->cmdidx != CMD_profile) {
|
||||
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,31 +684,32 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// Pretend it was a ":split fname" command
|
||||
eap->cmdidx = CMD_split;
|
||||
curwin->w_p_diff = true;
|
||||
do_exedit(eap, old_curwin);
|
||||
|
||||
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);
|
||||
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.
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
*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(' ');
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
*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);
|
||||
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');
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/// Get the two digraph characters from a typval.
|
||||
|
Reference in New Issue
Block a user