mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Problem: Cannot use :write when using a plugin with BufWriteCmd.
Solution: Reset BF_NOTEDITED after BufWriteCmd. (closes vim/vim#5807)
0fff44152d
This commit is contained in:
parent
b8ddca6554
commit
87334c00e0
@ -407,11 +407,27 @@ readfile(
|
|||||||
|
|
||||||
if (newfile) {
|
if (newfile) {
|
||||||
if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
|
if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
|
||||||
FALSE, curbuf, eap))
|
false, curbuf, eap)) {
|
||||||
return aborting() ? FAIL : OK;
|
int status = OK;
|
||||||
|
|
||||||
|
if (aborting()) {
|
||||||
|
status = FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The BufReadCmd code usually uses ":read" to get the text and
|
||||||
|
// perhaps ":file" to change the buffer name. But we should
|
||||||
|
// consider this to work like ":edit", thus reset the
|
||||||
|
// BF_NOTEDITED flag. Then ":write" will work to overwrite the
|
||||||
|
// same file.
|
||||||
|
if (status == OK) {
|
||||||
|
curbuf->b_flags &= ~BF_NOTEDITED;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
} else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
|
} else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
|
||||||
FALSE, NULL, eap))
|
false, NULL, eap)) {
|
||||||
return aborting() ? FAIL : OK;
|
return aborting() ? FAIL : OK;
|
||||||
|
}
|
||||||
|
|
||||||
curbuf->b_op_start = pos;
|
curbuf->b_op_start = pos;
|
||||||
}
|
}
|
||||||
|
@ -1072,6 +1072,40 @@ func Test_Cmd_Autocmds()
|
|||||||
enew!
|
enew!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func s:ReadFile()
|
||||||
|
setl noswapfile nomodified
|
||||||
|
let filename = resolve(expand("<afile>:p"))
|
||||||
|
execute 'read' fnameescape(filename)
|
||||||
|
1d_
|
||||||
|
exe 'file' fnameescape(filename)
|
||||||
|
setl buftype=acwrite
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func s:WriteFile()
|
||||||
|
let filename = resolve(expand("<afile>:p"))
|
||||||
|
setl buftype=
|
||||||
|
noautocmd execute 'write' fnameescape(filename)
|
||||||
|
setl buftype=acwrite
|
||||||
|
setl nomodified
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_BufReadCmd()
|
||||||
|
autocmd BufReadCmd *.test call s:ReadFile()
|
||||||
|
autocmd BufWriteCmd *.test call s:WriteFile()
|
||||||
|
|
||||||
|
call writefile(['one', 'two', 'three'], 'Xcmd.test')
|
||||||
|
edit Xcmd.test
|
||||||
|
call assert_match('Xcmd.test" line 1 of 3', execute('file'))
|
||||||
|
normal! Gofour
|
||||||
|
write
|
||||||
|
call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test'))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
call delete('Xcmd.test')
|
||||||
|
au! BufReadCmd
|
||||||
|
au! BufWriteCmd
|
||||||
|
endfunc
|
||||||
|
|
||||||
func SetChangeMarks(start, end)
|
func SetChangeMarks(start, end)
|
||||||
exe a:start. 'mark ['
|
exe a:start. 'mark ['
|
||||||
exe a:end. 'mark ]'
|
exe a:end. 'mark ]'
|
||||||
|
Loading…
Reference in New Issue
Block a user