diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-01 06:12:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-01 06:12:11 +0800 |
commit | b08667d4f00e434eac9874e4005ab8e1fd9d3e95 (patch) | |
tree | bf4b40e983294fbf96bdd6b9699cdb6526dd0fe6 /test | |
parent | e005b8d2eb0d5967d46cae604e3fac0ccae37555 (diff) | |
download | rneovim-b08667d4f00e434eac9874e4005ab8e1fd9d3e95.tar.gz rneovim-b08667d4f00e434eac9874e4005ab8e1fd9d3e95.tar.bz2 rneovim-b08667d4f00e434eac9874e4005ab8e1fd9d3e95.zip |
vim-patch:9.1.0231: Filetype may be undetected when SwapExists sets ft in other buf (#28136)
Problem: Filetype may be undetected when a SwapExists autocommand sets
filetype in another buffer.
Solution: Make filetype detection state buffer-specific. Also fix a
similar problem for 'modified' (zeertzjq).
closes: vim/vim#14344
https://github.com/vim/vim/commit/5bf6c2117fcef85fcf046c098dd3eb72a0147859
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/test_autocmd.vim | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim index 9dbd4ac521..61de6775fb 100644 --- a/test/old/testdir/test_autocmd.vim +++ b/test/old/testdir/test_autocmd.vim @@ -3977,4 +3977,81 @@ func Test_Changed_ChangedI_2() call delete('XTextChangedI3') endfunc +" Test that filetype detection still works when SwapExists autocommand sets +" filetype in another buffer. +func Test_SwapExists_set_other_buf_filetype() + let lines =<< trim END + set nocompatible directory=. + filetype on + + let g:buf = bufnr() + new + + func SwapExists() + let v:swapchoice = 'o' + call setbufvar(g:buf, '&filetype', 'text') + endfunc + + func SafeState() + edit <script> + redir! > XftSwapExists.out + set readonly? filetype? + redir END + qall! + endfunc + + autocmd SwapExists * ++nested call SwapExists() + autocmd SafeState * ++nested ++once call SafeState() + END + call writefile(lines, 'XftSwapExists.vim', 'D') + + new XftSwapExists.vim + if RunVim('', '', ' -S XftSwapExists.vim') + call assert_equal( + \ ['', ' readonly', ' filetype=vim'], + \ readfile('XftSwapExists.out')) + call delete('XftSwapExists.out') + endif + + bwipe! +endfunc + +" Test that file is not marked as modified when SwapExists autocommand sets +" 'modified' in another buffer. +func Test_SwapExists_set_other_buf_modified() + let lines =<< trim END + set nocompatible directory=. + + let g:buf = bufnr() + new + + func SwapExists() + let v:swapchoice = 'o' + call setbufvar(g:buf, '&modified', 1) + endfunc + + func SafeState() + edit <script> + redir! > XmodSwapExists.out + set readonly? modified? + redir END + qall! + endfunc + + autocmd SwapExists * ++nested call SwapExists() + autocmd SafeState * ++nested ++once call SafeState() + END + call writefile(lines, 'XmodSwapExists.vim', 'D') + + new XmodSwapExists.vim + if RunVim('', '', ' -S XmodSwapExists.vim') + call assert_equal( + \ ['', ' readonly', 'nomodified'], + \ readfile('XmodSwapExists.out')) + call delete('XmodSwapExists.out') + endif + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab |