forked from aniani/vim
patch 9.0.0837: append() reports failure when not appending anything
Problem: append() reports failure when not appending anything. Solution: Only report failure when appending something. (closes #11498)
This commit is contained in:
parent
91c75d18d9
commit
cd9c8d400c
@ -806,8 +806,10 @@ append({lnum}, {text}) *append()*
|
|||||||
{lnum} can be zero to insert a line before the first one.
|
{lnum} can be zero to insert a line before the first one.
|
||||||
{lnum} is used like with |getline()|.
|
{lnum} is used like with |getline()|.
|
||||||
Returns 1 for failure ({lnum} out of range or out of memory),
|
Returns 1 for failure ({lnum} out of range or out of memory),
|
||||||
0 for success. In |Vim9| script an invalid argument or
|
0 for success. When {text} is an empty list zero is returned,
|
||||||
negative number results in an error. Example: >
|
no matter the value of {lnum}.
|
||||||
|
In |Vim9| script an invalid argument or negative number
|
||||||
|
results in an error. Example: >
|
||||||
:let failed = append(line('$'), "# THE END")
|
:let failed = append(line('$'), "# THE END")
|
||||||
:let failed = append(0, ["Chapter 1", "the beginning"])
|
:let failed = append(0, ["Chapter 1", "the beginning"])
|
||||||
|
|
||||||
@ -835,7 +837,9 @@ appendbufline({buf}, {lnum}, {text}) *appendbufline()*
|
|||||||
If {buf} is not a valid buffer or {lnum} is not valid, an
|
If {buf} is not a valid buffer or {lnum} is not valid, an
|
||||||
error message is given. Example: >
|
error message is given. Example: >
|
||||||
:let failed = appendbufline(13, 0, "# THE START")
|
:let failed = appendbufline(13, 0, "# THE START")
|
||||||
<
|
< However, when {text} is an empty list then no error is given
|
||||||
|
for an invalid {lnum}, since {lnum} isn't actually used.
|
||||||
|
|
||||||
Can also be used as a |method| after a List, the base is
|
Can also be used as a |method| after a List, the base is
|
||||||
passed as the second argument: >
|
passed as the second argument: >
|
||||||
mylist->appendbufline(buf, lnum)
|
mylist->appendbufline(buf, lnum)
|
||||||
@ -981,7 +985,7 @@ autocmd_add({acmds}) *autocmd_add()*
|
|||||||
let acmd.bufnr = 5
|
let acmd.bufnr = 5
|
||||||
let acmd.cmd = 'call BufEnterFunc()'
|
let acmd.cmd = 'call BufEnterFunc()'
|
||||||
call autocmd_add([acmd])
|
call autocmd_add([acmd])
|
||||||
|
<
|
||||||
Can also be used as a |method|: >
|
Can also be used as a |method|: >
|
||||||
GetAutocmdList()->autocmd_add()
|
GetAutocmdList()->autocmd_add()
|
||||||
<
|
<
|
||||||
@ -7873,9 +7877,10 @@ setbufline({buf}, {lnum}, {text}) *setbufline()*
|
|||||||
To insert lines use |appendbufline()|.
|
To insert lines use |appendbufline()|.
|
||||||
Any text properties in {lnum} are cleared.
|
Any text properties in {lnum} are cleared.
|
||||||
|
|
||||||
{text} can be a string to set one line, or a list of strings
|
{text} can be a string to set one line, or a List of strings
|
||||||
to set multiple lines. If the list extends below the last
|
to set multiple lines. If the List extends below the last
|
||||||
line then those lines are added.
|
line then those lines are added. If the List is empty then
|
||||||
|
nothing is changed and zero is returned.
|
||||||
|
|
||||||
For the use of {buf}, see |bufname()| above.
|
For the use of {buf}, see |bufname()| above.
|
||||||
|
|
||||||
@ -8060,7 +8065,8 @@ setline({lnum}, {text}) *setline()*
|
|||||||
When {lnum} is just below the last line the {text} will be
|
When {lnum} is just below the last line the {text} will be
|
||||||
added below the last line.
|
added below the last line.
|
||||||
{text} can be any type or a List of any type, each item is
|
{text} can be any type or a List of any type, each item is
|
||||||
converted to a String.
|
converted to a String. When {text} is an empty List then
|
||||||
|
nothing is changed and FALSE is returned.
|
||||||
|
|
||||||
If this succeeds, FALSE is returned. If this fails (most likely
|
If this succeeds, FALSE is returned. If this fails (most likely
|
||||||
because {lnum} is invalid) TRUE is returned.
|
because {lnum} is invalid) TRUE is returned.
|
||||||
|
@ -175,9 +175,7 @@ set_buffer_lines(
|
|||||||
l = lines->vval.v_list;
|
l = lines->vval.v_list;
|
||||||
if (l == NULL || list_len(l) == 0)
|
if (l == NULL || list_len(l) == 0)
|
||||||
{
|
{
|
||||||
// set proper return code
|
// not appending anything always succeeds
|
||||||
if (lnum > curbuf->b_ml.ml_line_count)
|
|
||||||
rettv->vval.v_number = 1; // FAIL
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
CHECK_LIST_MATERIALIZE(l);
|
CHECK_LIST_MATERIALIZE(l);
|
||||||
|
@ -23,8 +23,8 @@ func Test_setbufline_getbufline()
|
|||||||
|
|
||||||
call assert_equal(1, setbufline(b, 5, 'x'))
|
call assert_equal(1, setbufline(b, 5, 'x'))
|
||||||
call assert_equal(1, setbufline(b, 5, ['x']))
|
call assert_equal(1, setbufline(b, 5, ['x']))
|
||||||
call assert_equal(1, setbufline(b, 5, []))
|
call assert_equal(0, setbufline(b, 5, []))
|
||||||
call assert_equal(1, setbufline(b, 5, test_null_list()))
|
call assert_equal(0, setbufline(b, 5, test_null_list()))
|
||||||
|
|
||||||
call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
|
call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
|
||||||
call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
|
call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
|
||||||
@ -86,6 +86,11 @@ func Test_setline_startup()
|
|||||||
sleep 50m
|
sleep 50m
|
||||||
call assert_equal(['Hello'], readfile('Xtest'))
|
call assert_equal(['Hello'], readfile('Xtest'))
|
||||||
|
|
||||||
|
call assert_equal(0, setline(1, []))
|
||||||
|
call assert_equal(0, setline(1, test_null_list()))
|
||||||
|
call assert_equal(0, setline(5, []))
|
||||||
|
call assert_equal(0, setline(6, test_null_list()))
|
||||||
|
|
||||||
call delete('Xtest')
|
call delete('Xtest')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -112,8 +117,8 @@ func Test_appendbufline()
|
|||||||
|
|
||||||
call assert_equal(1, appendbufline(b, 4, 'x'))
|
call assert_equal(1, appendbufline(b, 4, 'x'))
|
||||||
call assert_equal(1, appendbufline(b, 4, ['x']))
|
call assert_equal(1, appendbufline(b, 4, ['x']))
|
||||||
call assert_equal(1, appendbufline(b, 4, []))
|
call assert_equal(0, appendbufline(b, 4, []))
|
||||||
call assert_equal(1, appendbufline(b, 4, test_null_list()))
|
call assert_equal(0, appendbufline(b, 4, test_null_list()))
|
||||||
|
|
||||||
call assert_equal(1, appendbufline(1234, 1, 'x'))
|
call assert_equal(1, appendbufline(1234, 1, 'x'))
|
||||||
call assert_equal(1, appendbufline(1234, 1, ['x']))
|
call assert_equal(1, appendbufline(1234, 1, ['x']))
|
||||||
@ -122,8 +127,8 @@ func Test_appendbufline()
|
|||||||
|
|
||||||
call assert_equal(0, appendbufline(b, 1, []))
|
call assert_equal(0, appendbufline(b, 1, []))
|
||||||
call assert_equal(0, appendbufline(b, 1, test_null_list()))
|
call assert_equal(0, appendbufline(b, 1, test_null_list()))
|
||||||
call assert_equal(1, appendbufline(b, 3, []))
|
call assert_equal(0, appendbufline(b, 3, []))
|
||||||
call assert_equal(1, appendbufline(b, 3, test_null_list()))
|
call assert_equal(0, appendbufline(b, 3, test_null_list()))
|
||||||
|
|
||||||
call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
|
call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
|
||||||
|
|
||||||
|
@ -939,9 +939,13 @@ endfunc
|
|||||||
func Test_append()
|
func Test_append()
|
||||||
enew!
|
enew!
|
||||||
split
|
split
|
||||||
call append(0, ["foo"])
|
call assert_equal(0, append(1, []))
|
||||||
call append(1, [])
|
call assert_equal(0, append(1, test_null_list()))
|
||||||
call append(1, test_null_list())
|
call assert_equal(0, append(0, ["foo"]))
|
||||||
|
call assert_equal(0, append(1, []))
|
||||||
|
call assert_equal(0, append(1, test_null_list()))
|
||||||
|
call assert_equal(0, append(8, []))
|
||||||
|
call assert_equal(0, append(9, test_null_list()))
|
||||||
call assert_equal(['foo', ''], getline(1, '$'))
|
call assert_equal(['foo', ''], getline(1, '$'))
|
||||||
split
|
split
|
||||||
only
|
only
|
||||||
|
@ -3721,8 +3721,8 @@ def Test_set_get_bufline()
|
|||||||
|
|
||||||
assert_equal(1, setbufline(b, 5, 'x'))
|
assert_equal(1, setbufline(b, 5, 'x'))
|
||||||
assert_equal(1, setbufline(b, 5, ['x']))
|
assert_equal(1, setbufline(b, 5, ['x']))
|
||||||
assert_equal(1, setbufline(b, 5, []))
|
assert_equal(0, setbufline(b, 5, []))
|
||||||
assert_equal(1, setbufline(b, 5, test_null_list()))
|
assert_equal(0, setbufline(b, 5, test_null_list()))
|
||||||
|
|
||||||
assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
|
assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
|
||||||
assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
|
assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
|
||||||
|
@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
837,
|
||||||
/**/
|
/**/
|
||||||
836,
|
836,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user