vim-patch:8.2.4704: using "else" after return or break increases indent (#18032)

Problem:    Using "else" after return or break increases indent.
Solution:   Remove "else" and reduce indent. (Goc Dundar, closes vim/vim#10099)
f26c16144d
This commit is contained in:
zeertzjq
2022-04-08 10:25:22 +08:00
committed by GitHub
parent 4c9a71c69e
commit 356baae80a
4 changed files with 170 additions and 180 deletions

View File

@@ -1015,27 +1015,27 @@ retry:
} }
read_buf_col += n; read_buf_col += n;
break; break;
} else { }
// Append whole line and new-line. Change NL
// to NUL to reverse the effect done below. // Append whole line and new-line. Change NL
for (ni = 0; ni < n; ni++) { // to NUL to reverse the effect done below.
if (p[ni] == NL) { for (ni = 0; ni < n; ni++) {
ptr[tlen++] = NUL; if (p[ni] == NL) {
} else { ptr[tlen++] = NUL;
ptr[tlen++] = p[ni]; } else {
} ptr[tlen++] = p[ni];
} }
ptr[tlen++] = NL; }
read_buf_col = 0; ptr[tlen++] = NL;
if (++read_buf_lnum > from) { read_buf_col = 0;
// When the last line didn't have an if (++read_buf_lnum > from) {
// end-of-line don't add it now either. // When the last line didn't have an
if (!curbuf->b_p_eol) { // end-of-line don't add it now either.
--tlen; if (!curbuf->b_p_eol) {
} tlen--;
size = tlen;
break;
} }
size = tlen;
break;
} }
} }
} }

View File

@@ -2327,95 +2327,88 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
* We are finished, break the loop here. * We are finished, break the loop here.
*/ */
break; break;
} else { // pointer block full
/*
* split the pointer block
* allocate a new pointer block
* move some of the pointer into the new block
* prepare for updating the parent block
*/
for (;;) { // do this twice when splitting block 1
hp_new = ml_new_ptr(mfp);
if (hp_new == NULL) { // TODO: try to fix tree
return FAIL;
}
pp_new = hp_new->bh_data;
if (hp->bh_bnum != 1) {
break;
}
/*
* if block 1 becomes full the tree is given an extra level
* The pointers from block 1 are moved into the new block.
* block 1 is updated to point to the new block
* then continue to split the new block
*/
memmove(pp_new, pp, (size_t)page_size);
pp->pb_count = 1;
pp->pb_pointer[0].pe_bnum = hp_new->bh_bnum;
pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_page_count = 1;
mf_put(mfp, hp, true, false); // release block 1
hp = hp_new; // new block is to be split
pp = pp_new;
CHECK(stack_idx != 0, _("stack_idx should be 0"));
ip->ip_index = 0;
++stack_idx; // do block 1 again later
}
/*
* move the pointers after the current one to the new block
* If there are none, the new entry will be in the new block.
*/
total_moved = pp->pb_count - pb_idx - 1;
if (total_moved) {
memmove(&pp_new->pb_pointer[0],
&pp->pb_pointer[pb_idx + 1],
(size_t)(total_moved) * sizeof(PTR_EN));
pp_new->pb_count = total_moved;
pp->pb_count -= total_moved - 1;
pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right;
pp->pb_pointer[pb_idx + 1].pe_line_count = line_count_right;
pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right;
if (lnum_right) {
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
}
} else {
pp_new->pb_count = 1;
pp_new->pb_pointer[0].pe_bnum = bnum_right;
pp_new->pb_pointer[0].pe_line_count = line_count_right;
pp_new->pb_pointer[0].pe_page_count = page_count_right;
pp_new->pb_pointer[0].pe_old_lnum = lnum_right;
}
pp->pb_pointer[pb_idx].pe_bnum = bnum_left;
pp->pb_pointer[pb_idx].pe_line_count = line_count_left;
pp->pb_pointer[pb_idx].pe_page_count = page_count_left;
if (lnum_left) {
pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left;
}
lnum_left = 0;
lnum_right = 0;
/*
* recompute line counts
*/
line_count_right = 0;
for (i = 0; i < (int)pp_new->pb_count; ++i) {
line_count_right += pp_new->pb_pointer[i].pe_line_count;
}
line_count_left = 0;
for (i = 0; i < (int)pp->pb_count; ++i) {
line_count_left += pp->pb_pointer[i].pe_line_count;
}
bnum_left = hp->bh_bnum;
bnum_right = hp_new->bh_bnum;
page_count_left = 1;
page_count_right = 1;
mf_put(mfp, hp, true, false);
mf_put(mfp, hp_new, true, false);
} }
// pointer block full
//
// split the pointer block
// allocate a new pointer block
// move some of the pointer into the new block
// prepare for updating the parent block
for (;;) { // do this twice when splitting block 1
hp_new = ml_new_ptr(mfp);
if (hp_new == NULL) { // TODO(vim): try to fix tree
return FAIL;
}
pp_new = hp_new->bh_data;
if (hp->bh_bnum != 1) {
break;
}
// if block 1 becomes full the tree is given an extra level
// The pointers from block 1 are moved into the new block.
// block 1 is updated to point to the new block
// then continue to split the new block
memmove(pp_new, pp, (size_t)page_size);
pp->pb_count = 1;
pp->pb_pointer[0].pe_bnum = hp_new->bh_bnum;
pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
pp->pb_pointer[0].pe_old_lnum = 1;
pp->pb_pointer[0].pe_page_count = 1;
mf_put(mfp, hp, true, false); // release block 1
hp = hp_new; // new block is to be split
pp = pp_new;
CHECK(stack_idx != 0, _("stack_idx should be 0"));
ip->ip_index = 0;
stack_idx++; // do block 1 again later
}
// move the pointers after the current one to the new block
// If there are none, the new entry will be in the new block.
total_moved = pp->pb_count - pb_idx - 1;
if (total_moved) {
memmove(&pp_new->pb_pointer[0],
&pp->pb_pointer[pb_idx + 1],
(size_t)(total_moved) * sizeof(PTR_EN));
pp_new->pb_count = total_moved;
pp->pb_count -= total_moved - 1;
pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right;
pp->pb_pointer[pb_idx + 1].pe_line_count = line_count_right;
pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right;
if (lnum_right) {
pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
}
} else {
pp_new->pb_count = 1;
pp_new->pb_pointer[0].pe_bnum = bnum_right;
pp_new->pb_pointer[0].pe_line_count = line_count_right;
pp_new->pb_pointer[0].pe_page_count = page_count_right;
pp_new->pb_pointer[0].pe_old_lnum = lnum_right;
}
pp->pb_pointer[pb_idx].pe_bnum = bnum_left;
pp->pb_pointer[pb_idx].pe_line_count = line_count_left;
pp->pb_pointer[pb_idx].pe_page_count = page_count_left;
if (lnum_left) {
pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left;
}
lnum_left = 0;
lnum_right = 0;
// recompute line counts
line_count_right = 0;
for (i = 0; i < (int)pp_new->pb_count; i++) {
line_count_right += pp_new->pb_pointer[i].pe_line_count;
}
line_count_left = 0;
for (i = 0; i < (int)pp->pb_count; i++) {
line_count_left += pp->pb_pointer[i].pe_line_count;
}
bnum_left = hp->bh_bnum;
bnum_right = hp_new->bh_bnum;
page_count_left = 1;
page_count_right = 1;
mf_put(mfp, hp, true, false);
mf_put(mfp, hp_new, true, false);
} }
/* /*

View File

@@ -5140,43 +5140,43 @@ char *set_option_value(const char *const name, const long number, const char *co
s = ""; s = "";
} }
return set_string_option(opt_idx, s, opt_flags); return set_string_option(opt_idx, s, opt_flags);
} else { }
varp = get_varp_scope(&(options[opt_idx]), opt_flags);
if (varp != NULL) { // hidden option is not changed
if (number == 0 && string != NULL) {
int idx;
// Either we are given a string or we are setting option varp = get_varp_scope(&(options[opt_idx]), opt_flags);
// to zero. if (varp != NULL) { // hidden option is not changed
for (idx = 0; string[idx] == '0'; idx++) {} if (number == 0 && string != NULL) {
if (string[idx] != NUL || idx == 0) { int idx;
// There's another character after zeros or the string
// is empty. In both cases, we are trying to set a // Either we are given a string or we are setting option
// num option using a string. // to zero.
semsg(_("E521: Number required: &%s = '%s'"), for (idx = 0; string[idx] == '0'; idx++) {}
name, string); if (string[idx] != NUL || idx == 0) {
return NULL; // do nothing as we hit an error // There's another character after zeros or the string
} // is empty. In both cases, we are trying to set a
// num option using a string.
semsg(_("E521: Number required: &%s = '%s'"),
name, string);
return NULL; // do nothing as we hit an error
} }
long numval = number; }
if (opt_flags & OPT_CLEAR) { long numval = number;
if ((int *)varp == &curbuf->b_p_ar) { if (opt_flags & OPT_CLEAR) {
numval = -1; if ((int *)varp == &curbuf->b_p_ar) {
} else if ((long *)varp == &curbuf->b_p_ul) { numval = -1;
numval = NO_LOCAL_UNDOLEVEL; } else if ((long *)varp == &curbuf->b_p_ul) {
} else if ((long *)varp == &curwin->w_p_so || (long *)varp == &curwin->w_p_siso) { numval = NO_LOCAL_UNDOLEVEL;
numval = -1; } else if ((long *)varp == &curwin->w_p_so || (long *)varp == &curwin->w_p_siso) {
} else { numval = -1;
char *s = NULL;
(void)get_option_value(name, &numval, (char_u **)&s, OPT_GLOBAL);
}
}
if (flags & P_NUM) {
return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags);
} else { } else {
return set_bool_option(opt_idx, varp, (int)numval, opt_flags); char *s = NULL;
(void)get_option_value(name, &numval, (char_u **)&s, OPT_GLOBAL);
} }
} }
if (flags & P_NUM) {
return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags);
} else {
return set_bool_option(opt_idx, varp, (int)numval, opt_flags);
}
} }
} }
return NULL; return NULL;

View File

@@ -2289,55 +2289,52 @@ static void check_state_ends(void)
next_match_idx = 0; next_match_idx = 0;
next_match_col = MAXCOL; next_match_col = MAXCOL;
break; break;
} else { }
// handle next_list, unless at end of line and no "skipnl" or
// "skipempty"
current_next_list = cur_si->si_next_list;
current_next_flags = cur_si->si_flags;
if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))
&& syn_getcurline()[current_col] == NUL) {
current_next_list = NULL;
}
// When the ended item has "extend", another item with // handle next_list, unless at end of line and no "skipnl" or
// "keepend" now needs to check for its end. // "skipempty"
had_extend = (cur_si->si_flags & HL_EXTEND); current_next_list = cur_si->si_next_list;
current_next_flags = cur_si->si_flags;
if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))
&& syn_getcurline()[current_col] == NUL) {
current_next_list = NULL;
}
pop_current_state(); // When the ended item has "extend", another item with
// "keepend" now needs to check for its end.
had_extend = (cur_si->si_flags & HL_EXTEND);
pop_current_state();
if (GA_EMPTY(&current_state)) {
break;
}
if (had_extend && keepend_level >= 0) {
syn_update_ends(false);
if (GA_EMPTY(&current_state)) { if (GA_EMPTY(&current_state)) {
break; break;
} }
}
if (had_extend && keepend_level >= 0) { cur_si = &CUR_STATE(current_state.ga_len - 1);
syn_update_ends(false);
if (GA_EMPTY(&current_state)) {
break;
}
}
cur_si = &CUR_STATE(current_state.ga_len - 1); // Only for a region the search for the end continues after
// the end of the contained item. If the contained match
/* // included the end-of-line, break here, the region continues.
* Only for a region the search for the end continues after // Don't do this when:
* the end of the contained item. If the contained match // - "keepend" is used for the contained item
* included the end-of-line, break here, the region continues. // - not at the end of the line (could be end="x$"me=e-1).
* Don't do this when: // - "excludenl" is used (HL_HAS_EOL won't be set)
* - "keepend" is used for the contained item if (cur_si->si_idx >= 0
* - not at the end of the line (could be end="x$"me=e-1). && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type == SPTYPE_START
* - "excludenl" is used (HL_HAS_EOL won't be set) && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) {
*/ update_si_end(cur_si, (int)current_col, true);
if (cur_si->si_idx >= 0 check_keepend();
&& SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type if ((current_next_flags & HL_HAS_EOL)
== SPTYPE_START && keepend_level < 0
&& !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) { && syn_getcurline()[current_col] == NUL) {
update_si_end(cur_si, (int)current_col, true); break;
check_keepend();
if ((current_next_flags & HL_HAS_EOL)
&& keepend_level < 0
&& syn_getcurline()[current_col] == NUL) {
break;
}
} }
} }
} else { } else {