#if defined(FEAT_SIGNS) || defined(PROTO)
static hashtab_T sg_table; // sign group (signgroup_T) hashtable
+static int next_sign_id = 1; // next sign id in the global group
+
+/*
+ * Initialize data needed for managing signs
+ */
+ void
+init_signs(void)
+{
+ hash_init(&sg_table); // sign group hash table
+}
/*
* A new sign in group 'groupname' is added. If the group is not present,
static signgroup_T *
sign_group_ref(char_u *groupname)
{
- static int initialized = FALSE;
hash_T hash;
hashitem_T *hi;
signgroup_T *group;
- if (!initialized)
- {
- initialized = TRUE;
- hash_init(&sg_table);
- }
-
hash = hash_hash(groupname);
hi = hash_lookup(&sg_table, groupname, hash);
if (HASHITEM_EMPTY(hi))
return NULL;
STRCPY(group->sg_name, groupname);
group->refcount = 1;
+ group->next_sign_id = 1;
hash_add_item(&sg_table, hi, group->sg_name, hash);
}
else
}
}
+/*
+ * Get the next free sign identifier in the specified group
+ */
+ int
+sign_group_get_next_signid(buf_T *buf, char_u *groupname)
+{
+ int id = 1;
+ signgroup_T *group = NULL;
+ signlist_T *sign;
+ hashitem_T *hi;
+ int found = FALSE;
+
+ if (groupname != NULL)
+ {
+ hi = hash_find(&sg_table, groupname);
+ if (HASHITEM_EMPTY(hi))
+ return id;
+ group = HI2SG(hi);
+ }
+
+ // Search for the next usuable sign identifier
+ while (!found)
+ {
+ if (group == NULL)
+ id = next_sign_id++; // global group
+ else
+ id = group->next_sign_id++;
+
+ // Check whether this sign is already placed in the buffer
+ found = TRUE;
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
+ {
+ if (id == sign->id && sign_in_group(sign, groupname))
+ {
+ found = FALSE; // sign identifier is in use
+ break;
+ }
+ }
+ }
+
+ return id;
+}
+
/*
* Insert a new sign into the signlist for buffer 'buf' between the 'prev' and
* 'next' signs.
signlist_T *prev; // the previous sign
prev = NULL;
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
{
if (lnum == sign->lnum && id == sign->id &&
sign_in_group(sign, groupname))
{
signlist_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
{
if (sign->id == markId && sign_in_group(sign, group))
{
{
signlist_T *sign; /* a sign in a b_signlist */
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->lnum == lnum
&& (type == SIGN_ANY
# ifdef FEAT_SIGN_ICONS
{
signlist_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->id == id && sign_in_group(sign, group))
return sign->lnum;
{
signlist_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->lnum == lnum)
return sign;
{
signlist_T *sign; // a sign in the signlist
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->id == id && sign_in_group(sign, group))
return sign;
{
signlist_T *sign; /* a sign in the signlist */
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->lnum == lnum && sign->typenr == typenr)
return sign->id;
signlist_T *sign; // a sign in the signlist
int count = 0;
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
if (sign->lnum == lnum)
if (sign_get_image(sign->typenr) != NULL)
count++;
MSG_PUTS_ATTR(lbuf, HL_ATTR(HLF_D));
msg_putchar('\n');
}
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
{
if (got_int)
break;
{
signlist_T *sign; /* a sign in a b_signlist */
- FOR_ALL_SIGNS_IN_BUF(curbuf)
+ FOR_ALL_SIGNS_IN_BUF(curbuf, sign)
{
if (sign->lnum >= line1 && sign->lnum <= line2)
{
return FAIL;
}
if (*sign_id == 0)
- {
- // Allocate a new sign id
- int id = 1;
- signlist_T *sign;
-
- while ((sign = buf_getsign_with_id(buf, id, sign_group)) != NULL)
- id++;
-
- *sign_id = id;
- }
+ *sign_id = sign_group_get_next_signid(buf, sign_group);
if (lnum > 0)
// ":sign place {id} line={lnum} name={name} file={fname}":
else if (idx == SIGNCMD_JUMP)
{
/* ":sign jump {id} file={fname}" */
- if (lnum >= 0 || sign_name != NULL)
+ if (lnum >= 0 || sign_name != NULL || buf == NULL)
EMSG(_(e_invarg));
else if ((lnum = buf_findsign(buf, id, group)) > 0)
{ /* goto a sign ... */
return;
dict_add_list(d, "signs", l);
- FOR_ALL_SIGNS_IN_BUF(buf)
+ FOR_ALL_SIGNS_IN_BUF(buf, sign)
{
if (!sign_in_group(sign, sign_group))
continue;
sign undefine Sign
endfunc
-" Test for VimL functions for managing signs
+" Test for Vim script functions for managing signs
func Test_sign_funcs()
" Remove all the signs
call sign_unplace('*')
call assert_equal(3, sign_place(0, '', 'sign1', 'Xsign',
\ {'lnum' : 14}))
call sign_unplace('', {'buffer' : 'Xsign', 'id' : 2})
- call assert_equal(2, sign_place(0, '', 'sign1', 'Xsign',
+ call assert_equal(4, sign_place(0, '', 'sign1', 'Xsign',
\ {'lnum' : 12}))
call assert_equal(1, sign_place(0, 'g1', 'sign1', 'Xsign',