signs: Add "numhl" argument #9113

close #9113
ref #9040
This commit is contained in:
Reto Schnyder
2018-10-13 19:33:08 +02:00
committed by Justin M. Keyes
parent 8bbb28b973
commit bddcbbb571
10 changed files with 127 additions and 53 deletions

View File

@@ -5471,13 +5471,14 @@ void ex_helptags(exarg_T *eap)
struct sign
{
sign_T *sn_next; /* next sign in list */
int sn_typenr; /* type number of sign */
char_u *sn_name; /* name of sign */
char_u *sn_icon; /* name of pixmap */
char_u *sn_text; /* text used instead of pixmap */
int sn_line_hl; /* highlight ID for line */
int sn_text_hl; /* highlight ID for text */
sign_T *sn_next; // next sign in list
int sn_typenr; // type number of sign
char_u *sn_name; // name of sign
char_u *sn_icon; // name of pixmap
char_u *sn_text; // text used instead of pixmap
int sn_line_hl; // highlight ID for line
int sn_text_hl; // highlight ID for text
int sn_num_hl; // highlight ID for line number
};
static sign_T *first_sign = NULL;
@@ -5675,6 +5676,9 @@ void ex_sign(exarg_T *eap)
} else if (STRNCMP(arg, "texthl=", 7) == 0) {
arg += 7;
sp->sn_text_hl = syn_check_group(arg, (int)(p - arg));
} else if (STRNCMP(arg, "numhl=", 6) == 0) {
arg += 6;
sp->sn_num_hl = syn_check_group(arg, (int)(p - arg));
} else {
EMSG2(_(e_invarg2), arg);
return;
@@ -5901,6 +5905,16 @@ static void sign_list_defined(sign_T *sp)
msg_puts(p);
}
}
if (sp->sn_num_hl > 0) {
msg_puts(" numhl=");
const char *const p = get_highlight_name_ext(NULL,
sp->sn_num_hl - 1, false);
if (p == NULL) {
msg_puts("NONE");
} else {
msg_puts(p);
}
}
}
/*
@@ -5918,25 +5932,33 @@ static void sign_undefine(sign_T *sp, sign_T *sp_prev)
xfree(sp);
}
/*
* Get highlighting attribute for sign "typenr".
* If "line" is TRUE: line highl, if FALSE: text highl.
*/
int sign_get_attr(int typenr, int line)
/// Gets highlighting attribute for sign "typenr" corresponding to "type".
int sign_get_attr(int typenr, SignType type)
{
sign_T *sp;
int sign_hl = 0;
for (sp = first_sign; sp != NULL; sp = sp->sn_next)
for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
if (sp->sn_typenr == typenr) {
if (line) {
if (sp->sn_line_hl > 0)
return syn_id2attr(sp->sn_line_hl);
} else {
if (sp->sn_text_hl > 0)
return syn_id2attr(sp->sn_text_hl);
switch (type) {
case SIGN_TEXT:
sign_hl = sp->sn_text_hl;
break;
case SIGN_LINEHL:
sign_hl = sp->sn_line_hl;
break;
case SIGN_NUMHL:
sign_hl = sp->sn_num_hl;
break;
default:
abort();
}
if (sign_hl > 0) {
return syn_id2attr(sign_hl);
}
break;
}
}
return 0;
}
@@ -5997,7 +6019,8 @@ char_u * get_sign_name(expand_T *xp, int idx)
case EXP_SUBCMD:
return (char_u *)cmds[idx];
case EXP_DEFINE: {
char *define_arg[] = { "icon=", "linehl=", "text=", "texthl=", NULL };
char *define_arg[] = { "icon=", "linehl=", "text=", "texthl=", "numhl=",
NULL };
return (char_u *)define_arg[idx];
}
case EXP_PLACE: {
@@ -6120,7 +6143,8 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
{
case SIGNCMD_DEFINE:
if (STRNCMP(last, "texthl", p - last) == 0
|| STRNCMP(last, "linehl", p - last) == 0) {
|| STRNCMP(last, "linehl", p - last) == 0
|| STRNCMP(last, "numhl", p - last) == 0) {
xp->xp_context = EXPAND_HIGHLIGHT;
} else if (STRNCMP(last, "icon", p - last) == 0) {
xp->xp_context = EXPAND_FILES;