mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
vim-patch:9.0.1245: code is indented more than necessary (#21998)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11879)
032713f829
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -7823,34 +7823,35 @@ static void f_strftime(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
// MSVC returns NULL for an invalid value of seconds.
|
||||
if (curtime_ptr == NULL) {
|
||||
rettv->vval.v_string = xstrdup(_("(Invalid)"));
|
||||
} else {
|
||||
vimconv_T conv;
|
||||
|
||||
conv.vc_type = CONV_NONE;
|
||||
char *enc = enc_locale();
|
||||
convert_setup(&conv, p_enc, enc);
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
p = string_convert(&conv, p, NULL);
|
||||
}
|
||||
char result_buf[256];
|
||||
if (p == NULL || strftime(result_buf, sizeof(result_buf), p, curtime_ptr) == 0) {
|
||||
result_buf[0] = NUL;
|
||||
}
|
||||
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
xfree(p);
|
||||
}
|
||||
convert_setup(&conv, enc, p_enc);
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
|
||||
} else {
|
||||
rettv->vval.v_string = xstrdup(result_buf);
|
||||
}
|
||||
|
||||
// Release conversion descriptors.
|
||||
convert_setup(&conv, NULL, NULL);
|
||||
xfree(enc);
|
||||
return;
|
||||
}
|
||||
|
||||
vimconv_T conv;
|
||||
|
||||
conv.vc_type = CONV_NONE;
|
||||
char *enc = enc_locale();
|
||||
convert_setup(&conv, p_enc, enc);
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
p = string_convert(&conv, p, NULL);
|
||||
}
|
||||
char result_buf[256];
|
||||
if (p == NULL || strftime(result_buf, sizeof(result_buf), p, curtime_ptr) == 0) {
|
||||
result_buf[0] = NUL;
|
||||
}
|
||||
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
xfree(p);
|
||||
}
|
||||
convert_setup(&conv, enc, p_enc);
|
||||
if (conv.vc_type != CONV_NONE) {
|
||||
rettv->vval.v_string = string_convert(&conv, result_buf, NULL);
|
||||
} else {
|
||||
rettv->vval.v_string = xstrdup(result_buf);
|
||||
}
|
||||
|
||||
// Release conversion descriptors.
|
||||
convert_setup(&conv, NULL, NULL);
|
||||
xfree(enc);
|
||||
}
|
||||
|
||||
/// "strgetchar()" function
|
||||
@@ -8654,6 +8655,7 @@ static void f_timer_pause(typval_T *argvars, typval_T *unused, EvalFuncData fptr
|
||||
emsg(_(e_number_exp));
|
||||
return;
|
||||
}
|
||||
|
||||
int paused = (bool)tv_get_number(&argvars[1]);
|
||||
timer_T *timer = find_timer_by_nr(tv_get_number(&argvars[0]));
|
||||
if (timer != NULL) {
|
||||
|
@@ -3208,17 +3208,19 @@ static inline void _nothing_conv_dict_end(typval_T *const tv, dict_T **const dic
|
||||
/// @param[in,out] tv Value to free.
|
||||
void tv_clear(typval_T *const tv)
|
||||
{
|
||||
if (tv != NULL && tv->v_type != VAR_UNKNOWN) {
|
||||
// WARNING: do not translate the string here, gettext is slow and function
|
||||
// is used *very* often. At the current state encode_vim_to_nothing() does
|
||||
// not error out and does not use the argument anywhere.
|
||||
//
|
||||
// If situation changes and this argument will be used, translate it in the
|
||||
// place where it is used.
|
||||
const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument");
|
||||
(void)evn_ret;
|
||||
assert(evn_ret == OK);
|
||||
if (tv == NULL || tv->v_type == VAR_UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// WARNING: do not translate the string here, gettext is slow and function
|
||||
// is used *very* often. At the current state encode_vim_to_nothing() does
|
||||
// not error out and does not use the argument anywhere.
|
||||
//
|
||||
// If situation changes and this argument will be used, translate it in the
|
||||
// place where it is used.
|
||||
const int evn_ret = encode_vim_to_nothing(NULL, tv, "tv_clear() argument");
|
||||
(void)evn_ret;
|
||||
assert(evn_ret == OK);
|
||||
}
|
||||
|
||||
//{{{3 Free
|
||||
@@ -3228,35 +3230,37 @@ void tv_clear(typval_T *const tv)
|
||||
/// @param tv Object to free.
|
||||
void tv_free(typval_T *tv)
|
||||
{
|
||||
if (tv != NULL) {
|
||||
switch (tv->v_type) {
|
||||
case VAR_PARTIAL:
|
||||
partial_unref(tv->vval.v_partial);
|
||||
break;
|
||||
case VAR_FUNC:
|
||||
func_unref(tv->vval.v_string);
|
||||
FALLTHROUGH;
|
||||
case VAR_STRING:
|
||||
xfree(tv->vval.v_string);
|
||||
break;
|
||||
case VAR_BLOB:
|
||||
tv_blob_unref(tv->vval.v_blob);
|
||||
break;
|
||||
case VAR_LIST:
|
||||
tv_list_unref(tv->vval.v_list);
|
||||
break;
|
||||
case VAR_DICT:
|
||||
tv_dict_unref(tv->vval.v_dict);
|
||||
break;
|
||||
case VAR_BOOL:
|
||||
case VAR_SPECIAL:
|
||||
case VAR_NUMBER:
|
||||
case VAR_FLOAT:
|
||||
case VAR_UNKNOWN:
|
||||
break;
|
||||
}
|
||||
xfree(tv);
|
||||
if (tv == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (tv->v_type) {
|
||||
case VAR_PARTIAL:
|
||||
partial_unref(tv->vval.v_partial);
|
||||
break;
|
||||
case VAR_FUNC:
|
||||
func_unref(tv->vval.v_string);
|
||||
FALLTHROUGH;
|
||||
case VAR_STRING:
|
||||
xfree(tv->vval.v_string);
|
||||
break;
|
||||
case VAR_BLOB:
|
||||
tv_blob_unref(tv->vval.v_blob);
|
||||
break;
|
||||
case VAR_LIST:
|
||||
tv_list_unref(tv->vval.v_list);
|
||||
break;
|
||||
case VAR_DICT:
|
||||
tv_dict_unref(tv->vval.v_dict);
|
||||
break;
|
||||
case VAR_BOOL:
|
||||
case VAR_SPECIAL:
|
||||
case VAR_NUMBER:
|
||||
case VAR_FLOAT:
|
||||
case VAR_UNKNOWN:
|
||||
break;
|
||||
}
|
||||
xfree(tv);
|
||||
}
|
||||
|
||||
//{{{3 Copy
|
||||
|
220
src/nvim/tag.c
220
src/nvim/tag.c
@@ -2732,55 +2732,57 @@ static int parse_match(char *lbuf, tagptrs_T *tagp)
|
||||
tagp->tagline = 0;
|
||||
tagp->command_end = NULL;
|
||||
|
||||
if (retval == OK) {
|
||||
// Try to find a kind field: "kind:<kind>" or just "<kind>"
|
||||
p = tagp->command;
|
||||
if (find_extra(&p) == OK) {
|
||||
tagp->command_end = p;
|
||||
if (p > tagp->command && p[-1] == '|') {
|
||||
tagp->command_end = p - 1; // drop trailing bar
|
||||
}
|
||||
p += 2; // skip ";\""
|
||||
if (*p++ == TAB) {
|
||||
// Accept ASCII alphabetic kind characters and any multi-byte
|
||||
// character.
|
||||
while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) {
|
||||
if (strncmp(p, "kind:", 5) == 0) {
|
||||
tagp->tagkind = p + 5;
|
||||
} else if (strncmp(p, "user_data:", 10) == 0) {
|
||||
tagp->user_data = p + 10;
|
||||
} else if (strncmp(p, "line:", 5) == 0) {
|
||||
tagp->tagline = atoi(p + 5);
|
||||
}
|
||||
if (tagp->tagkind != NULL && tagp->user_data != NULL) {
|
||||
break;
|
||||
}
|
||||
if (retval != OK) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
pc = vim_strchr(p, ':');
|
||||
pt = vim_strchr(p, '\t');
|
||||
if (pc == NULL || (pt != NULL && pc > pt)) {
|
||||
tagp->tagkind = p;
|
||||
}
|
||||
if (pt == NULL) {
|
||||
break;
|
||||
}
|
||||
p = pt;
|
||||
MB_PTR_ADV(p);
|
||||
// Try to find a kind field: "kind:<kind>" or just "<kind>"
|
||||
p = tagp->command;
|
||||
if (find_extra(&p) == OK) {
|
||||
tagp->command_end = p;
|
||||
if (p > tagp->command && p[-1] == '|') {
|
||||
tagp->command_end = p - 1; // drop trailing bar
|
||||
}
|
||||
p += 2; // skip ";\""
|
||||
if (*p++ == TAB) {
|
||||
// Accept ASCII alphabetic kind characters and any multi-byte
|
||||
// character.
|
||||
while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) {
|
||||
if (strncmp(p, "kind:", 5) == 0) {
|
||||
tagp->tagkind = p + 5;
|
||||
} else if (strncmp(p, "user_data:", 10) == 0) {
|
||||
tagp->user_data = p + 10;
|
||||
} else if (strncmp(p, "line:", 5) == 0) {
|
||||
tagp->tagline = atoi(p + 5);
|
||||
}
|
||||
if (tagp->tagkind != NULL && tagp->user_data != NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
pc = vim_strchr(p, ':');
|
||||
pt = vim_strchr(p, '\t');
|
||||
if (pc == NULL || (pt != NULL && pc > pt)) {
|
||||
tagp->tagkind = p;
|
||||
}
|
||||
if (pt == NULL) {
|
||||
break;
|
||||
}
|
||||
p = pt;
|
||||
MB_PTR_ADV(p);
|
||||
}
|
||||
}
|
||||
if (tagp->tagkind != NULL) {
|
||||
for (p = tagp->tagkind;
|
||||
*p && *p != '\t' && *p != '\r' && *p != '\n';
|
||||
MB_PTR_ADV(p)) {}
|
||||
tagp->tagkind_end = p;
|
||||
}
|
||||
if (tagp->user_data != NULL) {
|
||||
for (p = tagp->user_data;
|
||||
*p && *p != '\t' && *p != '\r' && *p != '\n';
|
||||
MB_PTR_ADV(p)) {}
|
||||
tagp->user_data_end = p;
|
||||
}
|
||||
}
|
||||
if (tagp->tagkind != NULL) {
|
||||
for (p = tagp->tagkind;
|
||||
*p && *p != '\t' && *p != '\r' && *p != '\n';
|
||||
MB_PTR_ADV(p)) {}
|
||||
tagp->tagkind_end = p;
|
||||
}
|
||||
if (tagp->user_data != NULL) {
|
||||
for (p = tagp->user_data;
|
||||
*p && *p != '\t' && *p != '\r' && *p != '\n';
|
||||
MB_PTR_ADV(p)) {}
|
||||
tagp->user_data_end = p;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -3329,86 +3331,88 @@ int get_tags(list_T *list, char *pat, char *buf_fname)
|
||||
|
||||
ret = find_tags(pat, &num_matches, &matches,
|
||||
TAG_REGEXP | TAG_NOIC, MAXCOL, buf_fname);
|
||||
if (ret == OK && num_matches > 0) {
|
||||
for (i = 0; i < num_matches; i++) {
|
||||
int parse_result = parse_match(matches[i], &tp);
|
||||
if (ret != OK || num_matches <= 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Avoid an unused variable warning in release builds.
|
||||
(void)parse_result;
|
||||
assert(parse_result == OK);
|
||||
for (i = 0; i < num_matches; i++) {
|
||||
int parse_result = parse_match(matches[i], &tp);
|
||||
|
||||
is_static = test_for_static(&tp);
|
||||
// Avoid an unused variable warning in release builds.
|
||||
(void)parse_result;
|
||||
assert(parse_result == OK);
|
||||
|
||||
// Skip pseudo-tag lines.
|
||||
if (strncmp(tp.tagname, "!_TAG_", 6) == 0) {
|
||||
xfree(matches[i]);
|
||||
continue;
|
||||
}
|
||||
is_static = test_for_static(&tp);
|
||||
|
||||
dict = tv_dict_alloc();
|
||||
tv_list_append_dict(list, dict);
|
||||
// Skip pseudo-tag lines.
|
||||
if (strncmp(tp.tagname, "!_TAG_", 6) == 0) {
|
||||
xfree(matches[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
full_fname = tag_full_fname(&tp);
|
||||
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|
||||
|| add_tag_field(dict, "filename", full_fname, NULL) == FAIL
|
||||
|| add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
|
||||
|| add_tag_field(dict, "kind", tp.tagkind,
|
||||
tp.tagkind ? tp.tagkind_end : NULL) == FAIL
|
||||
|| tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) {
|
||||
ret = FAIL;
|
||||
}
|
||||
dict = tv_dict_alloc();
|
||||
tv_list_append_dict(list, dict);
|
||||
|
||||
xfree(full_fname);
|
||||
full_fname = tag_full_fname(&tp);
|
||||
if (add_tag_field(dict, "name", tp.tagname, tp.tagname_end) == FAIL
|
||||
|| add_tag_field(dict, "filename", full_fname, NULL) == FAIL
|
||||
|| add_tag_field(dict, "cmd", tp.command, tp.command_end) == FAIL
|
||||
|| add_tag_field(dict, "kind", tp.tagkind,
|
||||
tp.tagkind ? tp.tagkind_end : NULL) == FAIL
|
||||
|| tv_dict_add_nr(dict, S_LEN("static"), is_static) == FAIL) {
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
if (tp.command_end != NULL) {
|
||||
for (char *p = tp.command_end + 3;
|
||||
*p != NUL && *p != '\n' && *p != '\r';
|
||||
MB_PTR_ADV(p)) {
|
||||
if (p == tp.tagkind
|
||||
|| (p + 5 == tp.tagkind && strncmp(p, "kind:", 5) == 0)) {
|
||||
// skip "kind:<kind>" and "<kind>"
|
||||
p = tp.tagkind_end - 1;
|
||||
} else if (strncmp(p, "file:", 5) == 0) {
|
||||
// skip "file:" (static tag)
|
||||
p += 4;
|
||||
} else if (!ascii_iswhite(*p)) {
|
||||
char *s, *n;
|
||||
int len;
|
||||
xfree(full_fname);
|
||||
|
||||
// Add extra field as a dict entry. Fields are
|
||||
// separated by Tabs.
|
||||
n = p;
|
||||
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') {
|
||||
if (tp.command_end != NULL) {
|
||||
for (char *p = tp.command_end + 3;
|
||||
*p != NUL && *p != '\n' && *p != '\r';
|
||||
MB_PTR_ADV(p)) {
|
||||
if (p == tp.tagkind
|
||||
|| (p + 5 == tp.tagkind && strncmp(p, "kind:", 5) == 0)) {
|
||||
// skip "kind:<kind>" and "<kind>"
|
||||
p = tp.tagkind_end - 1;
|
||||
} else if (strncmp(p, "file:", 5) == 0) {
|
||||
// skip "file:" (static tag)
|
||||
p += 4;
|
||||
} else if (!ascii_iswhite(*p)) {
|
||||
char *s, *n;
|
||||
int len;
|
||||
|
||||
// Add extra field as a dict entry. Fields are
|
||||
// separated by Tabs.
|
||||
n = p;
|
||||
while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') {
|
||||
p++;
|
||||
}
|
||||
len = (int)(p - n);
|
||||
if (*p == ':' && len > 0) {
|
||||
s = ++p;
|
||||
while (*p != NUL && (uint8_t)(*p) >= ' ') {
|
||||
p++;
|
||||
}
|
||||
len = (int)(p - n);
|
||||
if (*p == ':' && len > 0) {
|
||||
s = ++p;
|
||||
while (*p != NUL && (uint8_t)(*p) >= ' ') {
|
||||
p++;
|
||||
}
|
||||
n[len] = NUL;
|
||||
if (add_tag_field(dict, n, s, p) == FAIL) {
|
||||
ret = FAIL;
|
||||
}
|
||||
n[len] = ':';
|
||||
} else {
|
||||
// Skip field without colon.
|
||||
while (*p != NUL && (uint8_t)(*p) >= ' ') {
|
||||
p++;
|
||||
}
|
||||
n[len] = NUL;
|
||||
if (add_tag_field(dict, n, s, p) == FAIL) {
|
||||
ret = FAIL;
|
||||
}
|
||||
if (*p == NUL) {
|
||||
break;
|
||||
n[len] = ':';
|
||||
} else {
|
||||
// Skip field without colon.
|
||||
while (*p != NUL && (uint8_t)(*p) >= ' ') {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
if (*p == NUL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xfree(matches[i]);
|
||||
}
|
||||
xfree(matches);
|
||||
|
||||
xfree(matches[i]);
|
||||
}
|
||||
xfree(matches);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -77,31 +77,32 @@ static void ga_concat_esc(garray_T *gap, const char *p, int clen)
|
||||
memmove(buf, p, (size_t)clen);
|
||||
buf[clen] = NUL;
|
||||
ga_concat(gap, buf);
|
||||
} else {
|
||||
switch (*p) {
|
||||
case BS:
|
||||
ga_concat(gap, "\\b"); break;
|
||||
case ESC:
|
||||
ga_concat(gap, "\\e"); break;
|
||||
case FF:
|
||||
ga_concat(gap, "\\f"); break;
|
||||
case NL:
|
||||
ga_concat(gap, "\\n"); break;
|
||||
case TAB:
|
||||
ga_concat(gap, "\\t"); break;
|
||||
case CAR:
|
||||
ga_concat(gap, "\\r"); break;
|
||||
case '\\':
|
||||
ga_concat(gap, "\\\\"); break;
|
||||
default:
|
||||
if ((uint8_t)(*p) < ' ' || *p == 0x7f) {
|
||||
vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p);
|
||||
ga_concat(gap, buf);
|
||||
} else {
|
||||
ga_append(gap, (uint8_t)(*p));
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (*p) {
|
||||
case BS:
|
||||
ga_concat(gap, "\\b"); break;
|
||||
case ESC:
|
||||
ga_concat(gap, "\\e"); break;
|
||||
case FF:
|
||||
ga_concat(gap, "\\f"); break;
|
||||
case NL:
|
||||
ga_concat(gap, "\\n"); break;
|
||||
case TAB:
|
||||
ga_concat(gap, "\\t"); break;
|
||||
case CAR:
|
||||
ga_concat(gap, "\\r"); break;
|
||||
case '\\':
|
||||
ga_concat(gap, "\\\\"); break;
|
||||
default:
|
||||
if ((uint8_t)(*p) < ' ' || *p == 0x7f) {
|
||||
vim_snprintf(buf, NUMBUFLEN, "\\x%02x", *p);
|
||||
ga_concat(gap, buf);
|
||||
} else {
|
||||
ga_append(gap, (uint8_t)(*p));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -736,22 +736,24 @@ void check_auto_format(bool end_insert)
|
||||
int c = ' ';
|
||||
int cc;
|
||||
|
||||
if (did_add_space) {
|
||||
cc = gchar_cursor();
|
||||
if (!WHITECHAR(cc)) {
|
||||
// Somehow the space was removed already.
|
||||
if (!did_add_space) {
|
||||
return;
|
||||
}
|
||||
|
||||
cc = gchar_cursor();
|
||||
if (!WHITECHAR(cc)) {
|
||||
// Somehow the space was removed already.
|
||||
did_add_space = false;
|
||||
} else {
|
||||
if (!end_insert) {
|
||||
inc_cursor();
|
||||
c = gchar_cursor();
|
||||
dec_cursor();
|
||||
}
|
||||
if (c != NUL) {
|
||||
// The space is no longer at the end of the line, delete it.
|
||||
del_char(false);
|
||||
did_add_space = false;
|
||||
} else {
|
||||
if (!end_insert) {
|
||||
inc_cursor();
|
||||
c = gchar_cursor();
|
||||
dec_cursor();
|
||||
}
|
||||
if (c != NUL) {
|
||||
// The space is no longer at the end of the line, delete it.
|
||||
del_char(false);
|
||||
did_add_space = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user