Patch 9.0.0837
Problem: append() reports failure when not appending anything.
Solution: Only report failure when appending something. (closes #11498)
Files: runtime/doc/builtin.txt, src/evalbuffer.c,
src/testdir/test_functions.vim, src/testdir/test_bufline.vim,
src/testdir/test_vim9_builtin.vim
*** ../vim-9.0.0836/runtime/doc/builtin.txt 2022-10-21 14:17:19.575639460
+0100
--- runtime/doc/builtin.txt 2022-11-05 23:35:20.344014573 +0000
***************
*** 806,813 ****
{lnum} can be zero to insert a line before the first one.
{lnum} is used like with |getline()|.
Returns 1 for failure ({lnum} out of range or out of memory),
! 0 for success. In |Vim9| script an invalid argument or
! negative number results in an error. Example: >
:let failed = append(line('$'), "# THE END")
:let failed = append(0, ["Chapter 1", "the beginning"])
--- 806,815 ----
{lnum} can be zero to insert a line before the first one.
{lnum} is used like with |getline()|.
Returns 1 for failure ({lnum} out of range or out of memory),
! 0 for success. When {text} is an empty list zero is returned,
! 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(0, ["Chapter 1", "the beginning"])
***************
*** 835,841 ****
If {buf} is not a valid buffer or {lnum} is not valid, an
error message is given. Example: >
:let failed = appendbufline(13, 0, "# THE START")
! <
Can also be used as a |method| after a List, the base is
passed as the second argument: >
mylist->appendbufline(buf, lnum)
--- 837,845 ----
If {buf} is not a valid buffer or {lnum} is not valid, an
error message is given. Example: >
: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
passed as the second argument: >
mylist->appendbufline(buf, lnum)
***************
*** 981,987 ****
let acmd.bufnr = 5
let acmd.cmd = 'call BufEnterFunc()'
call autocmd_add([acmd])
!
Can also be used as a |method|: >
GetAutocmdList()->autocmd_add()
<
--- 985,991 ----
let acmd.bufnr = 5
let acmd.cmd = 'call BufEnterFunc()'
call autocmd_add([acmd])
! <
Can also be used as a |method|: >
GetAutocmdList()->autocmd_add()
<
***************
*** 7874,7882 ****
To insert lines use |appendbufline()|.
Any text properties in {lnum} are cleared.
! {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
! line then those lines are added.
For the use of {buf}, see |bufname()| above.
--- 7878,7887 ----
To insert lines use |appendbufline()|.
Any text properties in {lnum} are cleared.
! {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
! 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.
***************
*** 8061,8067 ****
When {lnum} is just below the last line the {text} will be
added below the last line.
{text} can be any type or a List of any type, each item is
! converted to a String.
If this succeeds, FALSE is returned. If this fails (most likely
because {lnum} is invalid) TRUE is returned.
--- 8066,8073 ----
When {lnum} is just below the last line the {text} will be
added below the last line.
{text} can be any type or a List of any type, each item is
! 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
because {lnum} is invalid) TRUE is returned.
*** ../vim-9.0.0836/src/evalbuffer.c 2022-10-20 21:14:14.664098677 +0100
--- src/evalbuffer.c 2022-11-05 23:00:05.823632313 +0000
***************
*** 175,183 ****
l = lines->vval.v_list;
if (l == NULL || list_len(l) == 0)
{
! // set proper return code
! if (lnum > curbuf->b_ml.ml_line_count)
! rettv->vval.v_number = 1; // FAIL
goto done;
}
CHECK_LIST_MATERIALIZE(l);
--- 175,181 ----
l = lines->vval.v_list;
if (l == NULL || list_len(l) == 0)
{
! // not appending anything always succeeds
goto done;
}
CHECK_LIST_MATERIALIZE(l);
*** ../vim-9.0.0836/src/testdir/test_functions.vim 2022-11-05
20:21:50.601151478 +0000
--- src/testdir/test_functions.vim 2022-11-05 23:05:45.547797839 +0000
***************
*** 939,947 ****
func Test_append()
enew!
split
! call append(0, ["foo"])
! call append(1, [])
! call append(1, test_null_list())
call assert_equal(['foo', ''], getline(1, '$'))
split
only
--- 939,951 ----
func Test_append()
enew!
split
! call assert_equal(0, append(1, []))
! call assert_equal(0, 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, '$'))
split
only
*** ../vim-9.0.0836/src/testdir/test_bufline.vim 2022-09-08
12:27:58.281556519 +0100
--- src/testdir/test_bufline.vim 2022-11-05 23:31:57.339990219 +0000
***************
*** 23,30 ****
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(1, setbufline(b, 5, test_null_list()))
call assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
--- 23,30 ----
call assert_equal(1, setbufline(b, 5, 'x'))
call assert_equal(1, setbufline(b, 5, ['x']))
! call assert_equal(0, setbufline(b, 5, []))
! 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))
***************
*** 86,91 ****
--- 86,96 ----
sleep 50m
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')
endfunc
***************
*** 112,119 ****
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(1, appendbufline(b, 4, test_null_list()))
call assert_equal(1, appendbufline(1234, 1, 'x'))
call assert_equal(1, appendbufline(1234, 1, ['x']))
--- 117,124 ----
call assert_equal(1, appendbufline(b, 4, 'x'))
call assert_equal(1, appendbufline(b, 4, ['x']))
! call assert_equal(0, appendbufline(b, 4, []))
! 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']))
***************
*** 122,129 ****
call assert_equal(0, appendbufline(b, 1, []))
call assert_equal(0, appendbufline(b, 1, test_null_list()))
! call assert_equal(1, appendbufline(b, 3, []))
! call assert_equal(1, appendbufline(b, 3, test_null_list()))
call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
--- 127,134 ----
call assert_equal(0, appendbufline(b, 1, []))
call assert_equal(0, appendbufline(b, 1, test_null_list()))
! call assert_equal(0, appendbufline(b, 3, []))
! call assert_equal(0, appendbufline(b, 3, test_null_list()))
call assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
*** ../vim-9.0.0836/src/testdir/test_vim9_builtin.vim 2022-10-15
20:06:30.284328833 +0100
--- src/testdir/test_vim9_builtin.vim 2022-11-05 23:29:57.475982017 +0000
***************
*** 3721,3728 ****
assert_equal(1, setbufline(b, 5, 'x'))
assert_equal(1, setbufline(b, 5, ['x']))
! assert_equal(1, setbufline(b, 5, []))
! assert_equal(1, setbufline(b, 5, test_null_list()))
assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
--- 3721,3728 ----
assert_equal(1, setbufline(b, 5, 'x'))
assert_equal(1, setbufline(b, 5, ['x']))
! assert_equal(0, setbufline(b, 5, []))
! 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))
*** ../vim-9.0.0836/src/version.c 2022-11-05 20:21:50.601151478 +0000
--- src/version.c 2022-11-05 23:01:45.143683760 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 837,
/**/
--
I have a drinking problem -- I can't afford it.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20221105234755.D08F21C0739%40moolenaar.net.