summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-12-05 17:45:49 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-05 17:45:49 +0000
commit0bac5fc5e125b7aa0f3b596c9b7f4381279e6688 (patch)
tree4acb691bff59f2762fe0d7ad08ac95012c8ae9b6
parentc7d5fc8622f03cca8d1a9a54d4703e8f0c9941d0 (diff)
patch 8.2.3747: cannot remove highlight from an existing signv8.2.3747
Problem: Cannot remove highlight from an existing sign. (James McCoy) Solution: Only reject empty argument for a new sign.
-rw-r--r--src/sign.c33
-rw-r--r--src/testdir/test_signs.vim31
-rw-r--r--src/version.c2
3 files changed, 56 insertions, 10 deletions
diff --git a/src/sign.c b/src/sign.c
index 66a29db1d7..2c102e4e52 100644
--- a/src/sign.c
+++ b/src/sign.c
@@ -1078,13 +1078,28 @@ sign_define_by_name(
return FAIL;
if (linehl != NULL)
- sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
+ {
+ if (*linehl == NUL)
+ sp->sn_line_hl = 0;
+ else
+ sp->sn_line_hl = syn_check_group(linehl, (int)STRLEN(linehl));
+ }
if (texthl != NULL)
- sp->sn_text_hl = syn_check_group(texthl, (int)STRLEN(texthl));
+ {
+ if (*texthl == NUL)
+ sp->sn_text_hl = 0;
+ else
+ sp->sn_text_hl = syn_check_group(texthl, (int)STRLEN(texthl));
+ }
if (culhl != NULL)
- sp->sn_cul_hl = syn_check_group(culhl, (int)STRLEN(culhl));
+ {
+ if (*culhl == NUL)
+ sp->sn_cul_hl = 0;
+ else
+ sp->sn_cul_hl = syn_check_group(culhl, (int)STRLEN(culhl));
+ }
return OK;
}
@@ -1319,7 +1334,11 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
char_u *linehl = NULL;
char_u *texthl = NULL;
char_u *culhl = NULL;
- int failed = FALSE;
+ int failed = FALSE;
+ sign_T *sp_prev;
+ int exists;
+
+ exists = sign_find(sign_name, &sp_prev) != NULL;
// set values for a defined sign.
for (;;)
@@ -1341,7 +1360,7 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
else if (STRNCMP(arg, "linehl=", 7) == 0)
{
arg += 7;
- if (check_empty_group(p - arg, "linehl") == FAIL)
+ if (!exists && check_empty_group(p - arg, "linehl") == FAIL)
{
failed = TRUE;
break;
@@ -1351,7 +1370,7 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
else if (STRNCMP(arg, "texthl=", 7) == 0)
{
arg += 7;
- if (check_empty_group(p - arg, "texthl") == FAIL)
+ if (!exists && check_empty_group(p - arg, "texthl") == FAIL)
{
failed = TRUE;
break;
@@ -1361,7 +1380,7 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
else if (STRNCMP(arg, "culhl=", 6) == 0)
{
arg += 6;
- if (check_empty_group(p - arg, "culhl") == FAIL)
+ if (!exists && check_empty_group(p - arg, "culhl") == FAIL)
{
failed = TRUE;
break;
diff --git a/src/testdir/test_signs.vim b/src/testdir/test_signs.vim
index 18a6edc772..8511708ace 100644
--- a/src/testdir/test_signs.vim
+++ b/src/testdir/test_signs.vim
@@ -126,9 +126,34 @@ func Test_sign()
call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:')
- call assert_fails("sign define Sign4 linehl=", 'E1249: Group name missing for linehl')
- call assert_fails("sign define Sign4 culhl=", 'E1249: Group name missing for culhl')
- call assert_fails("sign define Sign4 texthl=", 'E1249: Group name missing for texthl')
+ " an empty highlight argument for a new sign is an error
+ call assert_fails("sign define SignX linehl=", 'E1249: Group name missing for linehl')
+ call assert_fails("sign define SignX culhl=", 'E1249: Group name missing for culhl')
+ call assert_fails("sign define SignX texthl=", 'E1249: Group name missing for texthl')
+
+ " an empty highlight argument for an existing sign clears it
+ sign define SignY texthl=TextHl culhl=CulHl linehl=LineHl
+ let sl = sign_getdefined('SignY')[0]
+ call assert_equal('TextHl', sl.texthl)
+ call assert_equal('CulHl', sl.culhl)
+ call assert_equal('LineHl', sl.linehl)
+
+ sign define SignY texthl= culhl=CulHl linehl=LineHl
+ let sl = sign_getdefined('SignY')[0]
+ call assert_false(has_key(sl, 'texthl'))
+ call assert_equal('CulHl', sl.culhl)
+ call assert_equal('LineHl', sl.linehl)
+
+ sign define SignY linehl=
+ let sl = sign_getdefined('SignY')[0]
+ call assert_false(has_key(sl, 'linehl'))
+ call assert_equal('CulHl', sl.culhl)
+
+ sign define SignY culhl=
+ let sl = sign_getdefined('SignY')[0]
+ call assert_false(has_key(sl, 'culhl'))
+
+ sign undefine SignY
" define sign with whitespace
sign define Sign4 text=\ X linehl=Comment
diff --git a/src/version.c b/src/version.c
index 0d00f207d1..e7b0b2e2d0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3747,
+/**/
3746,
/**/
3745,