aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt157
-rw-r--r--runtime/doc/usr_41.txt2
-rw-r--r--src/nvim/edit.c8
-rw-r--r--src/nvim/eval.lua2
-rw-r--r--src/nvim/eval/funcs.c213
-rw-r--r--src/nvim/ex_cmds.c5
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/ex_getln.c26
-rw-r--r--src/nvim/normal.c2
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/quickfix.c2
-rw-r--r--src/nvim/screen.c37
-rw-r--r--src/nvim/search.c18
-rw-r--r--src/nvim/sign.c434
-rw-r--r--src/nvim/sign_defs.h17
-rw-r--r--src/nvim/spell.c2
-rw-r--r--src/nvim/tag.c11
-rw-r--r--src/nvim/testdir/test_search.vim24
-rw-r--r--src/nvim/testdir/test_signs.vim146
-rw-r--r--test/functional/lua/buffer_updates_spec.lua26
-rw-r--r--test/functional/ui/searchhl_spec.lua14
21 files changed, 844 insertions, 308 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 78c7a8a69f..00b1be013a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2395,6 +2395,7 @@ shellescape({string} [, {special}])
command argument
shiftwidth([{col}]) Number effective value of 'shiftwidth'
sign_define({name} [, {dict}]) Number define or update a sign
+sign_define({list}) List define or update a list of signs
sign_getdefined([{name}]) List get a list of defined signs
sign_getplaced([{expr} [, {dict}]])
List get a list of placed signs
@@ -2402,9 +2403,12 @@ sign_jump({id}, {group}, {expr})
Number jump to a sign
sign_place({id}, {group}, {name}, {expr} [, {dict}])
Number place a sign
+sign_placelist({list}) List place a list of signs
sign_undefine([{name}]) Number undefine a sign
+sign_undefine({list}) List undefine a list of signs
sign_unplace({group} [, {dict}])
Number unplace a sign
+sign_unplacelist({list}) List unplace a list of signs
simplify({filename}) String simplify filename as much as possible
sin({expr}) Float sine of {expr}
sinh({expr}) Float hyperbolic sine of {expr}
@@ -7927,6 +7931,7 @@ shiftwidth([{col}]) *shiftwidth()*
will be assumed.
sign_define({name} [, {dict}]) *sign_define()*
+sign_define({list})
Define a new sign named {name} or modify the attributes of an
existing sign. This is similar to the |:sign-define| command.
@@ -7936,24 +7941,38 @@ sign_define({name} [, {dict}]) *sign_define()*
The {name} can be a String or a Number. The optional {dict}
argument specifies the sign attributes. The following values
are supported:
- icon full path to the bitmap file for the sign.
- linehl highlight group used for the whole line the
+ icon full path to the bitmap file for the sign.
+ linehl highlight group used for the whole line the
sign is placed in.
- text text that is displayed when there is no icon
+ text text that is displayed when there is no icon
or the GUI is not being used.
- texthl highlight group used for the text item
- numhl highlight group used for 'number' column at the
+ texthl highlight group used for the text item
+ numhl highlight group used for 'number' column at the
associated line. Overrides |hl-LineNr|,
|hl-CursorLineNr|.
If the sign named {name} already exists, then the attributes
of the sign are updated.
- Returns 0 on success and -1 on failure.
+ The one argument {list} can be used to define a list of signs.
+ Each list item is a dictionary with the above items in {dict}
+ and a 'name' item for the sign name.
+
+ Returns 0 on success and -1 on failure. When the one argument
+ {list} is used, then returns a List of values one for each
+ defined sign.
Examples: >
- call sign_define("mySign", {"text" : "=>", "texthl" :
- \ "Error", "linehl" : "Search"})
+ call sign_define("mySign", {
+ \ "text" : "=>",
+ \ "texthl" : "Error",
+ \ "linehl" : "Search"})
+ call sign_define([
+ \ {'name' : 'sign1',
+ \ 'text' : '=>'},
+ \ {'name' : 'sign2',
+ \ 'text' : '!!'}
+ \ ])
<
sign_getdefined([{name}]) *sign_getdefined()*
Get a list of defined signs and their attributes.
@@ -7965,14 +7984,14 @@ sign_getdefined([{name}]) *sign_getdefined()*
Each list item in the returned value is a dictionary with the
following entries:
- icon full path to the bitmap file of the sign
- linehl highlight group used for the whole line the
+ icon full path to the bitmap file of the sign
+ linehl highlight group used for the whole line the
sign is placed in.
- name name of the sign
- text text that is displayed when there is no icon
+ name name of the sign
+ text text that is displayed when there is no icon
or the GUI is not being used.
- texthl highlight group used for the text item
- numhl highlight group used for 'number' column at the
+ texthl highlight group used for the text item
+ numhl highlight group used for 'number' column at the
associated line. Overrides |hl-LineNr|,
|hl-CursorLineNr|.
@@ -8063,25 +8082,25 @@ sign_jump({id}, {group}, {expr})
<
*sign_place()*
sign_place({id}, {group}, {name}, {expr} [, {dict}])
- Place the sign defined as {name} at line {lnum} in file {expr}
- and assign {id} and {group} to sign. This is similar to the
- |:sign-place| command.
+ Place the sign defined as {name} at line {lnum} in file or
+ buffer {expr} and assign {id} and {group} to sign. This is
+ similar to the |:sign-place| command.
If the sign identifier {id} is zero, then a new identifier is
allocated. Otherwise the specified number is used. {group} is
the sign group name. To use the global sign group, use an
empty string. {group} functions as a namespace for {id}, thus
two groups can use the same IDs. Refer to |sign-identifier|
- for more information.
+ and |sign-group| for more information.
{name} refers to a defined sign.
{expr} refers to a buffer name or number. For the accepted
values, see |bufname()|.
The optional {dict} argument supports the following entries:
- lnum line number in the buffer {expr} where
- the sign is to be placed. For the
- accepted values, see |line()|.
+ lnum line number in the file or buffer
+ {expr} where the sign is to be placed.
+ For the accepted values, see |line()|.
priority priority of the sign. See
|sign-priority| for more information.
@@ -8110,17 +8129,85 @@ sign_place({id}, {group}, {name}, {expr} [, {dict}])
call sign_place(10, 'g3', 'sign4', 'json.c',
\ {'lnum' : 40, 'priority' : 90})
<
+ *sign_placelist()*
+sign_placelist({list})
+ Place one or more signs. This is similar to the
+ |sign_place()| function. The {list} argument specifies the
+ List of signs to place. Each list item is a dict with the
+ following sign attributes:
+ buffer buffer name or number. For the accepted
+ values, see |bufname()|.
+ group sign group. {group} functions as a namespace
+ for {id}, thus two groups can use the same
+ IDs. If not specified or set to an empty
+ string, then the global group is used. See
+ |sign-group| for more information.
+ id sign identifier. If not specified or zero,
+ then a new unique identifier is allocated.
+ Otherwise the specified number is used. See
+ |sign-identifier| for more information.
+ lnum line number in the buffer {expr} where the
+ sign is to be placed. For the accepted values,
+ see |line()|.
+ name name of the sign to place. See |sign_define()|
+ for more information.
+ 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
+ |sign-priority| for more information.
+
+ If {id} refers to an existing sign, then the existing sign is
+ modified to use the specified {name} and/or {priority}.
+
+ Returns a List of sign identifiers. If failed to place a
+ sign, the corresponding list item is set to -1.
+
+ Examples: >
+ " Place sign s1 with id 5 at line 20 and id 10 at line
+ " 30 in buffer a.c
+ let [n1, n2] = sign_place([
+ \ {'id' : 5,
+ \ 'name' : 's1',
+ \ 'buffer' : 'a.c',
+ \ 'lnum' : 20},
+ \ {'id' : 10,
+ \ 'name' : 's1',
+ \ 'buffer' : 'a.c',
+ \ 'lnum' : 30}
+ \ ])
+
+ " Place sign s1 in buffer a.c at line 40 and 50
+ " with auto-generated identifiers
+ let [n1, n2] = sign_place([
+ \ {'name' : 's1',
+ \ 'buffer' : 'a.c',
+ \ 'lnum' : 40},
+ \ {'name' : 's1',
+ \ 'buffer' : 'a.c',
+ \ 'lnum' : 50}
+ \ ])
+<
sign_undefine([{name}]) *sign_undefine()*
+sign_undefine({list})
Deletes a previously defined sign {name}. This is similar to
the |:sign-undefine| command. If {name} is not supplied, then
deletes all the defined signs.
- Returns 0 on success and -1 on failure.
+ The one argument {list} can be used to undefine a list of
+ signs. Each list item is the name of a sign.
+
+ Returns 0 on success and -1 on failure. For the one argument
+ {list} call, returns a list of values one for each undefined
+ sign.
Examples: >
" Delete a sign named mySign
call sign_undefine("mySign")
+ " Delete signs 'sign1' and 'sign2'
+ call sign_undefine(["sign1", "sign2"])
+
" Delete all the signs
call sign_undefine()
<
@@ -8166,6 +8253,32 @@ sign_unplace({group} [, {dict}]) *sign_unplace()*
" Remove all the placed signs from all the buffers
call sign_unplace('*')
<
+sign_unplacelist({list}) *sign_unplacelist()*
+ Remove previously placed signs from one or more buffers. This
+ is similar to the |sign_unplace()| function.
+
+ The {list} argument specifies the List of signs to remove.
+ Each list item is a dict with the following sign attributes:
+ buffer buffer name or number. For the accepted
+ values, see |bufname()|. If not specified,
+ then the specified sign is removed from all
+ the buffers.
+ group sign group name. If not specified or set to an
+ empty string, then the global sign group is
+ used. If set to '*', then all the groups
+ including the global group are used.
+ id sign identifier. If not specified, then all
+ the signs in the specified group are removed.
+
+ Returns a List where an entry is set to 0 if the corresponding
+ sign was successfully removed or -1 on failure.
+
+ Example: >
+ " Remove sign with id 10 from buffer a.vim and sign
+ " with id 20 from buffer b.vim
+ call sign_unplace([{'id' : 10, 'buffer' : "a.vim"},
+ \ {'id' : 20, 'buffer' : 'b.vim'}])
+<
simplify({filename}) *simplify()*
Simplify the file name as much as possible without changing
the meaning. Shortcuts (on MS-Windows) or symbolic links (on
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index ccf47044e7..21f5dcc815 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -943,8 +943,10 @@ Signs: *sign-functions*
sign_getplaced() get a list of placed signs
sign_jump() jump to a sign
sign_place() place a sign
+ sign_placelist() place a list of signs
sign_undefine() undefine a sign
sign_unplace() unplace a sign
+ sign_unplacelist() unplace a list of signs
Testing: *test-functions*
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 49bd170bcd..be0ab33d08 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -8787,10 +8787,6 @@ static bool ins_tab(void)
getvcol(curwin, &fpos, &vcol, NULL, NULL);
getvcol(curwin, cursor, &want_vcol, NULL, NULL);
- // save start of changed region for extmark_splice
- int start_row = fpos.lnum;
- colnr_T start_col = fpos.col;
-
// Use as many TABs as possible. Beware of 'breakindent', 'showbreak'
// and 'linebreak' adding extra virtual columns.
while (ascii_iswhite(*ptr)) {
@@ -8841,8 +8837,8 @@ static bool ins_tab(void)
}
}
if (!(State & VREPLACE_FLAG)) {
- extmark_splice_cols(curbuf, start_row - 1, start_col,
- cursor->col - start_col, fpos.col - start_col,
+ extmark_splice_cols(curbuf, fpos.lnum - 1, change_col,
+ cursor->col - change_col, fpos.col - change_col,
kExtmarkUndo);
}
}
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index aed0824ad6..b10e99fc08 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -316,8 +316,10 @@ return {
sign_getplaced={args={0, 2}},
sign_jump={args={3, 3}},
sign_place={args={4, 5}},
+ sign_placelist={args={1}},
sign_undefine={args={0, 1}},
sign_unplace={args={1, 2}},
+ sign_unplacelist={args={1}},
simplify={args=1},
sin={args=1, func="float_op_wrapper", data="&sin"},
sinh={args=1, func="float_op_wrapper", data="&sinh"},
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index a51618b994..1fbb2d8582 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -8861,56 +8861,30 @@ static void f_shiftwidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_sign_define(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const char *name;
- dict_T *dict;
- char *icon = NULL;
- char *linehl = NULL;
- char *text = NULL;
- char *texthl = NULL;
- char *numhl = NULL;
- rettv->vval.v_number = -1;
+ if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) {
+ // Define multiple signs
+ tv_list_alloc_ret(rettv, kListLenMayKnow);
- name = tv_get_string_chk(&argvars[0]);
- if (name == NULL) {
+ sign_define_multiple(argvars[0].vval.v_list, rettv->vval.v_list);
return;
}
- if (argvars[1].v_type != VAR_UNKNOWN) {
- if (argvars[1].v_type != VAR_DICT) {
- EMSG(_(e_dictreq));
- return;
- }
+ // Define a single sign
+ rettv->vval.v_number = -1;
- // sign attributes
- dict = argvars[1].vval.v_dict;
- if (tv_dict_find(dict, "icon", -1) != NULL) {
- icon = tv_dict_get_string(dict, "icon", true);
- }
- if (tv_dict_find(dict, "linehl", -1) != NULL) {
- linehl = tv_dict_get_string(dict, "linehl", true);
- }
- if (tv_dict_find(dict, "text", -1) != NULL) {
- text = tv_dict_get_string(dict, "text", true);
- }
- if (tv_dict_find(dict, "texthl", -1) != NULL) {
- texthl = tv_dict_get_string(dict, "texthl", true);
- }
- if (tv_dict_find(dict, "numhl", -1) != NULL) {
- numhl = tv_dict_get_string(dict, "numhl", true);
- }
+ name = tv_get_string_chk(&argvars[0]);
+ if (name == NULL) {
+ return;
}
- if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl,
- (char_u *)text, (char_u *)texthl, (char_u *)numhl)
- == OK) {
- rettv->vval.v_number = 0;
+ if (argvars[1].v_type != VAR_UNKNOWN && argvars[1].v_type != VAR_DICT) {
+ EMSG(_(e_dictreq));
+ return;
}
- xfree(icon);
- xfree(linehl);
- xfree(text);
- xfree(texthl);
- xfree(numhl);
+ rettv->vval.v_number = sign_define_from_dict(
+ name, argvars[1].v_type == VAR_DICT ? argvars[1].vval.v_dict : NULL);
}
/// "sign_getdefined()" function
@@ -9031,83 +9005,44 @@ cleanup:
/// "sign_place()" function
static void f_sign_place(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- int sign_id;
- char_u *group = NULL;
- const char *sign_name;
- buf_T *buf;
- dict_T *dict;
- dictitem_T *di;
- linenr_T lnum = 0;
- int prio = SIGN_DEF_PRIO;
- bool notanum = false;
+ dict_T *dict = NULL;
rettv->vval.v_number = -1;
- // Sign identifier
- sign_id = (int)tv_get_number_chk(&argvars[0], &notanum);
- if (notanum) {
- return;
- }
- if (sign_id < 0) {
- EMSG(_(e_invarg));
+ if (argvars[4].v_type != VAR_UNKNOWN
+ && (argvars[4].v_type != VAR_DICT
+ || ((dict = argvars[4].vval.v_dict) == NULL))) {
+ EMSG(_(e_dictreq));
return;
}
- // Sign group
- const char *group_chk = tv_get_string_chk(&argvars[1]);
- if (group_chk == NULL) {
- return;
- }
- if (group_chk[0] == '\0') {
- group = NULL; // global sign group
- } else {
- group = vim_strsave((const char_u *)group_chk);
- }
+ rettv->vval.v_number = sign_place_from_dict(
+ &argvars[0], &argvars[1], &argvars[2], &argvars[3], dict);
+}
- // Sign name
- sign_name = tv_get_string_chk(&argvars[2]);
- if (sign_name == NULL) {
- goto cleanup;
- }
+/// "sign_placelist()" function. Place multiple signs.
+static void f_sign_placelist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ int sign_id;
- // Buffer to place the sign
- buf = get_buf_arg(&argvars[3]);
- if (buf == NULL) {
- goto cleanup;
+ tv_list_alloc_ret(rettv, kListLenMayKnow);
+
+ if (argvars[0].v_type != VAR_LIST) {
+ EMSG(_(e_listreq));
+ return;
}
- if (argvars[4].v_type != VAR_UNKNOWN) {
- if (argvars[4].v_type != VAR_DICT
- || ((dict = argvars[4].vval.v_dict) == NULL)) {
+ // Process the List of sign attributes
+ TV_LIST_ITER_CONST(argvars[0].vval.v_list, li, {
+ sign_id = -1;
+ if (TV_LIST_ITEM_TV(li)->v_type == VAR_DICT) {
+ sign_id = sign_place_from_dict(
+ NULL, NULL, NULL, NULL, TV_LIST_ITEM_TV(li)->vval.v_dict);
+ } else {
EMSG(_(e_dictreq));
- goto cleanup;
- }
-
- // Line number where the sign is to be placed
- if ((di = tv_dict_find(dict, "lnum", -1)) != NULL) {
- lnum = (linenr_T)tv_get_number_chk(&di->di_tv, &notanum);
- if (notanum) {
- goto cleanup;
- }
- (void)lnum;
- lnum = tv_get_lnum(&di->di_tv);
- }
- if ((di = tv_dict_find(dict, "priority", -1)) != NULL) {
- // Sign priority
- prio = (int)tv_get_number_chk(&di->di_tv, &notanum);
- if (notanum) {
- goto cleanup;
- }
}
- }
-
- if (sign_place(&sign_id, group, (const char_u *)sign_name, buf, lnum, prio)
- == OK) {
- rettv->vval.v_number = sign_id;
- }
-
-cleanup:
- xfree(group);
+ tv_list_append_number(rettv->vval.v_list, sign_id);
+ });
}
/// "sign_undefine()" function
@@ -9115,6 +9050,14 @@ static void f_sign_undefine(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const char *name;
+ if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) {
+ // Undefine multiple signs
+ tv_list_alloc_ret(rettv, kListLenMayKnow);
+
+ sign_undefine_multiple(argvars[0].vval.v_list, rettv->vval.v_list);
+ return;
+ }
+
rettv->vval.v_number = -1;
if (argvars[0].v_type == VAR_UNKNOWN) {
@@ -9137,11 +9080,7 @@ static void f_sign_undefine(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "sign_unplace()" function
static void f_sign_unplace(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- dict_T *dict;
- dictitem_T *di;
- int sign_id = 0;
- buf_T *buf = NULL;
- char_u *group = NULL;
+ dict_T *dict = NULL;
rettv->vval.v_number = -1;
@@ -9150,46 +9089,38 @@ static void f_sign_unplace(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
- const char *group_chk = tv_get_string(&argvars[0]);
- if (group_chk[0] == '\0') {
- group = NULL; // global sign group
- } else {
- group = vim_strsave((const char_u *)group_chk);
- }
-
if (argvars[1].v_type != VAR_UNKNOWN) {
if (argvars[1].v_type != VAR_DICT) {
EMSG(_(e_dictreq));
- goto cleanup;
+ return;
}
dict = argvars[1].vval.v_dict;
-
- if ((di = tv_dict_find(dict, "buffer", -1)) != NULL) {
- buf = get_buf_arg(&di->di_tv);
- if (buf == NULL) {
- goto cleanup;
- }
- }
- if (tv_dict_find(dict, "id", -1) != NULL) {
- sign_id = tv_dict_get_number(dict, "id");
- }
}
- if (buf == NULL) {
- // Delete the sign in all the buffers
- FOR_ALL_BUFFERS(cbuf) {
- if (sign_unplace(sign_id, group, cbuf, 0) == OK) {
- rettv->vval.v_number = 0;
- }
- }
- } else {
- if (sign_unplace(sign_id, group, buf, 0) == OK) {
- rettv->vval.v_number = 0;
- }
+ rettv->vval.v_number = sign_unplace_from_dict(&argvars[0], dict);
+}
+
+/// "sign_unplacelist()" function
+static void f_sign_unplacelist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ int retval;
+
+ tv_list_alloc_ret(rettv, kListLenMayKnow);
+
+ if (argvars[0].v_type != VAR_LIST) {
+ EMSG(_(e_listreq));
+ return;
}
-cleanup:
- xfree(group);
+ TV_LIST_ITER_CONST(argvars[0].vval.v_list, li, {
+ retval = -1;
+ if (TV_LIST_ITEM_TV(li)->v_type == VAR_DICT) {
+ retval = sign_unplace_from_dict(NULL, TV_LIST_ITEM_TV(li)->vval.v_dict);
+ } else {
+ EMSG(_(e_dictreq));
+ }
+ tv_list_append_number(rettv->vval.v_list, retval);
+ });
}
/*
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index d34282419a..b191e8cf67 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -790,7 +790,8 @@ void ex_retab(exarg_T *eap)
/* len is actual number of white characters used */
len = num_spaces + num_tabs;
old_len = (long)STRLEN(ptr);
- new_line = xmalloc(old_len - col + start_col + len + 1);
+ long new_len = old_len - col + start_col + len + 1;
+ new_line = xmalloc(new_len);
if (start_col > 0)
memmove(new_line, ptr, (size_t)start_col);
@@ -803,6 +804,8 @@ void ex_retab(exarg_T *eap)
if (ml_replace(lnum, new_line, false) == OK) {
// "new_line" may have been copied
new_line = curbuf->b_ml.ml_line_ptr;
+ extmark_splice_cols(curbuf, lnum - 1, 0, (colnr_T)old_len,
+ (colnr_T)new_len - 1, kExtmarkUndo);
}
if (first_line == 0) {
first_line = lnum;
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 3aaf171b2c..d1eddfc74f 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -3928,7 +3928,7 @@ static linenr_T get_address(exarg_T *eap,
}
searchcmdlen = 0;
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
- if (!do_search(NULL, c, cmd, 1L, flags, NULL)) {
+ if (!do_search(NULL, c, c, cmd, 1L, flags, NULL)) {
curwin->w_cursor = pos;
cmd = NULL;
goto error;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 38385d19b2..e6b2b231f9 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -275,8 +275,9 @@ static void init_incsearch_state(incsearch_state_T *s)
// Return true when 'incsearch' highlighting is to be done.
// Sets search_first_line and search_last_line to the address range.
-static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
- int *skiplen, int *patlen)
+static bool do_incsearch_highlighting(int firstc, int *search_delim,
+ incsearch_state_T *s, int *skiplen,
+ int *patlen)
FUNC_ATTR_NONNULL_ALL
{
char_u *cmd;
@@ -303,6 +304,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
search_last_line = MAXLNUM;
if (firstc == '/' || firstc == '?') {
+ *search_delim = firstc;
return true;
}
if (firstc != ':') {
@@ -371,6 +373,7 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
p = skipwhite(p);
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
+ *search_delim = delim;
end = skip_regexp(p, delim, p_magic, NULL);
use_last_pat = end == p && *end == delim;
@@ -431,12 +434,14 @@ static void may_do_incsearch_highlighting(int firstc, long count,
int skiplen, patlen;
char_u next_char;
char_u use_last_pat;
+ int search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
- if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ if (!do_incsearch_highlighting(firstc, &search_delim, s, &skiplen,
+ &patlen)) {
restore_last_search_pattern();
finish_incsearch_highlighting(false, s, true);
return;
@@ -490,7 +495,7 @@ static void may_do_incsearch_highlighting(int firstc, long count,
ccline.cmdbuff[skiplen + patlen] = NUL;
memset(&sia, 0, sizeof(sia));
sia.sa_tm = &tm;
- found = do_search(NULL, firstc == ':' ? '/' : firstc,
+ found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
ccline.cmdbuff + skiplen, count,
search_flags, &sia);
ccline.cmdbuff[skiplen + patlen] = next_char;
@@ -581,13 +586,15 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
FUNC_ATTR_NONNULL_ALL
{
int skiplen, patlen;
+ int search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
// Add a character from under the cursor for 'incsearch'
- if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ if (!do_incsearch_highlighting(firstc, &search_delim, s, &skiplen,
+ &patlen)) {
restore_last_search_pattern();
return FAIL;
}
@@ -604,7 +611,7 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
&& !pat_has_uppercase(ccline.cmdbuff + skiplen)) {
*c = mb_tolower(*c);
}
- if (*c == firstc
+ if (*c == search_delim
|| vim_strchr((char_u *)(p_magic ? "\\~^$.*[" : "\\^$"), *c)
!= NULL) {
// put a backslash before special characters
@@ -1465,13 +1472,14 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
bool next_match)
FUNC_ATTR_NONNULL_ALL
{
- int skiplen, patlen;
+ int skiplen, patlen, search_delim;
// Parsing range may already set the last search pattern.
// NOTE: must call restore_last_search_pattern() before returning!
save_last_search_pattern();
- if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ if (!do_incsearch_highlighting(firstc, &search_delim, s, &skiplen,
+ &patlen)) {
restore_last_search_pattern();
return OK;
}
@@ -1489,7 +1497,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
char_u save;
- if (firstc == ccline.cmdbuff[skiplen]) {
+ if (search_delim == ccline.cmdbuff[skiplen]) {
pat = last_search_pattern();
skiplen = 0;
patlen = (int)STRLEN(pat);
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 3587b12277..3b40689f3e 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -5459,7 +5459,7 @@ static int normal_search(
curwin->w_set_curswant = true;
memset(&sia, 0, sizeof(sia));
- i = do_search(cap->oap, dir, pat, cap->count1,
+ i = do_search(cap->oap, dir, dir, pat, cap->count1,
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia);
if (wrapped != NULL) {
*wrapped = sia.sa_wrapped;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 612ecca96a..4c43521f4d 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -7607,7 +7607,9 @@ int win_signcol_count(win_T *wp)
}
}
- return MAX(minimum, MIN(maximum, needed_signcols));
+ int ret = MAX(minimum, MIN(maximum, needed_signcols));
+ assert(ret <= SIGN_SHOW_MAX);
+ return ret;
}
/// Get window or buffer local options
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 0785fa703d..464d72eccb 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -2798,7 +2798,7 @@ static void qf_jump_goto_line(linenr_T qf_lnum, int qf_col, char_u qf_viscol,
// Move the cursor to the first line in the buffer
pos_T save_cursor = curwin->w_cursor;
curwin->w_cursor.lnum = 0;
- if (!do_search(NULL, '/', qf_pattern, (long)1, SEARCH_KEEP, NULL)) {
+ if (!do_search(NULL, '/', '/', qf_pattern, (long)1, SEARCH_KEEP, NULL)) {
curwin->w_cursor = save_cursor;
}
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 0042d8a2a4..db033ee1ed 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -2084,6 +2084,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
colnr_T trailcol = MAXCOL; // start of trailing spaces
colnr_T leadcol = 0; // start of leading spaces
bool need_showbreak = false; // overlong line, skip first x chars
+ sign_attrs_T sattrs[SIGN_SHOW_MAX]; // attributes for signs
+ int num_signs; // number of signs for line
int line_attr = 0; // attribute for the whole line
int line_attr_lowprio = 0; // low-priority attribute for the line
matchitem_T *cur; // points to the match list
@@ -2375,11 +2377,14 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
wp->w_last_cursorline = wp->w_cursor.lnum;
}
+ memset(sattrs, 0, sizeof(sattrs));
+ num_signs = buf_get_signattrs(wp->w_buffer, lnum, sattrs);
+
// If this line has a sign with line highlighting set line_attr.
// TODO(bfredl, vigoux): this should not take priority over decoration!
- v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL, 0, 1);
- if (v != 0) {
- line_attr = sign_get_attr((int)v, SIGN_LINEHL);
+ sign_attrs_T * sattr = sign_get_attr(SIGN_LINEHL, sattrs, 0, 1);
+ if (sattr != NULL) {
+ line_attr = sattr->linehl;
}
// Highlight the current line in the quickfix window.
@@ -2696,7 +2701,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
int count = win_signcol_count(wp);
if (count > 0) {
get_sign_display_info(
- false, wp, lnum, row,
+ false, wp, sattrs, row,
startrow, filler_lines, filler_todo, count,
&c_extra, &c_final, extra, sizeof(extra),
&p_extra, &n_extra,
@@ -2715,10 +2720,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
// in 'lnum', then display the sign instead of the line
// number.
if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u'
- && buf_findsign_id(wp->w_buffer, lnum, (char_u *)"*") != 0) {
+ && num_signs > 0) {
int count = win_signcol_count(wp);
get_sign_display_info(
- true, wp, lnum, row,
+ true, wp, sattrs, row,
startrow, filler_lines, filler_todo, count,
&c_extra, &c_final, extra, sizeof(extra),
&p_extra, &n_extra,
@@ -2768,11 +2773,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
n_extra = number_width(wp) + 1;
char_attr = win_hl_attr(wp, HLF_N);
- int num_sign = buf_getsigntype(
- wp->w_buffer, lnum, SIGN_NUMHL, 0, 1);
- if (num_sign != 0) {
+ sign_attrs_T *num_sattr = sign_get_attr(SIGN_NUMHL, sattrs, 0, 1);
+ if (num_sattr != NULL) {
// :sign defined with "numhl" highlight.
- char_attr = sign_get_attr(num_sign, SIGN_NUMHL);
+ char_attr = num_sattr->numhl;
} else if ((wp->w_p_cul || wp->w_p_rnu)
&& lnum == wp->w_cursor.lnum
&& filler_todo == 0) {
@@ -4451,7 +4455,7 @@ void screen_adjust_grid(ScreenGrid **grid, int *row_off, int *col_off)
static void get_sign_display_info(
bool nrcol,
win_T *wp,
- linenr_T lnum,
+ sign_attrs_T sattrs[],
int row,
int startrow,
int filler_lines,
@@ -4468,8 +4472,6 @@ static void get_sign_display_info(
int *sign_idxp
)
{
- int text_sign;
-
// Draw cells with the sign value or blank.
*c_extrap = ' ';
*c_finalp = NUL;
@@ -4481,10 +4483,9 @@ static void get_sign_display_info(
}
if (row == startrow + filler_lines && filler_todo <= 0) {
- text_sign = buf_getsigntype(wp->w_buffer, lnum, SIGN_TEXT,
- *sign_idxp, count);
- if (text_sign != 0) {
- *pp_extra = sign_get_text(text_sign);
+ sign_attrs_T *sattr = sign_get_attr(SIGN_TEXT, sattrs, *sign_idxp, count);
+ if (sattr != NULL) {
+ *pp_extra = sattr->text;
if (*pp_extra != NULL) {
*c_extrap = NUL;
*c_finalp = NUL;
@@ -4517,7 +4518,7 @@ static void get_sign_display_info(
(*pp_extra)[*n_extrap] = NUL;
}
}
- *char_attrp = sign_get_attr(text_sign, SIGN_TEXT);
+ *char_attrp = sattr->texthl;
}
}
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 9d3d3061e4..c4479a077e 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1021,8 +1021,9 @@ static int first_submatch(regmmatch_T *rp)
* Return 0 for failure, 1 for found, 2 for found and line offset added.
*/
int do_search(
- oparg_T *oap, /* can be NULL */
- int dirc, /* '/' or '?' */
+ oparg_T *oap, // can be NULL
+ int dirc, // '/' or '?'
+ int search_delim, // delimiter for search, e.g. '%' in s%regex%replacement
char_u *pat,
long count,
int options,
@@ -1101,8 +1102,8 @@ int do_search(
searchstr = pat;
dircp = NULL;
- /* use previous pattern */
- if (pat == NULL || *pat == NUL || *pat == dirc) {
+ // use previous pattern
+ if (pat == NULL || *pat == NUL || *pat == search_delim) {
if (spats[RE_SEARCH].pat == NULL) { // no previous pattern
searchstr = spats[RE_SUBST].pat;
if (searchstr == NULL) {
@@ -1122,15 +1123,15 @@ int do_search(
* If there is a matching '/' or '?', toss it.
*/
ps = strcopy;
- p = skip_regexp(pat, dirc, p_magic, &strcopy);
+ p = skip_regexp(pat, search_delim, p_magic, &strcopy);
if (strcopy != ps) {
/* made a copy of "pat" to change "\?" to "?" */
searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy));
pat = strcopy;
searchstr = strcopy;
}
- if (*p == dirc) {
- dircp = p; /* remember where we put the NUL */
+ if (*p == search_delim) {
+ dircp = p; // remember where we put the NUL
*p++ = NUL;
}
spats[0].off.line = FALSE;
@@ -1320,7 +1321,7 @@ int do_search(
RE_LAST, sia);
if (dircp != NULL) {
- *dircp = dirc; // restore second '/' or '?' for normal_cmd()
+ *dircp = search_delim; // restore second '/' or '?' for normal_cmd()
}
if (!shortmess(SHM_SEARCH)
@@ -1400,6 +1401,7 @@ int do_search(
}
dirc = *++pat;
+ search_delim = dirc;
if (dirc != '?' && dirc != '/') {
retval = 0;
EMSG(_("E386: Expected '?' or '/' after ';'"));
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index fc9f53c192..cb4fee50b9 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -398,7 +398,8 @@ linenr_T buf_change_sign_type(
buf_T *buf, // buffer to store sign in
int markId, // sign ID
const char_u *group, // sign group
- int typenr // typenr of sign we are adding
+ int typenr, // typenr of sign we are adding
+ int prio // sign priority
)
{
signlist_T *sign; // a sign in the signlist
@@ -406,6 +407,8 @@ linenr_T buf_change_sign_type(
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
if (sign->id == markId && sign_in_group(sign, group)) {
sign->typenr = typenr;
+ sign->priority = prio;
+ sign_sort_by_prio_on_line(buf, sign);
return sign->lnum;
}
}
@@ -413,54 +416,101 @@ linenr_T buf_change_sign_type(
return (linenr_T)0;
}
-/// Gets a sign from a given line.
-///
-/// Return the type number of the sign at line number 'lnum' in buffer 'buf'
-/// which has the attribute specified by 'type'. Returns 0 if a sign is not
-/// found at the line number or it doesn't have the specified attribute.
-/// @param buf Buffer in which to search
-/// @param lnum Line in which to search
+/// Return the sign attrs which has the attribute specified by 'type'. Returns
+/// NULL if a sign is not found with the specified attribute.
/// @param type Type of sign to look for
+/// @param sattrs Sign attrs to search through
/// @param idx if there multiple signs, this index will pick the n-th
-// out of the most `max_signs` sorted ascending by Id.
+/// out of the most `max_signs` sorted ascending by Id.
/// @param max_signs the number of signs, with priority for the ones
-// with the highest Ids.
-/// @return Identifier of the matching sign, or 0
-int buf_getsigntype(buf_T *buf, linenr_T lnum, SignType type,
- int idx, int max_signs)
+/// with the highest Ids.
+/// @return Attrs of the matching sign, or NULL
+sign_attrs_T * sign_get_attr(SignType type, sign_attrs_T sattrs[],
+ int idx, int max_signs)
{
- signlist_T *sign; // a sign in a b_signlist
- signlist_T *matches[9];
+ sign_attrs_T *matches[SIGN_SHOW_MAX];
int nr_matches = 0;
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->lnum == lnum
- && (type == SIGN_ANY
- || (type == SIGN_TEXT
- && sign_get_text(sign->typenr) != NULL)
- || (type == SIGN_LINEHL
- && sign_get_attr(sign->typenr, SIGN_LINEHL) != 0)
- || (type == SIGN_NUMHL
- && sign_get_attr(sign->typenr, SIGN_NUMHL) != 0))) {
- matches[nr_matches] = sign;
+ for (int i = 0; i < SIGN_SHOW_MAX; i++) {
+ if ( (type == SIGN_TEXT && sattrs[i].text != NULL)
+ || (type == SIGN_LINEHL && sattrs[i].linehl != 0)
+ || (type == SIGN_NUMHL && sattrs[i].numhl != 0)) {
+ matches[nr_matches] = &sattrs[i];
nr_matches++;
- // signlist is sorted with most important (priority, id), thus we
+ // attr list is sorted with most important (priority, id), thus we
// may stop as soon as we have max_signs matches
- if (nr_matches == ARRAY_SIZE(matches) || nr_matches >= max_signs) {
+ if (nr_matches >= max_signs) {
break;
}
}
}
- if (nr_matches > 0) {
- if (idx >= nr_matches) {
- return 0;
- }
+ if (nr_matches > idx) {
+ return matches[nr_matches - idx - 1];
+ }
+
+ return NULL;
+}
+
+/// Lookup a sign by typenr. Returns NULL if sign is not found.
+static sign_T * find_sign_by_typenr(int typenr)
+{
+ sign_T *sp;
- return matches[nr_matches - idx -1]->typenr;
+ for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
+ if (sp->sn_typenr == typenr) {
+ return sp;
+ }
}
+ return NULL;
+}
- return 0;
+/// Return the attributes of all the signs placed on line 'lnum' in buffer
+/// 'buf'. Used when refreshing the screen. Returns the number of signs.
+/// @param buf Buffer in which to search
+/// @param lnum Line in which to search
+/// @param sattrs Output array for attrs
+/// @return Number of signs of which attrs were found
+int buf_get_signattrs(buf_T *buf, linenr_T lnum, sign_attrs_T sattrs[])
+{
+ signlist_T *sign;
+ sign_T *sp;
+
+ int nr_matches = 0;
+
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->lnum > lnum) {
+ // Signs are sorted by line number in the buffer. No need to check
+ // for signs after the specified line number 'lnum'.
+ break;
+ }
+
+ if (sign->lnum == lnum) {
+ sign_attrs_T sattr;
+ memset(&sattr, 0, sizeof(sattr));
+ sattr.typenr = sign->typenr;
+ sp = find_sign_by_typenr(sign->typenr);
+ if (sp != NULL) {
+ sattr.text = sp->sn_text;
+ if (sattr.text != NULL && sp->sn_text_hl != 0) {
+ sattr.texthl = syn_id2attr(sp->sn_text_hl);
+ }
+ if (sp->sn_line_hl != 0) {
+ sattr.linehl = syn_id2attr(sp->sn_line_hl);
+ }
+ if (sp->sn_num_hl != 0) {
+ sattr.numhl = syn_id2attr(sp->sn_num_hl);
+ }
+ }
+
+ sattrs[nr_matches] = sattr;
+ nr_matches++;
+ if (nr_matches == SIGN_SHOW_MAX) {
+ break;
+ }
+ }
+ }
+ return nr_matches;
}
/// Delete sign 'id' in group 'group' from buffer 'buf'.
@@ -557,6 +607,12 @@ static signlist_T * buf_getsign_at_line(
signlist_T *sign; // a sign in the signlist
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->lnum > lnum) {
+ // Signs are sorted by line number in the buffer. No need to check
+ // for signs after the specified line number 'lnum'.
+ break;
+ }
+
if (sign->lnum == lnum && sign_in_group(sign, groupname)) {
return sign;
}
@@ -973,8 +1029,8 @@ int sign_place(
sp->sn_typenr,
has_text_or_icon);
} else {
- // ":sign place {id} file={fname}": change sign type
- lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr);
+ // ":sign place {id} file={fname}": change sign type and/or priority
+ lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr, prio);
}
if (lnum > 0) {
redraw_buf_line_later(buf, lnum);
@@ -1613,50 +1669,6 @@ static void sign_undefine(sign_T *sp, sign_T *sp_prev)
xfree(sp);
}
-/// 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) {
- if (sp->sn_typenr == typenr) {
- 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;
-}
-
-/// Get text mark for sign "typenr".
-/// Returns NULL if there isn't one.
-char_u * sign_get_text(int typenr)
-{
- sign_T *sp;
-
- for (sp = first_sign; sp != NULL; sp = sp->sn_next) {
- if (sp->sn_typenr == typenr) {
- return sp->sn_text;
- }
- }
- return NULL;
-}
-
/// Undefine/free all signs.
void free_signs(void)
{
@@ -1860,3 +1872,267 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
}
}
+/// Define a sign using the attributes in 'dict'. Returns 0 on success and -1 on
+/// failure.
+int sign_define_from_dict(const char *name_arg, dict_T *dict)
+{
+ char *name = NULL;
+ char *icon = NULL;
+ char *linehl = NULL;
+ char *text = NULL;
+ char *texthl = NULL;
+ char *numhl = NULL;
+ int retval = -1;
+
+ if (name_arg == NULL) {
+ if (dict == NULL) {
+ return -1;
+ }
+ name = tv_dict_get_string(dict, "name", true);
+ } else {
+ name = xstrdup(name_arg);
+ }
+ if (name == NULL || name[0] == NUL) {
+ goto cleanup;
+ }
+ if (dict != NULL) {
+ icon = tv_dict_get_string(dict, "icon" , true);
+ linehl = tv_dict_get_string(dict, "linehl", true);
+ text = tv_dict_get_string(dict, "text" , true);
+ texthl = tv_dict_get_string(dict, "texthl", true);
+ numhl = tv_dict_get_string(dict, "numhl" , true);
+ }
+
+ if (sign_define_by_name((char_u *)name, (char_u *)icon, (char_u *)linehl,
+ (char_u *)text, (char_u *)texthl, (char_u *)numhl)
+ == OK) {
+ retval = 0;
+ }
+
+cleanup:
+ xfree(name);
+ xfree(icon);
+ xfree(linehl);
+ xfree(text);
+ xfree(texthl);
+ xfree(numhl);
+
+ return retval;
+}
+
+/// Define multiple signs using attributes from list 'l' and store the return
+/// values in 'retlist'.
+void sign_define_multiple(list_T *l, list_T *retlist)
+{
+ int retval;
+
+ TV_LIST_ITER_CONST(l, li, {
+ retval = -1;
+ if (TV_LIST_ITEM_TV(li)->v_type == VAR_DICT) {
+ retval = sign_define_from_dict(NULL, TV_LIST_ITEM_TV(li)->vval.v_dict);
+ } else {
+ EMSG(_(e_dictreq));
+ }
+ tv_list_append_number(retlist, retval);
+ });
+}
+
+/// Place a new sign using the values specified in dict 'dict'. Returns the sign
+/// identifier if successfully placed, otherwise returns 0.
+int sign_place_from_dict(
+ typval_T *id_tv,
+ typval_T *group_tv,
+ typval_T *name_tv,
+ typval_T *buf_tv,
+ dict_T *dict)
+{
+ int sign_id = 0;
+ char_u *group = NULL;
+ char_u *sign_name = NULL;
+ buf_T *buf = NULL;
+ dictitem_T *di;
+ linenr_T lnum = 0;
+ int prio = SIGN_DEF_PRIO;
+ bool notanum = false;
+ int ret_sign_id = -1;
+
+ // sign identifier
+ if (id_tv == NULL) {
+ di = tv_dict_find(dict, "id", -1);
+ if (di != NULL) {
+ id_tv = &di->di_tv;
+ }
+ }
+ if (id_tv == NULL) {
+ sign_id = 0;
+ } else {
+ sign_id = (int)tv_get_number_chk(id_tv, &notanum);
+ if (notanum) {
+ return -1;
+ }
+ if (sign_id < 0) {
+ EMSG(_(e_invarg));
+ return -1;
+ }
+ }
+
+ // sign group
+ if (group_tv == NULL) {
+ di = tv_dict_find(dict, "group", -1);
+ if (di != NULL) {
+ group_tv = &di->di_tv;
+ }
+ }
+ if (group_tv == NULL) {
+ group = NULL; // global group
+ } else {
+ group = (char_u *)tv_get_string_chk(group_tv);
+ if (group == NULL) {
+ goto cleanup;
+ }
+ if (group[0] == '\0') { // global sign group
+ group = NULL;
+ } else {
+ group = vim_strsave(group);
+ if (group == NULL) {
+ return -1;
+ }
+ }
+ }
+
+ // sign name
+ if (name_tv == NULL) {
+ di = tv_dict_find(dict, "name", -1);
+ if (di != NULL) {
+ name_tv = &di->di_tv;
+ }
+ }
+ if (name_tv == NULL) {
+ goto cleanup;
+ }
+ sign_name = (char_u *)tv_get_string_chk(name_tv);
+ if (sign_name == NULL) {
+ goto cleanup;
+ }
+
+ // buffer to place the sign
+ if (buf_tv == NULL) {
+ di = tv_dict_find(dict, "buffer", -1);
+ if (di != NULL) {
+ buf_tv = &di->di_tv;
+ }
+ }
+ if (buf_tv == NULL) {
+ goto cleanup;
+ }
+ buf = get_buf_arg(buf_tv);
+ if (buf == NULL) {
+ goto cleanup;
+ }
+
+ // line number of the sign
+ di = tv_dict_find(dict, "lnum", -1);
+ if (di != NULL) {
+ lnum = tv_get_lnum(&di->di_tv);
+ if (lnum <= 0) {
+ EMSG(_(e_invarg));
+ goto cleanup;
+ }
+ }
+
+ // sign priority
+ di = tv_dict_find(dict, "priority", -1);
+ if (di != NULL) {
+ prio = (int)tv_get_number_chk(&di->di_tv, &notanum);
+ if (notanum) {
+ goto cleanup;
+ }
+ }
+
+ if (sign_place(&sign_id, group, sign_name, buf, lnum, prio) == OK) {
+ ret_sign_id = sign_id;
+ }
+
+cleanup:
+ xfree(group);
+
+ return ret_sign_id;
+}
+
+/// Undefine multiple signs
+void sign_undefine_multiple(list_T *l, list_T *retlist)
+{
+ char_u *name;
+ int retval;
+
+ TV_LIST_ITER_CONST(l, li, {
+ retval = -1;
+ name = (char_u *)tv_get_string_chk(TV_LIST_ITEM_TV(li));
+ if (name != NULL && (sign_undefine_by_name(name) == OK)) {
+ retval = 0;
+ }
+ tv_list_append_number(retlist, retval);
+ });
+}
+
+/// Unplace the sign with attributes specified in 'dict'. Returns 0 on success
+/// and -1 on failure.
+int sign_unplace_from_dict(typval_T *group_tv, dict_T *dict)
+{
+ dictitem_T *di;
+ int sign_id = 0;
+ buf_T *buf = NULL;
+ char_u *group = NULL;
+ int retval = -1;
+
+ // sign group
+ if (group_tv != NULL) {
+ group = (char_u *)tv_get_string(group_tv);
+ } else {
+ group = (char_u *)tv_dict_get_string(dict, "group", false);
+ }
+ if (group != NULL) {
+ if (group[0] == '\0') { // global sign group
+ group = NULL;
+ } else {
+ group = vim_strsave(group);
+ if (group == NULL) {
+ return -1;
+ }
+ }
+ }
+
+ if (dict != NULL) {
+ if ((di = tv_dict_find(dict, "buffer", -1)) != NULL) {
+ buf = get_buf_arg(&di->di_tv);
+ if (buf == NULL) {
+ goto cleanup;
+ }
+ }
+ if (tv_dict_find(dict, "id", -1) != NULL) {
+ sign_id = (int)tv_dict_get_number(dict, "id");
+ if (sign_id <= 0) {
+ EMSG(_(e_invarg));
+ goto cleanup;
+ }
+ }
+ }
+
+ if (buf == NULL) {
+ // Delete the sign in all the buffers
+ retval = 0;
+ FOR_ALL_BUFFERS(buf2) {
+ if (sign_unplace(sign_id, group, buf2, 0) != OK) {
+ retval = -1;
+ }
+ }
+ } else if (sign_unplace(sign_id, group, buf, 0) == OK) {
+ retval = 0;
+ }
+
+cleanup:
+ xfree(group);
+
+ return retval;
+}
+
diff --git a/src/nvim/sign_defs.h b/src/nvim/sign_defs.h
index 19c0263cf1..724e1cf499 100644
--- a/src/nvim/sign_defs.h
+++ b/src/nvim/sign_defs.h
@@ -33,16 +33,25 @@ struct signlist
signlist_T *prev; // previous entry -- for easy reordering
};
+/// Sign attributes. Used by the screen refresh routines.
+typedef struct sign_attrs_S {
+ int typenr;
+ char_u *text;
+ int texthl;
+ int linehl;
+ int numhl;
+} sign_attrs_T;
+
+#define SIGN_SHOW_MAX 9
+
// Default sign priority for highlighting
#define SIGN_DEF_PRIO 10
-// type argument for buf_getsigntype() and sign_get_attr()
+// type argument for sign_get_attr()
typedef enum {
- SIGN_ANY,
SIGN_LINEHL,
- SIGN_ICON,
- SIGN_TEXT,
SIGN_NUMHL,
+ SIGN_TEXT,
} SignType;
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 55f9594de2..f6dc3a04a7 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -3035,7 +3035,7 @@ void ex_spellrepall(exarg_T *eap)
sub_nlines = 0;
curwin->w_cursor.lnum = 0;
while (!got_int) {
- if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
+ if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
|| u_save_cursor() == FAIL) {
break;
}
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 6b8f393572..588821f260 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -2811,7 +2811,7 @@ static int jumpto_tag(
// start search before first line
curwin->w_cursor.lnum = 0;
}
- if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
+ if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
search_options, NULL)) {
retval = OK;
} else {
@@ -2821,8 +2821,8 @@ static int jumpto_tag(
/*
* try again, ignore case now
*/
- p_ic = TRUE;
- if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1,
+ p_ic = true;
+ if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
search_options, NULL)) {
// Failed to find pattern, take a guess: "^func ("
found = 2;
@@ -2830,11 +2830,12 @@ static int jumpto_tag(
cc = *tagp.tagname_end;
*tagp.tagname_end = NUL;
snprintf((char *)pbuf, LSIZE, "^%s\\s\\*(", tagp.tagname);
- if (!do_search(NULL, '/', pbuf, (long)1, search_options, NULL)) {
+ if (!do_search(NULL, '/', '/', pbuf, (long)1, search_options, NULL)) {
// Guess again: "^char * \<func ("
snprintf((char *)pbuf, LSIZE, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
tagp.tagname);
- if (!do_search(NULL, '/', pbuf, (long)1, search_options, NULL)) {
+ if (!do_search(NULL, '/', '/', pbuf, (long)1,
+ search_options, NULL)) {
found = 0;
}
}
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index d4d529e4b9..7aa01c61ca 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -723,6 +723,30 @@ func Test_incsearch_substitute_dump()
call delete('Xis_subst_script')
endfunc
+func Test_incsearch_highlighting()
+ if !exists('+incsearch')
+ return
+ endif
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+
+ call writefile([
+ \ 'set incsearch hlsearch',
+ \ 'call setline(1, "hello/there")',
+ \ ], 'Xis_subst_hl_script')
+ let buf = RunVimInTerminal('-S Xis_subst_hl_script', {'rows': 4, 'cols': 20})
+ " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
+ " the 'ambiwidth' check.
+ sleep 300m
+
+ " Using a different search delimiter should still highlight matches
+ " that contain a '/'.
+ call term_sendkeys(buf, ":%s;ello/the")
+ call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {})
+ call term_sendkeys(buf, "<Esc>")
+endfunc
+
" Similar to Test_incsearch_substitute_dump() for :sort
func Test_incsearch_sort_dump()
if !exists('+incsearch')
diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim
index 9c3a5636ce..f6b96c1e5d 100644
--- a/src/nvim/testdir/test_signs.vim
+++ b/src/nvim/testdir/test_signs.vim
@@ -134,7 +134,7 @@ func Test_sign()
sign define Sign5 text=X\ linehl=Comment
sign undefine Sign5
- sign define Sign5 linehl=Comment text=X\
+ sign define Sign5 linehl=Comment text=X\
sign undefine Sign5
" define sign with backslash
@@ -415,7 +415,7 @@ func Test_sign_funcs()
" Tests for invalid arguments to sign_define()
call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:')
" call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:')
- call assert_fails('call sign_define([])', 'E730:')
+ call assert_fails('call sign_define({})', 'E731:')
call assert_fails('call sign_define("sign6", [])', 'E715:')
" Tests for sign_getdefined()
@@ -444,7 +444,7 @@ func Test_sign_funcs()
call assert_fails('call sign_place([], "", "mySign", 1)', 'E745:')
call assert_fails('call sign_place(5, "", "mySign", -1)', 'E158:')
call assert_fails('call sign_place(-1, "", "sign1", "Xsign", [])',
- \ 'E474:')
+ \ 'E715:')
call assert_fails('call sign_place(-1, "", "sign1", "Xsign",
\ {"lnum" : 30})', 'E474:')
call assert_fails('call sign_place(10, "", "xsign1x", "Xsign",
@@ -460,11 +460,11 @@ func Test_sign_funcs()
call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})',
\ 'E158:')
call assert_fails('call sign_place(21, "", "sign1", "Xsign",
- \ {"lnum" : -1})', 'E885:')
+ \ {"lnum" : -1})', 'E474:')
call assert_fails('call sign_place(22, "", "sign1", "Xsign",
- \ {"lnum" : 0})', 'E885:')
+ \ {"lnum" : 0})', 'E474:')
call assert_fails('call sign_place(22, "", "sign1", "Xsign",
- \ {"lnum" : []})', 'E745:')
+ \ {"lnum" : []})', 'E474:')
call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10}))
" Tests for sign_getplaced()
@@ -504,11 +504,21 @@ func Test_sign_funcs()
\ {'id' : 20, 'buffer' : 200})", 'E158:')
call assert_fails("call sign_unplace('g1', 'mySign')", 'E715:')
+ call sign_unplace('*')
+
+ " Test for modifying a placed sign
+ call assert_equal(15, sign_place(15, '', 'sign1', 'Xsign', {'lnum' : 20}))
+ call assert_equal(15, sign_place(15, '', 'sign2', 'Xsign'))
+ call assert_equal([{'bufnr' : bufnr(''), 'signs' :
+ \ [{'id' : 15, 'group' : '', 'lnum' : 20, 'name' : 'sign2',
+ \ 'priority' : 10}]}],
+ \ sign_getplaced())
+
" Tests for sign_undefine()
call assert_equal(0, sign_undefine("sign1"))
call assert_equal([], sign_getdefined("sign1"))
call assert_fails('call sign_undefine("none")', 'E155:')
- call assert_fails('call sign_undefine([])', 'E730:')
+ call assert_fails('call sign_undefine({})', 'E731:')
" Test for using '.' as the line number for sign_place()
call Sign_define_ignore_error("sign1", attr)
@@ -644,7 +654,7 @@ func Test_sign_group()
call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs)
" Error case
- call assert_fails("call sign_unplace([])", 'E474:')
+ call assert_fails("call sign_unplace({})", 'E474:')
" Place a sign in the global group and try to delete it using a group
call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10}))
@@ -1131,7 +1141,7 @@ func Test_sign_unplace()
endfunc
" Tests for auto-generating the sign identifier
-func Test_sign_id_autogen()
+func Test_aaa_sign_id_autogen()
enew | only
call sign_unplace('*')
call sign_undefine()
@@ -1868,3 +1878,121 @@ func Test_sign_numcol()
set number&
enew! | close
endfunc
+
+" Test for managing multiple signs using the sign functions
+func Test_sign_funcs_multi()
+ call writefile(repeat(["Sun is shining"], 30), "Xsign")
+ edit Xsign
+ let bnum = bufnr('')
+
+ " Define multiple signs at once
+ call assert_equal([0, 0, 0, 0], sign_define([
+ \ {'name' : 'sign1', 'text' : '=>', 'linehl' : 'Search',
+ \ 'texthl' : 'Search'},
+ \ {'name' : 'sign2', 'text' : '=>', 'linehl' : 'Search',
+ \ 'texthl' : 'Search'},
+ \ {'name' : 'sign3', 'text' : '=>', 'linehl' : 'Search',
+ \ 'texthl' : 'Search'},
+ \ {'name' : 'sign4', 'text' : '=>', 'linehl' : 'Search',
+ \ 'texthl' : 'Search'}]))
+
+ " Negative cases for sign_define()
+ call assert_equal([], sign_define([]))
+ call assert_equal([-1], sign_define([{}]))
+ call assert_fails('call sign_define([6])', 'E715:')
+ call assert_fails('call sign_define(["abc"])', 'E715:')
+ call assert_fails('call sign_define([[]])', 'E715:')
+
+ " Place multiple signs at once with specific sign identifier
+ let l = sign_placelist([{'id' : 1, 'group' : 'g1', 'name' : 'sign1',
+ \ 'buffer' : 'Xsign', 'lnum' : 11, 'priority' : 50},
+ \ {'id' : 2, 'group' : 'g2', 'name' : 'sign2',
+ \ 'buffer' : 'Xsign', 'lnum' : 11, 'priority' : 100},
+ \ {'id' : 3, 'group' : '', 'name' : 'sign3',
+ \ 'buffer' : 'Xsign', 'lnum' : 11}])
+ call assert_equal([1, 2, 3], l)
+ let s = sign_getplaced('Xsign', {'group' : '*'})
+ call assert_equal([
+ \ {'id' : 2, 'name' : 'sign2', 'lnum' : 11,
+ \ 'group' : 'g2', 'priority' : 100},
+ \ {'id' : 1, 'name' : 'sign1', 'lnum' : 11,
+ \ 'group' : 'g1', 'priority' : 50},
+ \ {'id' : 3, 'name' : 'sign3', 'lnum' : 11,
+ \ 'group' : '', 'priority' : 10}], s[0].signs)
+
+ call sign_unplace('*')
+
+ " Place multiple signs at once with auto-generated sign identifier
+ call assert_equal([1, 1, 5], sign_placelist([
+ \ {'group' : 'g1', 'name' : 'sign1',
+ \ 'buffer' : 'Xsign', 'lnum' : 11},
+ \ {'group' : 'g2', 'name' : 'sign2',
+ \ 'buffer' : 'Xsign', 'lnum' : 11},
+ \ {'group' : '', 'name' : 'sign3',
+ \ 'buffer' : 'Xsign', 'lnum' : 11}]))
+ let s = sign_getplaced('Xsign', {'group' : '*'})
+ call assert_equal([
+ \ {'id' : 5, 'name' : 'sign3', 'lnum' : 11,
+ \ 'group' : '', 'priority' : 10},
+ \ {'id' : 1, 'name' : 'sign2', 'lnum' : 11,
+ \ 'group' : 'g2', 'priority' : 10},
+ \ {'id' : 1, 'name' : 'sign1', 'lnum' : 11,
+ \ 'group' : 'g1', 'priority' : 10}], s[0].signs)
+
+ " Change an existing sign without specifying the group
+ call assert_equal([5], sign_placelist([
+ \ {'id' : 5, 'name' : 'sign1', 'buffer' : 'Xsign'}]))
+ let s = sign_getplaced('Xsign', {'id' : 5, 'group' : ''})
+ call assert_equal([{'id' : 5, 'name' : 'sign1', 'lnum' : 11,
+ \ 'group' : '', 'priority' : 10}], s[0].signs)
+
+ " Place a sign using '.' as the line number
+ call cursor(23, 1)
+ call assert_equal([7], sign_placelist([
+ \ {'id' : 7, 'name' : 'sign1', 'buffer' : '%', 'lnum' : '.'}]))
+ let s = sign_getplaced('%', {'lnum' : '.'})
+ call assert_equal([{'id' : 7, 'name' : 'sign1', 'lnum' : 23,
+ \ 'group' : '', 'priority' : 10}], s[0].signs)
+
+ " Place sign without a sign name
+ call assert_equal([-1], sign_placelist([{'id' : 10, 'buffer' : 'Xsign',
+ \ 'lnum' : 12, 'group' : ''}]))
+
+ " Place sign without a buffer
+ call assert_equal([-1], sign_placelist([{'id' : 10, 'name' : 'sign1',
+ \ 'lnum' : 12, 'group' : ''}]))
+
+ " Invalid arguments
+ call assert_equal([], sign_placelist([]))
+ call assert_fails('call sign_placelist({})', "E714:")
+ call assert_fails('call sign_placelist([[]])', "E715:")
+ call assert_fails('call sign_placelist(["abc"])', "E715:")
+ call assert_fails('call sign_placelist([100])', "E715:")
+
+ " Unplace multiple signs
+ call assert_equal([0, 0, 0], sign_unplacelist([{'id' : 5},
+ \ {'id' : 1, 'group' : 'g1'}, {'id' : 1, 'group' : 'g2'}]))
+
+ " Invalid arguments
+ call assert_equal([], sign_unplacelist([]))
+ call assert_fails('call sign_unplacelist({})', "E714:")
+ call assert_fails('call sign_unplacelist([[]])', "E715:")
+ call assert_fails('call sign_unplacelist(["abc"])', "E715:")
+ call assert_fails('call sign_unplacelist([100])', "E715:")
+ call assert_fails("call sign_unplacelist([{'id' : -1}])", 'E474')
+
+ call assert_equal([0, 0, 0, 0],
+ \ sign_undefine(['sign1', 'sign2', 'sign3', 'sign4']))
+ call assert_equal([], sign_getdefined())
+
+ " Invalid arguments
+ call assert_equal([], sign_undefine([]))
+ call assert_fails('call sign_undefine([[]])', 'E730:')
+ call assert_fails('call sign_undefine([{}])', 'E731:')
+ call assert_fails('call sign_undefine(["1abc2"])', 'E155:')
+
+ call sign_unplace('*')
+ call sign_undefine()
+ enew!
+ call delete("Xsign")
+endfunc
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 6d7d9b4d8b..abca018059 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -670,7 +670,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
command("set noet")
command("set ts=4")
command("set sw=2")
- command("set sts=2")
+ command("set sts=4")
local check_events = setup_eventcheck(verify, {'asdfasdf'})
@@ -689,6 +689,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 7, 0, 0, 0, 0, 4, 4, 0, 1, 1 },
}
+
feed("<esc>u")
check_events {
{ "test1", "bytes", 1, 8, 0, 0, 0, 0, 1, 1, 0, 4, 4 },
@@ -728,6 +729,29 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 29, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
{ "test1", "bytes", 1, 31, 0, 0, 0, 0, 4, 4, 0, 1, 1 };
}
+
+ -- inserting tab after other tabs
+ command("set sw=4")
+ feed("<esc>0a<tab>")
+ check_events {
+ { "test1", "bytes", 1, 32, 0, 1, 1, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 33, 0, 2, 2, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 34, 0, 3, 3, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 35, 0, 4, 4, 0, 0, 0, 0, 1, 1 };
+ { "test1", "bytes", 1, 36, 0, 1, 1, 0, 4, 4, 0, 1, 1 };
+ }
+ end)
+
+ it("retab", function()
+ command("set noet")
+ command("set ts=4")
+
+ local check_events = setup_eventcheck(verify, {" asdf"})
+ command("retab 8")
+
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 0, 7, 7, 0, 9, 9 };
+ }
end)
it("sends events when undoing with undofile", function()
diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua
index 656f613c6a..5540b3c2dc 100644
--- a/test/functional/ui/searchhl_spec.lua
+++ b/test/functional/ui/searchhl_spec.lua
@@ -507,7 +507,21 @@ describe('search highlighting', function()
{1:~ }|
:syntax keyword MyGroup special |
]])
+ end)
+ it('highlights entire pattern on :%g@a/b', function()
+ command('set inccommand=nosplit')
+ feed('ia/b/c<Esc>')
+ feed(':%g@a/b')
+ screen:expect([[
+ {3:a/b}/c |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ :%g@a/b^ |
+ ]])
end)
end)