vim-patch:8.1.0039: cannot easily delete lines in another buffer

Problem:    Cannot easily delete lines in another buffer.
Solution:   Add deletebufline().
d79a26219d
This commit is contained in:
Jan Edmund Lazo 2019-08-22 23:27:04 -04:00
parent 9358979d09
commit 7e6a2f2bed
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
2 changed files with 31 additions and 22 deletions

View File

@ -1224,9 +1224,7 @@ static void restore_vimvar(int idx, typval_T *save_tv)
/// If there is a window for "curbuf", make it the current window.
static void find_win_for_curbuf(void)
{
wininfo_T *wip;
for (wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next) {
for (wininfo_T *wip = curbuf->b_wininfo; wip != NULL; wip = wip->wi_next) {
if (wip->wi_win != NULL) {
curwin = wip->wi_win;
break;
@ -8260,22 +8258,18 @@ static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "deletebufline()" function
static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
linenr_T first, last;
linenr_T lnum;
long count;
int is_curbuf;
linenr_T last;
buf_T *curbuf_save = NULL;
win_T *curwin_save = NULL;
buf = tv_get_buf(&argvars[0], false);
buf_T *const buf = tv_get_buf(&argvars[0], false);
if (buf == NULL) {
rettv->vval.v_number = 1; // FAIL
return;
}
is_curbuf = buf == curbuf;
const bool is_curbuf = buf == curbuf;
first = tv_get_lnum_buf(&argvars[1], buf);
const linenr_T first = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type != VAR_UNKNOWN) {
last = tv_get_lnum_buf(&argvars[2], buf);
} else {
@ -8297,7 +8291,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (last > curbuf->b_ml.ml_line_count) {
last = curbuf->b_ml.ml_line_count;
}
count = last - first + 1;
const long count = last - first + 1;
// When coming here from Insert mode, sync undo, so that this can be
// undone separately from what was previously inserted.
@ -8311,7 +8305,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
for (lnum = first; lnum <= last; lnum++) {
for (linenr_T lnum = first; lnum <= last; lnum++) {
ml_delete(first, true);
}
@ -15116,17 +15110,10 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
}
if (!is_curbuf) {
wininfo_T *wip;
curbuf_save = curbuf;
curwin_save = curwin;
curbuf = buf;
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
if (wip->wi_win != NULL) {
curwin = wip->wi_win;
break;
}
}
find_win_for_curbuf();
}
if (append) {

View File

@ -1,4 +1,4 @@
" Tests for setbufline(), getbufline(), appendbufline()
" Tests for setbufline(), getbufline(), appendbufline(), deletebufline()
source shared.vim
@ -90,3 +90,25 @@ func Test_appendbufline()
call assert_equal([], getbufline(b, 6))
exe "bwipe! " . b
endfunc
func Test_deletebufline()
new
let b = bufnr('%')
call setline(1, ['aaa', 'bbb', 'ccc'])
hide
call assert_equal(0, deletebufline(b, 2))
call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2))
call assert_equal(0, deletebufline(b, 2, 8))
call assert_equal(['aaa'], getbufline(b, 1, 2))
exe "bd!" b
call assert_equal(1, deletebufline(b, 1))
split Xtest
call setline(1, ['a', 'b', 'c'])
let b = bufnr('%')
wincmd w
call assert_equal(1, deletebufline(b, 4))
call assert_equal(0, deletebufline(b, 1))
call assert_equal(['b', 'c'], getbufline(b, 1, 2))
exe "bwipe! " . b
endfunc