vim-patch:8.1.0772: the sign_define_by_name() function is too long

Problem:    The sign_define_by_name() function is too long.
Solution:   Split it into smaller functions. (Yegappan Lakshmanan,
            closes vim/vim#3819)
0314236aab
This commit is contained in:
Andrej Zieger
2019-05-21 20:20:55 +02:00
parent fb4cf05e44
commit 93e18e698e

View File

@@ -720,23 +720,12 @@ sign_find(char_u *name, sign_T **sp_prev)
} }
/* /*
* Define a new sign or update an existing sign * Allocate a new sign
*/ */
int sign_define_by_name( static sign_T *
char_u *name, alloc_new_sign(char_u *name)
char_u *icon,
char_u *linehl,
char_u *text,
char_u *texthl,
char_u *numhl
)
{ {
sign_T *sp_prev;
sign_T *sp; sign_T *sp;
sp = sign_find(name, &sp_prev);
if (sp == NULL)
{
sign_T *lp; sign_T *lp;
int start = next_sign_typenr; int start = next_sign_typenr;
@@ -755,7 +744,7 @@ int sign_define_by_name(
if (next_sign_typenr == start) { if (next_sign_typenr == start) {
xfree(sp); xfree(sp);
EMSG(_("E612: Too many signs defined")); EMSG(_("E612: Too many signs defined"));
return FAIL; return NULL;
} }
lp = first_sign; // start all over lp = first_sign; // start all over
continue; continue;
@@ -769,16 +758,14 @@ int sign_define_by_name(
sp->sn_name = vim_strsave(name); sp->sn_name = vim_strsave(name);
// add the new sign to the list of signs return sp;
if (sp_prev == NULL) {
first_sign = sp;
} else {
sp_prev->sn_next = sp;
}
} }
// set values for a defined sign. /*
if (icon != NULL) * Initialize the icon information for a new sign
*/
static void
sign_define_init_icon(sign_T *sp, char_u *icon)
{ {
xfree(sp->sn_icon); xfree(sp->sn_icon);
sp->sn_icon = vim_strsave(icon); sp->sn_icon = vim_strsave(icon);
@@ -794,7 +781,11 @@ int sign_define_by_name(
# endif # endif
} }
if (text != NULL) /*
* Initialize the text for a new sign
*/
static int
sign_define_init_text(sign_T *sp, char_u *text)
{ {
char_u *s; char_u *s;
char_u *endp; char_u *endp;
@@ -833,6 +824,49 @@ int sign_define_by_name(
if (cells == 1) if (cells == 1)
STRCPY(sp->sn_text + len - 1, " "); STRCPY(sp->sn_text + len - 1, " ");
return OK;
}
/*
* Define a new sign or update an existing sign
*/
int sign_define_by_name(
char_u *name,
char_u *icon,
char_u *linehl,
char_u *text,
char_u *texthl,
char_u *numhl
)
{
sign_T *sp_prev;
sign_T *sp;
sp = sign_find(name, &sp_prev);
if (sp == NULL)
{
sp = alloc_new_sign(name);
if (sp == NULL) {
return FAIL;
}
// add the new sign to the list of signs
if (sp_prev == NULL) {
first_sign = sp;
} else {
sp_prev->sn_next = sp;
}
}
// set values for a defined sign.
if (icon != NULL)
{
sign_define_init_icon(sp, icon);
}
if (text != NULL && (sign_define_init_text(sp, text) == FAIL)) {
return FAIL;
} }
if (linehl != NULL) if (linehl != NULL)