mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
fb4cf05e44
commit
93e18e698e
@ -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(
|
||||
char_u *name,
|
||||
char_u *icon,
|
||||
char_u *linehl,
|
||||
char_u *text,
|
||||
char_u *texthl,
|
||||
char_u *numhl
|
||||
)
|
||||
static sign_T *
|
||||
alloc_new_sign(char_u *name)
|
||||
{
|
||||
sign_T *sp_prev;
|
||||
sign_T *sp;
|
||||
|
||||
sp = sign_find(name, &sp_prev);
|
||||
if (sp == NULL)
|
||||
{
|
||||
sign_T *lp;
|
||||
int start = next_sign_typenr;
|
||||
|
||||
@ -755,7 +744,7 @@ int sign_define_by_name(
|
||||
if (next_sign_typenr == start) {
|
||||
xfree(sp);
|
||||
EMSG(_("E612: Too many signs defined"));
|
||||
return FAIL;
|
||||
return NULL;
|
||||
}
|
||||
lp = first_sign; // start all over
|
||||
continue;
|
||||
@ -769,17 +758,15 @@ int sign_define_by_name(
|
||||
|
||||
sp->sn_name = vim_strsave(name);
|
||||
|
||||
// add the new sign to the list of signs
|
||||
if (sp_prev == NULL) {
|
||||
first_sign = sp;
|
||||
} else {
|
||||
sp_prev->sn_next = sp;
|
||||
}
|
||||
}
|
||||
return 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);
|
||||
sp->sn_icon = vim_strsave(icon);
|
||||
backslash_halve(sp->sn_icon);
|
||||
@ -792,10 +779,14 @@ int sign_define_by_name(
|
||||
sp->sn_image = gui_mch_register_sign(sp->sn_icon);
|
||||
}
|
||||
# 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 *endp;
|
||||
int cells;
|
||||
@ -833,6 +824,49 @@ int sign_define_by_name(
|
||||
|
||||
if (cells == 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)
|
||||
|
Loading…
Reference in New Issue
Block a user