0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 9.1.0538: not possible to assign priority when defining a sign

Problem:  not possible to assign priority when defining a sign
          (Mathias Fußenegger)
Solution: Add the priority argument for the :sign-define ex command and
          the sign_define() function (LemonBoy)

Use the specified value instead of the default one (SIGN_DEF_PRIO) when
no priority is explicitly specified in sign_place or :sign place.

fixes: #8334
closes: #15124

Signed-off-by: LemonBoy <thatlemon@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
LemonBoy
2024-07-06 18:04:09 +02:00
committed by Christian Brabandt
parent 25ac6d67d9
commit b975ddfdf9
10 changed files with 94 additions and 22 deletions

View File

@@ -34,6 +34,7 @@ struct sign
int sn_text_hl; // highlight ID for text
int sn_cul_hl; // highlight ID for text on current line when 'cursorline' is set
int sn_num_hl; // highlight ID for line number
int sn_priority; // default priority of this sign, -1 means SIGN_DEF_PRIO
};
static sign_T *first_sign = NULL;
@@ -1047,7 +1048,8 @@ sign_define_by_name(
char_u *text,
char_u *texthl,
char_u *culhl,
char_u *numhl)
char_u *numhl,
int prio)
{
sign_T *sp_prev;
sign_T *sp;
@@ -1083,6 +1085,8 @@ sign_define_by_name(
if (text != NULL && (sign_define_init_text(sp, text) == FAIL))
return FAIL;
sp->sn_priority = prio;
if (linehl != NULL)
{
if (*linehl == NUL)
@@ -1206,6 +1210,10 @@ sign_place(
if (*sign_id == 0)
*sign_id = sign_group_get_next_signid(buf, sign_group);
// Use the default priority value for this sign.
if (prio == -1)
prio = (sp->sn_priority != -1) ? sp->sn_priority : SIGN_DEF_PRIO;
if (lnum > 0)
// ":sign place {id} line={lnum} name={name} file={fname}":
// place a sign
@@ -1338,6 +1346,7 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
char_u *texthl = NULL;
char_u *culhl = NULL;
char_u *numhl = NULL;
int prio = -1;
int failed = FALSE;
// set values for a defined sign.
@@ -1377,6 +1386,12 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
arg += 6;
numhl = vim_strnsave(arg, p - arg);
}
else if (STRNCMP(arg, "priority=", 9) == 0)
{
arg += 9;
prio = atoi((char *)arg);
arg = skiptowhite(arg);
}
else
{
semsg(_(e_invalid_argument_str), arg);
@@ -1386,7 +1401,7 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
}
if (!failed)
sign_define_by_name(sign_name, icon, linehl, text, texthl, culhl, numhl);
sign_define_by_name(sign_name, icon, linehl, text, texthl, culhl, numhl, prio);
vim_free(icon);
vim_free(text);
@@ -1721,7 +1736,7 @@ ex_sign(exarg_T *eap)
linenr_T lnum = -1;
char_u *sign_name = NULL;
char_u *group = NULL;
int prio = SIGN_DEF_PRIO;
int prio = -1;
// Parse command line arguments
if (parse_sign_cmd_args(idx, arg, &sign_name, &id, &group, &prio,
@@ -1750,6 +1765,8 @@ sign_getinfo(sign_T *sp, dict_T *retdict)
dict_add_string(retdict, "icon", sp->sn_icon);
if (sp->sn_text != NULL)
dict_add_string(retdict, "text", sp->sn_text);
if (sp->sn_priority > 0)
dict_add_number(retdict, "priority", sp->sn_priority);
if (sp->sn_line_hl > 0)
{
p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE);
@@ -1913,6 +1930,7 @@ sign_gui_started(void)
sign_list_defined(sign_T *sp)
{
char_u *p;
char lbuf[MSG_BUF_LEN];
smsg("sign %s", sp->sn_name);
if (sp->sn_icon != NULL)
@@ -1931,6 +1949,11 @@ sign_list_defined(sign_T *sp)
msg_puts(" text=");
msg_outtrans(sp->sn_text);
}
if (sp->sn_priority > 0)
{
vim_snprintf(lbuf, MSG_BUF_LEN, " priority=%d", sp->sn_priority);
msg_puts(lbuf);
}
if (sp->sn_line_hl > 0)
{
msg_puts(" linehl=");
@@ -2088,7 +2111,8 @@ get_sign_name(expand_T *xp UNUSED, int idx)
{
char *define_arg[] =
{
"culhl=", "icon=", "linehl=", "numhl=", "text=", "texthl=", NULL
"culhl=", "icon=", "linehl=", "numhl=", "text=", "texthl=", "priority=",
NULL
};
return (char_u *)define_arg[idx];
}
@@ -2261,6 +2285,7 @@ sign_define_from_dict(char_u *name_arg, dict_T *dict)
char_u *texthl = NULL;
char_u *culhl = NULL;
char_u *numhl = NULL;
int prio = -1;
int retval = -1;
if (name_arg == NULL)
@@ -2281,9 +2306,10 @@ sign_define_from_dict(char_u *name_arg, dict_T *dict)
texthl = dict_get_string(dict, "texthl", TRUE);
culhl = dict_get_string(dict, "culhl", TRUE);
numhl = dict_get_string(dict, "numhl", TRUE);
prio = dict_get_number_def(dict, "priority", -1);
}
if (sign_define_by_name(name, icon, linehl, text, texthl, culhl, numhl) == OK)
if (sign_define_by_name(name, icon, linehl, text, texthl, culhl, numhl, prio) == OK)
retval = 0;
cleanup:
@@ -2511,7 +2537,7 @@ sign_place_from_dict(
buf_T *buf = NULL;
dictitem_T *di;
linenr_T lnum = 0;
int prio = SIGN_DEF_PRIO;
int prio = -1;
int notanum = FALSE;
int ret_sign_id = -1;