mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18: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.
|
/// @param histype may be one of the HIST_ values.
|
||||||
static int del_history_entry(int histype, char_u *str)
|
static int del_history_entry(int histype, char_u *str)
|
||||||
{
|
{
|
||||||
regmatch_T regmatch;
|
if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL
|
||||||
histentry_T *hisptr;
|
|| hisidx[histype] < 0) {
|
||||||
int idx;
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
vim_regfree(regmatch.regprog);
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@@ -594,33 +594,35 @@ void ex_breakadd(exarg_T *eap)
|
|||||||
gap = &prof_ga;
|
gap = &prof_ga;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbg_parsearg(eap->arg, gap) == OK) {
|
if (dbg_parsearg(eap->arg, gap) != OK) {
|
||||||
struct debuggy *bp = &DEBUGGY(gap, gap->ga_len);
|
return;
|
||||||
bp->dbg_forceit = eap->forceit;
|
}
|
||||||
|
|
||||||
if (bp->dbg_type != DBG_EXPR) {
|
struct debuggy *bp = &DEBUGGY(gap, gap->ga_len);
|
||||||
char *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false);
|
bp->dbg_forceit = eap->forceit;
|
||||||
if (pat != NULL) {
|
|
||||||
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
|
if (bp->dbg_type != DBG_EXPR) {
|
||||||
xfree(pat);
|
char *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false);
|
||||||
}
|
if (pat != NULL) {
|
||||||
if (pat == NULL || bp->dbg_prog == NULL) {
|
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
|
||||||
xfree(bp->dbg_name);
|
xfree(pat);
|
||||||
} 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++;
|
|
||||||
}
|
}
|
||||||
|
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) {
|
if (todel < 0) {
|
||||||
semsg(_("E161: Breakpoint not found: %s"), eap->arg);
|
semsg(_("E161: Breakpoint not found: %s"), eap->arg);
|
||||||
} else {
|
return;
|
||||||
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.
|
while (!GA_EMPTY(gap)) {
|
||||||
if (GA_EMPTY(gap)) {
|
xfree(DEBUGGY(gap, todel).dbg_name);
|
||||||
ga_clear(gap);
|
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)) {
|
if (GA_EMPTY(&dbg_breakp)) {
|
||||||
msg(_("No breakpoints defined"));
|
msg(_("No breakpoints defined"));
|
||||||
} else {
|
return;
|
||||||
for (int i = 0; i < dbg_breakp.ga_len; i++) {
|
}
|
||||||
struct debuggy *bp = &BREAKP(i);
|
|
||||||
if (bp->dbg_type == DBG_FILE) {
|
for (int i = 0; i < dbg_breakp.ga_len; i++) {
|
||||||
home_replace(NULL, bp->dbg_name, (char *)NameBuff, MAXPATHL, true);
|
struct debuggy *bp = &BREAKP(i);
|
||||||
}
|
if (bp->dbg_type == DBG_FILE) {
|
||||||
if (bp->dbg_type != DBG_EXPR) {
|
home_replace(NULL, bp->dbg_name, (char *)NameBuff, MAXPATHL, true);
|
||||||
smsg(_("%3d %s %s line %" PRId64),
|
}
|
||||||
bp->dbg_nr,
|
if (bp->dbg_type != DBG_EXPR) {
|
||||||
bp->dbg_type == DBG_FUNC ? "func" : "file",
|
smsg(_("%3d %s %s line %" PRId64),
|
||||||
bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
|
bp->dbg_nr,
|
||||||
(int64_t)bp->dbg_lnum);
|
bp->dbg_type == DBG_FUNC ? "func" : "file",
|
||||||
} else {
|
bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
|
||||||
smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name);
|
(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) {
|
if (dio->dio_internal) {
|
||||||
return diff_file_internal(dio);
|
return diff_file_internal(dio);
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff)
|
const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff)
|
||||||
+ strlen(p_srr) + 27);
|
+ strlen(p_srr) + 27);
|
||||||
char *const cmd = xmalloc(len);
|
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
|
// don't use a new tab page, each tab page has its own diffs
|
||||||
cmdmod.cmod_tab = 0;
|
cmdmod.cmod_tab = 0;
|
||||||
|
|
||||||
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) {
|
if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL) {
|
||||||
// Pretend it was a ":split fname" command
|
return;
|
||||||
eap->cmdidx = CMD_split;
|
}
|
||||||
curwin->w_p_diff = true;
|
|
||||||
do_exedit(eap, old_curwin);
|
|
||||||
|
|
||||||
// split must have worked
|
// Pretend it was a ":split fname" command
|
||||||
if (curwin != old_curwin) {
|
eap->cmdidx = CMD_split;
|
||||||
// Set 'diff', 'scrollbind' on and 'wrap' off.
|
curwin->w_p_diff = true;
|
||||||
diff_win_options(curwin, true);
|
do_exedit(eap, old_curwin);
|
||||||
if (win_valid(old_curwin)) {
|
|
||||||
diff_win_options(old_curwin, true);
|
|
||||||
|
|
||||||
if (bufref_valid(&old_curbuf)) {
|
if (curwin == old_curwin) { // split didn't work
|
||||||
// Move the cursor position to that of the old window.
|
return;
|
||||||
curwin->w_cursor.lnum = diff_get_corresponding_line(old_curbuf.br_buf,
|
}
|
||||||
old_curwin->w_cursor.lnum);
|
|
||||||
}
|
// Set 'diff', 'scrollbind' on and 'wrap' off.
|
||||||
}
|
diff_win_options(curwin, true);
|
||||||
// Now that lines are folded scroll to show the cursor at the same
|
if (win_valid(old_curwin)) {
|
||||||
// relative position.
|
diff_win_options(old_curwin, true);
|
||||||
scroll_to_fraction(curwin, curwin->w_height);
|
|
||||||
|
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.
|
// 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];
|
char_u buf[30];
|
||||||
int list_width = 13;
|
int list_width = 13;
|
||||||
|
|
||||||
if (dp->result != 0) {
|
if (dp->result == 0) {
|
||||||
if (previous != NULL) {
|
return;
|
||||||
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 (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.
|
/// Get the two digraph characters from a typval.
|
||||||
|
Reference in New Issue
Block a user