diff options
-rw-r--r-- | src/nvim/ex_cmds.c | 7 | ||||
-rw-r--r-- | src/nvim/fileio.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 49 | ||||
-rw-r--r-- | src/nvim/testdir/test_edit.vim | 19 | ||||
-rw-r--r-- | src/nvim/testdir/test_substitute.vim | 11 | ||||
-rw-r--r-- | src/nvim/testdir/test_writefile.vim | 25 |
6 files changed, 83 insertions, 34 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 560f4e5df2..8436ac810e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3819,7 +3819,6 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, if (!preview || has_second_delim) { if (subflags.do_count) { // prevent accidentally changing the buffer by a function - save_ma = curbuf->b_p_ma; curbuf->b_p_ma = false; sandbox++; } @@ -3832,13 +3831,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, sub, sub_firstline, false, p_magic, true); // If getting the substitute string caused an error, don't do // the replacement. - if (aborting()) { - goto skip; - } - // Don't keep flags set by a recursive call subflags = subflags_save; - if (subflags.do_count) { + if (aborting() || subflags.do_count) { curbuf->b_p_ma = save_ma; if (sandbox > 0) { sandbox--; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 507bf3c032..8e4a210b66 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3693,9 +3693,11 @@ restore_backup: /* * Remove the backup unless 'backup' option is set */ - if (!p_bk && backup != NULL && os_remove((char *)backup) != 0) + if (!p_bk && backup != NULL + && !write_info.bw_conv_error + && os_remove((char *)backup) != 0) { EMSG(_("E207: Can't delete backup file")); - + } goto nofail; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 1c1da0572b..8182c6973b 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -72,7 +72,31 @@ if has('timers') au! CursorHoldI set updatetime& endfunc -endif + + func Test_OptionSet_modeline() + throw 'skipped: Nvim does not support test_override()' + call test_override('starting', 1) + au! OptionSet + augroup set_tabstop + au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")}) + augroup END + call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline') + set modeline + let v:errmsg = '' + call assert_fails('split XoptionsetModeline', 'E12:') + call assert_equal(7, &ts) + call assert_equal('', v:errmsg) + + augroup set_tabstop + au! + augroup END + bwipe! + set ts& + call delete('XoptionsetModeline') + call test_override('starting', 0) + endfunc + +endif "has('timers') func Test_bufunload() augroup test_bufunload_group @@ -677,29 +701,6 @@ func Test_OptionSet_diffmode_close() "delfunc! AutoCommandOptionSet endfunc -func Test_OptionSet_modeline() - throw 'skipped: Nvim does not support test_override()' - call test_override('starting', 1) - au! OptionSet - augroup set_tabstop - au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")}) - augroup END - call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline') - set modeline - let v:errmsg = '' - call assert_fails('split XoptionsetModeline', 'E12:') - call assert_equal(7, &ts) - call assert_equal('', v:errmsg) - - augroup set_tabstop - au! - augroup END - bwipe! - set ts& - call delete('XoptionsetModeline') - call test_override('starting', 0) -endfunc - " Test for Bufleave autocommand that deletes the buffer we are about to edit. func Test_BufleaveWithDelete() new | edit Xfile1 diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index de0f3ddb06..7f3994300f 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -1385,9 +1385,26 @@ func Test_edit_complete_very_long_name() return endtry - " Try to get the Vim window position before setting 'columns'. + " Try to get the Vim window position before setting 'columns', so that we can + " move the window back to where it was. let winposx = getwinposx() let winposy = getwinposy() + + if winposx >= 0 && winposy >= 0 && !has('gui_running') + " We did get the window position, but xterm may report the wrong numbers. + " Move the window to the reported position and compute any offset. + exe 'winpos ' . winposx . ' ' . winposy + sleep 100m + let x = getwinposx() + if x >= 0 + let winposx += winposx - x + endif + let y = getwinposy() + if y >= 0 + let winposy += winposy - y + endif + endif + let save_columns = &columns " Need at least about 1100 columns to reproduce the problem. set columns=2000 diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index e074a85530..8b306192f0 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -639,6 +639,17 @@ func Test_nocatch_sub_failure_handling() call assert_equal(1, error_caught) call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3)) + " Same, but using "n" flag so that "sandbox" gets set + call setline(1, ['1 aaa', '2 aaa', '3 aaa']) + let error_caught = 0 + try + %s/aaa/\=Foo()/gn + catch + let error_caught = 1 + endtry + call assert_equal(1, error_caught) + call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3)) + bwipe! endfunc diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 1cd5fb306a..b4585a72ef 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -36,13 +36,15 @@ func Test_writefile_fails_conversion() if !has('multi_byte') || !has('iconv') return endif + " Without a backup file the write won't happen if there is a conversion + " error. set nobackup nowritebackup new let contents = ["line one", "line two"] call writefile(contents, 'Xfile') edit Xfile call setline(1, ["first line", "cannot convert \u010b", "third line"]) - call assert_fails('write ++enc=cp932') + call assert_fails('write ++enc=cp932', 'E513:') call assert_equal(contents, readfile('Xfile')) call delete('Xfile') @@ -50,6 +52,27 @@ func Test_writefile_fails_conversion() set backup& writebackup& endfunc +func Test_writefile_fails_conversion2() + if !has('iconv') || has('sun') + return + endif + " With a backup file the write happens even if there is a conversion error, + " but then the backup file must remain + set nobackup writebackup + let contents = ["line one", "line two"] + call writefile(contents, 'Xfile_conversion_err') + edit Xfile_conversion_err + call setline(1, ["first line", "cannot convert \u010b", "third line"]) + set fileencoding=latin1 + let output = execute('write') + call assert_match('CONVERSION ERROR', output) + call assert_equal(contents, readfile('Xfile_conversion_err~')) + + call delete('Xfile_conversion_err') + call delete('Xfile_conversion_err~') + bwipe! +endfunc + func SetFlag(timer) let g:flag = 1 endfunc |