vim-patch:9.1.0538: not possible to assign priority when defining a sign (#29592)

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: vim/vim#8334
closes: vim/vim#15124

b975ddfdf9

Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
zeertzjq
2024-07-07 07:21:14 +08:00
committed by GitHub
parent 472b5b9b20
commit 6a886a2511
8 changed files with 96 additions and 26 deletions

View File

@@ -10112,6 +10112,7 @@ M.funcs = {
linehl highlight group used for the whole line the
sign is placed in; not present if not set.
name name of the sign
priority default priority value of the sign
numhl highlight group used for the line number where
the sign is placed; not present if not set.
text text that is displayed when there is no icon
@@ -10322,7 +10323,8 @@ M.funcs = {
priority Priority of the sign. When multiple signs are
placed on a line, the sign with the highest
priority is used. If not specified, the
default value of 10 is used. See
default value of 10 is used, unless specified
otherwise by the sign definition. See
|sign-priority| for more information.
If {id} refers to an existing sign, then the existing sign is

View File

@@ -401,7 +401,7 @@ int init_sign_text(sign_T *sp, schar_T *sign_text, char *text)
/// Define a new sign or update an existing sign
static int sign_define_by_name(char *name, char *icon, char *text, char *linehl, char *texthl,
char *culhl, char *numhl)
char *culhl, char *numhl, int prio)
{
cstr_t *key;
sign_T **sp = (sign_T **)pmap_put_ref(cstr_t)(&sign_map, name, &key, NULL);
@@ -431,6 +431,8 @@ static int sign_define_by_name(char *name, char *icon, char *text, char *linehl,
return FAIL;
}
(*sp)->sn_priority = prio;
char *arg[] = { linehl, texthl, culhl, numhl };
int *hl[] = { &(*sp)->sn_line_hl, &(*sp)->sn_text_hl, &(*sp)->sn_cul_hl, &(*sp)->sn_num_hl };
for (int i = 0; i < 4; i++) {
@@ -472,6 +474,11 @@ static void sign_list_defined(sign_T *sp)
describe_sign_text(buf, sp->sn_text);
msg_outtrans(buf, 0);
}
if (sp->sn_priority > 0) {
char lbuf[MSG_BUF_LEN];
vim_snprintf(lbuf, MSG_BUF_LEN, " priority=%d", sp->sn_priority);
msg_puts(lbuf);
}
static char *arg[] = { " linehl=", " texthl=", " culhl=", " numhl=" };
int hl[] = { sp->sn_line_hl, sp->sn_text_hl, sp->sn_cul_hl, sp->sn_num_hl };
for (int i = 0; i < 4; i++) {
@@ -508,6 +515,11 @@ static int sign_place(uint32_t *id, char *group, char *name, buf_T *buf, linenr_
return FAIL;
}
// 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
buf_set_sign(buf, id, group, prio, lnum, sp);
@@ -602,6 +614,7 @@ static void sign_define_cmd(char *name, char *cmdline)
char *texthl = NULL;
char *culhl = NULL;
char *numhl = NULL;
int prio = -1;
// set values for a defined sign.
while (true) {
@@ -622,6 +635,8 @@ static void sign_define_cmd(char *name, char *cmdline)
culhl = arg + 6;
} else if (strncmp(arg, "numhl=", 6) == 0) {
numhl = arg + 6;
} else if (strncmp(arg, "priority=", 9) == 0) {
prio = atoi(arg + 9);
} else {
semsg(_(e_invarg2), arg);
return;
@@ -632,7 +647,7 @@ static void sign_define_cmd(char *name, char *cmdline)
*cmdline++ = NUL;
}
sign_define_by_name(name, icon, text, linehl, texthl, culhl, numhl);
sign_define_by_name(name, icon, text, linehl, texthl, culhl, numhl, prio);
}
/// ":sign place" command
@@ -847,7 +862,7 @@ void ex_sign(exarg_T *eap)
linenr_T lnum = -1;
char *name = NULL;
char *group = NULL;
int prio = SIGN_DEF_PRIO;
int prio = -1;
buf_T *buf = NULL;
// Parse command line arguments
@@ -880,6 +895,9 @@ static dict_T *sign_get_info_dict(sign_T *sp)
describe_sign_text(buf, sp->sn_text);
tv_dict_add_str(d, S_LEN("text"), buf);
}
if (sp->sn_priority > 0) {
tv_dict_add_nr(d, S_LEN("priority"), sp->sn_priority);
}
static char *arg[] = { "linehl", "texthl", "culhl", "numhl" };
int hl[] = { sp->sn_line_hl, sp->sn_text_hl, sp->sn_cul_hl, sp->sn_num_hl };
for (int i = 0; i < 4; i++) {
@@ -1044,7 +1062,8 @@ char *get_sign_name(expand_T *xp, int idx)
case EXP_SUBCMD:
return cmds[idx];
case EXP_DEFINE: {
char *define_arg[] = { "culhl=", "icon=", "linehl=", "numhl=", "text=", "texthl=", NULL };
char *define_arg[] = { "culhl=", "icon=", "linehl=", "numhl=", "text=", "texthl=",
"priority=", NULL };
return define_arg[idx];
}
case EXP_PLACE: {
@@ -1200,6 +1219,7 @@ static int sign_define_from_dict(char *name, dict_T *dict)
char *texthl = NULL;
char *culhl = NULL;
char *numhl = NULL;
int prio = -1;
if (dict != NULL) {
icon = tv_dict_get_string(dict, "icon", false);
@@ -1208,9 +1228,10 @@ static int sign_define_from_dict(char *name, dict_T *dict)
texthl = tv_dict_get_string(dict, "texthl", false);
culhl = tv_dict_get_string(dict, "culhl", false);
numhl = tv_dict_get_string(dict, "numhl", false);
prio = (int)tv_dict_get_number_def(dict, "priority", -1);
}
return sign_define_by_name(name, icon, text, linehl, texthl, culhl, numhl) - 1;
return sign_define_by_name(name, icon, text, linehl, texthl, culhl, numhl, prio) - 1;
}
/// Define multiple signs using attributes from list 'l' and store the return
@@ -1442,7 +1463,7 @@ static int sign_place_from_dict(typval_T *id_tv, typval_T *group_tv, typval_T *n
}
}
int prio = SIGN_DEF_PRIO;
int prio = -1;
di = tv_dict_find(dict, "priority", -1);
if (di != NULL) {
prio = (int)tv_get_number_chk(&di->di_tv, &notanum);

View File

@@ -18,6 +18,7 @@ typedef struct {
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
} sign_T;
typedef struct {