Merge #10840 from janlazo/vim-8.1.1757

vim-patch:8.1.{1757,1924}
This commit is contained in:
Justin M. Keyes
2019-08-25 09:13:49 +02:00
committed by GitHub
5 changed files with 61 additions and 22 deletions

View File

@@ -7353,14 +7353,19 @@ static buf_T * get_buf_arg(typval_T *arg)
*/
static void f_bufname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const buf_T *buf;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (!tv_check_str_or_nr(&argvars[0])) {
return;
if (argvars[0].v_type == VAR_UNKNOWN) {
buf = curbuf;
} else {
if (!tv_check_str_or_nr(&argvars[0])) {
return;
}
emsg_off++;
buf = tv_get_buf(&argvars[0], false);
emsg_off--;
}
emsg_off++;
const buf_T *const buf = tv_get_buf(&argvars[0], false);
emsg_off--;
if (buf != NULL && buf->b_fname != NULL) {
rettv->vval.v_string = (char_u *)xstrdup((char *)buf->b_fname);
}
@@ -7371,15 +7376,21 @@ static void f_bufname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/
static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
const buf_T *buf;
bool error = false;
rettv->vval.v_number = -1;
if (!tv_check_str_or_nr(&argvars[0])) {
return;
if (argvars[0].v_type == VAR_UNKNOWN) {
buf = curbuf;
} else {
if (!tv_check_str_or_nr(&argvars[0])) {
return;
}
emsg_off++;
buf = tv_get_buf(&argvars[0], false);
emsg_off--;
}
emsg_off++;
const buf_T *buf = tv_get_buf(&argvars[0], false);
emsg_off--;
// If the buffer isn't found and the second argument is not zero create a
// new buffer.
@@ -15194,6 +15205,7 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
}
}
check_cursor_col();
update_topline();
}
if (!is_curbuf) {

View File

@@ -44,13 +44,13 @@ return {
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
buffer_name={args={0, 1}, func='f_bufname'}, -- obsolete
buffer_number={args={0, 1}, func='f_bufnr'}, -- obsolete
buflisted={args=1},
bufload={args=1},
bufloaded={args=1},
bufname={args=1},
bufnr={args={1, 2}},
bufname={args={0, 1}},
bufnr={args={0, 2}},
bufwinid={args=1},
bufwinnr={args=1},
byte2line={args=1},

View File

@@ -379,10 +379,10 @@ func Test_argedit()
" make sure to use a new buffer number for x when it is loaded
bw! x
new
let a = bufnr('')
let a = bufnr()
argedit x
call assert_equal(a, bufnr(''))
call assert_equal('x', bufname(''))
call assert_equal(a, bufnr())
call assert_equal('x', bufname())
%argd
bw! x
endfunc

View File

@@ -1,6 +1,7 @@
" Tests for setbufline(), getbufline(), appendbufline(), deletebufline()
source shared.vim
" source screendump.vim
func Test_setbufline_getbufline()
new
@@ -112,3 +113,28 @@ func Test_deletebufline()
call assert_equal(['b', 'c'], getbufline(b, 1, 2))
exe "bwipe! " . b
endfunc
func Test_appendbufline_redraw()
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'
endif
let lines =<< trim END
new foo
let winnr=bufwinnr('foo')
let buf=bufnr('foo')
wincmd p
call appendbufline(buf, '$', range(1,200))
exe winnr. 'wincmd w'
norm! G
wincmd p
call deletebufline(buf, 1, '$')
call appendbufline(buf, '$', 'Hello Vim world...')
END
call writefile(lines, 'XscriptMatchCommon')
let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10})
call term_wait(buf)
call VerifyScreenDump(buf, 'Test_appendbufline_1', {})
call StopVimInTerminal(buf)
call delete('XscriptMatchCommon')
endfunc