Merge #10435 from Shougo/vim-8.1.1610

This commit is contained in:
Justin M. Keyes
2019-07-13 12:36:32 +02:00
committed by GitHub
4 changed files with 86 additions and 0 deletions

View File

@@ -7294,6 +7294,14 @@ static buf_T *find_buffer(typval_T *avar)
return buf;
}
// "bufadd(expr)" function
static void f_bufadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *name = (char_u *)tv_get_string(&argvars[0]);
rettv->vval.v_number = buflist_add(*name == NUL ? NULL : name, 0);
}
/*
* "bufexists(expr)" function
*/
@@ -7313,6 +7321,21 @@ static void f_buflisted(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = (buf != NULL && buf->b_p_bl);
}
// "bufload(expr)" function
static void f_bufload(typval_T *argvars, typval_T *unused, FunPtr fptr)
{
buf_T *buf = get_buf_arg(&argvars[0]);
if (buf != NULL && buf->b_ml.ml_mfp == NULL) {
aco_save_T aco;
aucmd_prepbuf(&aco, buf);
swap_exists_action = SEA_NONE;
open_buffer(false, NULL, 0);
aucmd_restbuf(&aco);
}
}
/*
* "bufloaded(expr)" function
*/

View File

@@ -40,11 +40,13 @@ return {
atan2={args=2},
browse={args=4},
browsedir={args=2},
bufadd={args=1},
bufexists={args=1},
buffer_exists={args=1, func='f_bufexists'}, -- obsolete
buffer_name={args=1, func='f_bufname'}, -- obsolete
buffer_number={args=1, func='f_bufnr'}, -- obsolete
buflisted={args=1},
bufload={args=1},
bufloaded={args=1},
bufname={args=1},
bufnr={args={1, 2}},

View File

@@ -1188,3 +1188,45 @@ func Test_libcall_libcallnr()
call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:')
call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:')
endfunc
func Test_bufadd_bufload()
call assert_equal(0, bufexists('someName'))
let buf = bufadd('someName')
call assert_notequal(0, buf)
call assert_equal(1, bufexists('someName'))
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
call bufload(buf)
call assert_equal(1, bufloaded(buf))
call assert_equal([''], getbufline(buf, 1, '$'))
let curbuf = bufnr('')
call writefile(['some', 'text'], 'otherName')
let buf = bufadd('otherName')
call assert_notequal(0, buf)
call assert_equal(1, bufexists('otherName'))
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
call bufload(buf)
call assert_equal(1, bufloaded(buf))
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
call assert_equal(curbuf, bufnr(''))
let buf1 = bufadd('')
let buf2 = bufadd('')
call assert_notequal(0, buf1)
call assert_notequal(0, buf2)
call assert_notequal(buf1, buf2)
call assert_equal(1, bufexists(buf1))
call assert_equal(1, bufexists(buf2))
call assert_equal(0, bufloaded(buf1))
exe 'bwipe ' .. buf1
call assert_equal(0, bufexists(buf1))
call assert_equal(1, bufexists(buf2))
exe 'bwipe ' .. buf2
call assert_equal(0, bufexists(buf2))
bwipe someName
bwipe otherName
call assert_equal(0, bufexists('someName'))
endfunc