Merge pull request #40359 from janlazo/vim-8.2.1888

vim-patch:8.2.{1888,2117}
This commit is contained in:
zeertzjq
2026-06-22 09:35:30 +08:00
committed by GitHub
3 changed files with 14 additions and 8 deletions

View File

@@ -714,15 +714,19 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, bool retl
/// false: "getbufoneline()" function
static void getbufline(typval_T *argvars, typval_T *rettv, bool retlist)
{
linenr_T lnum = 1;
linenr_T end = 1;
const int did_emsg_before = did_emsg;
buf_T *const buf = tv_get_buf_from_arg(&argvars[0]);
const linenr_T lnum = tv_get_lnum_buf(&argvars[1], buf);
if (did_emsg > did_emsg_before) {
return;
if (buf != NULL) {
lnum = tv_get_lnum_buf(&argvars[1], buf);
if (did_emsg > did_emsg_before) {
return;
}
end = (argvars[2].v_type == VAR_UNKNOWN
? lnum
: tv_get_lnum_buf(&argvars[2], buf));
}
const linenr_T end = (argvars[2].v_type == VAR_UNKNOWN
? lnum
: tv_get_lnum_buf(&argvars[2], buf));
get_buffer_lines(buf, lnum, end, retlist, rettv);
}

View File

@@ -784,8 +784,6 @@ void f_getfsize(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
const char *fname = tv_get_string(&argvars[0]);
rettv->v_type = VAR_NUMBER;
FileInfo file_info;
if (os_fileinfo(fname, &file_info)) {
uint64_t filesize = os_fileinfo_size(&file_info);

View File

@@ -191,11 +191,15 @@ describe('getbufline() function', function()
end)
it('returns empty list when range is invalid', function()
eq({}, fn.getbufline(1, 0))
eq({}, fn.getbufline(-1, 1, '$'))
eq({}, fn.getbufline(-1, '$', '$'))
api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' })
eq({}, fn.getbufline(1, 2, 1))
eq({}, fn.getbufline(1, -10, -20))
eq({}, fn.getbufline(1, -2, -1))
eq({}, fn.getbufline(1, -1, 9999))
eq({}, fn.getbufline(-1, 1, '$'))
eq({}, fn.getbufline(-1, '$', '$'))
end)
it('returns expected lines', function()
api.nvim_set_option_value('hidden', true, {})