mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 06:58:35 +00: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:
@@ -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,17 +758,15 @@ 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);
|
||||||
backslash_halve(sp->sn_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);
|
sp->sn_image = gui_mch_register_sign(sp->sn_icon);
|
||||||
}
|
}
|
||||||
# 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;
|
||||||
int cells;
|
int cells;
|
||||||
@@ -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)
|
||||||
|
Reference in New Issue
Block a user