aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/sign.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-07-07 07:21:14 +0800
committerGitHub <noreply@github.com>2024-07-07 07:21:14 +0800
commit6a886a2511bbfd24a4d6ecc3f3a75f08a6df9de9 (patch)
treea7d77386bc98702631137c4bd8bc62c3eb4ebf82 /src/nvim/sign.c
parent472b5b9b20756146db39cf32c6fb678e1d8104c0 (diff)
downloadrneovim-6a886a2511bbfd24a4d6ecc3f3a75f08a6df9de9.tar.gz
rneovim-6a886a2511bbfd24a4d6ecc3f3a75f08a6df9de9.tar.bz2
rneovim-6a886a2511bbfd24a4d6ecc3f3a75f08a6df9de9.zip
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 https://github.com/vim/vim/commit/b975ddfdf96644b8df808415dee36f99abd48753 Co-authored-by: LemonBoy <thatlemon@gmail.com>
Diffstat (limited to 'src/nvim/sign.c')
-rw-r--r--src/nvim/sign.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index 605098fb66..fbd25493ef 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -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);