summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-02 13:40:31 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-02 13:40:31 +0100
commit2cbc1a02cb72916dfdbd0d307512c7c3fb766edf (patch)
tree893c5c3b2cba5127eb46c5d749d5e88d09d648d4
parent44746aa1eb506ebe6e8fc71f6e549a0dcb754526 (diff)
downloadvim-git-2cbc1a02cb72916dfdbd0d307512c7c3fb766edf.tar.gz
patch 8.1.0679: sign functions do not take buffer argument as documentedv8.1.0679
Problem: Sign functions do not take buffer argument as documented. Solution: Use get_buf_tv(). (Yegappan Lakshmanan, closes #3755)
-rw-r--r--src/evalfunc.c6
-rw-r--r--src/testdir/test_signs.vim73
-rw-r--r--src/version.c2
3 files changed, 71 insertions, 10 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 97921e7c0..a46b339cd 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -11365,7 +11365,7 @@ f_sign_getplaced(typval_T *argvars, typval_T *rettv)
if (argvars[0].v_type != VAR_UNKNOWN)
{
// get signs placed in this buffer
- buf = find_buffer(&argvars[0]);
+ buf = get_buf_tv(&argvars[0], FALSE);
if (buf == NULL)
{
EMSG2(_("E158: Invalid buffer name: %s"),
@@ -11457,7 +11457,7 @@ f_sign_place(typval_T *argvars, typval_T *rettv)
goto cleanup;
// Buffer to place the sign
- buf = find_buffer(&argvars[3]);
+ buf = get_buf_tv(&argvars[3], FALSE);
if (buf == NULL)
{
EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(&argvars[2]));
@@ -11566,7 +11566,7 @@ f_sign_unplace(typval_T *argvars, typval_T *rettv)
if ((di = dict_find(dict, (char_u *)"buffer", -1)) != NULL)
{
- buf = find_buffer(&di->di_tv);
+ buf = get_buf_tv(&di->di_tv, FALSE);
if (buf == NULL)
{
EMSG2(_("E158: Invalid buffer name: %s"),
diff --git a/src/testdir/test_signs.vim b/src/testdir/test_signs.vim
index 7663dd1a6..a9a347270 100644
--- a/src/testdir/test_signs.vim
+++ b/src/testdir/test_signs.vim
@@ -32,7 +32,7 @@ func Test_sign()
" current window if the buffer is displayed there.
let bn = bufnr('%')
let wn = winnr()
- exe 'sign place 41 line=3 name=Sign1 buffer=' . bn
+ exe 'sign place 41 line=3 name=Sign1 buffer=' . bn
1
bot split
exe 'sign jump 41 buffer=' . bufnr('%')
@@ -77,7 +77,7 @@ func Test_sign()
sign unplace
let a=execute('sign place')
call assert_equal("\n--- Signs ---\n", a)
-
+
" Try again to unplace sign on current line, it should fail this time.
call assert_fails('sign unplace', 'E159:')
@@ -386,11 +386,11 @@ func Test_sign_funcs()
call assert_equal([{'bufnr' : bufnr(''), 'signs' :
\ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1',
\ 'priority' : 10}]}],
- \ sign_getplaced('Xsign', {'lnum' : 20}))
+ \ sign_getplaced('%', {'lnum' : 20}))
call assert_equal([{'bufnr' : bufnr(''), 'signs' :
\ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1',
\ 'priority' : 10}]}],
- \ sign_getplaced('Xsign', {'id' : 10}))
+ \ sign_getplaced('', {'id' : 10}))
" Tests for invalid arguments to sign_place()
call assert_fails('call sign_place([], "", "mySign", 1)', 'E745:')
@@ -407,7 +407,7 @@ func Test_sign_funcs()
\ {"lnum" : 30})', 'E730:')
call assert_fails('call sign_place(5, "", "sign1", "abcxyz.xxx",
\ {"lnum" : 10})', 'E158:')
- call assert_fails('call sign_place(5, "", "sign1", "", {"lnum" : 10})',
+ call assert_fails('call sign_place(5, "", "sign1", "@", {"lnum" : 10})',
\ 'E158:')
call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})',
\ 'E158:')
@@ -429,7 +429,7 @@ func Test_sign_funcs()
\ 'priority' : 10}]}],
\ sign_getplaced())
call assert_fails("call sign_getplaced('dummy.sign')", 'E158:')
- call assert_fails('call sign_getplaced("")', 'E158:')
+ call assert_fails('call sign_getplaced("&")', 'E158:')
call assert_fails('call sign_getplaced(-1)', 'E158:')
call assert_fails('call sign_getplaced("Xsign", [])', 'E715:')
call assert_equal([{'bufnr' : bufnr(''), 'signs' : []}],
@@ -451,7 +451,7 @@ func Test_sign_funcs()
call assert_fails("call sign_unplace('',
\ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:')
call assert_fails("call sign_unplace('',
- \ {'id' : 20, 'buffer' : ''})", 'E158:')
+ \ {'id' : 20, 'buffer' : '&'})", 'E158:')
call assert_fails("call sign_unplace('g1',
\ {'id' : 20, 'buffer' : 200})", 'E158:')
call assert_fails("call sign_unplace('g1', 'mySign')", 'E715:')
@@ -1186,3 +1186,62 @@ func Test_sign_memfailures()
enew | only
call delete("Xsign")
endfunc
+
+" Test for auto-adjusting the line number of a placed sign.
+func Test_sign_lnum_adjust()
+ enew! | only!
+
+ sign define sign1 text=#> linehl=Comment
+ call setline(1, ['A', 'B', 'C', 'D'])
+ exe 'sign place 5 line=3 name=sign1 buffer=' . bufnr('')
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(3, l[0].signs[0].lnum)
+
+ " Add some lines before the sign and check the sign line number
+ call append(2, ['AA', 'AB', 'AC'])
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(6, l[0].signs[0].lnum)
+
+ " Delete some lines before the sign and check the sign line number
+ call deletebufline('%', 1, 2)
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(4, l[0].signs[0].lnum)
+
+ sign unplace * group=*
+ sign undefine sign1
+ enew!
+endfunc
+
+" Test for changing the type of a placed sign
+func Test_sign_change_type()
+ enew! | only!
+
+ sign define sign1 text=#> linehl=Comment
+ sign define sign2 text=@@ linehl=Comment
+
+ call setline(1, ['A', 'B', 'C', 'D'])
+ exe 'sign place 4 line=3 name=sign1 buffer=' . bufnr('')
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal('sign1', l[0].signs[0].name)
+ exe 'sign place 4 name=sign2 buffer=' . bufnr('')
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal('sign2', l[0].signs[0].name)
+ call sign_place(4, '', 'sign1', '')
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal('sign1', l[0].signs[0].name)
+
+ exe 'sign place 4 group=g1 line=4 name=sign1 buffer=' . bufnr('')
+ let l = sign_getplaced(bufnr(''), {'group' : 'g1'})
+ call assert_equal('sign1', l[0].signs[0].name)
+ exe 'sign place 4 group=g1 name=sign2 buffer=' . bufnr('')
+ let l = sign_getplaced(bufnr(''), {'group' : 'g1'})
+ call assert_equal('sign2', l[0].signs[0].name)
+ call sign_place(4, 'g1', 'sign1', '')
+ let l = sign_getplaced(bufnr(''), {'group' : 'g1'})
+ call assert_equal('sign1', l[0].signs[0].name)
+
+ sign unplace * group=*
+ sign undefine sign1
+ sign undefine sign2
+ enew!
+endfunc
diff --git a/src/version.c b/src/version.c
index fbd6110b6..2571a8c96 100644
--- a/src/version.c
+++ b/src/version.c
@@ -800,6 +800,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 679,
+/**/
678,
/**/
677,