Merge #8948 from janlazo/vim-8.1.0331

This commit is contained in:
Justin M. Keyes
2018-09-05 09:24:36 +02:00
committed by GitHub
2 changed files with 103 additions and 8 deletions

View File

@@ -9239,6 +9239,18 @@ static int ses_do_win(win_T *wp)
return true;
}
static int put_view_curpos(FILE *fd, const win_T *wp, char *spaces)
{
int r;
if (wp->w_curswant == MAXCOL) {
r = fprintf(fd, "%snormal! $", spaces);
} else {
r = fprintf(fd, "%snormal! 0%d|", spaces, wp->w_virtcol + 1);
}
return r < 0 || put_eol(fd) == FAIL ? FAIL : OK;
}
/*
* Write commands to "fd" to restore the view of a window.
* Caller must make sure 'scrolloff' is zero.
@@ -9405,14 +9417,11 @@ put_view(
(int64_t)(wp->w_virtcol + 1)) < 0
|| put_eol(fd) == FAIL
|| put_line(fd, "else") == FAIL
|| fprintf(fd, " normal! 0%d|", wp->w_virtcol + 1) < 0
|| put_eol(fd) == FAIL
|| put_view_curpos(fd, wp, " ") == FAIL
|| put_line(fd, "endif") == FAIL)
return FAIL;
} else {
if (fprintf(fd, "normal! 0%d|", wp->w_virtcol + 1) < 0
|| put_eol(fd) == FAIL)
return FAIL;
} else if (put_view_curpos(fd, wp, "") == FAIL) {
return FAIL;
}
}
}

View File

@@ -19,7 +19,8 @@ func Test_mksession()
\ 'two tabs in one line',
\ 'one <20> multibyteCharacter',
\ 'a<> <20> two multiByte characters',
\ 'A<><41><EFBFBD> three mulTibyte characters'
\ 'A<><41><EFBFBD> three mulTibyte characters',
\ 'short line',
\ ])
let tmpfile = 'Xtemp'
exec 'w! ' . tmpfile
@@ -41,6 +42,8 @@ func Test_mksession()
norm! j16|
split
norm! j16|
split
norm! j$
wincmd l
set nowrap
@@ -63,7 +66,7 @@ func Test_mksession()
split
call wincol()
mksession! Xtest_mks.out
let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! 0\\|^ *exe ''normal!\\)"')
let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"')
let expected = [
\ 'normal! 016|',
\ 'normal! 016|',
@@ -73,6 +76,7 @@ func Test_mksession()
\ 'normal! 016|',
\ 'normal! 016|',
\ 'normal! 016|',
\ 'normal! $',
\ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
\ " normal! 016|",
\ " exe 'normal! ' . s:c . '|zs' . 16 . '|'",
@@ -151,5 +155,87 @@ func Test_mksession_one_buffer_two_windows()
call delete('Xtest_mks.out')
endfunc
" Test :mkview with a file argument.
func Test_mkview_file()
" Create a view with line number and a fold.
help :mkview
set number
norm! V}zf0
let pos = getpos('.')
let linefoldclosed1 = foldclosed('.')
mkview! Xview
set nonumber
norm! zrj
" We can close the help window, as mkview with a file name should
" generate a command to edit the file.
helpclose
source Xview
call assert_equal(1, &number)
call assert_match('\*:mkview\*$', getline('.'))
call assert_equal(pos, getpos('.'))
call assert_equal(linefoldclosed1, foldclosed('.'))
" Creating a view again with the same file name should fail (file
" already exists). But with a !, the previous view should be
" overwritten without error.
help :loadview
call assert_fails('mkview Xview', 'E189:')
call assert_match('\*:loadview\*$', getline('.'))
mkview! Xview
call assert_match('\*:loadview\*$', getline('.'))
call delete('Xview')
bwipe
endfunc
" Test :mkview and :loadview with a custom 'viewdir'.
func Test_mkview_loadview_with_viewdir()
set viewdir=Xviewdir
help :mkview
set number
norm! V}zf
let pos = getpos('.')
let linefoldclosed1 = foldclosed('.')
mkview 1
set nonumber
norm! zrj
loadview 1
" The directory Xviewdir/ should have been created and the view
" should be stored in that directory.
let pathsep = has('win32') ? '\' : '/'
call assert_equal('Xviewdir' . pathsep .
\ substitute(
\ substitute(
\ expand('%:p'), pathsep, '=+', 'g'), ':', '=-', 'g') . '=1.vim',
\ glob('Xviewdir/*'))
call assert_equal(1, &number)
call assert_match('\*:mkview\*$', getline('.'))
call assert_equal(pos, getpos('.'))
call assert_equal(linefoldclosed1, foldclosed('.'))
call delete('Xviewdir', 'rf')
set viewdir&
helpclose
endfunc
func Test_mkview_no_file_name()
new
" :mkview or :mkview {nr} should fail in a unnamed buffer.
call assert_fails('mkview', 'E32:')
call assert_fails('mkview 1', 'E32:')
" :mkview {file} should succeed in a unnamed buffer.
mkview Xview
help
source Xview
call assert_equal('', bufname('%'))
call delete('Xview')
%bwipe
endfunc
" vim: shiftwidth=2 sts=2 expandtab